gssettingsuis/Gs/GSFramework/src/GSPubSubsListener.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2005 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 settings listener.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <gspubsubslistener.h>
       
    21 #include <mgssettingpsobserver.h>
       
    22 
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CGSPubSubsListener::CGSPubSubsListener
       
    28 // C++ constructor can NOT contain any code, that
       
    29 // might leave.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CGSPubSubsListener::CGSPubSubsListener( const TUid aUid, const TInt aKey, 
       
    33                                        MGSSettingPSObserver* aObserver ) 
       
    34     : CActive( CActive::EPriorityStandard )
       
    35     {
       
    36     iUid = aUid;
       
    37     iId = aKey;
       
    38     iCallback = aObserver;
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CGSPubSubsListener::~CGSPubSubsListener
       
    43 // Destructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 EXPORT_C CGSPubSubsListener::~CGSPubSubsListener()
       
    47     {
       
    48     Cancel();
       
    49     iProperty.Close();
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CGSPubSubsListener::RunL
       
    54 // From CActive.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CGSPubSubsListener::RunL()
       
    58     {
       
    59     const TRequestStatus status( iStatus );
       
    60     StartListening();
       
    61     iCallback->HandleNotifyPSL( iUid, iId, status );
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CGSPubSubsListener::DoCancel
       
    66 // From CActive.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CGSPubSubsListener::DoCancel()
       
    70     {
       
    71     iProperty.Cancel();
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CGSPubSubsListener::RunError
       
    76 // From CActive.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 TInt CGSPubSubsListener::RunError( TInt /*aError*/ )
       
    80     {
       
    81     return KErrNone;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CGSPubSubsListener::NewL
       
    86 //
       
    87 // Symbian OS two phased constructor
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C CGSPubSubsListener* CGSPubSubsListener::NewL( const TUid aUid, const TInt aKey,
       
    91                                               MGSSettingPSObserver* aObserver )
       
    92     {
       
    93     CGSPubSubsListener* self = new( ELeave ) 
       
    94         CGSPubSubsListener( aUid, aKey, aObserver );
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL();
       
    97     CleanupStack::Pop();
       
    98     return self;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CGSPubSubsListener::StartListening
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CGSPubSubsListener::StartListening() 
       
   106     {
       
   107     iProperty.Subscribe( iStatus );
       
   108     SetActive();
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CGSPubSubsListener::ConstructL
       
   113 //
       
   114 // Symbian OS default constructor
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CGSPubSubsListener::ConstructL()
       
   118     {
       
   119     CActiveScheduler::Add( this );
       
   120     
       
   121     User::LeaveIfError ( iProperty.Attach( iUid, iId, EOwnerThread ) );
       
   122     StartListening();
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CGSPubSubsListener::Get
       
   127 // Read integer value.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C TInt CGSPubSubsListener::Get( TInt& aVal )
       
   131     {
       
   132     return iProperty.Get( iUid, iId, aVal );
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CGSPubSubsListener::Get
       
   137 // Read binary value.
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C TInt CGSPubSubsListener::Get( TDes8& aVal )
       
   141     {
       
   142     return iProperty.Get( iUid, iId, aVal );
       
   143     }
       
   144   
       
   145 // -----------------------------------------------------------------------------
       
   146 // CGSPubSubsListener::Get
       
   147 // Read string value.
       
   148 // -----------------------------------------------------------------------------
       
   149 //      
       
   150 EXPORT_C TInt CGSPubSubsListener::Get( TDes16& aVal )
       
   151     {
       
   152     return iProperty.Get( iUid, iId, aVal );
       
   153     }
       
   154 
       
   155 // End of File