⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagemanager.cpp

📁 mtk simulator v2 new source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:

/******************************************************************************

	FUNCTION NAME		: GetFreq

  	PURPOSE				: Function to find the Frequency value
	
	INPUT PARAMETERS	: UINT32, CString (MessageId,DatasetName)

	OUTPUT PARAMETERS	: Frequency Value

	AUTHOR				: Gurdev Singh

	RETURNS				: UINT32
		 
	REMARKS				: MFC framework calls this function to find the 
						  Frequency associated with the datalist of Message 
						  by giving the MessageId and Dataset Name. 
*******************************************************************************/

UINT32 CMessageManager::GetFreq(UINT32 MsgId,CString sDataSet)
{
	CData cdata;
	GetDataSetDetails(MsgId,sDataSet,cdata);
	return cdata.GetFrequency();
}

/******************************************************************************

	FUNCTION NAME		: GetFreq (Overloaded)

  	PURPOSE				: Function to find the Frequency value
	
	INPUT PARAMETERS	: CString, CString (MessageName,DatasetName)

	OUTPUT PARAMETERS	: Frequency Value

	AUTHOR				: Gurdev Singh

	RETURNS				: UINT32
		 
	REMARKS				: MFC framework calls this function to find the 
						  Frequency associated with the datalist of Message 
						  by giving the MessageId and Dataset Name. 
*******************************************************************************/


UINT32 CMessageManager::GetFreq(CString MsgName,CString sDataSet)
{
	CData cdata;
	UINT32 MsgId;
	MsgId = GetMsgIdFromMsgName(MsgName);
	GetDataSetDetails(MsgId,sDataSet,cdata);
	return cdata.GetFrequency();
}

/******************************************************************************

	FUNCTION NAME		: GetDefaultDataSetForMessage

  	PURPOSE				: Function to find the default data set for a message
	
	INPUT PARAMETERS	: UINT32 MessageID

	OUTPUT PARAMETERS	: CString (Name of the default dataset)

	AUTHOR				: Gurdev Singh

	RETURNS				: CString
		 
	REMARKS				: MFC framework calls this function to find the default 
						  dataset associated with the datalist of Messageby 
						  giving the MessageId.
*******************************************************************************/

CString CMessageManager::GetDefaultDataSetForMessage(UINT32 MsgId)
{
	CString  msgformat;
	CPtrList * ptr_to_list_of_outgoing_msg = m_plstOutGoingMsg;
	CPtrList * ptr_to_format_list;
	COutgoingMessage * ptr_to_outgoing_msg;
	
	if(ptr_to_list_of_outgoing_msg->GetCount())
	{
		for(POSITION pos =  ptr_to_list_of_outgoing_msg->GetHeadPosition();pos!= NULL;)
		{
     		ptr_to_outgoing_msg = (COutgoingMessage *) (ptr_to_list_of_outgoing_msg->GetNext(pos));

			if(ptr_to_outgoing_msg->GetMessageId() == MsgId)
			{
				msgformat = ptr_to_outgoing_msg->GetFormat();
			}
		}
	}

	ptr_to_format_list= m_pFormatList;
	CFormat* FmtPtr;
	CDataList datalist;
    if(ptr_to_format_list->GetCount())
	{
		for(POSITION pos =  ptr_to_format_list->GetHeadPosition();pos!= NULL;)
		{
     		FmtPtr = (CFormat *) (ptr_to_format_list->GetNext (pos));
			CString name = FmtPtr->GetName();
			if(!msgformat.CompareNoCase((LPCTSTR)name))
			{
				datalist = FmtPtr->GetDataList();
				return datalist.GetDefault();
			}
		}
	}
	return CString("");
}


/******************************************************************************

	FUNCTION NAME		: GetMsgIdFromMsgName

  	PURPOSE				: Function to find the Message id by giving the Message
						  Name
	
	INPUT PARAMETERS	: CString MsgName

	OUTPUT PARAMETERS	: Message Id

	AUTHOR				: Gurdev Singh

	RETURNS				: UINT32
		 
	REMARKS				: MFC framework calls this function to find the Message 
						  Id by giving the message name.
*******************************************************************************/
UINT32 CMessageManager::GetMsgIdFromMsgName(CString MsgName)
{
	CString  msgformat;
	CPtrList * ptr_to_list_of_outgoing_msg = m_plstOutGoingMsg;
//	CPtrList * ptr_to_format_list;
	COutgoingMessage * ptr_to_outgoing_msg;
	
	if(ptr_to_list_of_outgoing_msg->GetCount())
	{
		for(POSITION pos =  ptr_to_list_of_outgoing_msg->GetHeadPosition();pos!= NULL;)
		{
     		ptr_to_outgoing_msg = (COutgoingMessage *) (ptr_to_list_of_outgoing_msg->GetNext(pos));

			if(ptr_to_outgoing_msg->GetMessageName() == MsgName)
			{
				return ptr_to_outgoing_msg->GetMessageId(); 
			}
		}
	}
	
	return 0;
}



void CMessageManager::SetDataSetDetails(UINT32 MsgId,CString sDataSet,CString sDefaultDataSet,CString sInputMode, UINT32 Freq, UINT32 Timer)
{
	CNWGCMLHandler nwgcmlhandler;
	CString  msgformat;
	CPtrList * ptr_to_list_of_outgoing_msg = m_plstOutGoingMsg;
	COutgoingMessage * ptr_to_outgoing_msg;
	
	if(ptr_to_list_of_outgoing_msg->GetCount())
	{
		for(POSITION pos =  ptr_to_list_of_outgoing_msg->GetHeadPosition();pos!= NULL;)
		{
     		ptr_to_outgoing_msg = (COutgoingMessage *) (ptr_to_list_of_outgoing_msg->GetNext(pos));
			
			if(ptr_to_outgoing_msg->GetMessageId() == MsgId)
			{
				msgformat = ptr_to_outgoing_msg->GetFormat();
			}
		}
	}

	CFormat* FmtPtr;
	CData dataobj;
	CDataList datalist;

	//find the format name and if found break
	if(m_pFormatList)
	{
		if(m_pFormatList->GetCount())
		{
			for(POSITION pos =  m_pFormatList->GetHeadPosition();pos!= NULL;)
			{
     			FmtPtr = (CFormat *) (m_pFormatList->GetAt(pos));
				CString name = FmtPtr->GetName();
				if(!msgformat.CompareNoCase((LPCTSTR)name))
				{
					datalist = FmtPtr->GetDataList(); 
					CList <CData,CData&>& datasetlist = datalist.GetData();
					if(datasetlist.GetCount())
                    {
                        for(POSITION pos =  datalist.GetData().GetHeadPosition();pos!= NULL;)
						{
                            dataobj = datalist.GetData().GetAt(pos);
                            if(!(sDataSet.CompareNoCase(dataobj.GetName())))
                            {	
                                dataobj.SetFrequency(Freq);
                                dataobj.SetTimer(Timer);
                                datalist.GetData().SetAt(pos,dataobj);
								nwgcmlhandler.UpDateDataListInDom(datalist,dataobj); 

								if(sDefaultDataSet.GetLength()) 
								{
									datalist.SetDefault(sDefaultDataSet); // to set default dataset
								}
								break;
							}
                            datalist.GetData().GetNext(pos);  
                        }
                    }
					FmtPtr->SetDataList(datalist); 
					if(sInputMode.GetLength())
					{
						FmtPtr->SetInputMode(sInputMode);// 
						nwgcmlhandler.UpDateInputModeInDom(*FmtPtr); 
					}
					break;
				}
				m_pFormatList->GetNext (pos);
			}
		}
	}
}


/******************************************************************************

	FUNCTION NAME		: GetMessageListForApp

  	PURPOSE				: Function to find the Messages associated with an application
						  Name
	
	INPUT PARAMETERS	: CString AppName ( name of the application)

	OUTPUT PARAMETERS	: CPtrList of Messages

	AUTHOR				: Pankaj Adlakha

	RETURNS				: CPtrList *
		 
	REMARKS				: MFC framework calls this function to find the Message 
						  Ids by giving the application name.
*******************************************************************************/

CList<CString,CString&>* CMessageManager::GetMessageListForApp(CString AppName)
{
	char *ptr_to_msgid;
	CPtrList * ptr_to_outgoing_msg_lst = m_plstOutGoingMsg;
	COutgoingMessage * ptr_to_outgoing_msg;
	UINT32 appid_selected = _ttoi(AppName);
	char * buffer_for_str = (char*) malloc(20);
	CList<CString,CString&>* message_list = new CList<CString,CString&>();
	CString message_name;
	if(ptr_to_outgoing_msg_lst)
	{
		if(ptr_to_outgoing_msg_lst->GetCount())
		{
			for(POSITION pos =  ptr_to_outgoing_msg_lst->GetHeadPosition();pos!= NULL;)
			{
     			ptr_to_outgoing_msg = (COutgoingMessage *) (ptr_to_outgoing_msg_lst->GetNext (pos));
				UINT32 AppId = ptr_to_outgoing_msg->GetAppId();
				if(AppId == appid_selected)
				{
					UINT msgid = ptr_to_outgoing_msg->GetMessageId();
					ptr_to_msgid = itoa(msgid,buffer_for_str,10);
					message_name = (CString (ptr_to_msgid) + ":" + (ptr_to_outgoing_msg->GetMessageName()));
					message_list->AddTail(message_name);
				}
			}
		}
	}
	free(buffer_for_str);
	return(message_list);
}


int CMessageManager::GetPluginStatusFromMsgId(UINT32 MsgId)
{
	
	CString sMsgId, msgformat;
    CPtrList *ptrOutGoingMsgList=m_plstOutGoingMsg;
	COutgoingMessage *ptrOutGoingMsg;

	if(ptrOutGoingMsgList->GetCount())
	{
		for(POSITION pos = ptrOutGoingMsgList->GetHeadPosition();pos!= NULL;)
		{
     		ptrOutGoingMsg = (COutgoingMessage *) (ptrOutGoingMsgList->GetNext (pos));
			if(ptrOutGoingMsg->GetMessageId()== MsgId)
			{
				msgformat = ptrOutGoingMsg->GetFormat();
				break;
			}
		}
	}

	if(msgformat.CompareNoCase(CString("NULL"))) // if msgformat is null means plugin
	{
		return 0;
	}
	else
	{
		return 1;
	}
}




void CMessageManager::SaveDataSetValues(UINT32 MsgId, CData& dataset)
{
	CPtrList * ptr_to_outgoing_lst = m_plstOutGoingMsg;
	COutgoingMessage * ptr_to_outgoing_msg;
	CString msgformat;
	if(ptr_to_outgoing_lst)
	{
		if(ptr_to_outgoing_lst->GetCount())
		{
			for(POSITION pos =  ptr_to_outgoing_lst->GetHeadPosition();pos!= NULL;)
			{
    			ptr_to_outgoing_msg = (COutgoingMessage *) (ptr_to_outgoing_lst->GetNext (pos));
				if(ptr_to_outgoing_msg->GetMessageId() == MsgId)
				{
					msgformat = ptr_to_outgoing_msg->GetFormat();
				}
			}
		}
		CFormat* FmtPtr;
		CData temp_dataset; 
        CNWGCMLHandler gcmlHandler;
		if(m_pFormatList)
		{
			if(m_pFormatList->GetCount())
			{
				for(POSITION pos1 =  m_pFormatList->GetHeadPosition();pos1!= NULL;)
				{
					FmtPtr = (CFormat *) (m_pFormatList->GetAt(pos1));
					CString name = FmtPtr->GetName();
					if(!msgformat.CompareNoCase((LPCTSTR)name))
					{
						CDataList datalist = FmtPtr->GetDataList();
						CList<CData,CData&>& datasetlist = datalist.GetData();
						if(datasetlist.GetCount())
						{
							for(POSITION pos = datalist.GetData().GetHeadPosition();pos!=NULL;)
							{
								temp_dataset = datalist.GetData().GetAt(pos);
								if(!temp_dataset.GetName().CompareNoCase(dataset.GetName()))
								{
									datalist.GetData().SetAt(pos,dataset);
									FmtPtr->SetDataList(datalist);//..AddValue(dataset);
									m_pFormatList->SetAt(pos1,FmtPtr);
									gcmlHandler.UpDateDataListInDom(datalist,dataset);
									break;
								}
								datalist.GetData().GetNext(pos);
								if(pos == NULL)
								{
									datalist.AddValue(dataset);
									FmtPtr->SetDataList(datalist);//..AddValue(dataset);
									m_pFormatList->SetAt(pos1,FmtPtr);
									gcmlHandler.SetDataSetInDom(dataset,datalist);
								}

							}
						}
						
						break;
					}
					m_pFormatList->GetNext(pos1);
				}
			}
		}
	}

}
void CMessageManager::SaveMessageAttributes(UINT32 MsgId,CString DefDSName,CString InputMode)
{
	COutgoingMessage* ptr_to_outgoing_msg;
	if(m_plstOutGoingMsg)
	{
		if(m_plstOutGoingMsg->GetCount())
		{
			for(POSITION pos =  m_plstOutGoingMsg->GetHeadPosition();pos!= NULL;)
			{
    			ptr_to_outgoing_msg = (COutgoingMessage *) (m_plstOutGoingMsg->GetNext (pos));
				if(ptr_to_outgoing_msg->GetMessageId() == MsgId)
				{
					CString fmtname = ptr_to_outgoing_msg->GetFormat();
					if(m_pFormatList->GetCount())
					{
						for(POSITION pos1 =  m_pFormatList->GetHeadPosition();pos1!= NULL;)
						{
							CFormat *FmtPtr = (CFormat *) (m_pFormatList->GetAt(pos1));
							CString name = FmtPtr->GetName();
							if(!fmtname.CompareNoCase((LPCTSTR)name))
							{
								CDataList datalist = FmtPtr->GetDataList();
								datalist.SetDefault(DefDSName);
								FmtPtr->SetInputMode(InputMode);
								FmtPtr->SetDataList(datalist);
								m_pFormatList->SetAt(pos1,FmtPtr);
								CNWGCMLHandler nwgcmlhandler;
								nwgcmlhandler.UpDateInputModeInDom(*FmtPtr);
								//dataset is being sent only for namesake....
								CData dataset;
								nwgcmlhandler.UpDateDefaultDataSetInDom(datalist,dataset);
								CGCMLGenerator generate_xml;
								generate_xml.MakeGCML();
								break;
							}
							m_pFormatList->GetNext(pos1);
						}
					}
					break;
					
				}
			}
		}
	}
}


CString CMessageManager::LongToCString(long int number)
{
	CString strNumber;
	char *dummy;
	dummy = (char*) malloc(sizeof(char)*20);
	strNumber = CString(ltoa(number,dummy,10));
	return strNumber;
}

char* CMessageManager::UnicodeToAscii(CString UnicodeCString)
{
	char *AsciiCharString;
	int loopcounter;
	long unicodecstringlength,countchar =0;;
	unicodecstringlength = UnicodeCString.GetLength();
	
	AsciiCharString = (char*) malloc(sizeof(char)*(unicodecstringlength));

	for(loopcounter=0;loopcounter<=unicodecstringlength-1;loopcounter++)
	{
		if(UnicodeCString.GetAt(loopcounter) != 0) // Second Byte which is having value 0
		{
			AsciiCharString[loopcounter] = (char)UnicodeCString.GetAt(loopcounter);
		}
	}
	AsciiCharString[loopcounter] =0;

	return AsciiCharString;
}
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -