📄 base_event.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_Event.cpp : Implementation of the class Event//==============================================================================// Added new attribute m_pszClassType to hold the class type.////==============================================================================#include "base_Event.h"#include "base_EventClient_Impl.h"using namespace Intel::Mobile::BaseAPI;//==============================================================================// C-Tor()//==============================================================================Event::Event( EventType eType, void* pReciever, const IntelMobileChar* pszObjectType, const IntelMobileChar* pszObjectKey, const IntelMobileChar* pszClassType, const IntelMobileChar* pszParentKey ) : EventBase ( eType ), m_pReciever ( pReciever ), m_pszObjectType( NULL ), m_pszObjectKey ( NULL ), m_pszClassType ( NULL ), m_pszParentKey ( NULL ){ if ( pszObjectType ) { m_pszObjectType = strcpy( new IntelMobileChar[::strlen(pszObjectType)+1], pszObjectType ); } if ( pszObjectKey ) { m_pszObjectKey = ::strcpy( new IntelMobileChar[::strlen(pszObjectKey)+1], pszObjectKey ); } // Added block for new class type attribute. if ( pszClassType ) { m_pszClassType = ::strcpy( new IntelMobileChar[::strlen(pszClassType)+1], pszClassType ); } if ( pszParentKey ) { m_pszParentKey = ::strcpy( new IntelMobileChar[::strlen(pszParentKey)+1], pszParentKey ); }} // C-Tor()//==============================================================================// D-Tor()//==============================================================================Event::~Event() { delete[] m_pszObjectType; delete[] m_pszObjectKey; delete[] m_pszClassType; delete[] m_pszParentKey; //XXX: CE code comment this out //delete reinterpret_cast<EventClientImplPtr*>(m_pReciever);}Event::Event(const Event& rhs){ if ( rhs.m_pszObjectType ) { m_pszObjectType = strcpy( new IntelMobileChar[::strlen(rhs.m_pszObjectType)+1], rhs.m_pszObjectType ); } if ( rhs.m_pszObjectKey ) { m_pszObjectKey = ::strcpy( new IntelMobileChar[::strlen(rhs.m_pszObjectKey)+1], rhs.m_pszObjectKey ); } // Added block for new class type attribute. if ( rhs.m_pszClassType ) { m_pszClassType = ::strcpy( new IntelMobileChar[::strlen(rhs.m_pszClassType)+1], rhs.m_pszClassType ); } if ( rhs.m_pszParentKey ) { m_pszParentKey = ::strcpy( new IntelMobileChar[::strlen(rhs.m_pszParentKey)+1], rhs.m_pszParentKey ); } //XXX: this is potential double free issue!! m_pReciever = rhs.m_pReciever; m_eType = rhs.m_eType; m_tTimestamp = rhs.m_tTimestamp; m_processId = rhs.m_processId;}//==============================================================================// SetObjectType()//==============================================================================void Event::SetObjectType( const IntelMobileChar* pszObjectType ) { delete m_pszObjectType; m_pszObjectType = new IntelMobileChar[::strlen(pszObjectType)+1]; if ( m_pszObjectType ) { ::strcpy( m_pszObjectType, pszObjectType ); }} // SetObjectType()//==============================================================================// SetObjectKey()//==============================================================================void Event::SetObjectKey( const IntelMobileChar* pszObjectKey ) { delete[] m_pszObjectKey; m_pszObjectKey = new IntelMobileChar[::strlen(pszObjectKey)+1]; if ( m_pszObjectKey ) { ::strcpy( m_pszObjectKey, pszObjectKey ); }} // SetObjectKey()//==============================================================================// SetClassType() : // //==============================================================================void Event::SetClassType( const IntelMobileChar* pszClassType ) { delete[] m_pszClassType; m_pszClassType = new IntelMobileChar[::strlen(pszClassType)+1]; if ( m_pszClassType ) { ::strcpy( m_pszClassType, pszClassType ); }} // SetClassType()//==============================================================================// SetParentKey()//==============================================================================void Event::SetParentKey( const IntelMobileChar* pszParentKey ) { delete[] m_pszParentKey; m_pszParentKey = new IntelMobileChar[::strlen(pszParentKey)+1]; if ( m_pszParentKey ) { ::strcpy( m_pszParentKey, pszParentKey ); }} // SetParentKey()//==============================================================================// GetOriginator()//==============================================================================const Object* Event::GetOriginator() const{ Object* pOriginator = NULL; if ( m_pReciever ) { EventClientImplPtr spReciever = *reinterpret_cast<EventClientImplPtr*>(m_pReciever) ; pOriginator = spReciever->GetOwner(); } return pOriginator;} // GetOriginator() //==============================================================================// GetObjectType()//==============================================================================const IntelMobileChar* Event::GetObjectType() const { return m_pszObjectType; } // GetObjectType()//==============================================================================// GetObjectKey()//==============================================================================const IntelMobileChar* Event::GetObjectKey() const { return m_pszObjectKey; } // GetObjectKey()//==============================================================================// GetClassType()////==============================================================================const IntelMobileChar* Event::GetClassType() const { return m_pszClassType; } // GetClassType()//==============================================================================// GetParentKey()//==============================================================================const IntelMobileChar* Event::GetParentKey() const { return m_pszParentKey; } // GetParentKey()//==============================================================================// GetTypeName()//==============================================================================const IntelMobileChar* Event::GetTypeName() const{ return GetTypeName( m_eType );} // GetTypeName()const IntelMobileChar* Event::GetTypeName( Event::EventType eType ){ const IntelMobileChar* pszName = IntelMobileText("Unknown"); switch ( eType ) { case eNone: pszName = IntelMobileText("None"); break; case eChanged: pszName = IntelMobileText("Changed"); break; case eAdded: pszName = IntelMobileText("Added"); break; case eRemoved: pszName = IntelMobileText("Removed"); break; case eConnected: pszName = IntelMobileText("Connected"); break; case eDisconnected: pszName = IntelMobileText("Disconnected"); break; case eRouteTableChanged: pszName = IntelMobileText("RouteTableChanged"); break; case eIpAddressChanged: pszName = IntelMobileText("IpAddressChanged"); break; // case eActivate: pszName = IntelMobileText("Activate"); break; // case eDeactivate: pszName = IntelMobileText("Deactivate"); break; case eMediaConnected: pszName = IntelMobileText("MediaConnected"); break; case eMediaDisconnected: pszName = IntelMobileText("MediaDisconnected"); break; case eStatusChanged: pszName = IntelMobileText("StatusChanged"); break; case eThresholdReached: pszName = IntelMobileText("ThresholdReached"); break; case eThresholdLow: pszName = IntelMobileText("ThresholdLow"); break; case eThresholdHigh: pszName = IntelMobileText("ThresholdHigh"); break; case eThresholdEqual: pszName = IntelMobileText("ThresholdEqual"); break; case eThresholdDiffer: pszName = IntelMobileText("ThresholdDiffer"); break; // ======== Platform events ===================== case eShutdownRequested: pszName = IntelMobileText("ShutdownRequested"); break; case eSuspendRequested: pszName = IntelMobileText("SuspendRequested"); break; case eShuttingDown: pszName = IntelMobileText("ShuttingDown"); break; case eSuspending: pszName = IntelMobileText("Suspending"); break; case eResumedCritically: pszName = IntelMobileText("ResumedCritically"); break; case eResumedNormally: pszName = IntelMobileText("ResumedNormally"); break; // ======== Platform events ===================== // ======== Power events ===================== case eInternallyPowered: pszName = IntelMobileText("InternallyPowered"); break; case eExternallyPowered: pszName = IntelMobileText("ExternallyPowered"); break; case eFullyCharged: pszName = IntelMobileText("FullyCharged"); break; // ======== Power events ===================== // ======== Battery events =================== case eScreenBlanked: pszName = IntelMobileText("ScreenBlanked"); break; case eScreenUnblanked: pszName = IntelMobileText("ScreenUnblanked"); break; // ======== Battery events =================== // ======== Display events =================== case eGoingOffline: pszName = IntelMobileText("GoingOffline"); break; case ePoweringSystem: pszName = IntelMobileText("PoweringSystem"); break; // ======== Display events =================== case eBandwidthChanged: pszName = IntelMobileText("BandwidthChanged"); break; //===== WWAN events ===== case eEnteringCoverage: pszName = IntelMobileText("EnteringCoverage"); break; case eLeavingCoverage: pszName = IntelMobileText("LeavingCoverage"); break; case eCallIncoming: pszName = IntelMobileText("CallIncoming"); break; case eCallConnecting: pszName = IntelMobileText("CallConnecting"); break; case eCallConnected: pszName = IntelMobileText("CallConnected"); break; case eCallDisconnected: pszName = IntelMobileText("CallDisconnected"); break; case eReset: pszName = IntelMobileText("Reset"); break; case eEnteringPowerSave: pszName = IntelMobileText("EnteringPowerSave"); break; case eLeavingPowerSave: pszName = IntelMobileText("LeavingPowerSave"); break; //====================== //===== 802.11 events ====== case eAssociated: pszName = IntelMobileText("Associated"); break; case eDisassociated: pszName = IntelMobileText("Disassociated"); break; case eStatisticsReset: pszName = IntelMobileText("StatisticsReset"); break; //====================== //===== Radio Adapter events ==== case eHardwareRadioDisabled: pszName = IntelMobileText("HardwareRadioDisabled"); break; case eHardwareRadioEnabled: pszName = IntelMobileText("HardwareRadioEnabled"); break; case eSoftwareRadioDisabled: pszName = IntelMobileText("SoftwareRadioDisabled"); break; case eSoftwareRadioEnabled: pszName = IntelMobileText("SoftwareRadioEnabled"); break; //===== Radio Adapter events ==== default: pszName = IntelMobileText("Unknown"); } return pszName;} // GetTypeName()//==============================================================================// GetTSstring()//==============================================================================const IntelMobileChar* Event::GetTSstring () const{ static IntelMobileChar pszTime[1024]; time_t tNow = ::time(NULL); struct tm* tmEventTime = ::localtime( &m_tTimestamp ); //struct tm* tmEventTime = ::localtime( &tNow ); //cout << "tNow " << tNow << endl; //cout << "m_tTimestamp " << m_tTimestamp << endl; strftime( pszTime, sizeof(pszTime), IntelMobileText("%m/%d/%y %H:%M:%S "), tmEventTime ); return pszTime;} // GetTSstring()//==============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -