locationsystemui/locationsysui/locverifier/src/lpdbkupevtlistenerao.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     1 /*
       
     2 * Copyright (c) 2002 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:  Active object which listens to Backup / Restore Events
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "lpdbkupevtlistenerao.h"
       
    21 #include "lpdbkupevtobserver.h"
       
    22 #include <connect/sbdefs.h>
       
    23 #include <e32property.h>
       
    24 
       
    25 // ================= MEMBER FUNCTIONS =======================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CLpdRequestAO::CLpdRequestAO
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CLpdBkupEvtListenerAO::CLpdBkupEvtListenerAO( MLpdBkupEvtObserver& aBkupObserver )
       
    34     : CActive( CActive::EPriorityHigh ), iBkupObserver( aBkupObserver )
       
    35     {
       
    36 	CActiveScheduler::Add(this);
       
    37 	}
       
    38 
       
    39 void CLpdBkupEvtListenerAO::ConstructL()
       
    40 	{
       
    41 	User::LeaveIfError(iProperty.Attach(KUidSystemCategory,conn::KUidBackupRestoreKey));
       
    42 	}
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CLpdRequestAO::NewL
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CLpdBkupEvtListenerAO* CLpdBkupEvtListenerAO::NewL( MLpdBkupEvtObserver& aBkupObserver )
       
    50 	{
       
    51     CLpdBkupEvtListenerAO* self = new( ELeave ) CLpdBkupEvtListenerAO( aBkupObserver );
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop(self);
       
    55     return self;
       
    56 	}
       
    57 
       
    58 // Destructor
       
    59 CLpdBkupEvtListenerAO::~CLpdBkupEvtListenerAO()
       
    60 	{
       
    61     Cancel();
       
    62     iProperty.Close();
       
    63 	}
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CLpdBkupEvtListenerAO::StartL
       
    67 // This method subscribes to Backup/Restore Event 
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CLpdBkupEvtListenerAO::StartL()
       
    71 	{
       
    72 	TInt backupFlag = 0;
       
    73 	TInt error = iProperty.Get(backupFlag);
       
    74 	switch(error)
       
    75 		{
       
    76 		case KErrNone:
       
    77 			// Backup/Restore is already running so Leave with KErrCancel.
       
    78 			// This will stop the verifier dialogs from being popped up.
       
    79 			if ((backupFlag & conn::KBackupIncTypeMask) != conn::ENoBackup )
       
    80 				{
       
    81 				User::Leave(KErrCancel);
       
    82 				}
       
    83 			// fall-through necessary
       
    84 
       
    85 		case KErrNotFound:
       
    86 			iProperty.Subscribe(iStatus);
       
    87 			SetActive();
       
    88 			break;
       
    89 		
       
    90 		default:
       
    91 			// In case of any other error Leave with the returned error code
       
    92 			User::LeaveIfError(error);
       
    93 			break;
       
    94 		}
       
    95 	}
       
    96 	
       
    97 // -----------------------------------------------------------------------------
       
    98 // CLpdBkupEvtListenerAO::RunL
       
    99 // Control is in this function when Backup / Restore event happens. 
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CLpdBkupEvtListenerAO::RunL()
       
   103     {
       
   104     // Check the value of the property.
       
   105     // If backup is started or restore is started then close the dialogs.
       
   106 	  TInt backupFlag;
       
   107 	  User::LeaveIfError(iProperty.Get(backupFlag));
       
   108 	  if ( (backupFlag & conn::KBackupIncTypeMask) != conn::ENoBackup )
       
   109 		  {
       
   110 		  iBkupObserver.ExitDialogL();	
       
   111 		  }
       
   112   	else
       
   113 		  {
       
   114 	    // Re-subscribe to the event
       
   115 	    iProperty.Subscribe(iStatus);
       
   116 	    SetActive();
       
   117 		  }
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CLpdBkupEvtListenerAO::DoCancel
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CLpdBkupEvtListenerAO::DoCancel()
       
   125     {
       
   126     iProperty.Cancel();
       
   127 	  }
       
   128 
       
   129 //  End of File