|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : HWRMTestAppPropertyObserver.cpp 00004 * Part of : HWRMTestApp 00005 * Interface : 00006 * Description : Hardware Resource Manager server Light common data object 00007 * implementation 00008 * Version : 00009 * 00010 * Copyright (c) 2002-2006 Nokia Corporation. 00011 * This material, including documentation and any related 00012 * computer programs, is protected by copyright controlled by 00013 * Nokia Corporation. 00014 * ============================================================================== 00015 */ 00016 00017 // INCLUDE FILES 00018 #include <HWRMPowerStateSDKPSKeys.h> 00019 #include "HWRMTestAppContainer.h" 00020 #include "HWRMTestAppPropertyObserver.h" 00021 00022 00023 // ============================ MEMBER FUNCTIONS =============================== 00024 00025 // ----------------------------------------------------------------------------- 00026 // CHWRMTestAppPropertyObserver::CHWRMTestAppPropertyObserver 00027 // C++ constructor 00028 // ----------------------------------------------------------------------------- 00029 // 00030 CHWRMTestAppPropertyObserver::CHWRMTestAppPropertyObserver( 00031 const TUid aUid, const TUint32 aKey, 00032 const CHWRMTestAppContainer* aAppContainer ) 00033 : CActive(EPriority), iUid( aUid ), 00034 iKey( aKey ), iAppContainer( aAppContainer) 00035 { 00036 } 00037 00038 // ----------------------------------------------------------------------------- 00039 // CHWRMTestAppPropertyObserver::NewL 00040 // Two-phased constructor. 00041 // ----------------------------------------------------------------------------- 00042 // 00043 CHWRMTestAppPropertyObserver* CHWRMTestAppPropertyObserver::NewL( 00044 const TUid aUid, const TUint32 aKey, 00045 const CHWRMTestAppContainer* aAppContainer ) 00046 { 00047 CHWRMTestAppPropertyObserver* me= 00048 new(ELeave) CHWRMTestAppPropertyObserver( aUid, aKey, aAppContainer ); 00049 CleanupStack::PushL(me); 00050 me->ConstructL(); 00051 CleanupStack::Pop(me); 00052 return me; 00053 } 00054 00055 // ----------------------------------------------------------------------------- 00056 // CHWRMTestAppPropertyObserver::ConstructL 00057 // Symbian 2nd phase constructor can leave. 00058 // ----------------------------------------------------------------------------- 00059 // 00060 void CHWRMTestAppPropertyObserver::ConstructL() 00061 { 00062 User::LeaveIfError( iProperty.Attach( iUid, iKey ) ); 00063 00064 CActiveScheduler::Add(this); 00065 // initial subscription and process current property value 00066 RunL(); 00067 } 00068 00069 // ----------------------------------------------------------------------------- 00070 // CHWRMTestAppPropertyObserver::~CHWRMTestAppPropertyObserver 00071 // Destructor 00072 // ----------------------------------------------------------------------------- 00073 // 00074 CHWRMTestAppPropertyObserver::~CHWRMTestAppPropertyObserver() 00075 { 00076 Cancel(); 00077 iProperty.Close(); 00078 } 00079 00080 // ----------------------------------------------------------------------------- 00081 // CHWRMTestAppPropertyObserver::DoCancel 00082 // 00083 // ----------------------------------------------------------------------------- 00084 // 00085 void CHWRMTestAppPropertyObserver::DoCancel() 00086 { 00087 iProperty.Cancel(); 00088 } 00089 00090 // ----------------------------------------------------------------------------- 00091 // CHWRMTestAppPropertyObserver::RunL 00092 // 00093 // ----------------------------------------------------------------------------- 00094 // 00095 void CHWRMTestAppPropertyObserver::RunL() 00096 { 00097 // resubscribe before processing new value to prevent missing updates 00098 iProperty.Subscribe( iStatus ); 00099 SetActive(); 00100 00101 TBuf<100> msg; 00102 00103 switch( iKey ) 00104 { 00105 case KHWRMBatteryLevel: 00106 { 00107 _LIT(KBatteryLevel, "KHWRMBatteryLevel updated"); 00108 iAppContainer->AddMessageL( KBatteryLevel ); 00109 break; 00110 } 00111 case KHWRMBatteryStatus: 00112 { 00113 _LIT(KBatteryStatus, "KHWRMBatteryStatus updated"); 00114 iAppContainer->AddMessageL( KBatteryStatus ); 00115 break; 00116 } 00117 case KHWRMChargingStatus: 00118 { 00119 _LIT(KChargingStatus, "KHWRMChargingStatus updated"); 00120 iAppContainer->AddMessageL( KChargingStatus ); 00121 break; 00122 } 00123 default: 00124 break; 00125 } 00126 00127 // property updated, get new value 00128 TInt keyValue; 00129 if( iProperty.Get( keyValue ) == KErrNotFound ) 00130 { 00131 // property deleted, do necessary actions here... 00132 _LIT(KPropertyDeleted, "Property deleted!"); 00133 msg.Format( KPropertyDeleted ); 00134 } 00135 else 00136 { 00137 // use new value ... 00138 _LIT(KNewValue, "New value = %d"); 00139 msg.Format( KNewValue, keyValue ); 00140 } 00141 00142 iAppContainer->AddMessageL( msg ); 00143 } 00144 00145 // End of File 00146
|
© Nokia 2006 |