videoconnutility/connutility/src/vcxconnutilsubscriber.cpp
branchRCL_3
changeset 23 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
22:826cea16efd9 23:13a33d82ad98
       
     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 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:    Class to handle subscribtions from PS*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #include "vcxconnutilsubscriber.h"
       
    20 #include "vcxconnutilpubsubobserver.h"
       
    21 
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // CVcxConnUtilSubscriber::CVcxConnUtilSubscriber()
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 CVcxConnUtilSubscriber::CVcxConnUtilSubscriber( const TUid aUid, 
       
    28                                                 const TUint32 aKey, 
       
    29                                                 RProperty::TType aType,
       
    30                                                 MConnUtilPubsubObserver* aObserver ) :
       
    31     CActive( EPriorityStandard ), 
       
    32     iUid( aUid ),
       
    33     iKey( aKey ), 
       
    34     iKeyType(aType), 
       
    35     iObserver( aObserver )
       
    36     {
       
    37         // NOP
       
    38     }
       
    39  
       
    40 // -----------------------------------------------------------------------------
       
    41 // CVcxConnUtilSubscriber::NewL()
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CVcxConnUtilSubscriber* CVcxConnUtilSubscriber::NewL( const TUid aUid, 
       
    45                                                       const TUint32 aKey,
       
    46                                                       RProperty::TType aType, 
       
    47                                                       MConnUtilPubsubObserver* aObserver )
       
    48     {
       
    49     CVcxConnUtilSubscriber* self =
       
    50                       new( ELeave ) CVcxConnUtilSubscriber( aUid, aKey, aType, aObserver );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56  
       
    57 // -----------------------------------------------------------------------------
       
    58 // CVcxConnUtilSubscriber::ConstructL()
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CVcxConnUtilSubscriber::ConstructL()
       
    62     {
       
    63     iInitialized = EFalse;
       
    64     User::LeaveIfError( iProperty.Attach( iUid, iKey ) );
       
    65     CActiveScheduler::Add( this );    
       
    66     }
       
    67  
       
    68 // -----------------------------------------------------------------------------
       
    69 // CVcxConnUtilSubscriber::~CVcxConnUtilSubscriber()
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CVcxConnUtilSubscriber::~CVcxConnUtilSubscriber()
       
    73     {
       
    74     if( IsActive() )
       
    75         {
       
    76         Cancel();
       
    77         }
       
    78     iProperty.Close();
       
    79     
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CVcxConnUtilSubscriber::Property()
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 RProperty& CVcxConnUtilSubscriber::Property()
       
    87     {
       
    88     return iProperty;
       
    89     }
       
    90   
       
    91 // -----------------------------------------------------------------------------
       
    92 // CVcxConnUtilSubscriber::Start()
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CVcxConnUtilSubscriber::Start()
       
    96     {
       
    97     if( !IsActive() )
       
    98         {
       
    99         iProperty.Subscribe( iStatus );
       
   100         SetActive();
       
   101         iInitialized = ETrue;
       
   102         }
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CVcxConnUtilSubscriber::DoCancel()
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CVcxConnUtilSubscriber::DoCancel()
       
   110     {
       
   111     if( IsActive() )
       
   112         {
       
   113         iProperty.Cancel();
       
   114         }   
       
   115     iInitialized = EFalse;
       
   116     }
       
   117  
       
   118 // -----------------------------------------------------------------------------
       
   119 // CVcxConnUtilSubscriber::RunL()
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CVcxConnUtilSubscriber::RunL()
       
   123     {
       
   124     // resubscribe before processing new 
       
   125     // value to prevent missing updates
       
   126     iProperty.Subscribe( iStatus );
       
   127     SetActive();
       
   128 
       
   129     if( iInitialized )
       
   130         {           
       
   131         if(iKeyType == RProperty::EInt )
       
   132             {
       
   133             TInt intValue;
       
   134             // int type changed
       
   135             if( iProperty.Get( intValue ) == KErrNone && iObserver )
       
   136                 {                
       
   137                 TRAP_IGNORE( iObserver->ValueChangedL( iKey, intValue ) );
       
   138                 }
       
   139             }
       
   140         }
       
   141     iInitialized = ETrue;
       
   142   }
       
   143 // end of file