systemswstubs/ssyreference/src/ssypslistener.cpp
changeset 52 3248d079cead
equal deleted inserted replaced
47:fb031b08c285 52:3248d079cead
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Listener for PS key changes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //#include "siftrace.h"
       
    21 #include "ssypslistener.h"
       
    22 
       
    23 _LIT( KPanicCategory, "SsyPsListener" );
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // Two-phased constructor.
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CSsyPsListener* CSsyPsListener::NewL(MSsyPsObserver& aObserver,
       
    30                                      TUid aCategory, 
       
    31                                      TUint aKey)
       
    32     {
       
    33     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::NewL(0x%x)" ), &aObserver ) );
       
    34 
       
    35     CSsyPsListener* self = new (ELeave) CSsyPsListener(aObserver, aCategory, aKey);
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL(); 
       
    38     CleanupStack::Pop(self); 
       
    39 
       
    40     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::NewL - return 0x%x" ), self ) );
       
    41 
       
    42     return self;
       
    43     }
       
    44     
       
    45 // ---------------------------------------------------------------------------
       
    46 // C++ constructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CSsyPsListener::CSsyPsListener(MSsyPsObserver& aObserver,
       
    50                                TUid aCategory, 
       
    51                                TUint aKey)
       
    52     : CActive(EPriorityStandard),
       
    53       iObserver(aObserver),
       
    54       iCategory(aCategory),
       
    55       iKey(aKey)
       
    56     {
       
    57     // Nothing to do
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // 2nd phase of construction.
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CSsyPsListener::ConstructL()
       
    65     {
       
    66     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::ConstructL()" ) ) );   
       
    67 
       
    68     CActiveScheduler::Add(this);
       
    69 
       
    70     // Start listening specified PS key
       
    71     User::LeaveIfError(iProperty.Attach(iCategory, iKey));
       
    72     
       
    73     iProperty.Subscribe(iStatus);
       
    74     SetActive();
       
    75 
       
    76     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::ConstructL - return" ) ) );
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Destructor
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CSsyPsListener::~CSsyPsListener()
       
    84     {
       
    85     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::~CSsyPsListener()" ) ) );
       
    86     
       
    87     Cancel(); 
       
    88 
       
    89     iProperty.Close();
       
    90     
       
    91     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::~CSsyPsListener - return" ) ) );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // Handle notification from the other thread.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CSsyPsListener::RunL()
       
    99     {
       
   100     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::RunL()" ) ) );
       
   101     
       
   102     TInt err(KErrNone);
       
   103     
       
   104     // Restart listening
       
   105     iProperty.Subscribe(iStatus);
       
   106     SetActive();
       
   107 
       
   108     // Get value
       
   109     err = iProperty.Get(iValue);
       
   110 
       
   111     if (err == KErrNone)
       
   112         {
       
   113         // Everything ok, notify owner about new plugins
       
   114         COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::RunL() - Notifying observer: iCategory: %d, iKey: %d, iValue: %d" ), iCategory, iKey, iValue ) );
       
   115         iObserver.PsValueSet(iCategory, iKey, iValue);
       
   116         }
       
   117     
       
   118     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::RunL - return" ) ) );
       
   119     }
       
   120     
       
   121 // -----------------------------------------------------------------------------
       
   122 // Handle error in RunL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 #ifdef COMPONENT_TRACE_DEBUG
       
   126 TInt CSsyPsListener::RunError(TInt aError)
       
   127 #else
       
   128 TInt CSsyPsListener::RunError(TInt /*aError*/)
       
   129 #endif
       
   130     {
       
   131     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::RunError(%d)" ), aError) );
       
   132 
       
   133     // Panic this thread if there is unhandled error in RunL.
       
   134     // This should not be possible.
       
   135     User::Panic(KPanicCategory, 0);
       
   136     
       
   137     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::RunError - return %d" ), KErrNone ) );
       
   138 
       
   139     return KErrNone;
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // Handle cancel order on this active object.
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CSsyPsListener::DoCancel()
       
   147     {
       
   148     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::DoCancel()" ) ) );
       
   149 
       
   150     iProperty.Cancel();
       
   151 
       
   152     COMPONENT_TRACE( ( _L( "SSYStub - CSsyPsListener::DoCancel - return" ) ) );
       
   153     }
       
   154