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

📄 base_threshold_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.

*/#include "./base_Threshold_Impl.h"  #include "./base_Observer_Impl.h"#include "./base_Exception.h"#include "IntelMobile/Ipc_Support.h"////////////////////////////////////////////////////////////////////////////////// Base Class for all Thresholds//==============================================================================// C-Tor() : Default constructor//==============================================================================ThresholdImpl::ThresholdImpl( Object*  pOwner,                               IntelMobileChar* sType )             : EventClientImpl      ( pOwner, IntelMobileText("Threshold") )             , m_sThresholdType     ( sType  )			 , m_pSvrThresholdObject  ( NULL   )             , m_spObservedProperty ( NULL   ){}//==============================================================================// D-Tor() : //==============================================================================ThresholdImpl::~ThresholdImpl(){	if (m_pSvrThresholdObject != NULL )	{		//delete m_pSvrThresholdObject;	 	EnterCriticalSection(&m_csIpc);		RELEASE( m_pSvrThresholdObject );	 	LeaveCriticalSection(&m_csIpc);		//IPC support		/*        int Type = ID_TYPE_RELEASE;        vector<string> vectParam, vectRtn;        //vectParam.push_back(IntelMobileText("Release"));        HRESULT hr = GetIpcClient()->IpcCall(Type, m_pSvrThresholdObject, vectParam, vectRtn);		*/	}	if ( m_spObservedProperty != NULL )    {        // Decrement the reference count on the parent        // instance to make sure it CAN go out of scope.        m_spObservedProperty->GetInstance()->Release();    }}//==============================================================================// operator==()//==============================================================================bool ThresholdImpl::operator==( const ObjectImpl& rhs ) const{    const ThresholdImpl& cmp = reinterpret_cast<const ThresholdImpl&>(rhs);        return ( m_sThresholdType     == cmp.m_sThresholdType  &&      // Cheap             *m_spObservedProperty == *(cmp.m_spObservedProperty) ); // REAL expensive.} // operator==()//==============================================================================// GetType()//==============================================================================IntelMobileChar* ThresholdImpl::GetType() const{ #ifdef _UNICODE    return ::wcscpy( new IntelMobileChar[m_sThresholdType.length()+1], m_sThresholdType.c_str() ); #else    return ::strcpy( new IntelMobileChar[m_sThresholdType.length()+1], m_sThresholdType.c_str() ); #endif}//==============================================================================// GetGranularityPeriod()//==============================================================================long ThresholdImpl::GetGranularityPeriod()  { 	EnterCriticalSection(&m_csIpc);    long nGranularityPeriod = 0;	//nGranularityPeriod = GetInterface()->GetGranularityPeriod( );	//IPC support    vector<string> vectParam, vectRtn;	    vectParam.push_back(IntelMobileText("GetGranularityPeriod"));	    HRESULT hr = GetIpcClient()->IpcCall(m_nDataType,GetInterface(), vectParam, vectRtn);	if ( FAILED ( hr ) )    {        IntelMobileException ex( IntelMobileText("No server connection"),                             IntelMobileText("Threshold"),                             IntelMobileText("GetGranularityPeriod"), hr );		LeaveCriticalSection(&m_csIpc);        throw( ex );    }	else	{		CStringHelper::Str2Param(vectRtn[0], nGranularityPeriod);	    		LeaveCriticalSection(&m_csIpc);		return nGranularityPeriod;	}} // GetGranularityPeriod()//==============================================================================// GetObservedProperty()//==============================================================================PropertyBaseImplPtr ThresholdImpl::GetObservedProperty() const {     return m_spObservedProperty;      } // GetObservedProperty()    //==============================================================================// SetObservedProperty()//==============================================================================bool ThresholdImpl::SetObservedProperty( PropertyBaseImplPtr spProperty ) { 	void* pIProp = spProperty->GetSvrProperty();		if ( pIProp != NULL )    {		//GetInterface()->SetObservedProperty( pIProp );		//IPC support		vector<string> vectParam, vectRtn;	 	EnterCriticalSection(&m_csIpc);        vectParam.push_back(IntelMobileText("SetObservedProperty"));	    //vectParam.push_back(CStringHelper::Param2Str(pIProp));	    //CHAR szBuf[MAX_PATH];        //memset(szBuf, 0, sizeof(CHAR) * MAX_PATH);        //sprintf(szBuf,  ("%d"), &(*pIProp));        vectParam.push_back(CStringHelper::Param2Str((HANDLE)pIProp));				HRESULT hr = GetIpcClient()->IpcCall(m_nDataType,GetInterface(), vectParam, vectRtn);	 	LeaveCriticalSection(&m_csIpc);		if ( FAILED ( hr ) )		{			m_spObservedProperty = NULL;			IntelMobileException ex( IntelMobileText("Invalid Property"), 								IntelMobileText("Threshold"), 								IntelMobileText("SetObservedProperty"), hr );			throw( ex );		}		else		{			// If we have a prior property that was being observed, 'release' 			// the additional reference on the instance object.			if ( m_spObservedProperty != NULL )  			{                                      				m_spObservedProperty->GetInstance()->Release();						}			m_spObservedProperty = spProperty;			// Increment the reference count on the parent			// instance to make sure it does not go out of scope.			m_spObservedProperty->GetInstance()->AddRef();			//return SetObserverEvent();    		return SUCCEEDED( hr );		}    }    else    {        m_spObservedProperty = NULL;        IntelMobileException ex( IntelMobileText("Invalid Property"),                             IntelMobileText("Threshold"),                             IntelMobileText("SetObservedProperty"));        throw( ex );    }    return true;} // SetObservedProperty()    //==============================================================================// SetGranularityPeriod()//==============================================================================bool ThresholdImpl::SetGranularityPeriod( long nPeriod ){ 	if ( m_spObservedProperty ) // Only if the property has been set    {        //GetInterface()->SetGranularityPeriod( nPeriod );		//IPC support		vector<string> vectParam, vectRtn;	 	EnterCriticalSection(&m_csIpc);		vectParam.push_back(IntelMobileText("SetGranularityPeriod"));		vectParam.push_back(CStringHelper::Param2Str(nPeriod));	    HRESULT hr = GetIpcClient()->IpcCall(m_nDataType,GetInterface(), vectParam, vectRtn);	 	LeaveCriticalSection(&m_csIpc);		return SUCCEEDED( hr );    }    return false;} // SetGranularityPeriod()//==============================================================================// GetObserverCount() : //==============================================================================unsigned int ThresholdImpl::GetObserverCount()  {     unsigned int nCount = 0;    m_vObservers.Lock();    nCount = static_cast<unsigned int>(m_vObservers.size());      m_vObservers.Unlock();    return nCount;  } // GetObserverCount()//==============================================================================// GetObserver() : //==============================================================================const ObserverImpl* ThresholdImpl::GetObserver( unsigned int nIndex )  {     const ObserverImpl* pObserver = NULL;    m_vObservers.Lock();    if ( nIndex < static_cast<unsigned int>(m_vObservers.size()) )    {        pObserver = m_vObservers.at( nIndex ).first;     }    m_vObservers.Unlock();    return pObserver; } // GetObserver()//==============================================================================// Start()  //==============================================================================bool ThresholdImpl::Start(){	SubscribeEvent( Event::eUnknown );    	return true;} // Start() //==============================================================================// SubscribeEvent()  //==============================================================================HRESULT ThresholdImpl::SubscribeEvent( Event::EventType eType ){		//m_pSvrThresholdObject->SetActive( true );	//IPC support	//HRESULT S_OK;	vector<string> vectParam, vectRtn;

⌨️ 快捷键说明

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