mpx/commonframework/common/src/mpxpskeywatcher.cpp
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Publish and Subscribe key watcher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32property.h>
       
    21 #include "mpxpskeywatcher.h"
       
    22 #include "mpxpskeyobserver.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Default Constructor
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CMPXPSKeyWatcher::CMPXPSKeyWatcher(  TUid aUid, TInt aKey,
       
    29                                      MMPXPSKeyObserver* aObserver ) :
       
    30                                                      CActive( EPriorityHigh ),
       
    31                                                      iObserver( aObserver ),
       
    32                                                      iUid( aUid ),
       
    33                                                      iKey( aKey )
       
    34                                                       
       
    35     {
       
    36     }
       
    37 
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // 2nd phased Constructor
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CMPXPSKeyWatcher::ConstructL()
       
    44     {
       
    45     CActiveScheduler::Add(this);
       
    46     
       
    47     iProperty.Attach( iUid, iKey );
       
    48     iProperty.Subscribe( iStatus );
       
    49     SetActive();
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Two-Phased COnstructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C CMPXPSKeyWatcher* CMPXPSKeyWatcher::NewL( TUid aUid, TInt aKey,
       
    58                                                    MMPXPSKeyObserver* aObserver )
       
    59     {
       
    60     CMPXPSKeyWatcher* self = new(ELeave) CMPXPSKeyWatcher( aUid, 
       
    61                                                            aKey, 
       
    62                                                            aObserver );
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Destructor
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CMPXPSKeyWatcher::~CMPXPSKeyWatcher()
       
    75     {
       
    76     Cancel();  // Cancels waiting request
       
    77     iProperty.Close();
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CMPXPSKeyWatcher::RunL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CMPXPSKeyWatcher::RunL()
       
    85     {
       
    86     iProperty.Subscribe( iStatus );
       
    87     SetActive();
       
    88     
       
    89     // Notify Observer and start watching again
       
    90     if( iObserver )
       
    91         {
       
    92         iObserver->HandlePSEvent( iUid, iKey );
       
    93         }
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CMPXPSKeyWatcher::DoCancel
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CMPXPSKeyWatcher::DoCancel()
       
   101     {
       
   102     iProperty.Cancel();
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CMPXPSKeyWatcher::GetValue
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C TInt CMPXPSKeyWatcher::GetValue( TInt& aValue )
       
   110     {
       
   111     return iProperty.Get( aValue );
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CMPXPSKeyWatcher::GetValue
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C TInt CMPXPSKeyWatcher::GetValue( TDes8& aValue )
       
   119     {
       
   120     return iProperty.Get( aValue );
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CMPXPSKeyWatcher::GetValue
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C TInt CMPXPSKeyWatcher::GetValue( TDes16& aValue )
       
   128     {
       
   129     return iProperty.Get( aValue );
       
   130     }
       
   131     
       
   132 // ---------------------------------------------------------------------------
       
   133 // CMPXPSKeyWatcher::SetValue
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C TInt CMPXPSKeyWatcher::SetValue( TInt aValue )
       
   137     {
       
   138     return iProperty.Set( aValue );
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CMPXPSKeyWatcher::SetValue
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 EXPORT_C TInt CMPXPSKeyWatcher::SetValue( const TDesC8& aValue )
       
   146     {
       
   147     return iProperty.Set( aValue );
       
   148     }
       
   149     
       
   150 // ---------------------------------------------------------------------------
       
   151 // CMPXPSKeyWatcher::SetValue
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C TInt CMPXPSKeyWatcher::SetValue( const TDesC16& aValue )
       
   155     {
       
   156     return iProperty.Set( aValue );
       
   157     }
       
   158