resourcemgmt/hwresourcesmgr/client/src/HWRMGenericAsyncObserver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "HWRMGenericAsyncObserver.h"
       
    20 #include "HWRMTrace.h"
       
    21 
       
    22 // ============================ MEMBER FUNCTIONS ===============================
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CHWRMGenericAsyncObserver::CHWRMGenericAsyncObserver
       
    26 // C++ constructor can NOT contain any code, that
       
    27 // might leave.
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CHWRMGenericAsyncObserver::CHWRMGenericAsyncObserver(RHWRMClient& aClient, 
       
    31                                                      TInt aCommand,
       
    32                                                      MHWRMGenericAsyncObserver* aCallback)
       
    33     : CActive(EPriorityStandard), 
       
    34       iCallback(aCallback),
       
    35       iCommand(aCommand),
       
    36       iClient(aClient)
       
    37     {
       
    38     COMPONENT_TRACE3(_L( "HWRM Client - CHWRMGenericAsyncObserver::CHWRMGenericAsyncObserver(0x%x, 0x%x, 0x%x)" ), &aClient, aCommand, aCallback);
       
    39 
       
    40     CActiveScheduler::Add(this);
       
    41 
       
    42     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::CHWRMGenericAsyncObserver - return" ) );
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CHWRMGenericAsyncObserver::NewL
       
    47 // Two-phased constructor
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CHWRMGenericAsyncObserver* CHWRMGenericAsyncObserver::NewL(RHWRMClient& aClient, 
       
    51                                                            TInt aCommand,
       
    52                                                            TInt aInitialCommand,
       
    53                                                            MHWRMGenericAsyncObserver* aCallback)
       
    54     {
       
    55 
       
    56     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::NewLC()" ) );
       
    57 
       
    58     if ( !aCallback )
       
    59         {
       
    60         User::Leave(KErrBadHandle);
       
    61         }
       
    62 
       
    63 	CHWRMGenericAsyncObserver* newInstance = new (ELeave) CHWRMGenericAsyncObserver(aClient, aCommand, aCallback);
       
    64 
       
    65 	CleanupStack::PushL( newInstance );
       
    66 	
       
    67 	newInstance->ConstructL(aInitialCommand);
       
    68 
       
    69 	CleanupStack::Pop();
       
    70 
       
    71     COMPONENT_TRACE2(_L( "HWRM Client - CHWRMGenericAsyncObserver::NewLC - return 0x%x" ), newInstance );
       
    72 
       
    73 	return newInstance;
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Destructor
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CHWRMGenericAsyncObserver::~CHWRMGenericAsyncObserver()
       
    82     {
       
    83     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::~CHWRMGenericAsyncObserver()" ));
       
    84 
       
    85     Cancel();
       
    86     
       
    87     iCallback = NULL; // PCLint demands
       
    88 
       
    89     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::~CHWRMGenericAsyncObserver - return" ) );
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CHWRMGenericAsyncObserver::ConstructL
       
    94 // Symbian 2nd phase constructor can leave.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CHWRMGenericAsyncObserver::ConstructL(TInt aInitialCommand)
       
    98     {
       
    99     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::ConstructL()" ));
       
   100 
       
   101     // Order notification
       
   102     OrderNotification();
       
   103 
       
   104     // Get initial value
       
   105     TPtr8 ptr( reinterpret_cast<TUint8*>(&iLatestStatus), sizeof(iLatestStatus), sizeof(iLatestStatus) );
       
   106     User::LeaveIfError(iClient.ExecuteOperation(aInitialCommand, TIpcArgs(&ptr)));
       
   107 
       
   108     if ( iCallback )
       
   109         {
       
   110         iCallback->AsyncRequestCompleted(iCommand, iLatestStatus);    
       
   111         }
       
   112     
       
   113     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::ConstructL - return" ));
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CHWRMGenericAsyncObserver::RunL
       
   118 // Handle notification from server.
       
   119 // No need for RunError, as RunL will never leave
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CHWRMGenericAsyncObserver::RunL()
       
   123     {
       
   124     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::RunL()" ));
       
   125     
       
   126     
       
   127     // Store value
       
   128     iLatestStatus = iStatus.Int();
       
   129 
       
   130     // Reorder notification
       
   131     OrderNotification();
       
   132 
       
   133     if ( iCallback )
       
   134         {
       
   135         iCallback->AsyncRequestCompleted(iCommand, iLatestStatus);    
       
   136         }
       
   137 
       
   138     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::RunL - return" ) );
       
   139     }
       
   140     
       
   141 // -----------------------------------------------------------------------------
       
   142 // CHWRMGenericAsyncObserver::DoCancel
       
   143 // Handle cancel order on this active object.
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CHWRMGenericAsyncObserver::DoCancel()
       
   147     {
       
   148     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::DoCancel()" ));
       
   149     
       
   150     // Nothing to do
       
   151 
       
   152     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::DoCancel - return" ) );
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CHWRMGenericAsyncObserver::OrderNotification
       
   157 // Order new notification from CenRep.
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CHWRMGenericAsyncObserver::OrderNotification()
       
   161     {
       
   162     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::OrderNotification()" ));
       
   163 
       
   164     iClient.ExecuteAsyncOperation( iCommand, TIpcArgs(), iStatus );
       
   165 
       
   166     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::OrderNotification - return" ) );
       
   167     }
       
   168 
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CHWRMGenericAsyncObserver::LatestStatus
       
   172 // Return vibra status
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TInt CHWRMGenericAsyncObserver::LatestStatus() const
       
   176     {
       
   177     COMPONENT_TRACE1(_L( "HWRM Client - CHWRMGenericAsyncObserver::LatestStatus()" ));
       
   178     
       
   179     COMPONENT_TRACE2(_L( "HWRM Client - CHWRMGenericAsyncObserver::LatestStatus - return 0x%x" ), iLatestStatus );
       
   180     
       
   181     return iLatestStatus;
       
   182     }
       
   183     
       
   184 
       
   185 // End of File