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

📄 base_instanceobject_impl.cpp

📁 270的linux说明
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.

*///==============================================================================//    base_InstanceObject_Impl.cpp////    Contents://        Implementation of InstanceObjectImpl class////==============================================================================#include "./base_InstanceObject_Impl.h"#include "base_Property_Impl.h"#include "base_Observer_Impl.h"#include "IntelMobile/Ipc_Support.h"#define LOG_DEBUG LOG_DEBUG_FRAMEWORK//==============================================================================//class InstanceObjectImpl;//==============================================================================// C-Tor()//==============================================================================InstanceObjectImpl::InstanceObjectImpl( void* pSvrInstObj,                                        Object *pOwner )                  : EventClientImpl   ( pOwner, IntelMobileText("InstanceObject") ),                    m_pSvrInstObj (pSvrInstObj){}            //==============================================================================// D-Tor()//==============================================================================InstanceObjectImpl::~InstanceObjectImpl(){    _Log( true, LOG_DEBUG, IntelMobileText("Destroying InstanceObjectImpl") );	EnterCriticalSection(&m_csIpc);	RELEASE(m_pSvrInstObj);	LeaveCriticalSection(&m_csIpc);}//==============================================================================// operator==()//==============================================================================bool InstanceObjectImpl::operator==( const ObjectImpl& rhs ) const{    IntelMobileChar* pszThisType = GetType();    IntelMobileChar* pszRhsType  = reinterpret_cast<const InstanceObjectImpl&>(rhs).GetType();    IntelMobileChar* pszThisKey = GetKey();    IntelMobileChar* pszRhsKey  = reinterpret_cast<const InstanceObjectImpl&>(rhs).GetKey();#ifdef _UNICODE        bool bEqual = !::strcmp( pszThisType, pszRhsType ) &&                  !::strcmp( pszThisKey , pszRhsKey );#else    bool bEqual = !strcmp( pszThisType, pszRhsType ) &&                  !strcmp( pszThisKey , pszRhsKey );#endif    delete[] pszThisType;    delete[] pszRhsType;    delete[] pszThisKey;    delete[] pszRhsKey;    return bEqual;} // operator==()//==============================================================================// GetProperty()//       necessary because the instance object is the only thing that properties//       know about, this is how to get the property from the server//==============================================================================void* InstanceObjectImpl::GetProperty( const IntelMobileString& sName ){              	EnterCriticalSection(&m_csIpc);	void* pPropertyBase = NULL;	//m_pSvrInstObj->GetProperty( &pPropertyBase, sName );	//IPC support	vector<string> vectParam, vectRtn;    vectParam.push_back(IntelMobileText("GetProperty"));    vectParam.push_back(sName);	HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		IntelMobileException ex(IntelMobileText("Operation Error"), IntelMobileText("InstanceObject"), IntelMobileText("GetProperty") , hr);		LeaveCriticalSection(&m_csIpc);		throw( ex ); 	}	else	{		CStringHelper::Str2Param(vectRtn[0], (HANDLE &)pPropertyBase);	}	LeaveCriticalSection(&m_csIpc);	return pPropertyBase;} //GetProperty()/*HRESULT InstanceObjectImpl::DoSubscribe  ( HANDLE hEvent, Event::EventType eType ){	//return m_pSvrInstObj->Subscribe(hEvent, eType);	//IPC support	//HRESULT S_OK;    vector<string> vectParam, vectRtn;    vectParam.push_back(IntelMobileText("Subscribe"));    vectParam.push_back( CStringHelper::Param2Str(hEvent));    vectParam.push_back( CStringHelper::Param2Str(eType));    GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);	//XXX: why not comment the return value out    //      CStringHelper::Str2Param(vectRtn[0], (int &)S_OK);    return S_OK;}*/HRESULT InstanceObjectImpl::DoSubscribe  ( Event::EventType eType, void* pCliObj ){	EnterCriticalSection(&m_csIpc);	//return m_pSvrInstObj->Subscribe(hEvent, eType);	//IPC support	//HRESULT S_OK;    vector<string> vectParam, vectRtn;    vectParam.push_back(IntelMobileText("Subscribe"));    vectParam.push_back( CStringHelper::Param2Str(eType));    vectParam.push_back( CStringHelper::Param2Str(pCliObj));	HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		 IntelMobileException ex( IntelMobileText("Error DoSubscriber for InstanceObject"), IntelMobileText("InstanceObject"), IntelMobileText("DoSubscribe"), hr );		  LeaveCriticalSection(&m_csIpc);          throw( ex ); 	}	else	{		cout << "InstanceObjectImpl::DoSubscribe " << "eType " << eType << endl;		//XXX: why not comment the return value out		//      CStringHelper::Str2Param(vectRtn[0], (int &)S_OK);		LeaveCriticalSection(&m_csIpc);		return S_OK;	}}/*HRESULT InstanceObjectImpl::UnDoSubscribe  ( HANDLE hEvent, Event::EventType eType ){	//return m_pSvrInstObj->Unsubscribe(hEvent, eType);	//IPC support	//HRESULT S_OK;    vector<string> vectParam, vectRtn;    vectParam.push_back(IntelMobileText("Unsubscribe"));    vectParam.push_back(CStringHelper::Param2Str(hEvent));    vectParam.push_back(CStringHelper::Param2Str(eType));    GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);	//XXX: why not comment out    //  CStringHelper::Str2Param(vectRtn[0], S_OK);    return S_OK;}*/HRESULT InstanceObjectImpl::UnDoSubscribe  ( Event::EventType eType, void* pCliObj ){	EnterCriticalSection(&m_csIpc);	//return m_pSvrInstObj->Unsubscribe(hEvent, eType);	//IPC support	//HRESULT S_OK;    vector<string> vectParam, vectRtn;    vectParam.push_back(IntelMobileText("Unsubscribe"));    vectParam.push_back(CStringHelper::Param2Str(eType));    vectParam.push_back(CStringHelper::Param2Str(pCliObj));	HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		 IntelMobileException ex( IntelMobileText("Error UnDoSubscribe for InstanceObject"), IntelMobileText("InstanceObject"), IntelMobileText("UnDoSubscribe"), hr );		LeaveCriticalSection(&m_csIpc);         throw( ex ); 	}	else	{		//XXX: why not comment out		//  CStringHelper::Str2Param(vectRtn[0], S_OK);		LeaveCriticalSection(&m_csIpc);		return S_OK;	}}Event *InstanceObjectImpl::CreateClassEvent(Event::EventType eType){	IntelMobileChar* pszThisType = NULL;	IntelMobileChar* pszThisKey = NULL;		Event *pTheEvent = NULL;	try	{		pszThisType = GetType();		pszThisKey = GetKey();    		pTheEvent = new Event( eType, new InstanceObjectImplPtr( this), IntelMobileText("InstanceObject"), pszThisKey, pszThisType );	}	catch(...)	{			delete[] pszThisType;		delete[] pszThisKey;		delete pTheEvent;		IntelMobileException ex( IntelMobileText("Operation Error"), IntelMobileText("InstanceObjectImpl"), IntelMobileText("CreateClassEvent") );        throw( ex ); 	}    delete[] pszThisType;    delete[] pszThisKey;	return pTheEvent;}//==============================================================================void* InstanceObjectImpl::GetSvrObj(){	return m_pSvrInstObj;}//==============================================================================// InvokeMethod()//==============================================================================IntelMobileChar* InstanceObjectImpl::InvokeMethod(  IntelMobileChar* methodName, IntelMobileChar* param ){ 	EnterCriticalSection(&m_csIpc);	IntelMobileChar* pszRtn = NULL;	IntelMobileString sResult(IntelMobileText(""));	if ( m_pSvrInstObj )    {		//IntelMobileString szName(methodName), szParam(param);		//sResult = m_pSvrInstObj->InvokeMethod( methodName, param );		//IPC support	    vector<string> vectParam, vectRtn;        vectParam.push_back(IntelMobileText("InvokeMethod"));        vectParam.push_back(CStringHelper::Param2Str(methodName));        vectParam.push_back(CStringHelper::Param2Str(param));		HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);		if ( FAILED( hr ) )		{			IntelMobileException ex( IntelMobileText("Error InvokeMethod for InstanceObject"), IntelMobileText("InstanceObject"), IntelMobileText("InvokeMethod"), hr );			LeaveCriticalSection(&m_csIpc);            throw( ex );  		}		else		{			CStringHelper::Str2Param(vectRtn[0], sResult);		}    }    else    {        InvalidInterfaceException ex( IntelMobileText("InstanceObjectImpl"), IntelMobileText("InvokeMethod") );		LeaveCriticalSection(&m_csIpc);        throw( ex );     }	int nLen = sResult.length();	pszRtn = new IntelMobileChar[nLen + 1];	pszRtn[nLen] = 0;//memset(pszRtn, 0, sizeof(IntelMobileChar) * (sResult.length() + 1));	memcpy(pszRtn, sResult.c_str(), sizeof(IntelMobileChar) * nLen);	LeaveCriticalSection(&m_csIpc);	return pszRtn;//(IntelMobileChar *)sResult.c_str();}//==============================================================================

⌨️ 快捷键说明

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