|
1 /* |
|
2 * Copyright (c) 2003 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: This module contains the implementation of CCbsSettings class |
|
15 * member functions. |
|
16 * |
|
17 * The server-side CbsClient subsession for modifying settings. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 |
|
24 #include "CbsCommon.h" |
|
25 #include "CbsServerPanic.h" |
|
26 #include "CbsServerConstants.h" |
|
27 #include "CCbsSettings.h" |
|
28 #include "CCbsDbImpSettings.H" |
|
29 #include "CCbsRecEtel.h" |
|
30 #include "CCbsServer.h" |
|
31 #include "CbsLogger.h" |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CCbsSettings::CCbsSettings |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CCbsSettings::CCbsSettings( |
|
42 CCbsSession& aSession, |
|
43 CCbsDbImpSettings& aSettings, |
|
44 CCbsRecEtel& aReceiver ) |
|
45 : CCbsObject( aSession ), |
|
46 iSettings( aSettings ), |
|
47 iReceiver( aReceiver ) |
|
48 { |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CCbsSettings::ConstructL |
|
53 // Symbian 2nd phase constructor can leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CCbsSettings::ConstructL() |
|
57 { |
|
58 // Add itself as an observer. |
|
59 iSettings.AddObserverL( this ); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CCbsSettings::NewL |
|
64 // Two-phased constructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CCbsSettings* CCbsSettings::NewL( |
|
68 CCbsSession& aSession, |
|
69 CCbsDbImpSettings& aSettings, |
|
70 CCbsRecEtel& aReceiver ) |
|
71 { |
|
72 CCbsSettings* self = |
|
73 new ( ELeave ) CCbsSettings( aSession, aSettings, aReceiver ); |
|
74 |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(); |
|
77 CleanupStack::Pop(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // Destructor |
|
82 CCbsSettings::~CCbsSettings() |
|
83 { |
|
84 CBSLOGSTRING("CBSSERVER: >>> CCbsSettings::~CCbsSettings()"); |
|
85 iSettings.RemoveObserver( this ); |
|
86 CBSLOGSTRING("CBSSERVER: <<< CCbsSettings::~CCbsSettings()"); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CCbsSettings::HandleRequestsL |
|
91 // Handles the requests for this subsession. |
|
92 // (other items were commented in a header). |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 TBool CCbsSettings::HandleRequestsL( |
|
96 const RMessage2& aMessage ) |
|
97 { |
|
98 CBSLOGSTRING("CBSSERVER: >>> CCbsSettings::HandleRequestsL()"); |
|
99 |
|
100 TBool requestHandled( ETrue ); |
|
101 |
|
102 // Check needed capabilities |
|
103 TBool hasCapWrite( EFalse ); |
|
104 hasCapWrite = aMessage.HasCapability( ECapabilityWriteDeviceData ); |
|
105 |
|
106 CBSLOGSTRING2("CBSSERVER: CCbsSettings::HandleRequestsL(), caps checked: %d", hasCapWrite ); |
|
107 |
|
108 // Get the request |
|
109 TInt function = aMessage.Function(); |
|
110 |
|
111 // If caps are not ok, leave |
|
112 if ( ( function == ECbsSetReceptionStatus || |
|
113 function == ECbsSetTopicDetectionStatus || |
|
114 function == ECbsSetLanguages ) && |
|
115 !hasCapWrite ) |
|
116 { |
|
117 CBSLOGSTRING("CBSSERVER: CCbsSettings::HandleRequestsL(): Caps NOT OK, leaving with KErrPermissionDenied..."); |
|
118 User::Leave( KErrPermissionDenied ); |
|
119 } |
|
120 |
|
121 // Handle the requests for the subsession |
|
122 switch ( function ) |
|
123 { |
|
124 case ECbsCloseSettingsSubsession: |
|
125 CloseSettings(); |
|
126 aMessage.Complete( KErrNone ); |
|
127 break; |
|
128 |
|
129 case ECbsGetReceptionStatus: |
|
130 GetReceptionStatusL(); |
|
131 break; |
|
132 |
|
133 case ECbsSetReceptionStatus: |
|
134 SetReceptionStatusL(); |
|
135 break; |
|
136 |
|
137 case ECbsGetTopicDetectionStatus: |
|
138 GetTopicDetectionStatusL(); |
|
139 break; |
|
140 |
|
141 case ECbsSetTopicDetectionStatus: |
|
142 SetTopicDetectionStatusL(); |
|
143 break; |
|
144 |
|
145 case ECbsGetLanguages: |
|
146 GetLanguagesL(); |
|
147 break; |
|
148 |
|
149 case ECbsSetLanguages: |
|
150 SetLanguagesL(); |
|
151 break; |
|
152 |
|
153 case ECbsNotifySettingsChanged: |
|
154 NotifySettingsChanged(); |
|
155 break; |
|
156 |
|
157 case ECbsNotifySettingsChangedCancel: |
|
158 NotifySettingsChangedCancel(); |
|
159 break; |
|
160 default: |
|
161 requestHandled = EFalse; |
|
162 break; |
|
163 } |
|
164 |
|
165 CBSLOGSTRING2("CBSSERVER: <<< CCbsSettings::HandleRequestsL(), returning requestHandled: %d", requestHandled ); |
|
166 return requestHandled; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CCbsSettings::TopicDetectionStatusChangedIndL |
|
171 // Called when the topic detection is changed. |
|
172 // (other items were commented in a header). |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CCbsSettings::TopicDetectionStatusChangedIndL() |
|
176 { |
|
177 // Notify the client in case there is a pending notification request. |
|
178 NotifyClientL( ECbsModifiedTopicDetectionStatus ); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CCbsSettings::ReceptionStatusChangedIndL |
|
183 // Called when reception status is changed. |
|
184 // (other items were commented in a header). |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CCbsSettings::ReceptionStatusChangedIndL() |
|
188 { |
|
189 // Notify the client in case there is a pending notification request. |
|
190 NotifyClientL( ECbsModifiedReceptionStatus ); |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CCbsSettings::LanguagesChangedIndL |
|
195 // Called when reception status is changed. |
|
196 // (other items were commented in a header). |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CCbsSettings::LanguagesChangedIndL() |
|
200 { |
|
201 // Notify the client in case there is a pending notification request. |
|
202 NotifyClientL( ECbsModifiedLanguages ); |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CCbsSettings::LimitedReceptionStatusChangedIndL |
|
207 // Called when reception status is changed. |
|
208 // (other items were commented in a header). |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CCbsSettings::LimitedReceptionStatusChangedIndL() |
|
212 { |
|
213 // Notify the client in case there is a pending notification request. |
|
214 NotifyClientL( ECbsModifiedLimitedReceptionStatus ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CCbsSettings::CleanupTimeChangedIndL |
|
219 // Called when clean up time of read messages is changed. |
|
220 // (other items were commented in a header). |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CCbsSettings::CleanupTimeChangedIndL() |
|
224 { |
|
225 // Notify the client in case there is a pending notification request. |
|
226 NotifyClientL( ECbsModifiedCleanupTime ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CCbsSettings::CloseSettings |
|
231 // Close the subsession. |
|
232 // Note that the method will delete itself, so the object is no |
|
233 // longer valid after the call. |
|
234 // (other items were commented in a header). |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CCbsSettings::CloseSettings() |
|
238 { |
|
239 // Removes the object. |
|
240 Session().Server().DeleteObjectByHandle( Message().Int3() ); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CCbsSettings::GetReceptionStatusL |
|
245 // Passes the reception status from the database to the client. |
|
246 // (other items were commented in a header). |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CCbsSettings::GetReceptionStatusL() |
|
250 { |
|
251 // First, get the reception status from the database. |
|
252 TBool receptionStatus( EFalse ); |
|
253 iSettings.GetReceptionStatus( receptionStatus ); |
|
254 |
|
255 // Write the reception status to the client side. |
|
256 TPckgBuf< TBool > statusPckg( receptionStatus ); |
|
257 Message().WriteL( 0, statusPckg ); |
|
258 |
|
259 // Complete the request. |
|
260 Message().Complete( KErrNone ); |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CCbsSettings::SetReceptionStatusL |
|
265 // Change the reception status to the requested one. |
|
266 // (other items were commented in a header). |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CCbsSettings::SetReceptionStatusL() |
|
270 { |
|
271 // Read the reception status from the client side and then |
|
272 // change the current status to the requested one. |
|
273 TPckgBuf< TBool > statusPckg( EFalse ); |
|
274 Message().ReadL( 0, statusPckg ); |
|
275 |
|
276 // Change the status. |
|
277 TBool status( statusPckg() ); |
|
278 iSettings.SetReceptionStatusL( status ); |
|
279 iReceiver.ApplyStateChangesL(); |
|
280 |
|
281 // Complete the request. |
|
282 Message().Complete( KErrNone ); |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CCbsSettings::GetTopicDetectionStatusL |
|
287 // Return the current topic detection status to the client. |
|
288 // (other items were commented in a header). |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CCbsSettings::GetTopicDetectionStatusL() |
|
292 { |
|
293 // First, get the topic detection status. |
|
294 TBool topicDetectionStatus( EFalse ); |
|
295 iSettings.GetTopicDetectionStatus( topicDetectionStatus ); |
|
296 |
|
297 // Write the topic detection status to the client side. |
|
298 TPckgBuf< TBool > statusPckg( topicDetectionStatus ); |
|
299 Message().WriteL( 0, statusPckg ); |
|
300 |
|
301 // Complete the request. |
|
302 Message().Complete( KErrNone ); |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CCbsSettings::SetTopicDetectionStatusL |
|
307 // Change the topic detection status to the requested one. |
|
308 // (other items were commented in a header). |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CCbsSettings::SetTopicDetectionStatusL() |
|
312 { |
|
313 // Read the topic detection status from the client side and then |
|
314 // change the current status to the requested one. |
|
315 TPckgBuf< TBool > statusPckg( EFalse ); |
|
316 Message().ReadL( 0, statusPckg ); |
|
317 |
|
318 iSettings.SetTopicDetectionStatusL( statusPckg() ); |
|
319 iReceiver.ApplyStateChangesL(); |
|
320 |
|
321 // Complete the request. |
|
322 Message().Complete( KErrNone ); |
|
323 } |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CCbsSettings::GetLanguagesL |
|
327 // Return the preferred languages to the client. |
|
328 // (other items were commented in a header). |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 void CCbsSettings::GetLanguagesL() |
|
332 { |
|
333 // Get the language settings. |
|
334 TCbsDbLanguages language; |
|
335 iSettings.GetLanguages( language ); |
|
336 |
|
337 // Write the preferred languages to the client side. |
|
338 TPckgBuf< TCbsSettingsLanguages > languagePckg( language ); |
|
339 Message().WriteL( 0, languagePckg ); |
|
340 |
|
341 // Complete the request. |
|
342 Message().Complete( KErrNone ); |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CCbsSettings::SetLanguagesL |
|
347 // Sets preferred languages. |
|
348 // (other items were commented in a header). |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CCbsSettings::SetLanguagesL() |
|
352 { |
|
353 // Read the preferred languages from the client side and then |
|
354 // change the current languages to the requested. |
|
355 TPckgBuf< TCbsSettingsLanguages > languagePckg; |
|
356 Message().ReadL( 0, languagePckg ); |
|
357 |
|
358 // Update db's language settings. |
|
359 TCbsDbLanguages languages( languagePckg() ); |
|
360 iSettings.SetLanguagesL( languages ); |
|
361 |
|
362 // Complete the request. |
|
363 Message().Complete( KErrNone ); |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CCbsSettings::NotifySettingsChanged |
|
368 // Make request to notify when settings are changed. |
|
369 // (other items were commented in a header). |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CCbsSettings::NotifySettingsChanged() |
|
373 { |
|
374 // If there is already a pending request, cancel it. |
|
375 if ( iIsMessage ) |
|
376 { |
|
377 NotifySettingsChangedCancel(); |
|
378 } |
|
379 |
|
380 // And then save the message. |
|
381 iMessage = Message(); |
|
382 iIsMessage = ETrue; |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // CCbsSettings::NotifySettingsChangedCancel |
|
387 // Cancel the request to notify when settings are changed. |
|
388 // (other items were commented in a header). |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 void CCbsSettings::NotifySettingsChangedCancel() |
|
392 { |
|
393 if ( iIsMessage ) |
|
394 { |
|
395 iMessage.Complete( KErrCancel ); |
|
396 } |
|
397 |
|
398 iIsMessage = EFalse; |
|
399 Message().Complete( KErrNone ); |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CCbsSettings::NotifyClientL |
|
404 // Notifies the client (if there is a pending request). |
|
405 // (other items were commented in a header). |
|
406 // ----------------------------------------------------------------------------- |
|
407 // |
|
408 void CCbsSettings::NotifyClientL( |
|
409 TCbsSettingsEvent aEvent ) |
|
410 { |
|
411 // If there is a pending request, then process it. |
|
412 if ( iIsMessage ) |
|
413 { |
|
414 // Make a pointer descriptor |
|
415 TPckg<TCbsSettingsEvent> eventPckg( aEvent ); |
|
416 iMessage.WriteL( 0, eventPckg ); |
|
417 |
|
418 iMessage.Complete( KErrNone ); |
|
419 iIsMessage = EFalse; |
|
420 } |
|
421 } |
|
422 |
|
423 |
|
424 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
425 // End of File |
|
426 |