📄 base_threshold_impl.cpp
字号:
EnterCriticalSection(&m_csIpc); vectParam.push_back(IntelMobileText("SetActive")); bool active=true; vectParam.push_back(CStringHelper::Param2Str(active)); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType,m_pSvrThresholdObject, vectParam, vectRtn); LeaveCriticalSection(&m_csIpc); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Failure SubscribeEvent for ThresholdImpl"), IntelMobileText("ThresholdImpl"), IntelMobileText("SubscribeEvent"), hr ); throw( ex ); } else { return S_OK; }} // SubscribeEvent()//==============================================================================// Stop() //==============================================================================bool ThresholdImpl::Stop(){ return SUCCEEDED( UnsubscribeEvent( Event::eNone ) );} // Stop()//==============================================================================// UnsubscribeEvent() //==============================================================================HRESULT ThresholdImpl::UnsubscribeEvent( Event::EventType eType ){ //m_pSvrThresholdObject->SetActive( false ); //IPC support vector<string> vectParam, vectRtn; EnterCriticalSection(&m_csIpc); vectParam.push_back(IntelMobileText("SetActive")); bool active=false; vectParam.push_back(CStringHelper::Param2Str(active)); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType,m_pSvrThresholdObject, vectParam, vectRtn); LeaveCriticalSection(&m_csIpc); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Failure UnsubscribeEvent for ThresholdImpl"), IntelMobileText("ThresholdImpl"), IntelMobileText("UnsubscribeEvent"), hr ); throw( ex ); } else { return S_OK; }} // UnsubscribeEvent() //==============================================================================HRESULT ThresholdImpl::DoSubscribe(/*HANDLE hEvent,*/ Event::EventType eType, void* pCliObj){ //return m_pSvrThresholdObject->Subscribe(hEvent, eType); //IPC support //HRESULT S_OK; vector<string> vectParam, vectRtn; EnterCriticalSection(&m_csIpc); 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, GetSvrObj(), vectParam, vectRtn); LeaveCriticalSection(&m_csIpc); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Failure DoSubscribe for ThresholdImpl"), IntelMobileText("ThresholdImpl"), IntelMobileText("DoSubscribe"), hr ); throw( ex ); } else { // CStringHelper::Str2Param(vectRtn[0], (int &)S_OK); return S_OK; }}HRESULT ThresholdImpl::UnDoSubscribe(/*HANDLE hEvent,*/ Event::EventType eType, void* pCliObj){ //return m_pSvrThresholdObject->Unsubscribe(hEvent, eType); //HRESULT S_OK; vector<string> vectParam, vectRtn; EnterCriticalSection(&m_csIpc); 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, GetSvrObj(), vectParam, vectRtn); LeaveCriticalSection(&m_csIpc); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Failure UnDoSubscribe for ThresholdImpl"), IntelMobileText("ThresholdImpl"), IntelMobileText("UnDoSubscribe"), hr ); throw( ex ); } else { // CStringHelper::Str2Param(vectRtn[0], (int &)S_OK); return S_OK; }}Event *ThresholdImpl::CreateClassEvent(Event::EventType eType){ IntelMobileChar* pszParentType = NULL; IntelMobileChar* pszParentKey = NULL; IntelMobileChar* pszName = NULL; if (m_spObservedProperty) { pszParentType = m_spObservedProperty->GetInstance()->GetType(); pszParentKey = m_spObservedProperty->GetInstance()->GetKey(); pszName = m_spObservedProperty->GetName(); } Event *pTheEvent = new Event( eType, new ThresholdImplPtr( this), IntelMobileText("Threshold"),pszName , pszParentType, pszParentKey ); delete[] pszName; delete[] pszParentType; delete[] pszParentKey; return pTheEvent;}void* ThresholdImpl::GetSvrObj(){ return m_pSvrThresholdObject;}//==============================================================================// AddObserver() : //==============================================================================bool ThresholdImpl::AddObserver( ObserverImpl& observer ) { return AddObserver( Event::eUnknown, observer );} // AddObserver()//==============================================================================// AddObserver() //==============================================================================bool ThresholdImpl::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)) { observer.AddEventClient( this ); m_vObservers.push_back( ObserverMap(&observer,eType) ); } else { IntelMobileException ex( IntelMobileText("Failure Add Observer for Threshold Object"), IntelMobileText("ThresholdImpl"), IntelMobileText("AddObserver"), hr ); throw( ex ); } return SUCCEEDED(hr);} // AddObserver() //==============================================================================// RemoveObserver() : //==============================================================================bool ThresholdImpl::RemoveObserver( ObserverImpl& observer ) { return RemoveObserver( Event::eUnknown, observer );} // RemoveObserver()//==============================================================================// RemoveObserver() : Remove it from the observer first. This returns a pointer // That may, or may not, be 'this' it is however garaunteed // to be of the same type.//==============================================================================bool ThresholdImpl::RemoveObserver( Event::EventType eType, ObserverImpl& observer ){ bool bRemoved = false; EventClientImplPtr spRemoved = observer.RemoveEventClient( this ); if ( spRemoved != NULL ) { ThresholdImplPtr spThreshold( *reinterpret_cast<ThresholdImpl**>(&spRemoved) ); spThreshold->m_vObservers.remove( ObserverMap(&observer,eType) ); bRemoved = true; HRESULT hr = UnDoSubscribe( eType, reinterpret_cast<void *>(this) ); if (FAILED(hr)) { IntelMobileException ex( IntelMobileText("Call UnsubscribeEvent error"), IntelMobileText("ThresholdImpl"), IntelMobileText("RemoveObserver"), hr ); throw( ex ); } } return bRemoved;} // RemoveObserver() //==============================================================================// RemoveObservers() : //==============================================================================bool ThresholdImpl::RemoveObservers() { m_vObservers.clear(); return m_vObservers.empty();} // RemoveObservers()//==============================================================================// EventFired() //==============================================================================bool ThresholdImpl::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 strPropertName; IntelMobileString strParentType; IntelMobileString strParentKey; try { IntelMobileChar* pszPropertName = m_spObservedProperty->GetName(); IntelMobileChar* pszParentType = m_spObservedProperty->GetInstance()->GetType(); IntelMobileChar* pszParentKey = m_spObservedProperty->GetInstance()->GetKey(); strPropertName = pszPropertName; strParentType = pszParentType; strParentKey = pszParentKey; delete[] pszPropertName; 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 ThresholdImplPtr( this ), IntelMobileText("Threshold"), strPropertName.c_str(), strParentType.c_str(), strParentKey.c_str() ); theEvent.SetTimestamp( lTimeStamp ); // Copy in the server timestamp. _Log( LOG_DEBUG_FRAMEWORK, IntelMobileText("Threshold 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 ) { ittr->first->Notify( theEvent ); } } catch ( ... ) { _Log( LOG_SOFT_ERROR, TEXT("EventFired Exception when call Observer's Notify function")); } m_vObservers.Unlock(); return true;} // EventFired() //==============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -