|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ASSrvServerWideData.h" |
|
17 |
|
18 // User Includes |
|
19 #include "ASSrvTimer.h" |
|
20 #include "ASSrvSession.h" |
|
21 #include "ASSrvDataPool.h" |
|
22 #include "ASSrvAlarmQueue.h" |
|
23 #include "ASSrvAlarmStore.h" |
|
24 #include "ASSrvStaticUtils.h" |
|
25 #include "ASSrvSessionEngine.h" |
|
26 #include "ASSrvSoundSettings.h" |
|
27 #include "ASSrvSoundController.h" |
|
28 #include "ASSrvAnyEventObserver.h" |
|
29 #include "ASSrvNotificationCoordinator.h" |
|
30 #include "ASSrvEnvironmentChangeManager.h" |
|
31 |
|
32 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
33 #include "assrvsystemstate.h" |
|
34 #endif |
|
35 |
|
36 CASSrvServerWideData::CASSrvServerWideData() : iCachedUtcOffset(0) |
|
37 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
38 , iServerIsReadOnly(EFalse) |
|
39 #endif |
|
40 { |
|
41 } |
|
42 |
|
43 CASSrvServerWideData::~CASSrvServerWideData() |
|
44 { |
|
45 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
46 delete iASSrvSystemState; |
|
47 #endif |
|
48 delete iStore; |
|
49 delete iSoundCountroller; |
|
50 delete iNotificationCoordinator; |
|
51 delete iDataPool; |
|
52 delete iSoundSettings; |
|
53 delete iTimer; |
|
54 delete iQueue; |
|
55 delete iEnvironmentChangeManager; |
|
56 |
|
57 iAnyEventObservers.Close(); |
|
58 iActiveSessions.Close(); |
|
59 |
|
60 iFsSession.Close(); |
|
61 } |
|
62 |
|
63 void CASSrvServerWideData::ConstructL() |
|
64 { |
|
65 User::LeaveIfError(iFsSession.Connect()); |
|
66 |
|
67 // NOTE: The construction order ***IS IMPORTANT*** |
|
68 iEnvironmentChangeManager = CASSrvEnvironmentChangeManager::NewL(*this); |
|
69 iQueue = CASSrvAlarmQueue::NewL(*this); |
|
70 iTimer = CASSrvAlarmTimer::NewL(*this); |
|
71 iSoundSettings = CASSrvSoundSettings::NewL(*this); |
|
72 iDataPool = CASSrvDataPool::NewL(*this); |
|
73 iNotificationCoordinator = CASSrvNotificationCoordinator::NewL(*this); |
|
74 iSoundCountroller = CASSrvSoundController::NewL(*this, *iNotificationCoordinator); |
|
75 iStore = CASSrvAlarmStore::NewL(*this); |
|
76 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
77 iASSrvSystemState = CASSrvSystemState::NewL(); |
|
78 iASSrvSystemState->RequestNotificationL(*iStore); |
|
79 iASSrvSystemState->RequestNotificationL(*this); |
|
80 #endif |
|
81 } |
|
82 |
|
83 CASSrvServerWideData* CASSrvServerWideData::NewL() |
|
84 { |
|
85 CASSrvServerWideData* self = new(ELeave) CASSrvServerWideData(); |
|
86 CleanupStack::PushL(self); |
|
87 self->ConstructL(); |
|
88 CleanupStack::Pop(self); |
|
89 return self; |
|
90 } |
|
91 |
|
92 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
93 void CASSrvServerWideData::MHandleSystemStateChange(TState aState) |
|
94 { |
|
95 switch (aState) |
|
96 { |
|
97 case EShutdown: |
|
98 { |
|
99 iServerIsReadOnly = ETrue; |
|
100 break; |
|
101 } |
|
102 case ENormal: |
|
103 { |
|
104 iServerIsReadOnly = EFalse; |
|
105 break; |
|
106 } |
|
107 default: |
|
108 break; |
|
109 } |
|
110 } |
|
111 |
|
112 TBool CASSrvServerWideData::ServerIsReadOnly() |
|
113 { |
|
114 return iServerIsReadOnly; |
|
115 } |
|
116 #endif |
|
117 |
|
118 /** |
|
119 * Access the file server session |
|
120 */ |
|
121 RFs& CASSrvServerWideData::FsSession() const |
|
122 { |
|
123 return const_cast<CASSrvServerWideData*>(this)->iFsSession; |
|
124 } |
|
125 |
|
126 /** |
|
127 * Access the sound settings |
|
128 */ |
|
129 CASSrvSoundSettings& CASSrvServerWideData::SoundSettings() const |
|
130 { |
|
131 return *iSoundSettings; |
|
132 } |
|
133 |
|
134 /** |
|
135 * Access the alarm queue |
|
136 */ |
|
137 CASSrvAlarmQueue& CASSrvServerWideData::Queue() const |
|
138 { |
|
139 return *iQueue; |
|
140 } |
|
141 |
|
142 /** |
|
143 * Access the sound controller |
|
144 */ |
|
145 CASSrvSoundController& CASSrvServerWideData::SoundController() const |
|
146 { |
|
147 return *iSoundCountroller; |
|
148 } |
|
149 |
|
150 /** |
|
151 * Access the data pool |
|
152 */ |
|
153 CASSrvDataPool& CASSrvServerWideData::DataPool() const |
|
154 { |
|
155 return *iDataPool; |
|
156 } |
|
157 |
|
158 /** |
|
159 * Access the timer |
|
160 */ |
|
161 CASSrvAlarmTimer& CASSrvServerWideData::Timer() const |
|
162 { |
|
163 return *iTimer; |
|
164 } |
|
165 |
|
166 /** |
|
167 * Access the "any event manager" |
|
168 */ |
|
169 MASSrvAnyEventManager& CASSrvServerWideData::AnyEventManager() const |
|
170 { |
|
171 return *const_cast<CASSrvServerWideData*>(this); |
|
172 } |
|
173 |
|
174 /** |
|
175 * Access the environment change manager |
|
176 */ |
|
177 CASSrvEnvironmentChangeManager& CASSrvServerWideData::EnvironmentChangeManager() const |
|
178 { |
|
179 return *iEnvironmentChangeManager; |
|
180 } |
|
181 |
|
182 /** |
|
183 * Access the notification co-ordinator |
|
184 */ |
|
185 CASSrvNotificationCoordinator& CASSrvServerWideData::NotificationCoordinator() const |
|
186 { |
|
187 return *iNotificationCoordinator; |
|
188 } |
|
189 |
|
190 /** |
|
191 * Access the session collection |
|
192 */ |
|
193 MASSrvSessionCollection& CASSrvServerWideData::SessionCollection() const |
|
194 { |
|
195 return *const_cast<CASSrvServerWideData*>(this); |
|
196 } |
|
197 |
|
198 /** |
|
199 * @see MASSrvAnyEventManager |
|
200 */ |
|
201 void CASSrvServerWideData::MASAnyEventManagerObserverAddL(MASSrvAnyEventObserver& aObserver) |
|
202 { |
|
203 User::LeaveIfError(iAnyEventObservers.InsertInAddressOrder(&aObserver)); |
|
204 } |
|
205 |
|
206 /** |
|
207 * @see MASSrvAnyEventManager |
|
208 */ |
|
209 void CASSrvServerWideData::MASAnyEventManagerObserverRemove(const MASSrvAnyEventObserver& aObserver) |
|
210 { |
|
211 TInt index = KErrNotFound; |
|
212 const TInt error = iAnyEventObservers.FindInAddressOrder(&aObserver, index); |
|
213 if (error != KErrNotFound) |
|
214 { |
|
215 iAnyEventObservers.Remove(index); |
|
216 } |
|
217 } |
|
218 |
|
219 /** |
|
220 * @see MASSrvAnyEventManager |
|
221 */ |
|
222 void CASSrvServerWideData::MASAnyEventManagerObserverNotifyChanges(TAlarmChangeEvent aEvent, TAlarmId aAlarmId) |
|
223 { |
|
224 const TInt count = iAnyEventObservers.Count(); |
|
225 for(TInt i=0; i<count; i++) |
|
226 { |
|
227 // Notify observers |
|
228 iAnyEventObservers[i]->MASSrvAnyEventHandleChange(aEvent, aAlarmId); |
|
229 } |
|
230 } |
|
231 |
|
232 /** |
|
233 * @see MASSrvSessionCollection |
|
234 */ |
|
235 TASSrvSessionId CASSrvServerWideData::MASSessionCollectionAttachL(const MASSrvSession& aSession) |
|
236 { |
|
237 // Add to collection |
|
238 User::LeaveIfError(iActiveSessions.InsertInAddressOrder(&aSession)); |
|
239 |
|
240 // Generate Id |
|
241 if (++iNextFreeSessionId == KMaxTInt) |
|
242 { |
|
243 iNextFreeSessionId = 0; |
|
244 } |
|
245 |
|
246 return iNextFreeSessionId; |
|
247 } |
|
248 |
|
249 /** |
|
250 * @see MASSrvSessionCollection |
|
251 */ |
|
252 void CASSrvServerWideData::MASSessionCollectionDetach(const MASSrvSession& aSession) |
|
253 { |
|
254 TInt index = KErrNotFound; |
|
255 const TInt error = iActiveSessions.FindInAddressOrder(&aSession, index); |
|
256 if (error != KErrNotFound) |
|
257 { |
|
258 iActiveSessions.Remove(index); |
|
259 } |
|
260 |
|
261 // Remove any session alarms for this session |
|
262 Queue().RemoveAllSessionAlarmsBySessionId(aSession.MASSrvSessionId()); |
|
263 } |
|
264 |
|
265 /** |
|
266 * @see MASSrvSessionCollection |
|
267 */ |
|
268 TInt CASSrvServerWideData::MASSessionCollectionAlarmOwner(TAlarmId aAlarmId, TDes& aFullName) const |
|
269 { |
|
270 // If the alarm doesn't have an originating session id then we can't return the owning session name. |
|
271 const TASSrvAlarm* alarm = Queue().QueueAlarmById(aAlarmId); |
|
272 if (!alarm) |
|
273 { |
|
274 // If the alarm doesn't exist then we can't return the owning session |
|
275 return KErrNotFound; |
|
276 } |
|
277 if (alarm->OriginatingSessionId() == KNullSessionId) |
|
278 { |
|
279 return KErrNotFound; |
|
280 } |
|
281 |
|
282 // If the originating session is no longer connected then we can't return the session name. |
|
283 const TInt count = iActiveSessions.Count(); |
|
284 for(TInt i=0; i<count; i++) |
|
285 { |
|
286 // Find the session which matches the originating session id |
|
287 const MASSrvSession& session = *iActiveSessions[i]; |
|
288 if (session.MASSrvSessionId() == alarm->OriginatingSessionId()) |
|
289 { |
|
290 // Get the session name |
|
291 session.MASSrvSessionFullName(aFullName); |
|
292 return KErrNone; |
|
293 } |
|
294 } |
|
295 return KErrNotFound; |
|
296 } |