wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlmplatformsubscriber.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2002-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 the License "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:  Observer class for platformwide events
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h>
       
    20 #include "wlmplatformsubscriber.h"
       
    21 #include "am_debug.h"
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CWlmPlatformSubscriber::CWlmPlatformSubscriber
       
    27 // C++ default constructor can NOT contain any code, that
       
    28 // might leave.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CWlmPlatformSubscriber::CWlmPlatformSubscriber(
       
    32     TWlmSubscribeType aType,
       
    33     MWlmPlatformResponder& aCallback,
       
    34     const TUid& aCategory,
       
    35     const TUint aKey ) :
       
    36     CActive( CActive::EPriorityStandard ),
       
    37     iType( aType ),
       
    38     iCallback( aCallback ),
       
    39     iCategory( aCategory ),
       
    40     iKey( aKey ),
       
    41     iCenRep( NULL )
       
    42     {
       
    43     DEBUG( "CWlmPlatformSubscriber::CWlmPlatformSubscriber()" );
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CWlmPlatformSubscriber::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CWlmPlatformSubscriber::ConstructL()
       
    52     {
       
    53     DEBUG( "CWlmPlatformSubscriber::ConstructL()" );
       
    54     
       
    55     CActiveScheduler::Add( this );
       
    56     
       
    57     // In case PubSub, attach to a certain key
       
    58     if ( iType == EWlmSubscribeTypePubSub )
       
    59         {
       
    60         iProperty.Attach( iCategory, iKey );    
       
    61         }
       
    62     // In case CenRep, open connection to a certain repository
       
    63     else if ( iType == EWlmSubscribeTypeCenRep )
       
    64         {
       
    65         iCenRep = CRepository::NewL( iCategory );
       
    66         }
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CWlmPlatformSubscriber::NewL
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CWlmPlatformSubscriber* CWlmPlatformSubscriber::NewL(
       
    75     TWlmSubscribeType aType,
       
    76     MWlmPlatformResponder& aCallback,
       
    77     const TUid& aCategory,
       
    78     const TUint aKey )
       
    79     {
       
    80     DEBUG( "CWlmPlatformSubscriber::NewL()" );
       
    81 
       
    82     CWlmPlatformSubscriber* self = new( ELeave ) CWlmPlatformSubscriber(
       
    83         aType,
       
    84         aCallback,
       
    85         aCategory,
       
    86         aKey );
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // Destructor
       
    94 CWlmPlatformSubscriber::~CWlmPlatformSubscriber()
       
    95     {
       
    96     DEBUG( "CWlmPlatformSubscriber::~CWlmPlatformSubscriber()" );
       
    97 
       
    98     Cancel();
       
    99     if ( iType == EWlmSubscribeTypePubSub )
       
   100         {        
       
   101         iProperty.Close();   
       
   102         }
       
   103     else if ( iType == EWlmSubscribeTypeCenRep )
       
   104         {
       
   105         delete iCenRep;
       
   106         }    
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CWlmPlatformSubscriber::IssueRequest
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CWlmPlatformSubscriber::IssueRequest()
       
   114     {
       
   115     DEBUG( "CWlmPlatformSubscriber::IssueRequest()" );
       
   116 
       
   117     if( !IsActive() )
       
   118         {
       
   119         if ( iType == EWlmSubscribeTypePubSub )
       
   120             {
       
   121             DEBUG( "CWlmPlatformSubscriber::IssueRequest() - requestType == PubSub" );
       
   122             iProperty.Subscribe( iStatus );
       
   123             }
       
   124         else if ( iType == EWlmSubscribeTypeCenRep )     
       
   125             {
       
   126             DEBUG( "CWlmPlatformSubscriber::IssueRequest() - requestType == CenRep" );
       
   127             iCenRep->NotifyRequest( iKey, iStatus );
       
   128             }
       
   129         SetActive();
       
   130         }
       
   131     else
       
   132         {
       
   133         DEBUG("CWlmPlatformSubscriber::IssueRequest() - already active, ignoring");
       
   134         }
       
   135     }
       
   136     
       
   137 // -----------------------------------------------------------------------------
       
   138 // CWlmPlatformSubscriber::DoCancel
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CWlmPlatformSubscriber::DoCancel()
       
   142     {
       
   143     DEBUG( "CWlmPlatformSubscriber::DoCancel()" );
       
   144 
       
   145     if ( iType == EWlmSubscribeTypePubSub )
       
   146         {
       
   147         iProperty.Cancel();
       
   148         }
       
   149     else if ( iType == EWlmSubscribeTypeCenRep )    
       
   150         {
       
   151         iCenRep->NotifyCancel( iKey );
       
   152         }    
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CWlmPlatformSubscriber::RunError
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CWlmPlatformSubscriber::RunError(
       
   160     TInt aError )
       
   161     {
       
   162     DEBUG( "CWlmPlatformSubscriber::RunError()" );
       
   163     
       
   164     if ( aError != KErrNone )
       
   165         {
       
   166         DEBUG1( "CWlmPlatformSubscriber::RunError() - aError = %d", aError );    
       
   167         }
       
   168 
       
   169     return KErrNone;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CWlmPlatformSubscriber::RunL
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CWlmPlatformSubscriber::RunL()
       
   177     {
       
   178     DEBUG( "CWlmPlatformSubscriber::RunL()" );
       
   179     
       
   180     DEBUG1( "CWlmPlatformSubscriber::RunL() - iStatus = %d", iStatus.Int() );
       
   181     iCallback.HandlePropertyChangedL( iCategory, iKey );
       
   182     IssueRequest();
       
   183     }
       
   184     
       
   185 // -----------------------------------------------------------------------------
       
   186 // CWlmPlatformSubscriber::Get
       
   187 // -----------------------------------------------------------------------------
       
   188 //    
       
   189 TInt CWlmPlatformSubscriber::Get( TInt& aValue )
       
   190     {
       
   191     DEBUG( "CWlmPlatformSubscriber::Get()" );
       
   192               
       
   193     if ( iType == EWlmSubscribeTypePubSub )
       
   194         {
       
   195         return iProperty.Get( aValue );
       
   196         }
       
   197     else if ( iType == EWlmSubscribeTypeCenRep )
       
   198         {
       
   199         return iCenRep->Get( iKey, aValue );
       
   200         }
       
   201         
       
   202     return KErrNotFound;
       
   203     }