systemswstubs/hwrmstubplugins/src/PowerStatePlugin.cpp
changeset 0 0ce1b5ce9557
equal deleted inserted replaced
-1:000000000000 0:0ce1b5ce9557
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Hardware Resource Manager stub plugins Power State plugin 
       
    15 *                implementation.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <hwrmpowerstatesdkpskeys.h>
       
    21 #include "PowerStatePlugin.h"
       
    22 
       
    23 
       
    24 //CONSTANTS
       
    25 #ifdef ENABLE_NOTIFICATIONS
       
    26     // Timer begins triggering notifications after this time period
       
    27     const TInt KDelay(5000000);      //5 seconds
       
    28     // Timer triggers notifications at this time interval
       
    29     const TInt KInterval(5000000);   //5 seconds
       
    30 #endif
       
    31 
       
    32 
       
    33 CPowerStatePlugin* CPowerStatePlugin::NewL()
       
    34     {
       
    35     CPowerStatePlugin* self = new(ELeave) CPowerStatePlugin();
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop();
       
    39     return self;
       
    40     }
       
    41 
       
    42 CPowerStatePlugin::~CPowerStatePlugin()
       
    43     {
       
    44 #ifdef ENABLE_NOTIFICATIONS
       
    45     delete iPeriodic;
       
    46 #endif
       
    47     }
       
    48 
       
    49 CPowerStatePlugin::CPowerStatePlugin() : iKey( KHWRMBatteryLevel ),
       
    50                                          iKeyValue( EBatteryLevelUnknown )
       
    51     {
       
    52     }
       
    53 
       
    54 void CPowerStatePlugin::ConstructL()
       
    55     {
       
    56     // Only send periodic notifications if flag is defined
       
    57 #ifdef ENABLE_NOTIFICATIONS
       
    58     RDebug::Print( _L("HWRM PowerStatePlugin: Notifications enabled.") );
       
    59     // Use CPeriodic to generate state changes
       
    60     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
    61     
       
    62     // Start the timer after KDelay and for every KInterval
       
    63     iPeriodic->Start( KDelay, KInterval,
       
    64                       TCallBack( CPowerStatePlugin::Callback, this ) );
       
    65 #else
       
    66     RDebug::Print( _L("HWRM PowerStatePlugin: Notifications disabled.") );
       
    67 #endif
       
    68     }
       
    69 
       
    70 TInt CPowerStatePlugin::Callback( TAny* aPtr )
       
    71     {
       
    72     CPowerStatePlugin* ptr = (CPowerStatePlugin*) aPtr;
       
    73     // use callback to call the notification method in the plugin callback
       
    74     RDebug::Print( _L("HWRM PowerStatePlugin: Key=%d, Value=%d"), ptr->iKey, ptr->iKeyValue );
       
    75     TRAPD( err, ptr->iNotificationCallback->NotifyStateChange(
       
    76                                                 ptr->iKey, ptr->iKeyValue ) );
       
    77     ptr->IncrementKeyAndValue();
       
    78     
       
    79     return err;
       
    80     }
       
    81 
       
    82 void CPowerStatePlugin::IncrementKeyAndValue()
       
    83     {
       
    84     switch( iKey )
       
    85         {
       
    86         case KHWRMBatteryLevel:
       
    87             {
       
    88             // key has values -1 to 7
       
    89             if( iKeyValue == EBatteryLevelLevel7 )
       
    90                 {
       
    91                 // last value so set next key
       
    92                 iKey = KHWRMBatteryStatus;
       
    93                 iKeyValue = EBatteryStatusUnknown;
       
    94                 }
       
    95             else
       
    96                 {
       
    97                 // Otherwise just increment it
       
    98                 iKeyValue++;
       
    99                 }
       
   100             break;
       
   101             }
       
   102         case KHWRMBatteryStatus:
       
   103             {
       
   104             // key has values -1 to 2
       
   105             if( iKeyValue == EBatteryStatusEmpty )
       
   106                 {
       
   107                 // last value so set next key
       
   108                 iKey = KHWRMChargingStatus;
       
   109                 iKeyValue = EChargingStatusError;
       
   110                 }
       
   111             else
       
   112                 {
       
   113                 // Otherwise just increment it
       
   114                 iKeyValue++;
       
   115                 }
       
   116             break;
       
   117             }
       
   118         case KHWRMChargingStatus:
       
   119             {
       
   120             // key has values -1 to 5
       
   121             if( iKeyValue == EChargingStatusChargingContinued )
       
   122                 {
       
   123                 // last value so set next key
       
   124                 iKey = KHWRMBatteryLevel;
       
   125                 iKeyValue = EBatteryLevelUnknown;
       
   126                 }
       
   127             else
       
   128                 {
       
   129                 // Otherwise just increment it
       
   130                 iKeyValue++;
       
   131                 }
       
   132             break;
       
   133             }
       
   134         default:
       
   135             break;
       
   136         }
       
   137     }