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

📄 base_instanceobject_impl.cpp

📁 270的linux说明
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// GetPropertyImplByName()//==============================================================================PropertyBaseImpl* InstanceObjectImpl::GetPropertyImplByName(  IntelMobileChar* name, IntelMobileChar* type ){ 	IntelMobileString namestr = name;	PROPERTYIMPLMAP::iterator it = m_Properties.find( namestr );	if ( it != m_Properties.end() )		return (*it).second;		if ( GetProperty( name ) == NULL ) // property is not support by the device		return NULL;	PropertyBaseImpl* pProperty = NULL;	if ( m_pSvrInstObj )	{		if ( ::strcmp(type, IntelMobileText("Byte")) == 0 ) pProperty = new BytePropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("Int")) == 0 ) pProperty = new IntPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("UInt")) == 0 ) pProperty = new UIntPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("Int64")) == 0 ) pProperty = new Int64PropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("UInt64")) == 0 ) pProperty = new UInt64PropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("String")) == 0 ) pProperty = new StringPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("Bool")) == 0 ) pProperty = new BoolPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("DateTime")) == 0 ) pProperty = new DateTimePropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("Float")) == 0 ) pProperty = new FloatPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("ByteArray")) == 0 ) pProperty = new ByteArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("IntArray")) == 0 ) pProperty = new IntArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("UIntArray")) == 0 ) pProperty = new UIntArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("Int64Array")) == 0 ) pProperty = new Int64ArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("UInt64Array")) == 0 ) pProperty = new UInt64ArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("StringArray")) == 0 ) pProperty = new StringArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("BoolArray")) == 0 ) pProperty = new BoolArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("DateTimeArray")) == 0 ) pProperty = new DateTimeArrayPropertyImpl( name, this );		else if ( ::strcmp(type, IntelMobileText("FloatArray")) == 0 ) pProperty = new FloatArrayPropertyImpl( name, this );	}			if ( pProperty )		m_Properties.insert( it, pair<IntelMobileString, PropertyBaseImpl*>(namestr, pProperty) );	return pProperty;}//==============================================================================// IsAvailable()//==============================================================================bool InstanceObjectImpl::IsAvailable(  IntelMobileChar* methodName ){ 	EnterCriticalSection(&m_csIpc);	bool bAvailable = false;    if ( m_pSvrInstObj )    {        //bAvailable = m_pSvrInstObj->IsAvailable( methodName );		//IPC support		vector<string> vectParam, vectRtn;        vectParam.push_back(IntelMobileText("IsAvailable"));        vectParam.push_back(CStringHelper::Param2Str(methodName));		HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);		if ( FAILED( hr ) )		{			  IntelMobileException ex( IntelMobileText("Error IsAvailable for InstanceObject"), IntelMobileText("InstanceObject"), IntelMobileText("IsAvailable"), hr );			LeaveCriticalSection(&m_csIpc);            throw( ex );  		}		else		{			CStringHelper::Str2Param(vectRtn[0], bAvailable);		}    }    else    {        InvalidInterfaceException ex( IntelMobileText("InstanceObjectImpl"), IntelMobileText("IsAvailable") );		LeaveCriticalSection(&m_csIpc);        throw( ex );     }	LeaveCriticalSection(&m_csIpc);    return bAvailable;}//==============================================================================// IsEventAvailable() //==============================================================================bool InstanceObjectImpl::IsEventAvailable( Event::EventType eType ){	EnterCriticalSection(&m_csIpc);    bool bAvailable = false;    if ( m_pSvrInstObj )    {        //bAvailable = m_pSvrInstObj->IsEventAvailable( eType) ;		//IPC support		vector<string> vectParam, vectRtn;        vectParam.push_back(IntelMobileText("IsEventAvailable"));        vectParam.push_back(CStringHelper::Param2Str(eType));		//cout << "eType: " << eType << endl;		HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);		if ( FAILED( hr ) )		{			  IntelMobileException ex( IntelMobileText("Error IsEventAvailable for InstanceObject"), IntelMobileText("InstanceObject"), IntelMobileText("IsEventAvailable"), hr );			LeaveCriticalSection(&m_csIpc);            throw( ex );  		}		else		{			CStringHelper::Str2Param(vectRtn[0], bAvailable);		}    }    else    {        InvalidInterfaceException ex( IntelMobileText("InstanceObject"), IntelMobileText("IsEventAvailable") );		LeaveCriticalSection(&m_csIpc);        throw( ex );     }	LeaveCriticalSection(&m_csIpc);    return bAvailable;} // IsEventAvailable() IntelMobileChar*  InstanceObjectImpl::GetType (){	EnterCriticalSection(&m_csIpc);	if ( m_pSvrInstObj )    {		//XXX: memeory leak risk?		IntelMobileChar *pszType, *buf;		//IPC support		vector<string> vectParam, vectRtn;        vectParam.push_back(IntelMobileText("GetType"));		HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);		if ( FAILED( hr ) )		{			  IntelMobileException ex( IntelMobileText("Error GetType for InstanceObject"), IntelMobileText("InstanceObject"), IntelMobileText("GetType"), hr );			LeaveCriticalSection(&m_csIpc);            throw( ex );  		}		else		{			CStringHelper::Str2Param(vectRtn[0], pszType);		//pszType = ::strcpy(new IntelMobileChar[::strlen(buf) + 1], buf);			LeaveCriticalSection(&m_csIpc);			return pszType;		}    }    else    {        InvalidInterfaceException ex( IntelMobileText("InstanceObject"), IntelMobileText("IsEventAvailable") );		LeaveCriticalSection(&m_csIpc);        throw( ex );     }	LeaveCriticalSection(&m_csIpc);}IntelMobileChar*  InstanceObjectImpl::GetKey  (){	EnterCriticalSection(&m_csIpc);	if ( m_pSvrInstObj )    {		//XXX: memeory leak risk?		IntelMobileChar *pszKey, *buf;		//IPC support		vector<string> vectParam, vectRtn;        vectParam.push_back(IntelMobileText("GetKey"));		HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrObj(), vectParam, vectRtn);		if ( FAILED( hr ) )		{			IntelMobileException ex( IntelMobileText("Error GetKey for InstanceObject"), IntelMobileText("InstanceObject"), IntelMobileText("GetKey"), hr );			LeaveCriticalSection(&m_csIpc);            throw( ex );  		}		else		{			CStringHelper::Str2Param(vectRtn[0], pszKey);			//pszKey = ::strcpy(new IntelMobileChar[::strlen(buf) + 1], buf);			LeaveCriticalSection(&m_csIpc);			return pszKey;		}    }    else    {        InvalidInterfaceException ex( IntelMobileText("InstanceObject"), IntelMobileText("IsEventAvailable") );		LeaveCriticalSection(&m_csIpc);        throw( ex );     }	LeaveCriticalSection(&m_csIpc);}bool InstanceObjectImpl::AddObserver   ( Intel::Mobile::BaseAPI::Event::EventType eType, ObserverImpl& observer ){	HRESULT hr = E_POINTER;	//use the this pointer as the Client Event Subject	hr = DoSubscribe(eType, reinterpret_cast<void *>(this));	if(SUCCEEDED(hr))	{		observer.AddEventClient(this);		m_vObservers.push_back(ObserverMap(&observer, eType));	}	else	{		IntelMobileException ex( IntelMobileText("Failure Add Observer for Instance Object"), IntelMobileText("InstaceObject"), IntelMobileText("AddObserver"), hr );		throw( ex );	}	return SUCCEEDED(hr);}bool InstanceObjectImpl::RemoveObserver( Intel::Mobile::BaseAPI::Event::EventType eType, ObserverImpl& observer ){    bool bRemoved = false;    EventClientImplPtr spRemoved = observer.RemoveEventClient( this );    if ( spRemoved != NULL )    {        InstanceObjectImplPtr spClass( *reinterpret_cast<InstanceObjectImpl**>(&spRemoved) );								                spClass->m_vObservers.remove( ObserverMap(&observer,eType) );	        HRESULT hr = UnDoSubscribe( eType, reinterpret_cast<void *>(this) );        if (FAILED(hr))        {           IntelMobileException ex( IntelMobileText("Call UnsubscribeEvent error"), IntelMobileText("InstaceObject"), IntelMobileText("RemoveObserver"), hr );           throw( ex );         }       /* else        {            IntelMobileException ex( IntelMobileText("Failure RemoveObserver for Instance Object"), IntelMobileText("InstanceObserver"), IntelMobileText("RemoveObserver"), 0x80047002 );            throw( ex );         }*/        bRemoved = true;    }    return bRemoved;}bool InstanceObjectImpl::EventFired( LONG lType, time_t lTimeStamp ){    // Create an event object passing in the type of event and the     // address of the public object that ownes this impl object.    Event::EventType eType = static_cast<Event::EventType>(lType);    //============================================================    //		  The retreival of the identifying data is called in the     //        context of the server thread. This can throw an exception     //        which would cause problems with the interface.    //            IntelMobileString strKey;    try    {        IntelMobileChar* pszKey = GetType();        strKey = pszKey;        delete[] pszKey;    }    catch ( IntelMobileException ex )    {        strKey = IntelMobileText("Unknown");    }    //============================================================    // Duplicated the use of pszKey as the class key IS the class type.    //            Event theEvent( eType, new InstanceObjectImplPtr( this),                     IntelMobileText("InstanceObject"), strKey.c_str(), strKey.c_str() );    theEvent.SetTimestamp( lTimeStamp );  // Copy in the server timestamp.    _Log( LOG_DEBUG_FRAMEWORK, IntelMobileText("Class event of type %s fired, timestamp = %s"),                                theEvent.GetTypeName(), theEvent.GetTSstring() );    // Now notify all the local observers    ObserverCollection::const_iterator ittr;    m_vObservers.Lock();     try    {        for ( ittr = m_vObservers.begin(); ittr < m_vObservers.end(); ++ittr )        {            if ( ittr->second == eType )            {                ittr->first->Notify( theEvent );            }        }    }    catch ( ... )     {        _Log( LOG_SOFT_ERROR, _T("EventFired: Exception calling Observer's Notify function"));    }    m_vObservers.Unlock();        return true;} // EventFired() 

⌨️ 快捷键说明

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