resourcemgmt/hwresourcesmgr/vibra/src/HWRMVibraStatusObserver.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 
       
    19 // INCLUDE FILES
       
    20 #include "HWRMPrivatePSKeys.h"
       
    21 #include "HWRMtrace.h"
       
    22 #include "HWRMVibra.h"
       
    23 #include "HWRMVibraStatusObserver.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CHWRMVibraStatusObserver::CHWRMVibraStatusObserver
       
    29 // C++ constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CHWRMVibraStatusObserver::CHWRMVibraStatusObserver(MHWRMVibraObserver* aCallback)
       
    34     : CActive(EPriorityStandard), iCallback(aCallback)
       
    35     {
       
    36     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::CHWRMVibraStatusObserver(0x%x)" ), aCallback);
       
    37 
       
    38     CActiveScheduler::Add(this);
       
    39 
       
    40     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::CHWRMVibraStatusObserver - return" ) );
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CHWRMVibraStatusObserver::NewL
       
    45 // Two-phased constructor
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CHWRMVibraStatusObserver* CHWRMVibraStatusObserver::NewL(MHWRMVibraObserver* aCallback)
       
    49     {
       
    50 
       
    51     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::NewLC(0x%x)" ), aCallback);
       
    52 
       
    53 	CHWRMVibraStatusObserver* newInstance = new (ELeave) CHWRMVibraStatusObserver(aCallback);
       
    54 
       
    55 	CleanupStack::PushL( newInstance );
       
    56 	
       
    57 	newInstance->ConstructL();
       
    58 
       
    59 	CleanupStack::Pop();
       
    60 
       
    61     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::NewLC - return 0x%x" ), newInstance);
       
    62 
       
    63 	return newInstance;
       
    64     }
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // Destructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CHWRMVibraStatusObserver::~CHWRMVibraStatusObserver()
       
    72     {
       
    73     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::~CHWRMVibraStatusObserver()" ));
       
    74 
       
    75     // Cancel property separately, as the following Cancel() call doesn't seem to 
       
    76     // cause DoCancel to fire.
       
    77     iProperty.Cancel();
       
    78 
       
    79     Cancel();
       
    80     
       
    81     iProperty.Close();
       
    82     
       
    83     iCallback = NULL; // PCLint demands
       
    84 
       
    85     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::~CHWRMVibraStatusObserver - return" ) );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CHWRMVibraStatusObserver::ConstructL
       
    90 // Symbian 2nd phase constructor can leave.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CHWRMVibraStatusObserver::ConstructL()
       
    94     {
       
    95     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::ConstructL()" ));
       
    96 
       
    97     User::LeaveIfError(iProperty.Attach(KPSUidHWResourceNotification, KHWRMVibraStatus));
       
    98     
       
    99     // Call RunL to order notification and do the initial notifying of the client
       
   100     RunL();
       
   101 
       
   102     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::ConstructL - return" ) );
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CHWRMVibraStatusObserver::RunL
       
   107 // Handle notification from pubsub session.
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CHWRMVibraStatusObserver::RunL()
       
   111     {
       
   112     // NOTE: RunL cannot currently leave, so it's not necessary to implement RunError. 
       
   113     // Remember to implement it if any change to RunL make it a leaving function.
       
   114     
       
   115     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::RunL()" ));
       
   116 
       
   117 	User::LeaveIfError(KErrNone); // avoid leavescan error
       
   118 	
       
   119     // Reorder notification
       
   120     OrderNotification();
       
   121 
       
   122     // get value from pubsub
       
   123     TInt value(CHWRMVibra::EVibraStatusUnknown);
       
   124     
       
   125     TInt err = iProperty.Get(value);
       
   126     
       
   127     // if no error or not found then no problem.
       
   128     // Otherwise leave as something went wrong
       
   129     if ( err == KErrNotFound || err == KErrNone )
       
   130         {
       
   131         CHWRMVibra::TVibraStatus status = static_cast<CHWRMVibra::TVibraStatus>(value);
       
   132         
       
   133         // Only notify if value actually changed
       
   134         if ( iCallback && iVibraStatus != status)
       
   135             {            
       
   136             iCallback->VibraStatusChanged(status);    
       
   137             }
       
   138         iVibraStatus = status;
       
   139         }
       
   140     else
       
   141         {
       
   142         COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::RunL. Error (%d) in iProperty.Get()" ), err);
       
   143 	    if ( iCallback && iVibraStatus != CHWRMVibra::EVibraStatusUnknown)
       
   144 	        {        
       
   145 	        iCallback->VibraStatusChanged(CHWRMVibra::EVibraStatusUnknown);
       
   146 	        }
       
   147 	    
       
   148 	    iVibraStatus = CHWRMVibra::EVibraStatusUnknown;
       
   149         }
       
   150 
       
   151     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::RunL - return" ) );
       
   152     }
       
   153     
       
   154 // -----------------------------------------------------------------------------
       
   155 // CHWRMVibraStatusObserver::DoCancel
       
   156 // Handle cancel order on this active object.
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CHWRMVibraStatusObserver::DoCancel()
       
   160     {
       
   161     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::DoCancel()" ));
       
   162 
       
   163     iProperty.Cancel();
       
   164 
       
   165     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::DoCancel - return" ) );
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CHWRMVibraStatusObserver::OrderNotification
       
   170 // Order new notification from CenRep.
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CHWRMVibraStatusObserver::OrderNotification()
       
   174     {
       
   175     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::OrderNotification()" ));
       
   176 
       
   177     iProperty.Subscribe(iStatus);
       
   178     SetActive();
       
   179 
       
   180     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::OrderNotification - return" ) );
       
   181     }
       
   182 
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CHWRMVibraStatusObserver::CurrentStatus
       
   186 // Return vibra status
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 CHWRMVibra::TVibraStatus CHWRMVibraStatusObserver::CurrentStatus() const
       
   190     {
       
   191     COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::CurrentStatus()" ));
       
   192     
       
   193     TInt value(CHWRMVibra::EVibraStatusUnknown);
       
   194     CHWRMVibra::TVibraStatus retval(CHWRMVibra::EVibraStatusUnknown);
       
   195     
       
   196     TInt err = RProperty::Get(KPSUidHWResourceNotification, KHWRMVibraStatus, value);
       
   197     
       
   198     if ( err != KErrNone )
       
   199         {
       
   200         // Perhaps a different status value other than the current one 
       
   201         // should be considered
       
   202         retval = iVibraStatus;
       
   203         }
       
   204     else
       
   205         {
       
   206         retval = static_cast<CHWRMVibra::TVibraStatus>(value);
       
   207         }
       
   208     
       
   209     COMPONENT_TRACE2(_L( "HWRM VibraClient - CHWRMVibraStatusObserver::CurrentStatus - return 0x%x" ), retval );
       
   210     
       
   211     return retval;
       
   212     }
       
   213     
       
   214 
       
   215 // End of File