📄 counterthreshold_impl.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.
*///==============================================================================// CounterThreshold_Impl.cpp // Implementation of base class CounterThresholdImpl//==============================================================================#include "./CounterThreshold_Impl.h" #include "../Base/base_Exception.h"//#include "IntelMobile_Server/IntelMobile_Server.h"#include "../Ipc_Support.h"//==============================================================================// C-Tor() : Explicit constructor//==============================================================================CounterThresholdImpl::CounterThresholdImpl( Object* pOwner, IntelMobileChar* sType ) : ThresholdImpl( pOwner, sType ){}//==============================================================================// D-Tor() : //==============================================================================CounterThresholdImpl::~CounterThresholdImpl(){}//==============================================================================// GetNotify() : //==============================================================================bool CounterThresholdImpl::GetNotify() { //return (reinterpret_cast<ServerCounterThreshold*>(GetInterface()))->GetNotify(); //IPC support EnterCriticalSection(&m_csIpc); bool retValue; vector<string> vectParam, vectRtn; vectParam.push_back(IntelMobileText("GetNotify")); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, GetInterface(), vectParam, vectRtn); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error retrieving Notify value"), m_sThresholdType.c_str(), IntelMobileText("GetNotify"), hr); LeaveCriticalSection(&m_csIpc); throw( ex ); } else { CStringHelper::Str2Param(vectRtn[0], retValue); LeaveCriticalSection(&m_csIpc); return retValue; } LeaveCriticalSection(&m_csIpc);} // GetNotify()//==============================================================================// SetNotify() : //==============================================================================bool CounterThresholdImpl::SetNotify( bool bNotify ) { //(reinterpret_cast<ServerCounterThreshold*>(GetInterface()))->SetNotify( bNotify ); //IPC support EnterCriticalSection(&m_csIpc); bool retValue; vector<string> vectParam, vectRtn; vectParam.push_back(IntelMobileText("SetNotify")); vectParam.push_back(CStringHelper::Param2Str(bNotify)); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, (GetInterface()), vectParam, vectRtn); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error setting Notify value"), m_sThresholdType.c_str(), IntelMobileText("SetNotify"), hr ); LeaveCriticalSection(&m_csIpc); throw( ex ); } else { CStringHelper::Str2Param(vectRtn[0], retValue); LeaveCriticalSection(&m_csIpc); return retValue; } LeaveCriticalSection(&m_csIpc); return true;} // SetNotify()/*//==============================================================================// AddObserver() : //==============================================================================bool CounterThresholdImpl::AddObserver( ObserverImpl& observer ) { return EventClientImpl::AddObserver( Event::eThresholdReached, observer );} // AddObserver()//==============================================================================// RemoveObserver() : //==============================================================================bool CounterThresholdImpl::RemoveObserver( ObserverImpl& observer ) { return EventClientImpl::RemoveObserver( Event::eThresholdReached, observer );} // RemoveObserver()//==============================================================================// RemoveObservers() : //==============================================================================bool CounterThresholdImpl::RemoveObservers( ) { CClientImplEventManager &eventMgr = CClientImplEventManager::GetClientImplEventManagerInst(); //CEventBind *pEb = eventMgr.GetEventBind(this, Event::eThresholdReached ); //if (NULL != pEb) { //return eventMgr.RemoveObservers(pEb->GetHandle()); return eventMgr.RemoveObservers(Event::eThresholdReached, this); } return false; } // RemoveObservers()//==============================================================================// SetObserverEvent() : //==============================================================================bool CounterThresholdImpl::SetObserverEvent( ) { bool bRet = false; Event * event = ThresholdImpl::CreateClassEvent( Event::eThresholdReached ); bRet = EventClientImpl::UpdateEvent( Event::eThresholdReached, *event); delete event; return bRet;} // SetObserverEvent()*///==============================================================================// GetDistinctEvent() : //==============================================================================Event::EventType CounterThresholdImpl::GetDistinctEvent( ) { return Event::eThresholdReached;} // GetDistinctEvent()//++++++++++++++++++++++++++++++++++++++++++++++++++++// // Class ByteCounterThreshold////++++++++++++++++++++++++++++++++++++++++++++++++++++//==============================================================================// C-Tor() : Explicit constructor//==============================================================================ByteCounterThresholdImpl::ByteCounterThresholdImpl( Object* pOwner, unsigned char threshold, unsigned char offset ) : CounterThresholdImpl( pOwner, IntelMobileText("ByteCounterThreshold") ){ SetThreshold( threshold ); if ( offset != 0U ) { SetOffset( offset ); }}//==============================================================================// GetThreshold() : //==============================================================================unsigned char ByteCounterThresholdImpl::GetThreshold() { //return reinterpret_cast<ServerByteCounterThreshold*> (GetInterface())->GetThreshold(); //IPC support EnterCriticalSection(&m_csIpc); unsigned char retValue; vector<string> vectParam, vectRtn; vectParam.push_back(IntelMobileText("GetThreshold")); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, reinterpret_cast<ServerByteCounterThreshold*>(GetInterface()), vectParam, vectRtn); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error getting Threshold value"), m_sThresholdType.c_str(), IntelMobileText("GetThreshold"), hr ); LeaveCriticalSection(&m_csIpc); throw( ex ); } else { CStringHelper::Str2Param(vectRtn[0], retValue); LeaveCriticalSection(&m_csIpc); return retValue; } LeaveCriticalSection(&m_csIpc);} // GetThreshold()//==============================================================================// SetThreshold() : //==============================================================================bool ByteCounterThresholdImpl::SetThreshold( unsigned char threshold ) { //reinterpret_cast<ServerByteCounterThreshold*> (GetInterface())->SetThreshold( threshold ); //IPC support EnterCriticalSection(&m_csIpc); vector<string> vectParam, vectRtn; vectParam.push_back(IntelMobileText("SetThreshold")); vectParam.push_back(CStringHelper::Param2Str(threshold)); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, (GetInterface()), vectParam, vectRtn); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error setting Threshold value"), m_sThresholdType.c_str(), IntelMobileText("SetThreshold"), hr ); LeaveCriticalSection(&m_csIpc); throw( ex ); } LeaveCriticalSection(&m_csIpc);} // SetThreshold()//==============================================================================// GetOffset() : //==============================================================================unsigned char ByteCounterThresholdImpl::GetOffset() { //return reinterpret_cast<ServerByteCounterThreshold*> (GetInterface())->GetOffset(); //IPC support EnterCriticalSection(&m_csIpc); unsigned char retValue; vector<string> vectParam, vectRtn; vectParam.push_back(IntelMobileText("GetOffset")); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, (GetInterface()), vectParam, vectRtn); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error retrieving Offset value"), m_sThresholdType.c_str(), IntelMobileText("GetOffset"), hr ); LeaveCriticalSection(&m_csIpc); throw( ex ); } else { CStringHelper::Str2Param(vectRtn[0], retValue); LeaveCriticalSection(&m_csIpc); return retValue; } LeaveCriticalSection(&m_csIpc);} // GetOffset()//==============================================================================// SetOffset() : //==============================================================================bool ByteCounterThresholdImpl::SetOffset( unsigned char offset ) { //reinterpret_cast<ServerByteCounterThreshold*> (GetInterface())->SetOffset( offset ); //IPC support EnterCriticalSection(&m_csIpc); vector<string> vectParam, vectRtn; vectParam.push_back(IntelMobileText("SetOffset")); vectParam.push_back(CStringHelper::Param2Str(offset)); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, (GetInterface()), vectParam, vectRtn); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error setting Offset value"), m_sThresholdType.c_str(), IntelMobileText("SetOffset"), hr ); LeaveCriticalSection(&m_csIpc); throw( ex ); } LeaveCriticalSection(&m_csIpc); return true;} // SetOffset()//==============================================================================// GetInterface() : Returns the interface pointer, having instantiated it if needed.//==============================================================================//IByteCounterThresholdCOM* ByteCounterThresholdImpl::GetInterface()void* ByteCounterThresholdImpl::GetInterface(){ EnterCriticalSection(&m_csIpc); if (m_pSvrThresholdObject == NULL) { //m_pSvrThresholdObject = GetNewServerThreshold(IntelMobileText("ByteCounterThreshold")); //IPC support m_sName = "ByteCounterThreshold"; m_nDataType = ID_TYPE_THRESHOLD; vector<string> vectParam, vectRtn; vectParam.push_back(CStringHelper::Param2Str(m_sName)); //printf("want to send %s\n",vectParam[0].c_str()); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, /*GetSvrObj()*/NULL, vectParam, vectRtn); //now GetSvrObj() should be null //printf("getted %s\n",vectRtn[0].c_str()); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error setting GetInterface value"), m_sThresholdType.c_str(), IntelMobileText("GetInterface"), hr ); LeaveCriticalSection(&m_csIpc); throw( ex ); } else CStringHelper::Str2Param(vectRtn[0], (int &)m_pSvrThresholdObject); } LeaveCriticalSection(&m_csIpc); return (m_pSvrThresholdObject);} // GetInterface()//++++++++++++++++++++++++++++++++++++++++++++++++++++// // Class IntCounterThreshold////++++++++++++++++++++++++++++++++++++++++++++++++++++//==============================================================================// C-Tor() : Explicit constructor//==============================================================================IntCounterThresholdImpl::IntCounterThresholdImpl( Object* pOwner, int threshold , int offset ) : CounterThresholdImpl( pOwner, IntelMobileText("IntCounterThreshold") ){ SetThreshold( threshold ); if ( offset != 0 ) { SetOffset( offset ); }}//==============================================================================// GetThreshold() : //==============================================================================int IntCounterThresholdImpl::GetThreshold() { //return reinterpret_cast<ServerIntCounterThreshold*> (GetInterface())->GetThreshold(); //IPC support EnterCriticalSection(&m_csIpc); int retValue; vector<string> vectParam, vectRtn; vectParam.push_back(IntelMobileText("GetThreshold")); HRESULT hr = GetIpcClient()->IpcCall(m_nDataType, (GetInterface()), vectParam, vectRtn); if ( FAILED( hr ) ) { IntelMobileException ex( IntelMobileText("Error getting Threshold value"), m_sThresholdType.c_str(), IntelMobileText("GetThreshold"), hr ); LeaveCriticalSection(&m_csIpc); throw( ex );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -