srsf/nssvascontacthdlr/src/nssvasdatasyncwatcher.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2005-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 "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:  Watches changes of the PC-Suite data sync state
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "nssvasdatasyncwatcher.h"
       
    20 #include "rubydebug.h"
       
    21 
       
    22 // Destructors cannot be pure virtual
       
    23 MNssDataSyncWatcher::~MNssDataSyncWatcher() 
       
    24     {
       
    25     // empty
       
    26     }
       
    27 
       
    28 
       
    29 
       
    30 ///////////////////////////////////
       
    31 // CNssDataSyncWatcherFactory::ConstructDataSyncWatcherL
       
    32 //
       
    33 // Constructs and returns the data sync watcher according to what's
       
    34 // available in the system. I.e RProperty based watcher or
       
    35 // shared data client based watcher
       
    36 // @param aHost Observer to be notified about data sync state changes
       
    37 //
       
    38 // @return Constructed and already started watcher
       
    39 ///////////////////////////////////
       
    40 MNssDataSyncWatcher* CNssDataSyncWatcherFactory::ConstructDataSyncWatcherL( 
       
    41                                         MNssDataSyncStateObserver& aHost )
       
    42     {
       
    43     RUBY_DEBUG_BLOCKL( "ConstructDataSyncWatcherL" );
       
    44     MNssDataSyncWatcher* watcher = CNssDataSyncPropertyWatcher::NewL( aHost );
       
    45     return watcher;
       
    46     }
       
    47 
       
    48 ///////////////////////////////////
       
    49 // CNssDataSyncPropertyWatcher::NewL
       
    50 //
       
    51 // Two phased construction
       
    52 ///////////////////////////////////
       
    53 CNssDataSyncPropertyWatcher* CNssDataSyncPropertyWatcher::NewL( MNssDataSyncStateObserver& aHost )
       
    54     {
       
    55     CNssDataSyncPropertyWatcher* self = new (ELeave) CNssDataSyncPropertyWatcher( aHost );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61     
       
    62 ///////////////////////////////////
       
    63 // CNssDataSyncPropertyWatcher::CNssDataSyncPropertyWatcher
       
    64 //
       
    65 // Constructor
       
    66 ///////////////////////////////////
       
    67 CNssDataSyncPropertyWatcher::CNssDataSyncPropertyWatcher( MNssDataSyncStateObserver& aHost ) :
       
    68     CActive( EPriorityStandard ),
       
    69     iHost( &aHost ),
       
    70     iDataSyncStatus( EDataSyncNotRunning )
       
    71     {
       
    72     // Nothing
       
    73     }
       
    74     
       
    75 ///////////////////////////////////
       
    76 // CNssDataSyncPropertyWatcher::ConstructL
       
    77 //
       
    78 // Second-pase constructor
       
    79 ///////////////////////////////////
       
    80 void CNssDataSyncPropertyWatcher::ConstructL() 
       
    81     {
       
    82     RUBY_DEBUG_BLOCK( "CNssDataSyncPropertyWatcher::ConstructL" );
       
    83     User::LeaveIfError( iProperty.Attach( KPSUidDataSynchronizationInternalKeys, KDataSyncStatus ) );
       
    84     CActiveScheduler::Add( this );
       
    85     // initial subscription and process current property value
       
    86     RunL();
       
    87     }
       
    88     
       
    89 ///////////////////////////////////
       
    90 // CNssDataSyncPropertyWatcher::~CNssDataSyncPropertyWatcher
       
    91 //
       
    92 // Destructor
       
    93 ///////////////////////////////////
       
    94 CNssDataSyncPropertyWatcher::~CNssDataSyncPropertyWatcher()
       
    95     {
       
    96     if( IsAdded() ) 
       
    97         {
       
    98         Deque();
       
    99         }
       
   100     iProperty.Close();
       
   101     }
       
   102     
       
   103 ///////////////////////////////////
       
   104 // CNssDataSyncPropertyWatcher::DoCancel
       
   105 //
       
   106 // Cancel listening now
       
   107 ///////////////////////////////////
       
   108 void CNssDataSyncPropertyWatcher::DoCancel() 
       
   109     {
       
   110     iProperty.Cancel();
       
   111     }
       
   112 
       
   113 
       
   114 ///////////////////////////////////
       
   115 // CNssDataSyncPropertyWatcher::runL
       
   116 //
       
   117 // Is called, when property changed
       
   118 ///////////////////////////////////
       
   119 void CNssDataSyncPropertyWatcher::RunL()
       
   120     {
       
   121     RUBY_DEBUG_BLOCK( "CNssDataSyncPropertyWatcher::RunL" );
       
   122     if( iStatus != KErrNone ) 
       
   123         {
       
   124         // At least report the error
       
   125         RUBY_ERROR1( "CNssDataSyncPropertyWatcher::RunL iStatus is [%d]", iStatus.Int() );
       
   126         }
       
   127         
       
   128     // resubscribe before processing new value to prevent missing updates
       
   129     // even if some error happened
       
   130     iProperty.Subscribe( iStatus );
       
   131     SetActive();
       
   132     // property updated, get new value
       
   133     TInt dataSyncStatus;
       
   134     if ( iProperty.Get( dataSyncStatus) == KErrNotFound )
       
   135         {
       
   136         // not defined is the same as sync is not running
       
   137         dataSyncStatus = EDataSyncNotRunning;
       
   138         }
       
   139     iDataSyncStatus = static_cast<TDataSyncStatus>( dataSyncStatus );
       
   140     iHost->DataSyncStateChanged( InProgress() );
       
   141 
       
   142     }
       
   143     
       
   144 ///////////////////////////////////
       
   145 // CNssDataSyncPropertyWatcher::InProgress
       
   146 //
       
   147 // Tells if data sync is active right now
       
   148 ///////////////////////////////////
       
   149 TBool CNssDataSyncPropertyWatcher::InProgress()
       
   150 	{
       
   151 	// There can be several different "running" statuses, but only one "not running"
       
   152     // So check for not running
       
   153 	return iDataSyncStatus != EDataSyncNotRunning;
       
   154 	}
       
   155 
       
   156 //  End of File