filemanager/schbkup/src/filemanagerschsubscriber.cpp
branchRCL_3
changeset 21 65326cf895ed
parent 0 6a9f87576119
equal deleted inserted replaced
20:491b3ed49290 21:65326cf895ed
       
     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 "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:  Handles P&S and CenRep notifications
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <centralrepository.h>
       
    22 #include "filemanagerschsubscriber.h"
       
    23 #include "filemanagerschobserver.h"
       
    24 #include "FileManagerDebug.h"
       
    25 
       
    26 
       
    27 // CONSTANTS
       
    28 const TUint32 KMicroSecsPerSec = 1000000;
       
    29 
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CFileManagerSchSubscriber::NewL()
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CFileManagerSchSubscriber* CFileManagerSchSubscriber::NewL(
       
    38         MFileManagerSchObserver& aObserver,
       
    39         const TUid& aCategory,
       
    40         const TUint aKey,
       
    41         const TType aType,
       
    42         const TInt aTimeoutSecs )
       
    43     {
       
    44     CFileManagerSchSubscriber* self =
       
    45         new (ELeave)CFileManagerSchSubscriber(
       
    46             aObserver, aCategory, aKey, aType, aTimeoutSecs );
       
    47 
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop( self );
       
    51 
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CFileManagerSchSubscriber::ConstructL()
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CFileManagerSchSubscriber::ConstructL()
       
    60     {
       
    61     CActiveScheduler::Add( this );
       
    62 
       
    63     if ( iType == ESubscribePS )
       
    64         {
       
    65         User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    66         }
       
    67     else
       
    68         {
       
    69         iCenRep = CRepository::NewL( iCategory );
       
    70         }
       
    71 
       
    72     SubscribeL();
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CFileManagerSchSubscriber::SubscribeL()
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CFileManagerSchSubscriber::SubscribeL()
       
    80     {
       
    81     iTimeout = EFalse;
       
    82 
       
    83     if ( iType == ESubscribePS )
       
    84         {
       
    85         iProperty.Subscribe( iStatus );
       
    86         }
       
    87     else
       
    88         {
       
    89         User::LeaveIfError( iCenRep->NotifyRequest( iKey, iStatus ) );
       
    90         }
       
    91 
       
    92     if ( iTimeoutSecs > 0 )
       
    93         {
       
    94         delete iTimer;
       
    95         iTimer = NULL;
       
    96 
       
    97         iTimer = CPeriodic::NewL( EPriorityStandard );
       
    98         TUint32 us( iTimeoutSecs * KMicroSecsPerSec );
       
    99         iTimer->Start( us, us, TCallBack( TimeoutCB, this ) );
       
   100         }
       
   101 
       
   102     SetActive();
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CFileManagerSchSubscriber::TimeoutCB()
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 TInt CFileManagerSchSubscriber::TimeoutCB( void* aPtr )
       
   110     {
       
   111     CFileManagerSchSubscriber* self =
       
   112         static_cast< CFileManagerSchSubscriber* >( aPtr );
       
   113 
       
   114     self->Timeout();
       
   115 
       
   116     return KErrNone;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CFileManagerSchSubscriber::Timeout()
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CFileManagerSchSubscriber::Timeout()
       
   124     {
       
   125     delete iTimer;
       
   126     iTimer = NULL;
       
   127 
       
   128     Cancel();
       
   129 
       
   130     // Set timeout status
       
   131     iTimeout = ETrue;
       
   132 
       
   133     // Complete
       
   134     TRequestStatus* status = &iStatus;
       
   135     User::RequestComplete( status, KErrNone );
       
   136     SetActive();
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CFileManagerSchSubscriber::CFileManagerSchSubscriber()
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 CFileManagerSchSubscriber::CFileManagerSchSubscriber(
       
   144         MFileManagerSchObserver& aObserver,
       
   145         const TUid& aCategory,
       
   146         const TUint aKey,
       
   147         const TType aType,
       
   148         const TInt aTimeoutSecs ) :
       
   149     CActive( EPriorityStandard ),
       
   150     iObserver( aObserver ),
       
   151     iCategory( aCategory),
       
   152     iKey( aKey ),
       
   153     iType( aType ),
       
   154     iTimeoutSecs ( aTimeoutSecs )
       
   155     {
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CFileManagerSchSubscriber::RunL()
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CFileManagerSchSubscriber::RunL()
       
   163     {
       
   164     // If timeout, no need to resubscribe
       
   165     if ( !iTimeout )
       
   166         {
       
   167         SubscribeL();
       
   168         }
       
   169 
       
   170     iObserver.NotifyKeyChangeOrTimeoutL( iCategory, iKey, iTimeout );
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CFileManagerSchSubscriber::DoCancel()
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 void CFileManagerSchSubscriber::DoCancel()
       
   178     {
       
   179     delete iTimer;
       
   180     iTimer = NULL;
       
   181 
       
   182     if ( iType == ESubscribePS )
       
   183         {
       
   184         iProperty.Cancel();
       
   185         }
       
   186     else
       
   187         {
       
   188         iCenRep->NotifyCancel( iKey );
       
   189         }
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CFileManagerSchSubscriber::RunError()
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 TInt CFileManagerSchSubscriber::RunError( TInt aError )
       
   197     {    
       
   198     ERROR_LOG1( "CFileManagerSchSubscriber::RunError()-Error=%d", aError )
       
   199     return aError;
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CFileManagerSchSubscriber::~CFileManagerSchSubscriber()
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 CFileManagerSchSubscriber::~CFileManagerSchSubscriber()
       
   207     {
       
   208     Cancel();
       
   209     iProperty.Close();
       
   210     delete iCenRep;
       
   211     delete iTimer;
       
   212     }
       
   213 
       
   214 // End of File
       
   215 
       
   216