|
1 /* |
|
2 * Copyright (c) 2009 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: Service provider settings backup helper monitor |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "spsapilogger.h" |
|
19 #include "spsbackuphelpermonitor.h" |
|
20 #include "spsbackuphelperperformer.h" |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CSpsBackupHelperMonitor* CSpsBackupHelperMonitor::NewL() |
|
30 { |
|
31 CSpsBackupHelperMonitor* self = new ( ELeave ) CSpsBackupHelperMonitor; |
|
32 CleanupStack::PushL( self ); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop( self ); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CSpsBackupHelperMonitor::~CSpsBackupHelperMonitor() |
|
43 { |
|
44 Cancel(); |
|
45 iProperty.Close(); |
|
46 delete iPerformer; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CSpsBackupHelperMonitor::CSpsBackupHelperMonitor() : |
|
54 CActive( CActive::EPriorityStandard ) |
|
55 { |
|
56 |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CSpsBackupHelperMonitor::ConstructL() |
|
64 { |
|
65 TInt err( KErrNone ); |
|
66 |
|
67 // Add to active scheduler |
|
68 CActiveScheduler::Add(this); |
|
69 |
|
70 // Set up the property to catch the BUR flag. |
|
71 TInt backupStateValue = 0; |
|
72 iProperty.Attach( KUidSystemCategory, conn::KUidBackupRestoreKey ); |
|
73 |
|
74 // Check current state to see if we were started for backup purposes |
|
75 iProperty.Get(backupStateValue); |
|
76 |
|
77 // Subscribe to the P&S flag to catch transitions |
|
78 Subscribe(); |
|
79 |
|
80 // Construct performer |
|
81 iPerformer = CSpsBackupHelperPerformer::NewL(); |
|
82 |
|
83 TRAP( err, ProcessBackupStateL(backupStateValue) ); |
|
84 XSPSLOGSTRING2( "CSpsBackupHelperMonitor::ConstructL, %i", err ); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void CSpsBackupHelperMonitor::ProcessBackupStateL( TInt aBackupStateValue ) |
|
92 { |
|
93 XSPSLOGSTRING2( "CSpsBackupHelperMonitor::ProcessBackupStateL, %i", aBackupStateValue ); |
|
94 |
|
95 // Do special logic when restore has ended |
|
96 if( RestoreOngoing( aBackupStateValue ) ) |
|
97 { |
|
98 XSPSLOGSTRING( "CSpsBackupHelperMonitor::ProcessBackupStateL, restore started" ); |
|
99 // Restore started. |
|
100 iParticipateRestore = ETrue; |
|
101 } |
|
102 else if( NoBackupRestore( aBackupStateValue ) && iParticipateRestore ) |
|
103 { |
|
104 XSPSLOGSTRING( "CSpsBackupHelperMonitor::ProcessBackupStateL, restore ended" ); |
|
105 // Increase priority so that restore process wont be interrupted so easily |
|
106 RProcess().SetPriority( ::EPriorityHigh ); |
|
107 |
|
108 // Performer available and no backup or restore ongoing |
|
109 // -> Restore has been ended. |
|
110 iPerformer->PerformL(); |
|
111 } |
|
112 |
|
113 if( NoBackupRestore( aBackupStateValue ) ) |
|
114 { |
|
115 XSPSLOGSTRING( "CSpsBackupHelperMonitor::ProcessBackupStateL, cleanup" ); |
|
116 iParticipateRestore = EFalse; |
|
117 } |
|
118 |
|
119 XSPSLOGSTRING( "CSpsBackupHelperMonitor::ProcessBackupStateL OUT" ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 TBool CSpsBackupHelperMonitor::RestoreOngoing( TInt aBackupStateValue ) |
|
127 { |
|
128 // Full or partial restore started/ongoing |
|
129 TBool ret = |
|
130 ( ( ( aBackupStateValue & conn::EBURRestoreFull ) == |
|
131 conn::EBURRestoreFull ) || |
|
132 ( ( aBackupStateValue & conn::EBURRestorePartial ) == |
|
133 conn::EBURRestorePartial ) ); |
|
134 |
|
135 return ret; |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 TBool CSpsBackupHelperMonitor::NoBackupRestore( TInt aBackupStateValue ) |
|
143 { |
|
144 // Not set or no backup or restore ongoing |
|
145 TBool ret = |
|
146 ( ( aBackupStateValue == conn::EBURUnset ) || |
|
147 ( aBackupStateValue == conn::EBURNormal ) ); |
|
148 |
|
149 return ret; |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 void CSpsBackupHelperMonitor::Subscribe() |
|
157 { |
|
158 iStatus = KRequestPending; |
|
159 iProperty.Subscribe(iStatus); |
|
160 SetActive(); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CSpsBackupHelperMonitor::RunL() |
|
168 { |
|
169 XSPSLOGSTRING( "CSpsBackupHelperMonitor::RunL IN" ); |
|
170 // The P&S flag has changed state, which could mean that the device is |
|
171 // either entering a backup, restore or normal state |
|
172 TInt backupStateValue = 0; // To store the P&S value |
|
173 |
|
174 // re-subscribe to the flag to monitor future changes |
|
175 Subscribe(); |
|
176 |
|
177 iProperty.Get(backupStateValue); |
|
178 |
|
179 // Process the mode change accordingly |
|
180 ProcessBackupStateL(backupStateValue); |
|
181 XSPSLOGSTRING( "CSpsBackupHelperMonitor::RunL OUT" ); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 TInt CSpsBackupHelperMonitor::RunError( TInt /*aError*/ ) |
|
189 { |
|
190 XSPSLOGSTRING( "CSpsBackupHelperMonitor::RunError" ); |
|
191 return KErrNone; |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CSpsBackupHelperMonitor::DoCancel() |
|
199 { |
|
200 iProperty.Cancel(); |
|
201 } |
|
202 |
|
203 // End of file |
|
204 |