|
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: |
|
15 * Methods for DB recovery. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkDbRecovery.h" |
|
22 #include "MPbkRecoveryErrorHandler.h" |
|
23 #include <PbkDebug.h> |
|
24 |
|
25 |
|
26 // ==================== MEMBER FUNCTIONS ==================== |
|
27 |
|
28 inline CPbkDbRecovery::CPbkDbRecovery(CContactDatabase& aDb) : |
|
29 iDb(aDb) |
|
30 { |
|
31 } |
|
32 |
|
33 inline void CPbkDbRecovery::ConstructL() |
|
34 { |
|
35 iDbChangeNotifier = CContactChangeNotifier::NewL(iDb,this); |
|
36 // High priority is used to prevent input events getting through before |
|
37 // the recover is started |
|
38 iStarter = CIdle::NewL(CActive::EPriorityHigh); |
|
39 } |
|
40 |
|
41 EXPORT_C CPbkDbRecovery* CPbkDbRecovery::NewL(CContactDatabase& aDb) |
|
42 { |
|
43 CPbkDbRecovery* self = new(ELeave) CPbkDbRecovery(aDb); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 CPbkDbRecovery::~CPbkDbRecovery() |
|
51 { |
|
52 delete iStarter; |
|
53 delete iDbChangeNotifier; |
|
54 } |
|
55 |
|
56 EXPORT_C void CPbkDbRecovery::SetErrorHandler |
|
57 (MPbkRecoveryErrorHandler* aErrorHandler) |
|
58 { |
|
59 iErrorHandler = aErrorHandler; |
|
60 } |
|
61 |
|
62 void CPbkDbRecovery::HandleDatabaseEventL(TContactDbObserverEvent aEvent) |
|
63 { |
|
64 if (aEvent.iType == EContactDbObserverEventRollback) |
|
65 { |
|
66 PBK_DEBUG_PRINT(PBK_DEBUG_STRING |
|
67 ("CPbkDbRecovery::HandleDatabaseEventL(0x%x,EContactDbObserverEventRollback)"), |
|
68 this); |
|
69 StartRecovery(); |
|
70 } |
|
71 } |
|
72 |
|
73 void CPbkDbRecovery::StartRecovery() |
|
74 { |
|
75 if(iStarter->IsActive()) |
|
76 { |
|
77 iStarter->Cancel(); |
|
78 } |
|
79 // Start the recovery using an asynchronous callback so that the Contact |
|
80 // DB event handler is able to return before starting the recovery. |
|
81 iStarter->Start(TCallBack(CPbkDbRecovery::DoRecoveryL,this)); |
|
82 } |
|
83 |
|
84 TBool CPbkDbRecovery::DoRecoveryL() |
|
85 { |
|
86 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkDbRecovery::DoRecoveryL(0x%x)"), |
|
87 this); |
|
88 TBool result = EFalse; |
|
89 |
|
90 TRAPD(err, iDb.RecoverL()); |
|
91 |
|
92 PBK_DEBUG_PRINT(PBK_DEBUG_STRING |
|
93 ("CPbkDbRecovery::DoRecoveryL(0x%x) recovery result=%d"), this, err); |
|
94 |
|
95 if (err != KErrNone) |
|
96 { |
|
97 if (iErrorHandler) |
|
98 { |
|
99 // Use error handler to determine if recovery is to be tried again |
|
100 result = iErrorHandler->HandleDbRecoveryError(err); |
|
101 } |
|
102 else |
|
103 { |
|
104 // No error handler -> just leave with the error code |
|
105 User::Leave(err); |
|
106 } |
|
107 } |
|
108 |
|
109 return result; |
|
110 } |
|
111 |
|
112 TInt CPbkDbRecovery::DoRecoveryL(TAny* aSelf) |
|
113 { |
|
114 return (static_cast<CPbkDbRecovery*>(aSelf)->DoRecoveryL()); |
|
115 } |
|
116 |
|
117 |
|
118 // End of File |