homescreenpluginsrv/hspsmanager/src/hspsbrobserver.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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 "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:  Implementation of CHSPSBRObserver class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sbdefs.h>
       
    20 #include "hspsbrobserver.h"
       
    21 #include "hspsthemeserver.h"
       
    22 
       
    23 
       
    24 // ======== LOCAL FUNCTIONS ====================================================
       
    25 
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ===================================================
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CHSPSBRObserver::CHSPSBRObserver
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CHSPSBRObserver::CHSPSBRObserver( ChspsThemeServer& aServer ):
       
    37     CActive(CActive::EPriorityStandard),
       
    38     iServer( aServer )
       
    39     {
       
    40     CActiveScheduler::Add( this );
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CHSPSBRObserver::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CHSPSBRObserver::ConstructL()
       
    49     {
       
    50     User::LeaveIfError( iProperty.Attach( 
       
    51         KUidSystemCategory, 
       
    52         conn::KUidBackupRestoreKey ) );
       
    53     }
       
    54                     
       
    55 // -----------------------------------------------------------------------------
       
    56 // CHSPSBRObserver::NewL
       
    57 // Two-phased constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CHSPSBRObserver* CHSPSBRObserver::NewL( ChspsThemeServer& aServer )
       
    61     {
       
    62     CHSPSBRObserver* self = new( ELeave ) CHSPSBRObserver( aServer );
       
    63     
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop( self );
       
    67 
       
    68     return self;
       
    69     }
       
    70 
       
    71     
       
    72 // Destructor
       
    73 CHSPSBRObserver::~CHSPSBRObserver()
       
    74     {
       
    75     Cancel();
       
    76     iProperty.Close();
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CHSPSBRObserver::Start
       
    82 // Start the system agent to listen to the event
       
    83 // (other items were commented in a header).
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CHSPSBRObserver::Start()
       
    87     {
       
    88     Cancel();
       
    89     iProperty.Subscribe( iStatus );
       
    90     SetActive();
       
    91     }
       
    92 
       
    93 
       
    94 // -----------------------------------------------------------------------------                        
       
    95 // CHSPSBRObserver::RunError
       
    96 // -----------------------------------------------------------------------------
       
    97 //  
       
    98 TInt CHSPSBRObserver::RunError(TInt aError)
       
    99     {
       
   100     if( aError != KErrCancel )
       
   101         {
       
   102         Start();           
       
   103         }
       
   104     else 
       
   105         {
       
   106         Cancel();
       
   107         iProperty.Close();    
       
   108         }
       
   109     return KErrNone;
       
   110     };
       
   111 
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CHSPSBRObserver::RunL
       
   115 // from CActive
       
   116 // (other items were commented in a header).
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CHSPSBRObserver::RunL()
       
   120     {
       
   121     // Resubscribe before processing new value to prevent missing updates
       
   122     TInt backupStatus = 0;
       
   123     TInt err( iStatus.Int() );
       
   124     if ( err == KErrNone )
       
   125         {
       
   126         Start();
       
   127         User::LeaveIfError( iProperty.Get( 
       
   128                 KUidSystemCategory, 
       
   129                 conn::KUidBackupRestoreKey, backupStatus ) );
       
   130         // Forward backup status to listening server
       
   131         iServer.HandleBREventL( backupStatus );
       
   132         }
       
   133     else if ( err != KErrCancel ) // Ignore all errors except cancel
       
   134         {
       
   135         Start();
       
   136         }
       
   137     else // When cancel occurs, stop everything
       
   138         {
       
   139         User::Leave( KErrCancel );    
       
   140         }
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CHSPSBRObserver::DoCancel
       
   145 // From CActive
       
   146 // (other items were commented in a header).
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CHSPSBRObserver::DoCancel()
       
   150     {
       
   151     iProperty.Cancel();
       
   152     }
       
   153 
       
   154 // End of file