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

📄 messagemanager.cpp

📁 mtk simulator v2 new source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/**************************************************************

	FILENAME	: SendMessage.cpp

  	PURPOSE		: Declaration file.

	REMARKS		: nil

	AUTHOR		: Gurdev

	DATE		: Nov,04

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

#include "stdafx.h"
#include "MessageManager.h"
#include "Message.h"
#include "Format.h"
#include "Data.h"
#include "DataList.h"
#include "DataType.h"
#include "TaskInit.h"
#include "NSRThread.h"
#include "GlobalConstants.h"
#include "NWGCMLHandler.h"
extern void* MyMallocDataPtr(U32 size);
extern CNSRThread *myNSRThread;

CPtrList* CMessageManager::m_pFormatList;		// This declaration is 
CPtrList* CMessageManager::m_plstOutGoingMsg;	// because their storage class is static
CPtrList* CMessageManager::m_plstIncomingMsg;	
CPtrList* CMessageManager::m_plstAsyncMsg;		
CPtrList* CMessageManager::m_pAppList;			
CPtrList* CMessageManager::m_pBootupList;		
CPtrList* CMessageManager::m_pFreqList;			
CPtrList*	CMessageManager::m_pDataList;
CPtrList* CMessageManager::m_TimerList;	
CStdioFile	CMessageManager::m_fErrorFile;
CString		CMessageManager::m_XMLErrors;
int			CMessageManager::AppIdErrorPrintedStatus;
CString		CMessageManager::AppIdError[MAX_APPLICATIONS];

CMessageManager::CMessageManager(void)
{
	
}


CMessageManager::~CMessageManager(void)
{
}

void CMessageManager::InitializeXMLLists()
{
	DWORD retWord;
	char iniFileName[500];
	retWord = GetPrivateProfileString(_T("Section1"),_T("FileName"),_T(""),(U16*)iniFileName,80,XML_CONFIG_INI_FILE_NAME);
	
	if(0==retWord)// XMLConfig.ini File does not exist or empty
	{
		AfxMessageBox(CString("XMLConfig.ini file does not exist or empty"));
		exit(0);
	}

	//following : if xmlconfig.ini file exists and is not empty
	// then check for the entry in xmlconfig.ini file is correct or not
	CFile fCFile;
	if(fCFile.Open((LPCTSTR)iniFileName,CFile::modeRead)==FALSE) 
	{
		AfxMessageBox(CString("Unable to open XML file, Invalid entry in XMLConfig.ini file"));
		exit(0);
	}
	else
	{
		fCFile.Close();
	}

	CNWGCMLHandler *GCMLHandler = new CNWGCMLHandler((LPTSTR)iniFileName);
	MSXML::IXMLDOMDocument *m_pDom;
	if(GCMLHandler->GetDOM(m_pDom) == SUCCESS)
	{
		m_pFormatList		= GCMLHandler->GetFormatsList(); 
		m_plstOutGoingMsg	= GCMLHandler->GetOutGoingMessageList();
		m_plstIncomingMsg	= GCMLHandler->GetIncomingMessageList();
		m_plstAsyncMsg		= GCMLHandler->GetAsyncMessageList();
		m_pAppList			= GCMLHandler->GetApplicationList(); 
		m_pBootupList		= GCMLHandler->GetBootUpMessageList();
		m_pFreqList			= GCMLHandler->GetFrequentlyUsedMessageList();
		m_pDataList			= GCMLHandler->GetDataList();
		m_TimerList			= new CPtrList();
		
		m_XMLErrors= CString("XML Errors \n\n");
		AppIdErrorPrintedStatus=0;
		if(VerifyLists()!=0)
		{
		AMLOGINFO(_T("Success In Initialization of XML"));
		}
		else
		{
			exit(0);
		}

	}
	else
	{
		AMLOGERROR(_T("Error in getting the XML initialized"));
		//AfxMessageBox(_T("Error in reading GCML.txt file"));
		exit(0);
	}
	
}

int CMessageManager::VerifyLists()
{
	int flagIncomingMsg,flagOutGoingMsg,flagFormatList,flagDataList,flagAsyncMsg,flagFreqlist,flagBootupList;
	flagIncomingMsg=flagOutGoingMsg=flagFormatList=flagDataList=flagAsyncMsg = 1; // 1 means no error
	flagFreqlist = flagBootupList = 1;
	
	flagIncomingMsg = VerifyIncomingMsg();
	flagOutGoingMsg = VerifyOutGoingMsg();
	flagFormatList  = VerifyFormatList();
	flagDataList    = VerifyDataList();
	flagAsyncMsg    = VerifyAsyncMsg();
	flagFreqlist	= VerifyFreqList();
	flagBootupList	= VerifyBootupList();
	if(flagIncomingMsg&&flagOutGoingMsg&&flagFormatList&&flagDataList&&flagAsyncMsg)// 1 means no error
	{
		return 1; //Success, no error
	}
	else  // error is there
	{
		AfxMessageBox(m_XMLErrors);
		if(m_fErrorFile.Open(XML_ERROR_FILE_NAME,CFile::modeCreate|CFile::modeWrite|CFile::typeText)==TRUE) 
		{
			int length = m_XMLErrors.GetLength();
			m_fErrorFile.Write((char *)UnicodeToAscii(m_XMLErrors),length);
			m_fErrorFile.Close();
		}
		else
		{
			 AfxMessageBox(CString("Error in File Handling : XMLError file"));
		}
		return 0; // error
	}
}

int CMessageManager::VerifyIncomingMsg()
{	
	//take one message from incomming list
	//check that its AppId is there in the appidlist, traverse the appid list for each
	//check its response message id exists or not, traverse the outgoing message list
	CIncomingMsg *IncMsg;
	CApplication *App_ptr;
	COutgoingMessage *outgoing_msg;
	UINT32 AppId, RspMsgId;
	int AppIdStatus,RspMsgIdStatus,ErrorStatus=0;//will be one even if single error occure 

	if(m_plstIncomingMsg && m_plstIncomingMsg->GetCount())
	{
		for(POSITION pos = m_plstIncomingMsg->GetHeadPosition();pos!=NULL;)
		{
			IncMsg = (CIncomingMsg *) m_plstIncomingMsg->GetNext(pos);
			AppId = IncMsg->GetAppId(); 
			
			// now search for the appid in appid list for existance
			AppIdStatus=0;
			if(m_pAppList && m_pAppList->GetCount())
			{
				for(POSITION pos =  m_pAppList->GetHeadPosition();pos!= NULL;)
				{

     				App_ptr = (CApplication *) (m_pAppList->GetNext (pos));
					if(App_ptr->GetAppId()==AppId)
					{
						AppIdStatus =1; // appid found, its ok
						break; // if found, get out of loop
					}
				}

				if(AppIdStatus==0) // means not found
				{
					//m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[MsgId - ")+LongToCString(IncMsg->GetMessageId())+CString("] Invalid Application Id - ")+LongToCString(AppId)+CString("\n") ;
					AppIdError[AppId] = AppIdError[AppId] +CString(" ")+LongToCString(IncMsg->GetMessageId());
					ErrorStatus=1;
					
				}
			}
			else
			{
				if(AppIdErrorPrintedStatus==0)
				{
					m_XMLErrors = m_XMLErrors+CString("ERROR : Application Id are not defined in XML")+CString("\n");
					ErrorStatus=1;
					AppIdErrorPrintedStatus=1;
				}
			}

			//----------------- now search for Resp message id ---------------------
			//take a list of response message ids
			CList<UINT32, UINT32>& lstRespId = IncMsg->GetResponseMessageList();

			//check if the list is empty
			if(lstRespId.GetCount()) // response messageid list is not empty
			{
				for( POSITION posResp = lstRespId.GetHeadPosition(); posResp != NULL; )
				{			
					
					RspMsgId  = (UINT32) lstRespId.GetNext(posResp);
					RspMsgIdStatus=0;
					if(m_plstOutGoingMsg)
					{
						for(POSITION pos=m_plstOutGoingMsg->GetHeadPosition();pos!=NULL;)
						{
							outgoing_msg = (COutgoingMessage*)m_plstOutGoingMsg->GetNext(pos);
							if(outgoing_msg->GetMessageId() ==RspMsgId)
							{
								RspMsgIdStatus=1; // Response Message id is there, its ok
								break;			// break the loop
							}
						}
						
						if(RspMsgIdStatus==0)
						{
							m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[MsgId - ")+LongToCString(IncMsg->GetMessageId())+CString("] Invalid Response Message Id - ")+LongToCString(RspMsgId)+CString("\n");
							ErrorStatus=1;
						}
					}
					else
					{
						m_XMLErrors = m_XMLErrors+CString("ERROR : Outgoing Message List is empty")+CString("\n");
						ErrorStatus=1;
					}
				}
			}
	else
	{
	
	}
}
	}
	else
	{
		AfxMessageBox(_T("ERROR : Incoming Msg list is Empty"));
		ErrorStatus=1;
	}

	int index;
	for(index=0;index<=MAX_APPLICATIONS-1;index++)
	{
		if(AppIdError[index].GetLength()>0)
		{
			m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[For Incoming Messages - ")+AppIdError[index]+CString(" : Invalid AppId - ")+LongToCString(index)+CString("\n");
		}
		AppIdError[index] = CString(""); // because outgoing varifier also have to fill

	}

	if(ErrorStatus==1)
	{
		
        return 0; // Some error occur
	}
	else
	{
		return 1; // No Error Occure
	}
}

int CMessageManager::VerifyOutGoingMsg()
{	
	//take one message from out going list
	//check that its AppId is there in the appidlist, traverse the appid list for each message
	//check that its format name is there in the formatlist, traverse format list for each message
	COutgoingMessage *OutGoingMsg;
	CApplication *App_ptr;
	CString FormatName,PluginName;
	
	UINT32 AppId;
	int AppIdStatus,FormatNameStatus,ErrorStatus=0;//ErrorStatus will be one even if single error occure 

	if(m_plstOutGoingMsg && m_plstOutGoingMsg->GetCount())
	{
		for(POSITION pos = m_plstOutGoingMsg->GetHeadPosition();pos!=NULL;)
		{
			OutGoingMsg = (COutgoingMessage *) m_plstOutGoingMsg->GetNext(pos);
			AppId = OutGoingMsg->GetAppId(); 
			
			// now search for the appid in appid list for existance
			AppIdStatus=0; 
			if(m_pAppList && m_pAppList->GetCount())
			{
				for(POSITION pos =  m_pAppList->GetHeadPosition();pos!= NULL;)
				{

     				App_ptr = (CApplication *) (m_pAppList->GetNext (pos));
					if(App_ptr->GetAppId()==AppId)
					{
						AppIdStatus =1; // appid found, its ok
						break; // if found, get out of loop
					}
				}

				if(AppIdStatus==0) // means not found
				{
					//m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[MsgId - ")+LongToCString(OutGoingMsg->GetMessageId())+CString("] Invalid Application Id - ")+LongToCString(AppId)+CString("\n") ;
					AppIdError[AppId] = AppIdError[AppId] +CString(" ")+LongToCString(OutGoingMsg->GetMessageId());
					ErrorStatus=1;
					
				}
			}
			else
			{
				if(AppIdErrorPrintedStatus==0) //AppIdErrorPrintedStatus is a member variable
				{
					m_XMLErrors = m_XMLErrors+CString("ERROR : Application Id are not defined in XML")+CString("\n");
					ErrorStatus=1;
					AppIdErrorPrintedStatus=1;
				}
			}
			
			// following is the chech for availability of format name in format list
			FormatName = OutGoingMsg->GetFormat();
			PluginName = OutGoingMsg->GetPluginName();
			if(!FormatName.CompareNoCase(CString("null"))) // If format is Null, that means plugin should be there
			{
				if(PluginName.GetLength()==0)
				{
					m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[MsgId - ")+LongToCString(OutGoingMsg->GetMessageId())+CString("] Format is \"Null\" and Plugin is not there\n") ;
					ErrorStatus=1;
				}
			}
			else
			{
				if(FormatName.GetLength()) // some format is there and it is not "NULL"
				{
			// Now search this format name in the list of formats
			if(m_pFormatList)
			{
				CFormat *pFormat;
				FormatNameStatus=0;
				for(POSITION pos = m_pFormatList->GetHeadPosition(); pos != NULL;)
				{
					pFormat = (CFormat*)m_pFormatList->GetNext( pos ) ;
					if(!FormatName.CompareNoCase(pFormat->GetName()))				
					{
						FormatNameStatus=1;
						break;
					}
				
				}	
				if(FormatNameStatus==0) // means not found
				{
					m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[MsgId - ")+LongToCString(OutGoingMsg->GetMessageId())+CString("] Invalid Format Name - ")+FormatName+CString("\n") ;
					ErrorStatus=1;
				}
					}
					else
					{
						m_XMLErrors = m_XMLErrors+CString("ERROR : Format list is Empty\n") ;
						ErrorStatus=1;
					}
				}
				else // format is ""
				{
					m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[MsgId - ")+LongToCString(OutGoingMsg->GetMessageId())+CString("] Invalid Format entry \"\" \n");
					ErrorStatus=1;
			}

		}
	}
	}
	else
	{
		AfxMessageBox(_T("ERROR : Outgoing Msg list is Empty"));
		ErrorStatus=1;
	}

	int index;
	for(index=0;index<=MAX_APPLICATIONS-1;index++)
	{
		if(AppIdError[index].GetLength()>0)
		{
			m_XMLErrors = m_XMLErrors+CString("ERROR : ")+CString("[For Outgoing Messages - ")+AppIdError[index]+CString(" : Invalid AppId - ")+LongToCString(index)+CString("\n");
		}
	}

	if(ErrorStatus==1)
	{
		return 0; // Some error occur
	}
	else
	{
		return 1; // No Error Occure
	}
}


int CMessageManager::VerifyFormatList()
{
	//get one format from format list
	//find the data list name associated with it
	//Check that datalist name in the list of datalist
	CDataList cdatalist,*ptrdatalist; 
	CString inputmode;
	int DataListNameStatus,ErrorStatus=0;
    
	if(m_pFormatList)
	{
		CFormat *pFormat;
		
		for(POSITION pos = m_pFormatList->GetHeadPosition(); pos != NULL;)
		{
			pFormat = (CFormat*)m_pFormatList->GetNext( pos ) ;
			if((pFormat->GetName()).GetLength()) // if format is there but format name is not defined
			{
                cdatalist = pFormat->GetDataList();
				if((cdatalist.GetName()).GetLength()>0) //Datalist name is there
				
				{
					if(m_pDataList)
					{
						DataListNameStatus=0;
						for(POSITION pos = m_pDataList->GetHeadPosition(); pos != NULL;) //search for the datalist name in data list ptrdatalist
						{
							ptrdatalist = (	CDataList*) m_pDataList->GetNext( pos ) ;
							if(!(cdatalist.GetName()).CompareNoCase(ptrdatalist->GetName()))
							{

⌨️ 快捷键说明

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