|
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 CCbsSession class |
|
15 * member functions. |
|
16 * |
|
17 * This class represents a server-side session. |
|
18 * |
|
19 * The instances of the class are responsible of handling |
|
20 * the requests of client-side RCbs and RCbsMcnSession objects. |
|
21 * |
|
22 * This class contains handlers for opening subsessions and |
|
23 * retrieving some general CBS information. |
|
24 * |
|
25 * Client will be panicked, if a request is invalid. |
|
26 * |
|
27 */ |
|
28 |
|
29 |
|
30 |
|
31 // INCLUDE FILES |
|
32 |
|
33 #include "CbsCommon.h" |
|
34 #include "CbsServerConstants.h" |
|
35 #include "CbsServerPanic.h" |
|
36 #include "CCbsServer.h" |
|
37 #include "CCbsSession.h" |
|
38 #include "CCbsObject.h" |
|
39 #include "CCbsRecEtel.h" |
|
40 #include "CCbsSettings.h" |
|
41 #include "CCbsTopicList.h" |
|
42 #include "CCbsTopicCollection.h" |
|
43 #include "CCbsTopicMessages.h" |
|
44 #include "CCbsMcnSession.h" |
|
45 |
|
46 #include "CCbsDbImp.H" |
|
47 #include "CbsLogger.h" |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CCbsSession::CCbsSession |
|
53 // C++ default constructor can NOT contain any code, that |
|
54 // might leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CCbsSession::CCbsSession( |
|
58 CCbsServer& aServer ) |
|
59 : CSession2(), |
|
60 iCbsServer( aServer ) |
|
61 { |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CCbsSession::ConstructL |
|
66 // Symbian 2nd phase constructor can leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CCbsSession::ConstructL() |
|
70 { |
|
71 CBSLOGSTRING("CBSSERVER: >>> CCbsSession::ConstructL()"); |
|
72 CBSLOGSTRING("CBSSERVER: <<< CCbsSession::ConstructL()"); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CCbsSession::NewL |
|
77 // Two-phased constructor. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CSession2* CCbsSession::NewL( |
|
81 CCbsServer& aServer ) |
|
82 { |
|
83 CCbsSession* self = new ( ELeave ) CCbsSession( aServer ); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 |
|
91 // Destructor |
|
92 // Session destructor is called when the client-side session |
|
93 // object makes a Close()-call. There's no need to send |
|
94 // a "close session" request to the server. |
|
95 CCbsSession::~CCbsSession() |
|
96 { |
|
97 CBSLOGSTRING("CBSSERVER: >>> CCbsSession::~CCbsSession()"); |
|
98 CBSLOGSTRING("CBSSERVER: <<< CCbsSession::~CCbsSession()"); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CCbsSession::DispatchMessageL |
|
103 // Finds the appropriate message service method and calls it to |
|
104 // handle the request. |
|
105 // |
|
106 // Relays a message to a proper message handling method. |
|
107 // (other items were commented in a header). |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CCbsSession::DispatchMessageL( |
|
111 const RMessage2& aMessage ) |
|
112 { |
|
113 if ( !HandleSessionRequestsL( aMessage ) ) |
|
114 { |
|
115 // The request was not for the session. Submit requests to |
|
116 // the correct subsessions. |
|
117 CCbsObject* object = iCbsServer.ReturnObjectByHandle( aMessage.Int3() ); |
|
118 |
|
119 if ( object ) |
|
120 { |
|
121 // Let the subsession to handle the request |
|
122 if ( !object->HandleRequestsL( aMessage ) ) |
|
123 { |
|
124 aMessage.Complete( KErrNotSupported ); |
|
125 } |
|
126 } |
|
127 else |
|
128 { |
|
129 PanicClient( ECbsBadRequest ); |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CCbsSession::HandleSessionRequestsL |
|
136 // Handles the session-based requests. |
|
137 // (other items were commented in a header). |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TBool CCbsSession::HandleSessionRequestsL( |
|
141 const RMessage2& aMessage ) |
|
142 { |
|
143 TBool result( ETrue ); |
|
144 TCbsServerRequest request( ( TCbsServerRequest ) aMessage.Function() ); |
|
145 |
|
146 // Handle requests for the session. |
|
147 switch ( request ) |
|
148 { |
|
149 case EMcnCloseSession: |
|
150 { |
|
151 // Close the session |
|
152 aMessage.Complete( KErrNone ); |
|
153 } |
|
154 break; |
|
155 |
|
156 case ECbsCloseSession: |
|
157 { |
|
158 // Close the session |
|
159 aMessage.Complete( KErrNone ); |
|
160 } |
|
161 break; |
|
162 |
|
163 case EMcnGetCellInfo: |
|
164 case EMcnGetInfoMessage: |
|
165 { |
|
166 GetCurrentMcnInfoL(); |
|
167 } |
|
168 break; |
|
169 |
|
170 case ECbsCreateSettingsSubsession: |
|
171 { |
|
172 NewSettingsL(); |
|
173 } |
|
174 break; |
|
175 |
|
176 case ECbsCreateTopicListSubsession: |
|
177 { |
|
178 NewTopicListL(); |
|
179 } |
|
180 |
|
181 break; |
|
182 |
|
183 case ECbsCreateTopicMessagesSubsession: |
|
184 { |
|
185 NewTopicMessagesL(); |
|
186 } |
|
187 break; |
|
188 |
|
189 case ECbsCreateTopicCollectionSubsession: |
|
190 { |
|
191 NewTopicCollectionL(); |
|
192 } |
|
193 break; |
|
194 |
|
195 case EMcnCreateSubsession: |
|
196 { |
|
197 NewMcnSubsessionL(); |
|
198 } |
|
199 break; |
|
200 |
|
201 case ECbsShutdown: |
|
202 { |
|
203 iCbsServer.Shutdown(); |
|
204 aMessage.Complete( KErrNone ); |
|
205 } |
|
206 break; |
|
207 |
|
208 default: |
|
209 // The request was not for the session. |
|
210 result = EFalse; |
|
211 } |
|
212 return result; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CCbsSession::PanicClient |
|
217 // Panics the client. |
|
218 // (other items were commented in a header). |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CCbsSession::PanicClient( |
|
222 TCbsSessionPanic aPanic ) const |
|
223 { |
|
224 // Panic |
|
225 iCurrentMessage.Panic( KCbsServerName, aPanic ); |
|
226 } |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CCbsSession::TotalTopicsDetected |
|
230 // Returns the number of new topics detected. |
|
231 // The counter will be reset after a call. |
|
232 // (other items were commented in a header). |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 TInt CCbsSession::TotalTopicsDetected() |
|
236 { |
|
237 return iCbsServer.TotalTopicsDetected(); |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CCbsSession::Message |
|
242 // Returns the current message in process |
|
243 // (other items were commented in a header). |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 RMessage2& CCbsSession::Message() |
|
247 { |
|
248 return iCurrentMessage; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CCbsSession::ServiceL |
|
253 // Handles the received message. |
|
254 // The method simply calls DispatchMessageL to process a |
|
255 // message and informs the client if the handling failed. |
|
256 // (other items were commented in a header). |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CCbsSession::ServiceL( |
|
260 const RMessage2& aMessage ) |
|
261 { |
|
262 iCurrentMessage = aMessage; |
|
263 |
|
264 TRAPD( result, DispatchMessageL( aMessage ) ); |
|
265 |
|
266 if ( result != KErrNone ) |
|
267 { |
|
268 // Inform the client |
|
269 aMessage.Complete( result ); |
|
270 } |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CCbsSession::NewSettingsL |
|
275 // Create a new subsession, settings, for the session. |
|
276 // (other items were commented in a header). |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 void CCbsSession::NewSettingsL() |
|
280 { |
|
281 // Create a new settings object |
|
282 CCbsSettings* object = |
|
283 CCbsSettings::NewL( *this, iCbsServer.Database().SettingsL(), |
|
284 iCbsServer.Receiver() ); |
|
285 |
|
286 // Add the object to the object container to generate unique id |
|
287 iCbsServer.Container().AddL( object ); |
|
288 |
|
289 // Add object to object index; this returns a unique handle so |
|
290 // we can get it again |
|
291 TInt handle( iCbsServer.ObjectIx().AddL( object ) ); |
|
292 |
|
293 // Write the handle to client |
|
294 TPckg< TInt > handlePckg( handle ); |
|
295 TRAPD( result, iCurrentMessage.WriteL( 3, handlePckg ) ); |
|
296 |
|
297 if ( result != KErrNone ) |
|
298 { |
|
299 // Writing failed, the client called the server in a wrong way |
|
300 iCbsServer.ObjectIx().Remove( handle ); |
|
301 PanicClient( ECbsBadDescriptor ); |
|
302 } |
|
303 else |
|
304 { |
|
305 Message().Complete( KErrNone ); |
|
306 } |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CCbsSession::NewTopicListL |
|
311 // Create a new subsession, topic list, for the session. |
|
312 // (other items were commented in a header). |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 void CCbsSession::NewTopicListL() |
|
316 { |
|
317 // Create a new topic list object |
|
318 CCbsTopicList* object = |
|
319 CCbsTopicList::NewL( *this, iCbsServer.Database().TopicListL(), |
|
320 iCbsServer.Receiver() ); |
|
321 |
|
322 // Add the object to the object container to generate unique id |
|
323 iCbsServer.Container().AddL( object ); |
|
324 |
|
325 // Add object to object index; this returns a unique handle |
|
326 // so we can get it again |
|
327 TInt handle( iCbsServer.ObjectIx().AddL( object ) ); |
|
328 |
|
329 // Write the handle to client |
|
330 TPckg< TInt > handlePckg2( handle ); |
|
331 TRAPD( result, iCurrentMessage.WriteL( 3, handlePckg2 ) ); |
|
332 |
|
333 if ( result != KErrNone ) |
|
334 { |
|
335 // Writing failed, the client called the server in a wrong way |
|
336 iCbsServer.ObjectIx().Remove( handle ); |
|
337 PanicClient( ECbsBadDescriptor ); |
|
338 } |
|
339 else |
|
340 { |
|
341 Message().Complete( KErrNone ); |
|
342 } |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CCbsSession::NewTopicCollectionL |
|
347 // Create a new subsession, topic collection, for the session. |
|
348 // (other items were commented in a header). |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CCbsSession::NewTopicCollectionL() |
|
352 { |
|
353 // Create a new topic list object |
|
354 CCbsTopicCollection* object = |
|
355 CCbsTopicCollection::NewL( *this, |
|
356 iCbsServer.Database().TopicCollectionL(), |
|
357 iCbsServer.Database().TopicListL() ); |
|
358 |
|
359 // Add the object to the object container to generate unique id |
|
360 iCbsServer.Container().AddL( object ); |
|
361 |
|
362 // Add object to object index; this returns a unique handle |
|
363 // so we can get it again |
|
364 TInt handle( iCbsServer.ObjectIx().AddL( object ) ); |
|
365 |
|
366 // Write the handle to client |
|
367 TPckg< TInt > handlePckg2( handle ); |
|
368 TRAPD( result, iCurrentMessage.WriteL( 3, handlePckg2 ) ); |
|
369 |
|
370 if ( result != KErrNone ) |
|
371 { |
|
372 // Writing failed, the client called the server in a wrong way |
|
373 iCbsServer.ObjectIx().Remove( handle ); |
|
374 PanicClient( ECbsBadDescriptor ); |
|
375 } |
|
376 else |
|
377 { |
|
378 Message().Complete( KErrNone ); |
|
379 } |
|
380 } |
|
381 |
|
382 // ----------------------------------------------------------------------------- |
|
383 // CCbsSession::NewTopicMessagesL |
|
384 // Create a new subsession, topic messages, for the session. |
|
385 // (other items were commented in a header). |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 void CCbsSession::NewTopicMessagesL() |
|
389 { |
|
390 // Create a new topic list object |
|
391 CCbsTopicMessages* object = |
|
392 CCbsTopicMessages::NewL( *this, |
|
393 iCbsServer.Database().TopicMessagesL(), |
|
394 iCbsServer.Receiver() ); |
|
395 |
|
396 // Add the object to the object container to generate unique id |
|
397 iCbsServer.Container().AddL( object ); |
|
398 |
|
399 // Add object to object index; this returns a unique handle |
|
400 // so we can get it again |
|
401 TInt handle( iCbsServer.ObjectIx().AddL( object ) ); |
|
402 |
|
403 // Write the handle to client |
|
404 TPckg< TInt > handlePckg2( handle ); |
|
405 TRAPD( result, iCurrentMessage.WriteL( 3, handlePckg2 ) ); |
|
406 |
|
407 if ( result != KErrNone ) |
|
408 { |
|
409 // Writing failed, the client called the server in a wrong way |
|
410 iCbsServer.ObjectIx().Remove( handle ); |
|
411 PanicClient( ECbsBadDescriptor ); |
|
412 } |
|
413 else |
|
414 { |
|
415 Message().Complete( KErrNone ); |
|
416 } |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CCbsSession::NewMcnSubsessionL |
|
421 // Create a new MCN subsession. |
|
422 // (other items were commented in a header). |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CCbsSession::NewMcnSubsessionL() |
|
426 { |
|
427 // Create a new settings object |
|
428 CCbsMcnSession* object = |
|
429 CCbsMcnSession::NewL( *this, iCbsServer.Receiver() ); |
|
430 |
|
431 // Add the object to the object container to generate unique id |
|
432 iCbsServer.Container().AddL( object ); |
|
433 |
|
434 // Add object to object index; this returns a unique handle so |
|
435 // we can get it again |
|
436 TInt handle( iCbsServer.ObjectIx().AddL( object ) ); |
|
437 |
|
438 // Write the handle to client |
|
439 TPckg< TInt > handlePckg( handle ); |
|
440 TRAPD( result, iCurrentMessage.WriteL( 3, handlePckg ) ); |
|
441 |
|
442 if ( result != KErrNone ) |
|
443 { |
|
444 // Writing failed, the client called the server in a wrong way |
|
445 iCbsServer.ObjectIx().Remove( handle ); |
|
446 PanicClient( ECbsBadDescriptor ); |
|
447 } |
|
448 else |
|
449 { |
|
450 Message().Complete( KErrNone ); |
|
451 } |
|
452 } |
|
453 |
|
454 // ----------------------------------------------------------------------------- |
|
455 // CCbsSession::GetCurrentMcnInfoL |
|
456 // Return the current cell info message to the client. |
|
457 // (other items were commented in a header). |
|
458 // ----------------------------------------------------------------------------- |
|
459 // |
|
460 void CCbsSession::GetCurrentMcnInfoL() |
|
461 { |
|
462 TBuf<KCbsMcnMessageMaxLength> buf; |
|
463 |
|
464 // First, read topic number from the client |
|
465 |
|
466 TInt topicNumber( 0 ); |
|
467 topicNumber = iCurrentMessage.Int1(); |
|
468 |
|
469 TInt infoReceived( KErrNone ); |
|
470 if ( topicNumber == KCellInfoTopic ) |
|
471 { |
|
472 infoReceived = iCbsServer.Receiver().GetCurrentMessage( buf, KCellInfoTopic ); |
|
473 } |
|
474 else if ( topicNumber == KHomeZoneTopic ) |
|
475 { |
|
476 infoReceived = iCbsServer.Receiver().GetCurrentMessage( buf, KHomeZoneTopic ); |
|
477 } |
|
478 else |
|
479 { |
|
480 infoReceived = KErrNotSupported; |
|
481 } |
|
482 |
|
483 TRAPD( result, iCurrentMessage.WriteL( 0, buf ) ); |
|
484 |
|
485 if ( result != KErrNone ) |
|
486 { |
|
487 PanicClient( ECbsBadDescriptor ); |
|
488 } |
|
489 else |
|
490 { |
|
491 Message().Complete( infoReceived ); |
|
492 } |
|
493 } |
|
494 |
|
495 // ----------------------------------------------------------------------------- |
|
496 // CCbsSession::Server |
|
497 // Return the server instance |
|
498 // (other items were commented in a header). |
|
499 // ----------------------------------------------------------------------------- |
|
500 // |
|
501 CCbsServer& CCbsSession::Server() |
|
502 { |
|
503 return iCbsServer; |
|
504 } |
|
505 |
|
506 // End of File |