resourcemgmt/hwresourcesmgr/server/src/HWRMPSChangeObserver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-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 
       
    19 // INCLUDE FILES
       
    20 #include "HWRMtrace.h"
       
    21 #include "HWRMPSChangeObserver.h"
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CHWRMPSChangeObserver::CHWRMPSChangeObserver
       
    27 // C++ constructor can NOT contain any code, that
       
    28 // might leave.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CHWRMPSChangeObserver::CHWRMPSChangeObserver(MHWRMPSChangeObserver& aCallback,
       
    32                                              const TUid& aUid,
       
    33                                              TUint32 aKey)
       
    34     : CActive(EPriorityStandard), 
       
    35       iCallback(aCallback),
       
    36       iUid(aUid),
       
    37       iKey(aKey)
       
    38     {
       
    39     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPSChangeObserver::CHWRMPSChangeObserver(0x%x)" ), &aCallback);
       
    40 
       
    41     CActiveScheduler::Add(this);
       
    42 
       
    43     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::CHWRMPSChangeObserver - return" ) );
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CHWRMPSChangeObserver::NewL
       
    48 // Two-phased constructor
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CHWRMPSChangeObserver* CHWRMPSChangeObserver::NewL(MHWRMPSChangeObserver& aCallback,
       
    52                                                    const TUid& aUid,
       
    53                                                    TUint32 aKey)
       
    54     {
       
    55 
       
    56     CHWRMPSChangeObserver* newInstance = NewLC(aCallback, aUid, aKey);
       
    57 	CleanupStack::Pop();
       
    58 
       
    59 	return newInstance;
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CHWRMPSChangeObserver::NewLC
       
    65 // Two-phased constructor. Leaves instance to cleanup stack
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CHWRMPSChangeObserver* CHWRMPSChangeObserver::NewLC(MHWRMPSChangeObserver& aCallback,
       
    69                                                     const TUid& aUid,
       
    70                                                     TUint32 aKey)
       
    71     {
       
    72     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPSChangeObserver::NewLC(0x%x)" ), &aCallback);
       
    73 
       
    74 	CHWRMPSChangeObserver* newInstance = new (ELeave) CHWRMPSChangeObserver(aCallback, aUid, aKey);
       
    75 	CleanupStack::PushL( newInstance );
       
    76 	
       
    77 	newInstance->ConstructL();
       
    78 
       
    79     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPSChangeObserver::NewLC - return 0x%x" ), newInstance );
       
    80 
       
    81 	return newInstance;
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // Destructor
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CHWRMPSChangeObserver::~CHWRMPSChangeObserver()
       
    90     {
       
    91     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::~CHWRMPSChangeObserver()" ));
       
    92 
       
    93     // Cancel property separately, as the following Cancel() call doesn't seem to 
       
    94     // cause DoCancel to fire.
       
    95     iProperty.Cancel();
       
    96 
       
    97     Cancel();
       
    98     
       
    99     iProperty.Close();
       
   100 
       
   101     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::~CHWRMPSChangeObserver - return" ) );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CHWRMPSChangeObserver::ConstructL
       
   106 // Symbian 2nd phase constructor can leave.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CHWRMPSChangeObserver::ConstructL()
       
   110     {
       
   111     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::ConstructL()" ));
       
   112 
       
   113     User::LeaveIfError(iProperty.Attach(iUid, iKey));
       
   114     
       
   115     // Call RunL to order notification and do the initial notifying of the client
       
   116     RunL();
       
   117 
       
   118     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::ConstructL - return" ) );
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CHWRMPSChangeObserver::RunL
       
   123 // Handle notification from pubsub session.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CHWRMPSChangeObserver::RunL()
       
   127     {
       
   128     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::RunL()" ));
       
   129 
       
   130     // Reorder notification
       
   131     OrderNotification();
       
   132 
       
   133     // get value from pubsub
       
   134     TInt value(0);
       
   135     
       
   136     TInt err = iProperty.Get(value);
       
   137     
       
   138     // if no error or not found then no problem.
       
   139     // Otherwise leave as something went wrong
       
   140     if ( err == KErrNotFound || err == KErrNone )
       
   141         {
       
   142         iCallback.PSValueChanged(iUid, iKey, value);    
       
   143         }
       
   144     else
       
   145         {
       
   146         COMPONENT_TRACE2( _L( "HWRM Server - CHWRMPSChangeObserver::RunL(), err %d" ), err);
       
   147         User::Leave(err);
       
   148         }
       
   149 
       
   150     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::RunL - return" ) );
       
   151     }
       
   152     
       
   153 // -----------------------------------------------------------------------------
       
   154 // CHWRMPSChangeObserver::RunError
       
   155 // Handle error in RunL
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 #if defined(_DEBUG) && defined(COMPONENT_TRACE_FLAG)
       
   159 TInt CHWRMPSChangeObserver::RunError(TInt aError)
       
   160 #else
       
   161 TInt CHWRMPSChangeObserver::RunError(TInt /*aError*/)
       
   162 #endif
       
   163     {
       
   164     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPSChangeObserver::RunError(%d)" ), aError);
       
   165 
       
   166     // Error occurred either while reordering notification or getting property value.
       
   167     // We can't really do anything about it, so ignore.
       
   168     // (possible errors are KErrPermissionDenied and KErrArgument, which indicate fundamental
       
   169     //  problem with property, and will be caught on the first RunL execution by ConstructL)
       
   170 
       
   171     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPSChangeObserver::RunError - return %d" ), KErrNone );
       
   172 
       
   173     return KErrNone;
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CHWRMPSChangeObserver::DoCancel
       
   178 // Handle cancel order on this active object.
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CHWRMPSChangeObserver::DoCancel()
       
   182     {
       
   183     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::DoCancel()" ));
       
   184 
       
   185     iProperty.Cancel();
       
   186 
       
   187     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::DoCancel - return" ) );
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CHWRMPSChangeObserver::OrderNotification
       
   192 // Order new notification from CenRep.
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CHWRMPSChangeObserver::OrderNotification()
       
   196     {
       
   197     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::OrderNotification()" ));
       
   198 
       
   199 	if (IsActive())
       
   200 		{
       
   201 		COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::OrderNotification - returning early as already active" ) );	
       
   202 		return;
       
   203 		}
       
   204 		
       
   205     iProperty.Subscribe(iStatus);
       
   206     SetActive();
       
   207 
       
   208     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPSChangeObserver::OrderNotification - return" ) );
       
   209     }
       
   210 
       
   211 
       
   212 
       
   213 // End of File