📄 base_threshold.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.
*///==============================================================================// base_Threshold.cpp // Implementation of base class Threshold//==============================================================================#include "base_Threshold.h" #include "base_Observer.h"#include "base_Exception.h"#include "IntelMobile/Base/base_Exception.h"#include "IntelMobile/Base/base_Threshold.h"#include "../ObserverWrapper.h"using namespace Intel::Mobile::Base;////////////////////////////////////////////////////////////////////////////////// Base Class for all Thresholdsnamespace Intel{ namespace Mobile { namespace Base { //==============================================================================
// C-Tor() : Default constructor
//==============================================================================
Threshold::Threshold()
: Object( NULL ),
m_pObservedProperty( NULL )
{
}
Threshold::Threshold(void *pImpl)
: Object(pImpl),
m_pObservedProperty( NULL )
{
}
//==============================================================================
// D-Tor() :
//==============================================================================
Threshold::~Threshold()
{
if (m_pObservedProperty)
delete m_pObservedProperty;
} //============================================================================== // GetType() //============================================================================== StringObject Threshold::GetType() const { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { TRYBLOCK { IntelMobileChar* pType = pAPI_Threshold->GetType(); StringObject sType( pType ); delete[] pType; return sType; } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetType")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetType")); } // GetType() //============================================================================== // GetGranularityPeriod() : //============================================================================== __int32 Threshold::GetGranularityPeriod() const { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { TRYBLOCK { return pAPI_Threshold->GetGranularityPeriod(); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetGranularityPeriod")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetGranularityPeriod")); } // GetGranularityPeriod() //============================================================================== // GetObservedProperty() : //============================================================================== const Intel::Mobile::Base::Property& Threshold::GetObservedProperty () const { //Intel::Mobile::Base::Property* pProperty = NULL;
if (m_pObservedProperty == NULL)
{
if ( m_pImpl )
{
Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl);
if ( pAPI_Threshold )
{
void *pAPI_Property = NULL;
{ TRYBLOCK { pAPI_Property = (void *)(&(pAPI_Threshold->GetObservedProperty())); } CATCHBLOCK }
Intel::Mobile::Base::Threshold* pThisThreshold = const_cast<Intel::Mobile::Base::Threshold*>(this);
pThisThreshold->CreateObservedProperty( pAPI_Property );
}
}
}
if (m_pObservedProperty)
return *m_pObservedProperty;
else
THROWNE("Intel::Mobile::Base::Threshold", "GetObservedProperty"); } // GetObservedProperty() //==============================================================================
// CreateObservedProperty() :
//==============================================================================
void Threshold::CreateObservedProperty (void * pProperty)
{
if (pProperty)
{
Intel::Mobile::BaseAPI::Property* pAPI_Property = reinterpret_cast<Intel::Mobile::BaseAPI::Property*>(pProperty);
IntelMobileChar* sType = ((Intel::Mobile::BaseAPI::Property *)pAPI_Property)->GetType();
m_pObservedProperty = CObserverWrapper::CreateProperty(sType, pAPI_Property);
delete[] sType;
}
}
//==============================================================================
// ResetPorperty() :
//==============================================================================
void Threshold::ResetProperty ()
{
if (m_pObservedProperty)
{
delete m_pObservedProperty;
m_pObservedProperty = NULL;
}
} //============================================================================== // SetGranularityPeriod() : //============================================================================== bool Threshold::SetGranularityPeriod( __int32 nPeriod ) { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { TRYBLOCK { return pAPI_Threshold->SetGranularityPeriod( nPeriod ); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("SetGranularityPeriod")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("SetGranularityPeriod")); } // SetGranularityPeriod() //============================================================================== // GetObserverCount() : //============================================================================== unsigned __int32 Threshold::GetObserverCount() const { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { TRYBLOCK { return pAPI_Threshold->GetObserverCount(); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetObserverCount")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetObserverCount")); } // GetObserverCount() //============================================================================== // GetObserver() : //============================================================================== const Intel::Mobile::Base::Observer& Threshold::GetObserver( unsigned __int32 nIndex ) const { if (m_pImpl) { Intel::Mobile::BaseAPI::Threshold *pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { const Intel::Mobile::BaseAPI::Observer& API_Observer = pAPI_Threshold->GetObserver( nIndex ); CObserverWrapper* pObserverWrapper = (CObserverWrapper*)(&API_Observer); //any problem??? if (pObserverWrapper) { Observer *pObserver = reinterpret_cast<Observer*>(pObserverWrapper->GetObserver()); if (pObserver) { return *pObserver; } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetObserver")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetObserver")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetObserver")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("GetObserver")); } // GetObserver() //============================================================================== // AddObserver() : //============================================================================== bool Threshold::AddObserver( Intel::Mobile::Base::Observer& observer ) { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); void *pObserver = observer.GetWrapper(); if ( pObserver && pAPI_Threshold ) { Intel::Mobile::BaseAPI::Observer* pAPI_Observer = reinterpret_cast<Intel::Mobile::BaseAPI::Observer*>(pObserver); if ( pAPI_Observer ) { TRYBLOCK { return pAPI_Threshold->AddObserver( *pAPI_Observer ); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("AddObserver")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("AddObserver")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("AddObserver")); } // AddObserver() //============================================================================== // RemoveObserver() : //============================================================================== bool Threshold::RemoveObserver( Observer& observer ) { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); void *pObserver = observer.GetWrapper(); if ( pObserver && pAPI_Threshold ) { Intel::Mobile::BaseAPI::Observer* pAPI_Observer = reinterpret_cast<Intel::Mobile::BaseAPI::Observer*>(pObserver); if ( pAPI_Observer ) { TRYBLOCK { return pAPI_Threshold->RemoveObserver( *pAPI_Observer ); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("RemoveObserver")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("RemoveObserver")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("RemoveObserver")); } // RemoveObserver() //============================================================================== // RemoveObservers() : //============================================================================== bool Threshold::RemoveObservers() { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { TRYBLOCK { return pAPI_Threshold->RemoveObservers(); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("RemoveObservers")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("RemoveObservers")); } // RemoveObservers() //============================================================================== // Start() : //============================================================================== bool Threshold::Start() { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { TRYBLOCK { return pAPI_Threshold->Start(); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("Start")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("Start")); } // Start() //============================================================================== // Stop() : //============================================================================== bool Threshold::Stop() { if ( m_pImpl ) { Intel::Mobile::BaseAPI::Threshold* pAPI_Threshold = reinterpret_cast<Intel::Mobile::BaseAPI::Threshold*>(m_pImpl); if (pAPI_Threshold) { TRYBLOCK { return pAPI_Threshold->Stop(); } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("Stop")); } else THROWNE(IntelMobileText("Intel::Mobile::Base::Threshold"), IntelMobileText("Stop")); } // Stop() } }}//==============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -