sysstatemgmt/ssmutilityplugins/ssmpowersup/src/ssmpowersup.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2009 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: Implementation of CSsmPowerSup class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <ssm/ssmclayer.h>
       
    19 #include <ssm/ssmstatemanager.h>
       
    20 #include <ssm/starterclient.h>
       
    21 
       
    22 #include "ssmpowersup.h"
       
    23 #include "trace.h"
       
    24 
       
    25 // ======== LOCAL FUNCTIONS ========
       
    26 
       
    27 static TInt ShutdownWithReason( const TInt aReason )
       
    28     {
       
    29     FUNC_LOG;
       
    30 
       
    31     RSsmStateManager session;
       
    32     TInt errorCode = session.Connect();
       
    33     ERROR( errorCode, "Failed to connect to RSsmStateManager" );
       
    34 
       
    35     if ( errorCode == KErrNone )
       
    36         {
       
    37         TUint16 mainstate = ESsmShutdown;
       
    38         TUint16 substate = KSsmAnySubState;
       
    39         TInt reason = aReason;
       
    40         TSsmStateTransition stateinfo( mainstate, substate, reason );
       
    41 
       
    42         // Make request and ignore return value
       
    43         session.RequestStateTransition( stateinfo );
       
    44         session.Close();
       
    45         }
       
    46 
       
    47     return errorCode;
       
    48     }
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CSsmPowerSup::NewL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C MSsmUtility* CSsmPowerSup::NewL()
       
    57 	{
       
    58     FUNC_LOG;
       
    59 
       
    60 	CSsmPowerSup* self = new ( ELeave ) CSsmPowerSup;
       
    61 	return self;
       
    62 	}
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CSsmPowerSup::~CSsmPowerSup
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CSsmPowerSup::~CSsmPowerSup()
       
    70     {
       
    71     FUNC_LOG;
       
    72 
       
    73     Cancel();
       
    74     iAdaptation.Close();
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CSsmPowerSup::RunL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CSsmPowerSup::RunL()
       
    83 	{
       
    84     FUNC_LOG;
       
    85 
       
    86     TInt errorCode = iStatus.Int();
       
    87     ERROR( errorCode, "RSsmStateAdaptation::NotifyCoopSysEvent completed with error" );
       
    88 
       
    89     if ( errorCode == KErrNone )
       
    90         {
       
    91         if ( iEventBuf() == ESsmShutdownDevice )
       
    92             {
       
    93             INFO( "DOS-originated shutdown" );
       
    94             errorCode = ShutdownWithReason( KSsmCLayerPowerOffReason );
       
    95             }
       
    96         else if ( iEventBuf() == ESsmRestartDevice ||
       
    97                   iEventBuf() == ESsmFatalCoopSysError )
       
    98             {
       
    99             INFO( "DOS-originated reset" );
       
   100             errorCode = ShutdownWithReason( RStarterSession::EUnknownReset );
       
   101             }
       
   102         }
       
   103     else if ( errorCode != KErrServerTerminated )
       
   104         {
       
   105         Activate();
       
   106         }
       
   107 	}
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CSsmPowerSup::DoCancel()
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CSsmPowerSup::DoCancel()
       
   115     {
       
   116     FUNC_LOG;
       
   117 
       
   118     iAdaptation.NotifyCancel();
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CSsmPowerSup::InitializeL()
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CSsmPowerSup::InitializeL()
       
   127     {
       
   128     FUNC_LOG;
       
   129 
       
   130     User::LeaveIfError( iAdaptation.Connect() );
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CSsmPowerSup::StartL()
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CSsmPowerSup::StartL()
       
   139     {
       
   140     FUNC_LOG;
       
   141 
       
   142     Activate();
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CSsmPowerSup::Release()
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CSsmPowerSup::Release()
       
   151     {
       
   152     FUNC_LOG;
       
   153 
       
   154 	delete this;
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CSsmPowerSup::CSsmPowerSup
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 CSsmPowerSup::CSsmPowerSup() : CActive( EPriorityNormal )
       
   163     {
       
   164     FUNC_LOG;
       
   165 
       
   166 	CActiveScheduler::Add( this );
       
   167     }
       
   168 
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CSsmPowerSup::Activate
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CSsmPowerSup::Activate()
       
   175     {
       
   176     FUNC_LOG;
       
   177 
       
   178     ASSERT_TRACE( !IsActive() );
       
   179 
       
   180     iAdaptation.NotifyCoopSysEvent( iEventBuf, iStatus );
       
   181     SetActive();
       
   182     }