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

📄 base_property_impl.cpp

📁 270的linux说明
💻 CPP
字号:
/*

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.

*/#include "./base_Property_Impl.h"  #include "./base_Exception.h"#include "base_Observer_Impl.h"#include "IntelMobile/Ipc_Support.h"////////////////////////////////////////////////////////////////////////////////// Base Class for all properties//==============================================================================// C-Tor()//==============================================================================PropertyBaseImpl::PropertyBaseImpl( IntelMobileChar* szName, InstanceObjectImpl* pParent )                 : EventClientImpl   ( NULL, IntelMobileText("Property") ),                  m_sName          ( szName   ),                  m_pParentObject  ( pParent  ),				  m_pSvrPropBase   ( NULL     )                  //m_spIEventSubject( NULL     ){}//==============================================================================// operator==() : NOTE, We may not need to check the parent type if we//                      decide that the property name and the instance key//                      provide sufficient unique identifaciation.//==============================================================================bool PropertyBaseImpl::operator==( const ObjectImpl& rhs ) const{    const PropertyBaseImpl& cmp = reinterpret_cast<const PropertyBaseImpl&>(rhs);   #ifdef _UNICODE     return ( m_sName == cmp.m_sName                      &&  // Cheap             !::wcscmp(     m_pParentObject->GetType(),                        cmp.m_pParentObject->GetType() ) &&  // Middling             !::wcscmp(     m_pParentObject->GetKey (),                         cmp.m_pParentObject->GetKey () ) );  // Expensive!#else	return ( m_sName == cmp.m_sName                      &&  // Cheap             !::strcmp(     m_pParentObject->GetType(),                        cmp.m_pParentObject->GetType() ) &&  // Middling             !::strcmp(     m_pParentObject->GetKey (),                        cmp.m_pParentObject->GetKey () ) );  // Expensive!#endif} // operator==()//==============================================================================// GetSvrProperty()//==============================================================================void* PropertyBaseImpl::GetSvrProperty(){		if ( (m_pSvrPropBase == NULL ) &&         (m_pSvrPropBase  = m_pParentObject->GetProperty(m_sName)) == NULL )    {        _Log( LOG_HARD_ERROR, IntelMobileText("Error getting Property interface pointer.") );        InvalidInterfaceException ex( IntelMobileText("PropertyBase"), IntelMobileText("GetInterface") );        throw( ex );     }    return m_pSvrPropBase;} // GetSvrProperty()//==============================================================================// IsNull()//==============================================================================bool PropertyBaseImpl::IsNull() { 	 EnterCriticalSection(&m_csIpc);	//return GetSvrProperty()->IsNull()	;	//IPC support	 bool res=false;     vector<string> vectParam, vectRtn;     vectParam.push_back(IntelMobileText("IsNull"));	 HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrProperty(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		 IntelMobileException ex( IntelMobileText("Failure IsNull for Property"), IntelMobileText("Property"), IntelMobileText("IsNull"), hr );	 	LeaveCriticalSection(&m_csIpc);            throw( ex ); 	}	else	{		CStringHelper::Str2Param(vectRtn[0], res);	 	LeaveCriticalSection(&m_csIpc);		return res;	}	LeaveCriticalSection(&m_csIpc);}//==============================================================================// IsSettable()//==============================================================================bool PropertyBaseImpl::IsSettable(){ 	EnterCriticalSection(&m_csIpc);	//return GetSvrProperty()->IsSettable();	//IPC support	bool res=false;    vector<string> vectParam, vectRtn;    vectParam.push_back(IntelMobileText("IsSettable"));    HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrProperty(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		 IntelMobileException ex( IntelMobileText("Failure IsSettable for Property"), IntelMobileText("Property"), IntelMobileText("IsSettable"), hr );		 LeaveCriticalSection(&m_csIpc);            throw( ex ); 	}	else	{		CStringHelper::Str2Param(vectRtn[0], res);		LeaveCriticalSection(&m_csIpc);		return res;	}	LeaveCriticalSection(&m_csIpc);}    //==============================================================================// IsStatic()//==============================================================================bool PropertyBaseImpl::IsStatic() { 	EnterCriticalSection(&m_csIpc);	//return GetSvrProperty()->IsStatic();	//IPC support	bool res=false;    vector<string> vectParam, vectRtn;    vectParam.push_back(IntelMobileText("IsStatic"));    HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrProperty(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		 IntelMobileException ex( IntelMobileText("Failure IsStatic for Property"), IntelMobileText("Property"), IntelMobileText("IsStatic"), hr );		LeaveCriticalSection(&m_csIpc);            throw( ex ); 	}	else	{		CStringHelper::Str2Param(vectRtn[0], res);		LeaveCriticalSection(&m_csIpc);		return res;	}	LeaveCriticalSection(&m_csIpc);}    //==============================================================================// GetName()//==============================================================================IntelMobileChar* PropertyBaseImpl::GetName() { #ifdef _UNICODE    return ::wcscpy( new IntelMobileChar[ (m_sName.size() + 1) * 2], m_sName.c_str() );#else    return ::strcpy( new IntelMobileChar[ (m_sName.size() + 1) * 2], m_sName.c_str() );#endif}HRESULT PropertyBaseImpl::DoSubscribe  ( /*HANDLE hEvent,*/ Event::EventType eType, void* pCliObj ){	 EnterCriticalSection(&m_csIpc);	 //return GetSvrProperty()->Subscribe(/*(EventServer*)*/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));    vectParam.push_back(CStringHelper::Param2Str(pCliObj));	    HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrProperty(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		 IntelMobileException ex( IntelMobileText("Failure DoSubscribe for Property"), IntelMobileText("Property"), IntelMobileText("DoSubscribe"), hr );	 	LeaveCriticalSection(&m_csIpc);            throw( ex ); 	}	else	{		//  CStringHelper::Str2Param(vectRtn[0], (int &)S_OK);	 	LeaveCriticalSection(&m_csIpc);		return S_OK;	}	LeaveCriticalSection(&m_csIpc);}HRESULT PropertyBaseImpl::UnDoSubscribe  ( /*HANDLE hEvent,*/ Event::EventType eType, void* pCliObj ){	 EnterCriticalSection(&m_csIpc);	//return GetSvrProperty()->Unsubscribe(/*(EventServer*)*/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));    vectParam.push_back(CStringHelper::Param2Str(pCliObj));	    HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetSvrProperty(), vectParam, vectRtn);	if ( FAILED( hr ) )	{		 IntelMobileException ex( IntelMobileText("Failure DoSubscribe for Property"), IntelMobileText("Property"), IntelMobileText("DoSubscribe"), hr );	 	LeaveCriticalSection(&m_csIpc);            throw( ex ); 	}	else	{		//  CStringHelper::Str2Param(vectRtn[0], (int &)S_OK);	 	LeaveCriticalSection(&m_csIpc);		return S_OK;		//	 GetSvrProperty()->Unsubscribe(hEvent, eType);		//	return GetSvrProperty()->EndMonitoring();	}	LeaveCriticalSection(&m_csIpc);}Event *PropertyBaseImpl::CreateClassEvent(Event::EventType eType){	IntelMobileChar* pszParentType = NULL;	IntelMobileChar* pszParentKey  = NULL;	Event *pTheEvent = NULL;	try	{		pszParentType = m_pParentObject->GetType();		pszParentKey  = m_pParentObject->GetKey();		pTheEvent = new Event( eType, new PropertyBaseImplPtr( this), IntelMobileText("Property"), m_sName.c_str(), pszParentType, pszParentKey );	}	catch(...)	{			delete[] pszParentType;		delete[] pszParentKey;		delete pTheEvent;		IntelMobileException ex( IntelMobileText("Operation Error"), IntelMobileText("PropertyBaseImpl"), IntelMobileText("CreateClassEvent") );        throw( ex ); 	}    delete[] pszParentType;    delete[] pszParentKey;	return pTheEvent;}void* PropertyBaseImpl::GetSvrObj(){	return m_pSvrPropBase;}bool PropertyBaseImpl::AddObserver   ( 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))	{		m_pParentObject->AddRef();		observer.AddEventClient(this);		m_vObservers.push_back(ObserverMap(&observer, eType));	}	else	{		IntelMobileException ex( IntelMobileText("Failure Add Observer for Property"), IntelMobileText("Property"), IntelMobileText("AddObserver"), hr );		throw( ex );	}	return SUCCEEDED(hr);}bool PropertyBaseImpl::RemoveObserver( Event::EventType eType, ObserverImpl& observer ){	bool bRemoved = false;    EventClientImplPtr spRemoved = observer.RemoveEventClient( this );    if ( spRemoved != NULL )    {        PropertyBaseImplPtr spClass( *reinterpret_cast<PropertyBaseImpl**>(&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("PropertyObject"), IntelMobileText("RemoveObserver"), hr );           throw( ex );         }        else        {			spClass->GetInstance()->Release();            IntelMobileException ex( IntelMobileText("Failure RemoveObserver for Property Object"), IntelMobileText("PropertyObserver"), IntelMobileText("RemoveObserver"), 0x80047002 );            throw( ex );         }		spClass->GetInstance()->Release();        bRemoved = true;    }    return bRemoved;}bool PropertyBaseImpl::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 strParentType;    IntelMobileString strParentKey;    try    {        IntelMobileChar* pszParentType = m_pParentObject->GetType();        IntelMobileChar* pszParentKey  = m_pParentObject->GetKey();            strParentType = pszParentType;        strParentKey  = pszParentKey;        delete[] pszParentType;        delete[] pszParentKey;    }    catch ( IntelMobileException ex )    {        strParentType = IntelMobileText("Unknown");        strParentKey  = IntelMobileText("Unknown");    }    //============================================================    //   Added the local pszParentType to hold the class type.    //            Event theEvent( eType, new PropertyBaseImplPtr( this),                     IntelMobileText("Property"), m_sName.c_str(),                     strParentType.c_str(), strParentKey.c_str() );    theEvent.SetTimestamp( lTimeStamp );  // Copy in the server timestamp.    _Log( LOG_DEBUG_FRAMEWORK, IntelMobileText("Property %s: %s event fired, timestamp = %s"),                                m_sName.c_str(), 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, IntelMobileText("EventFired: Exception calling Observer's Notify function"));    }    m_vObservers.Unlock();        return true;}	

⌨️ 快捷键说明

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