videoutils_plat/videoconnutility_api/tsrc/src/VCXConnUtilTestSubscriber.cpp
branchRCL_3
changeset 48 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
47:826cea16efd9 48: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 #include "VCXTestLog.h"
       
    19 #include "VCXConnUtilTestSubscriber.h"
       
    20 #include "VCXConnUtilTestPSObserver.h"
       
    21 
       
    22 const TInt KMaxStrLenght( 100 );
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CVCXConnUtilTestSubscriber::CVCXConnUtilTestSubscriber()
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CVCXConnUtilTestSubscriber::CVCXConnUtilTestSubscriber( const TUid aUid,
       
    29                                                 const TUint32 aKey,
       
    30                                                 RProperty::TType aType,
       
    31                                                 MVCXConnUtilTestPSObserver* aObserver ) :
       
    32     CActive( EPriorityStandard ),
       
    33     iUid( aUid ),
       
    34     iKey( aKey ),
       
    35     iKeyType(aType),
       
    36     iObserver( aObserver )
       
    37     {
       
    38         // NOP
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CVCXConnUtilTestSubscriber::NewL()
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CVCXConnUtilTestSubscriber* CVCXConnUtilTestSubscriber::NewL( const TUid aUid,
       
    46                                                       const TUint32 aKey,
       
    47                                                       RProperty::TType aType,
       
    48                                                       MVCXConnUtilTestPSObserver* aObserver )
       
    49     {
       
    50     CVCXConnUtilTestSubscriber* self =
       
    51                       new( ELeave ) CVCXConnUtilTestSubscriber( aUid, aKey, aType, aObserver );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CVCXConnUtilTestSubscriber::ConstructL()
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CVCXConnUtilTestSubscriber::ConstructL()
       
    63     {
       
    64     iInitialized = EFalse;
       
    65     User::LeaveIfError( iProperty.Attach( iUid, iKey ) );
       
    66     CActiveScheduler::Add( this );
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CVCXConnUtilTestSubscriber::~CVCXConnUtilTestSubscriber()
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CVCXConnUtilTestSubscriber::~CVCXConnUtilTestSubscriber()
       
    74     {
       
    75     if( IsActive() )
       
    76         {
       
    77         Cancel();
       
    78         }
       
    79     iProperty.Close();
       
    80 
       
    81     delete iSafeWait;
       
    82     iSafeWait = NULL;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CVCXConnUtilTestSubscriber::Get()
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TInt CVCXConnUtilTestSubscriber::Get( TInt& aValue )
       
    90     {
       
    91     return iProperty.Get( aValue );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CVCXConnUtilTestSubscriber::Get()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CVCXConnUtilTestSubscriber::Get( TDes& aValue )
       
    99     {
       
   100     return iProperty.Get( aValue );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CVCXConnUtilTestSubscriber::Set()
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CVCXConnUtilTestSubscriber::Set( TInt& aValue )
       
   108     {
       
   109     return iProperty.Set( aValue );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CVCXConnUtilTestSubscriber::Set()
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CVCXConnUtilTestSubscriber::Set( const TDesC& aValue )
       
   117     {
       
   118     return iProperty.Set( aValue );
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CVCXConnUtilTestSubscriber::Start()
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CVCXConnUtilTestSubscriber::Start()
       
   126     {
       
   127     if( !IsActive() )
       
   128         {
       
   129         iProperty.Subscribe( iStatus );
       
   130         SetActive();
       
   131         iInitialized = ETrue;
       
   132         }
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CVCXConnUtilTestSubscriber::WaitChange()
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CVCXConnUtilTestSubscriber::WaitChangeL()
       
   140     {
       
   141     if( !iSafeWait )
       
   142         {
       
   143         iSafeWait = new ( ELeave ) CActiveSchedulerWait;
       
   144         }
       
   145     if ( iSafeWait && !iSafeWait->IsStarted() )
       
   146         {
       
   147         iSafeWait->Start();
       
   148         }
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CVCXConnUtilTestSubscriber::EndWait()
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CVCXConnUtilTestSubscriber::EndWait()
       
   156     {
       
   157     if ( iSafeWait && iSafeWait->IsStarted() )
       
   158         {
       
   159         iSafeWait->AsyncStop();
       
   160         }
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CVCXConnUtilTestSubscriber::DoCancel()
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CVCXConnUtilTestSubscriber::DoCancel()
       
   168     {
       
   169     if( IsActive() )
       
   170         {
       
   171         iProperty.Cancel();
       
   172         }
       
   173     iInitialized = EFalse;
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CVCXConnUtilTestSubscriber::RunL()
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CVCXConnUtilTestSubscriber::RunL()
       
   181     {
       
   182     VCXLOGLO1(">>>CVCXConnUtilTestSubscriber::RunL");
       
   183     // resubscribe before processing new
       
   184     // value to prevent missing updates
       
   185     iProperty.Subscribe( iStatus );
       
   186     SetActive();
       
   187 
       
   188     if( iInitialized )
       
   189         {
       
   190         TBuf< KMaxStrLenght > strValue;
       
   191         TInt intValue;
       
   192 
       
   193         if( iKeyType == RProperty::EInt )
       
   194             {
       
   195             // int type changed
       
   196             if( iProperty.Get( intValue ) == KErrNone && iObserver )
       
   197                 {
       
   198                 iObserver->ValueChangedL( iUid, iKey, intValue );
       
   199                 }
       
   200             }
       
   201         else if( iKeyType == RProperty::EText )
       
   202             {
       
   203             if( iProperty.Get( strValue ) == KErrNone && iObserver )
       
   204                 {
       
   205                 iObserver->ValueChangedL( iUid, iKey, strValue );
       
   206                 }
       
   207             }
       
   208         }
       
   209     EndWait();
       
   210     iInitialized = ETrue;
       
   211     VCXLOGLO1("<<<CVCXConnUtilTestSubscriber::RunL");
       
   212   }
       
   213 
       
   214 //  End of File