📄 base_classobject.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_ClassObject.cpp// Implementation of base class InstanceCollection//==============================================================================#include "base_ClassObject.h"#include "base_ClassObject_Impl.h"using namespace Intel::Mobile::BaseAPI;//==============================================================================// C_Tor()//==============================================================================ClassObject::ClassObject( IntelMobileChar* type, const IntelMobileChar* version, void *pImpl ) : EventClient( pImpl ){ if ( type ) { m_Type = ::strcpy( new IntelMobileChar[::strlen(type)+1], type ); } if ( version ) { m_Version = ::strcpy( new IntelMobileChar[::strlen(version)+1], version ); } m_pImpl = new ClassObjectImplPtr( new ClassObjectImpl( this, type, version ) );} //==============================================================================// D_Tor()//==============================================================================ClassObject::~ClassObject() { if ( m_pImpl ) // If we have a valid impl * delete the SMART POINTER object { if ( m_Type ) delete[] m_Type; if ( m_Version ) delete[] m_Version; ClassObjectImplPtr* pClassImpl = reinterpret_cast<ClassObjectImplPtr*>(m_pImpl); (*pClassImpl)->SetOwner( NULL ); // Remove this as owner of the impl. delete pClassImpl; }} //==============================================================================// GetType()//==============================================================================IntelMobileChar* ClassObject::GetType() const{ IntelMobileChar* pszType = NULL; if ( m_pImpl ) { pszType = ::strcpy( new IntelMobileChar[::strlen(m_Type)+1], m_Type ); } return pszType;} // GetType()//==============================================================================// GetVersion()//==============================================================================IntelMobileChar* ClassObject::GetVersion() const{ IntelMobileChar* pszVersion = NULL; if ( m_pImpl ) { pszVersion = ::strcpy( new IntelMobileChar[::strlen(m_Version)+1], m_Version ); } return pszVersion;} // GetVersion()//==============================================================================//==============================================================================// AddObserver() //==============================================================================bool ClassObject::AddObserver( Event::EventType eType, Observer& observer ){ if ( IsEventAvailable( eType ) ) { if ( m_pImpl ) { ClassObjectImplPtr spImpl = *reinterpret_cast<ClassObjectImplPtr*>(m_pImpl); return spImpl->AddObserver( eType, *reinterpret_cast<ObserverImpl*>(observer.GetImpl()) ); } } else { IntelMobileException ex( IntelMobileText("ClassObject : NotSupportEvent Exception"), IntelMobileText("AddObserver"), IntelMobileText("AddObserver") ); throw( ex ); } return false;} // AddObserver() //==============================================================================// 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 ClassObject::RemoveObserver( Event::EventType eType, Observer& observer ){ if ( IsEventAvailable( eType ) ) { if ( m_pImpl ) { ClassObjectImplPtr spImpl = *reinterpret_cast<ClassObjectImplPtr*>(m_pImpl); return spImpl->RemoveObserver( eType, *reinterpret_cast<ObserverImpl*>(observer.GetImpl()) ); } } else { IntelMobileException ex( IntelMobileText("ClassObject : NotSupportEvent Exception"), IntelMobileText("RemoveObserver"), IntelMobileText("RemoveObserver") ); throw( ex ); } return false;} // RemoveObserver() //==============================================================================// IsEventAvailable() : //==============================================================================bool ClassObject::IsEventAvailable( Event::EventType eType ) { if ( m_pImpl ) { ClassObjectImplPtr spImpl = *reinterpret_cast<ClassObjectImplPtr*>(m_pImpl); return spImpl->IsEventAvailable( eType ); } return false;} // IsEventAvailable()//==============================================================================// GetInstances() : Get the collection interface and return it in a wrapper.//==============================================================================InstanceCollection* ClassObject::GetInstances( const IntelMobileChar* sType ){ InstanceCollection *pCollectionWrapper = NULL; if ( m_pImpl ) { ClassObjectImplPtr spImpl = *reinterpret_cast<ClassObjectImplPtr*>(m_pImpl); InstanceCollectionImplPtr spCollection = spImpl->GetInstances( sType ); if ( spCollection ) { pCollectionWrapper = new InstanceCollection( new InstanceCollectionImplPtr( spCollection ) ); } } return pCollectionWrapper;} // GetInstances()//==============================================================================// GetInstance() : Get a specific instance interface //==============================================================================InstanceObject* ClassObject::GetInstance( const IntelMobileChar* sKey ) { InstanceObject *pInstanceWrapper = NULL; if ( m_pImpl ) { ClassObjectImplPtr spImpl = *reinterpret_cast<ClassObjectImplPtr*>(m_pImpl); InstanceObjectImplPtr spInstance = spImpl->GetInstance( sKey ); if ( spInstance ) { pInstanceWrapper = new InstanceObject( new InstanceObjectImplPtr( spInstance ) ); } } return pInstanceWrapper;} // GetInstance() //==============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -