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