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

📄 messagemanager.cpp

📁 mtk simulator v2 new source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:
								++Array;
								strEval = strEval.Right((TotalLen - (iComma+1)));
							}
							memcpy(buffer,back,arraySize);
							//buffer = Array;						
							buffer = (char*)buffer+arraySize;
							break;
								
						}
						else if(cVarName.Find(_T("har"),0) > 0)
						{								
							char* Array = (char*)malloc(iNoOfElements*datatype.GetSize());
							char* back = Array;
							memset(Array,0,iNoOfElements);
							arraySize =	iNoOfElements;
							strEval.Insert((strEval.GetLength()+1),',');
							for(int iCount=0;iCount < iNoOfElements ;++iCount)
							{
								//this is the number of elements exist in the array
								//so look out for the number 
								CString First = strEval;
								int TotalLen = First.GetLength();
								int iComma = strEval.Find(_T(","),0);
								First = First.Left(iComma);							
								memcpy(Array,First.GetBuffer(0),datatype.GetSize());
								if((iCount+1) < iNoOfElements)
								++Array;
								//Array[iCount] = (char)First.GetBuffer(0);
								strEval = strEval.Right((TotalLen - (iComma+1)));
							}
							memcpy(buffer,back,iNoOfElements);
							//buffer = Array;
							buffer = (char*)buffer+arraySize;						
							break;					
						}//its the char array
						else if(cVarName.Find(_T("tra"),0) > 0)
						{							
							strEval.Insert((strEval.GetLength()+1),',');
							arraySize = iNoOfElements*(cVar.GetValueSize());
							for(int iCount=0;iCount < iNoOfElements ;++iCount)
							{
								//this is the number of elements exist in the array
								//so look out for the number 
								CString First = strEval;
								int TotalLen = First.GetLength();
								int iComma = strEval.Find(_T(","),0);
								First = First.Left(iComma);
								WideCharToMultiByte(CP_ACP, 0,(LPCWSTR)First.GetBuffer(0),-1,(char*)buffer,arraySize,NULL,NULL);
								//memcpy(buffer,First.GetBuffer(0),cVar.GetValueSize());
								//buffer = (char*)First.GetBuffer(0);
								strEval = strEval.Right((TotalLen - (iComma+1)));
								buffer = (char*)buffer+(cVar.GetValueSize());
							}								
							break;
						}//its the string array
						//stuff the buffer now with the values;						
					}
					else
					{					
						int value = _ttoi(valueObj.GetSourceValue());
						memcpy(buffer,&value,datatype.GetSize());
						buffer = (char*)buffer + datatype.GetSize();
						break;					
					}
				}//that variable is contant
				else if(type == 3)//the varaiable is not constant ,, it can be file req ,, dialog
				{
					//the value is requested
					//get the value from the incoming message data pointer and stuff it in buffer
					//void* GetBufferFromIncomingMessage(CMessage *pMessage,CDatatype Datatype,CValue Valueobj)					
					GetBufferFromIncomingMessage
							(buffer,_ttoi(valueObj.GetSourceValue()));					
				}
			}
		}			
	}
return buffer1;		
}


void CMessageManager::GetBufferFromIncomingMessage(void *pBuffer,int nIndex)
{
	int nNoOfVariable = 0;
	INT16 iNoOfElements;
	//get the value at the given index from the void data buffer
	INPTRLIST *stPtrListIncomingMsg = NULL;	
	for( POSITION pos = m_IncomingMsgDataList->GetHeadPosition(); pos != NULL;)
	{
		stPtrListIncomingMsg = (INPTRLIST*)(m_IncomingMsgDataList->GetNext( pos ));
		if(stPtrListIncomingMsg->index == m_inComingMsgSelIndex)
		{
			CMessage *pMessage = LocateMessageInList(m_plstIncomingMsg,stPtrListIncomingMsg->stMessage.nMsgType);
			if(pMessage)
			{
				CFormat *pFormat;// = new CFormat();	
				CDataList dataList;	
				CData dataObj;		
				pFormat = GetFormatForMessage(pMessage);
				if(pFormat!=NULL)
				{
					CList<CVar,CVar&>& varList = pFormat->GetVarList();
					dataList = pFormat->GetDataList();
					CList<CData,CData&>& data= dataList.GetData();
					if(data.GetCount() > 0)
					{
						for( POSITION datapos = data.GetHeadPosition(); datapos != NULL;)
						{
							dataObj = (data.GetNext( datapos ));
							break;
						}
					}
					//CList<CData,CData&>& data= dataList.GetData();			
					for( POSITION pos = varList.GetHeadPosition(); pos != NULL;)
					{
						CVar&  cVar = (CVar&)(varList.GetNext( pos )) ;
						nNoOfVariable++;
						CList<CValue,CValue&>& valueList= dataObj.GetValueList();
						for( POSITION valpos = valueList.GetHeadPosition(); valpos != NULL;)
						//matched the name
						{
							CValue& valueObj = (CValue&)(valueList.GetNext( valpos )) ;			
							if(valueObj.GetName() == cVar.GetName())
							{
								//name matched 
								CDataType& datatype = cVar.GetDataType();
								CString cVarName = datatype.GetName();
								if(cVarName.Find(_T("array")) > 0)
								{									
									if(cVarName.Find(_T("nt"),0) > 0)
									{
										iNoOfElements = cVar.GetCount();
										if(nNoOfVariable == nIndex)//this is the variable
										{
											memcpy(pBuffer,stPtrListIncomingMsg->stMessage.nDataPtr,iNoOfElements*datatype.GetSize());
											pBuffer = (char*)pBuffer + (iNoOfElements*datatype.GetSize());
										}
										break;
											
									}
									else if(cVarName.Find(_T("har"),0) > 0)
									{		
										iNoOfElements = cVar.GetCount();
										if(nNoOfVariable == nIndex)//this is the variable
										{
											memcpy(pBuffer,stPtrListIncomingMsg->stMessage.nDataPtr,iNoOfElements*datatype.GetSize());
											pBuffer = (char*)pBuffer + (iNoOfElements*datatype.GetSize());										
										}
										break;					
									}//its the char array
									else if(cVarName.Find(_T("tra"),0) > 0)
									{										
										iNoOfElements = (cVar.GetCount()*cVar.GetValueSize());
										if(nNoOfVariable == nIndex)//this is the variable
										{
											memcpy(pBuffer,stPtrListIncomingMsg->stMessage.nDataPtr,iNoOfElements*datatype.GetSize());
											pBuffer = (char*)pBuffer + (iNoOfElements*datatype.GetSize());
										}
										break;
									}//its the string array
								//stuff the buffer now with the values;						
								}								
								else
								{
									if(nNoOfVariable == nIndex)//this is the variable
									{								
										memcpy(pBuffer,stPtrListIncomingMsg->stMessage.nDataPtr,datatype.GetSize());									
										pBuffer = (char*)pBuffer + datatype.GetSize();
									}
									break;
								}								
							}
						}
					}
				}
			}
			else
			{
				//pMessage is null
			}	
		}	
	}		
}


CMessage* CMessageManager::LocateMessageInList(CPtrList *msgList,UINT32 iMsgId)
{
	//returns the CMessage Object for the iMsgId
	CMessage *pMsg ;
	if(msgList)
	{
	if(msgList->GetCount())
	{
		for( POSITION pos = msgList->GetHeadPosition(); pos != NULL;)
		{
			pMsg = (CMessage*)(msgList->GetNext( pos )) ;
			CString cs1= pMsg->GetPluginName();
			if(pMsg->GetMessageId() == iMsgId)				
				return pMsg;
		}
	}
	}
	return NULL;
}

UINT32 CMessageManager::LocateMessageIdForName(CPtrList *msgList,CString MsgName)
{
	//returns the CMessage Object for the iMsgId
	CMessage *pMsg ;
	if(msgList->GetCount())
	{
		for( POSITION pos = msgList->GetHeadPosition(); pos != NULL;)
		{
			pMsg = (CMessage*)(msgList->GetNext( pos )) ;		
			if(!MsgName.CompareNoCase(pMsg->GetMessageName()))
			{
				return(pMsg->GetMessageId());
			}				
		}
	}
	return NULL;
}

UINT32 CMessageManager::GetTotalSizeOfVariable(CList<CVar,CVar&>& varList)
{
	UINT32 iTotal = 0;
	CDataType datatype;
	if(varList.GetCount() > 0)
	{
		for( POSITION pos = varList.GetHeadPosition(); pos != NULL;)
		{			
			CVar&  cVar = (CVar&)(varList.GetNext( pos )) ;
			datatype = cVar.GetDataType();
			CString cVarName = datatype.GetName();
			if(cVarName.Find(_T("array")) > 0)
			{
				if(cVarName.Find(_T("nt"),0) > 0)
				{
					iTotal+=4*(cVar.GetCount());
				}
				else if(cVarName.Find(_T("har"),0) > 0)
				{
					iTotal+=(cVar.GetValueSize())*(cVar.GetCount());
				}
				else if(cVarName.Find(_T("tra"),0) > 0)
				{
					iTotal+=(cVar.GetValueSize())*(cVar.GetCount());
				}
				else if(cVarName.Find(_T("yte"),0) > 0)
				{
					iTotal+=(cVar.GetValueSize())*(cVar.GetCount());
				}

			}
			else
			iTotal+=datatype.GetSize();		
		}			
	}
	return iTotal;
}

CString CMessageManager::LocateMessageNameInList(CPtrList *msgList,UINT16 iMsgId)
{
	//returns the CMessage Object for the iMsgId
	CMessage *pMsg;
	if(msgList->GetCount())
	{
		for( POSITION pos = msgList->GetHeadPosition(); pos != NULL;)
		{
			pMsg = (CMessage*)(msgList->GetNext( pos )) ;
			if(pMsg->GetMessageId() == iMsgId)				
				return pMsg->GetMessageName();
		}
	}
	return _T("");
}

CFormat* CMessageManager::GetFormatForMessage(CMessage *pMessage)
{
	if(pMessage!=NULL)
	{
		CFormat *pFormat;
		if(m_pFormatList->GetCount() > 0)//check if emtpy message list 
		{	
			for( POSITION pos = m_pFormatList->GetHeadPosition(); pos != NULL;)
			{
				pFormat = (CFormat*)(m_pFormatList->GetNext( pos )) ;
				if(!(pMessage->GetFormat().CompareNoCase(pFormat->GetName())))				
				{
					return pFormat;
				}
			}
		}	
	}
	return NULL;
}

//----------------------------------------------------------------------------------
//------------------------ Gurdev Additions ----------------------------------------
//----------------------------------------------------------------------------------

/*---------------------------------------------------------------------------------*/
/* This function receive message id and dataset name as input parameter and -------*/
/* fill the 'datasetdetails' parameters with associative values -------------------*/
/* User of this function can use this and evaluate freq, timer out of it ----------*/
/*---------------------------------------------------------------------------------*/

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

	FUNCTION NAME		: GetDataSetDetails

  	PURPOSE				: Called to fill the details of dataset
	
	INPUT PARAMETERS	: MessageID, Dataset and datasetdetails which is a 
						  reference veriable and will be filled by the function.		

	OUTPUT PARAMETERS	: CData datasetdetails

	AUTHOR				: Gurdev Singh

	RETURNS				: void
		 
	REMARKS				: MFC framework calls this function and the details 
						  returned could be parsed to get dataset attribute.
*******************************************************************************/


void CMessageManager::GetDataSetDetails(UINT32 MsgId,CString sDataSet,CData &datasetdetails)
{
	CString  msgformat;
	CPtrList * ptr_to_list_of_outgoing_msg = m_plstOutGoingMsg;
	CPtrList * ptr_to_format_list; // Pointer 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;
	//find the format name and if found break
    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(); 
				break;
			}
		}
	}

	CData dataobj;
	CString datalistname = datalist.GetName(); 
	//get the data list from datalist
	CList <CData,CData&>&  dataset = datalist.GetData();
	CList <CVar,CVar&>&    varlist = FmtPtr->GetVarList();
	if(dataset.GetCount() > 0 && varlist.GetCount() > 0)
	{
	
        for(POSITION pos =  dataset.GetHeadPosition();pos!= NULL;)
		{
			dataobj = dataset.GetNext(pos);
			if(sDataSet.GetLength())// non default, if length > 0 
			{
				if(!(sDataSet.CompareNoCase(dataobj.GetName())))
				{	
					datasetdetails = dataobj;
					break;
				}
			}
			else					// Default dataset will be considered
			{
				if(!(datalist.GetDefault().CompareNoCase(dataobj.GetName())))
				{	
					datasetdetails = dataobj;
					break;
				}
			}
		}
	}
	else
	{
		datasetdetails.SetFrequency(0);
		datasetdetails.SetTimer (0);
	}
	
}



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

	FUNCTION NAME		: GetTimer

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

	OUTPUT PARAMETERS	: Timer Value

	AUTHOR				: Gurdev Singh

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

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

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

	FUNCTION NAME		: GetTimer  (Overloaded)

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

	OUTPUT PARAMETERS	: Timer Value

	AUTHOR				: Gurdev Singh

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




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


⌨️ 快捷键说明

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