|
1 /* |
|
2 * Copyright (c) 2005 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 the License "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: Class for making Feed Engine backup and restore aware. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "BackRestoreHandler.h" |
|
20 #include "FeedsServer.h" |
|
21 #include <e32property.h> // For RProperty Object; |
|
22 #include <SaCls.h> // For KUidBackupRestoreKey global variable |
|
23 #include <connect/sbdefs.h> // for conn Namespace |
|
24 |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CBackRestoreHandler::NewL |
|
28 // |
|
29 // Two-phased constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CBackRestoreHandler* CBackRestoreHandler::NewL(CFeedsServer* aFeedServer) |
|
33 { |
|
34 CBackRestoreHandler *self = NewLC(aFeedServer); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CBackRestoreHandler::NewLC |
|
43 // |
|
44 // Two-phased constructor. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CBackRestoreHandler* CBackRestoreHandler::NewLC(CFeedsServer* aFeedServer) |
|
48 { |
|
49 CBackRestoreHandler *self = new (ELeave) CBackRestoreHandler; |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aFeedServer); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CBackRestoreHandler::ConstructL |
|
59 // |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CBackRestoreHandler::ConstructL(CFeedsServer* aFeedServer) |
|
64 { |
|
65 CActiveScheduler::Add(this); |
|
66 iFeedServer = aFeedServer; |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CBackRestoreHandler::~CBackRestoreHandler() |
|
73 // |
|
74 // Destructor |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CBackRestoreHandler::~CBackRestoreHandler() |
|
78 { |
|
79 if(iIsListening) |
|
80 { |
|
81 StopListening(); |
|
82 } |
|
83 } |
|
84 |
|
85 |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CBackRestoreHandler::CBackRestoreHandler |
|
89 // |
|
90 // C++ default constructor can NOT contain any code that |
|
91 // might leave. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CBackRestoreHandler::CBackRestoreHandler():CActive(EPriorityStandard),iIsListening(EFalse),iIsBkpRestoreInProgress(EFalse) |
|
95 { |
|
96 |
|
97 } |
|
98 |
|
99 |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CBackRestoreHandler::RunL() |
|
103 // |
|
104 // To Receive event from Subscribe and publish server and |
|
105 // based on the status of backup or restore operation |
|
106 // this function wakes up or makes server sleeping |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CBackRestoreHandler::RunL() |
|
110 { |
|
111 if(iStatus == KErrNone) |
|
112 { |
|
113 TInt backupStateValue=-1; |
|
114 iProperty.Subscribe(iStatus); |
|
115 SetActive(); |
|
116 iProperty.Get(backupStateValue); |
|
117 if((backupStateValue == conn::EBURNormal | conn::ENoBackup )||backupStateValue == 0) // No backup or Restore activities |
|
118 { |
|
119 if(iIsBkpRestoreInProgress) // Check whether server was made sleeping by this class |
|
120 { |
|
121 iFeedServer->WakeupServerL(); |
|
122 iIsBkpRestoreInProgress = EFalse; |
|
123 } |
|
124 } |
|
125 else // Either backup or Restore is in Progress |
|
126 { |
|
127 if(!iIsBkpRestoreInProgress) // Check whether Server is already sleeping |
|
128 { |
|
129 iFeedServer->SleepServer(); |
|
130 iIsBkpRestoreInProgress = ETrue; |
|
131 } |
|
132 } |
|
133 } |
|
134 else if(iStatus == KErrCancel) |
|
135 { |
|
136 iIsListening = EFalse; |
|
137 } |
|
138 else |
|
139 { |
|
140 iIsListening = EFalse; |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CBackRestoreHandler::RunError() |
|
148 // |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 |
|
152 void CBackRestoreHandler::RunError() |
|
153 { |
|
154 |
|
155 } |
|
156 |
|
157 |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CBackRestoreHandler::DoCancel() |
|
161 // |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 |
|
165 void CBackRestoreHandler::DoCancel() |
|
166 { |
|
167 iProperty.Cancel(); |
|
168 } |
|
169 |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CBackRestoreHandler::StartListening() |
|
173 // |
|
174 // This function subscribe to receive events on active backup or restore activities |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CBackRestoreHandler::StartListening() |
|
178 { |
|
179 if(!IsActive()) |
|
180 { |
|
181 iProperty.Attach(KUidSystemCategory, KUidBackupRestoreKey); |
|
182 iProperty.Subscribe(iStatus); |
|
183 SetActive(); |
|
184 iIsListening = ETrue; |
|
185 } |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CBackRestoreHandler::StopListening() |
|
190 // |
|
191 // For cancellation of subscription |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CBackRestoreHandler::StopListening() |
|
195 { |
|
196 if(IsActive()) |
|
197 { |
|
198 this->Cancel(); |
|
199 iIsListening = EFalse; |
|
200 } |
|
201 } |