33
|
1 |
/*
|
|
2 |
* Copyright (c) 2003-2008 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 CCbsServer class
|
|
15 |
* member functions.
|
|
16 |
*
|
|
17 |
* This file contains the entry point for CbsServer.exe/dll.
|
|
18 |
*
|
|
19 |
*/
|
|
20 |
|
|
21 |
|
|
22 |
// INCLUDE FILES
|
|
23 |
|
|
24 |
#include <e32svr.h>
|
|
25 |
#include <barsc.h>
|
|
26 |
|
|
27 |
#include "CbsCommon.h"
|
|
28 |
#include "CCbsScheduler.h"
|
|
29 |
#include "CbsServerConstants.h"
|
|
30 |
#include "CbsServerPanic.h"
|
|
31 |
#include "CCbsServer.h"
|
|
32 |
#include "CCbsSession.h"
|
|
33 |
#include "CbsUtils.h"
|
|
34 |
|
|
35 |
#include "CCbsRecEtel.h"
|
|
36 |
#include "CCbsDbImp.H"
|
|
37 |
|
|
38 |
#include "CCbsDbImp.H"
|
|
39 |
#include "CCbsRecEtel.h"
|
|
40 |
|
|
41 |
#include "CCbsDbImpSettings.H"
|
|
42 |
#include "CCbsDbImpTopicList.h"
|
|
43 |
#include "CCbsReceiverHelper.h"
|
|
44 |
#include "CCbsSatRefresh.h"
|
|
45 |
|
|
46 |
#include <e32property.h>
|
|
47 |
#include "CbsServerInternalPSKeys.h"
|
|
48 |
#include "CCbsShutdownMonitor.h"
|
|
49 |
#include "CbsLogger.h"
|
|
50 |
#include "CbsServerUid.h"
|
|
51 |
|
|
52 |
|
|
53 |
// LOCAL FUNCTION PROTOTYPES
|
|
54 |
LOCAL_C void InitServerL();
|
|
55 |
|
|
56 |
// ==================== LOCAL FUNCTIONS ====================
|
|
57 |
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
// InitServerL
|
|
60 |
// Initializes and starts CBS Server.
|
|
61 |
// Creates the active scheduler and an instance of the server.
|
|
62 |
// Returns: None
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
LOCAL_C void InitServerL()
|
|
66 |
{
|
|
67 |
CBSLOGSTRING("CBSSERVER: >>> InitServerL()");
|
|
68 |
// perform init code under the cleanup stack
|
|
69 |
User::RenameThread( KCbsServerName );
|
|
70 |
|
|
71 |
// create server - if one of this name does not already exist
|
|
72 |
TFindServer findCbsServer( KCbsServerName );
|
|
73 |
TFullName pathName;
|
|
74 |
|
|
75 |
RMutex serverStartMutex;
|
|
76 |
TInt createErr( serverStartMutex.CreateGlobal( _L("CBSSERVERMTX") ) );
|
|
77 |
if ( createErr )
|
|
78 |
{
|
|
79 |
TInt openErr( serverStartMutex.OpenGlobal( _L("CBSSERVERMTX") ) );
|
|
80 |
User::LeaveIfError( openErr );
|
|
81 |
}
|
|
82 |
serverStartMutex.Wait();
|
|
83 |
|
|
84 |
if ( findCbsServer.Next( pathName ) != KErrNone )
|
|
85 |
{
|
|
86 |
// start scheduler and server
|
|
87 |
CCbsScheduler* scheduler = new (ELeave) CCbsScheduler;
|
|
88 |
CleanupStack::PushL( scheduler );
|
|
89 |
CActiveScheduler::Install( scheduler );
|
|
90 |
|
|
91 |
CCbsServer* server = CCbsServer::NewL();
|
|
92 |
CleanupStack::PushL( server );
|
|
93 |
|
|
94 |
// The scheduler needs access to the server instance.
|
|
95 |
scheduler->SetServer( server );
|
|
96 |
|
|
97 |
// Set the key using Publish & Subscribe
|
|
98 |
RProperty property;
|
|
99 |
_LIT_SECURITY_POLICY_PASS( KCbsServerReadPolicy );
|
|
100 |
_LIT_SECURITY_POLICY_S0( KCbsServerWritePolicy, KCbsServerUid3 );
|
|
101 |
|
|
102 |
property.Define( KPSUidCellBroadcast, KCbsServerStarted, RProperty::EInt, KCbsServerReadPolicy, KCbsServerWritePolicy );
|
|
103 |
CBSLOGSTRING("CBSSERVER: InitServerL(): Property defined.");
|
|
104 |
|
|
105 |
property.Set( KPSUidCellBroadcast, KCbsServerStarted, 1 );
|
|
106 |
CBSLOGSTRING("CBSSERVER: InitServerL(): Property set.");
|
|
107 |
|
|
108 |
property.Close();
|
|
109 |
|
|
110 |
serverStartMutex.Signal();
|
|
111 |
serverStartMutex.Close();
|
|
112 |
|
|
113 |
CBSLOGSTRING("CBSSERVER: InitServerL(): CbsServer created ok, starting active schduler.");
|
|
114 |
|
|
115 |
RProcess::Rendezvous( KErrNone );
|
|
116 |
|
|
117 |
// start fielding requests from clients
|
|
118 |
CActiveScheduler::Start();
|
|
119 |
CBSLOGSTRING("CBSSERVER: InitServerL(): CbsServer shutting down, destroying scheduler & server instances.");
|
|
120 |
|
|
121 |
// finished when the scheduler stops
|
|
122 |
CleanupStack::PopAndDestroy(2); // server, scheduler
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
serverStartMutex.Signal();
|
|
127 |
serverStartMutex.Close();
|
|
128 |
}
|
|
129 |
CBSLOGSTRING("CBSSERVER: <<< InitServerL()");
|
|
130 |
}
|
|
131 |
|
|
132 |
|
|
133 |
// ================= MEMBER FUNCTIONS =======================
|
|
134 |
|
|
135 |
// -----------------------------------------------------------------------------
|
|
136 |
// CCbsServer::CCbsServer
|
|
137 |
// C++ default constructor can NOT contain any code, that
|
|
138 |
// might leave.
|
|
139 |
// -----------------------------------------------------------------------------
|
|
140 |
//
|
|
141 |
CCbsServer::CCbsServer(
|
|
142 |
TInt aPriority )
|
|
143 |
: CServer2( aPriority )
|
|
144 |
{
|
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
// CCbsServer::ConstructL
|
|
149 |
// Symbian 2nd phase constructor can leave.
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
void CCbsServer::ConstructL()
|
|
153 |
{
|
|
154 |
CBSLOGSTRING( "CBSSERVER: >>> CCbsServer::ConstructL()" );
|
|
155 |
// Use PubSub to monitor shutdown event
|
|
156 |
iShutdownMonitor = CCbsShutdownMonitor::NewL( *this );
|
|
157 |
|
|
158 |
iReceiver = CCbsRecEtel::NewL();
|
|
159 |
|
|
160 |
iDatabase = CCbsDbImp::NewL();
|
|
161 |
|
|
162 |
iHelper = CCbsReceiverHelper::NewL( *iDatabase );
|
|
163 |
|
|
164 |
iReceiver->SetInterface( iHelper );
|
|
165 |
InitReceiverL();
|
|
166 |
|
|
167 |
// Create the container index.
|
|
168 |
iContainerIx = CObjectConIx::NewL();
|
|
169 |
iContainer = NewContainerL();
|
|
170 |
iIndex = CObjectIx::NewL();
|
|
171 |
|
|
172 |
// Create SAT refresh listener
|
|
173 |
TInt error( KErrNone );
|
|
174 |
TRAP( error, iSatRefresh = CCbsSatRefresh::NewL( *this ));
|
|
175 |
CBSLOGSTRING2( "CBSSERVER: CCbsServer::ConstructL(): CCbsSatRefresh::NewL error: %d", error );
|
|
176 |
|
|
177 |
// Start the server
|
|
178 |
if ( Start( KCbsServerName ) != KErrNone )
|
|
179 |
{
|
|
180 |
CbsServerPanic( ECbsServerStartFailed );
|
|
181 |
}
|
|
182 |
|
|
183 |
CBSLOGSTRING( "CBSSERVER: <<< CCbsServer::ConstructL()" );
|
|
184 |
}
|
|
185 |
|
|
186 |
// -----------------------------------------------------------------------------
|
|
187 |
// CCbsServer::NewL
|
|
188 |
// Two-phased constructor.
|
|
189 |
// -----------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
CCbsServer* CCbsServer::NewL()
|
|
192 |
{
|
|
193 |
CBSLOGSTRING("CBSSERVER: >>> CCbsServer::NewL()");
|
|
194 |
CCbsServer* self = new ( ELeave ) CCbsServer( KCbsServerPriority );
|
|
195 |
CleanupStack::PushL( self );
|
|
196 |
self->ConstructL();
|
|
197 |
CleanupStack::Pop();
|
|
198 |
CBSLOGSTRING("CBSSERVER: <<< CCbsServer::NewL()");
|
|
199 |
return self;
|
|
200 |
}
|
|
201 |
|
|
202 |
|
|
203 |
// Destructor
|
|
204 |
CCbsServer::~CCbsServer()
|
|
205 |
{
|
|
206 |
CBSLOGSTRING("CBSSERVER: >>> CCbsServer::~CCbsServer()");
|
|
207 |
// Note: it is important to delete in correct order
|
|
208 |
|
|
209 |
// The correct order is:
|
|
210 |
// 1st: sessions, subsessions and other server related objects
|
|
211 |
// 2nd: receiver
|
|
212 |
// 3rd: database
|
|
213 |
|
|
214 |
if ( iIndex )
|
|
215 |
{
|
|
216 |
delete iIndex;
|
|
217 |
iIndex = NULL;
|
|
218 |
}
|
|
219 |
|
|
220 |
if ( iContainer )
|
|
221 |
{
|
|
222 |
if ( iContainerIx )
|
|
223 |
{
|
|
224 |
iContainerIx->Remove( iContainer );
|
|
225 |
iContainer = NULL;
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
// Delete subsessions
|
|
230 |
if ( iContainerIx )
|
|
231 |
{
|
|
232 |
delete iContainerIx;
|
|
233 |
iContainerIx = NULL;
|
|
234 |
}
|
|
235 |
|
|
236 |
if ( iSatRefresh )
|
|
237 |
{
|
|
238 |
delete iSatRefresh;
|
|
239 |
iSatRefresh = NULL;
|
|
240 |
}
|
|
241 |
|
|
242 |
if ( iReceiver )
|
|
243 |
{
|
|
244 |
delete iReceiver;
|
|
245 |
iReceiver = NULL;
|
|
246 |
}
|
|
247 |
|
|
248 |
if ( iDatabase )
|
|
249 |
{
|
|
250 |
delete iDatabase;
|
|
251 |
iDatabase = NULL;
|
|
252 |
}
|
|
253 |
|
|
254 |
if ( iHelper )
|
|
255 |
{
|
|
256 |
delete iHelper;
|
|
257 |
iHelper = NULL;
|
|
258 |
}
|
|
259 |
|
|
260 |
if ( iShutdownMonitor )
|
|
261 |
{
|
|
262 |
delete iShutdownMonitor;
|
|
263 |
iShutdownMonitor = NULL;
|
|
264 |
}
|
|
265 |
|
|
266 |
CBSLOGSTRING("CBSSERVER: <<< CCbsServer::~CCbsServer()");
|
|
267 |
}
|
|
268 |
|
|
269 |
// -----------------------------------------------------------------------------
|
|
270 |
// CCbsServer::NewSessionL
|
|
271 |
// Creates a new session (an instance of CCbsSession).
|
|
272 |
//
|
|
273 |
// The method is meant to be called by the Symbian OS server framework and
|
|
274 |
// so it should not be used in any other case.
|
|
275 |
//
|
|
276 |
// The method leaves if the version given as parameter and the server
|
|
277 |
// version differ.
|
|
278 |
// (other items were commented in a header).
|
|
279 |
// -----------------------------------------------------------------------------
|
|
280 |
//
|
|
281 |
CSession2* CCbsServer::NewSessionL(
|
|
282 |
const TVersion& aVersion,
|
|
283 |
const RMessage2& /*aMessage*/ ) const
|
|
284 |
{
|
|
285 |
TVersion currentVersion( KCbsServerVersionMajor,
|
|
286 |
KCbsServerVersionMinor,
|
|
287 |
KCbsServerVersionBuild );
|
|
288 |
|
|
289 |
// Check the client version
|
|
290 |
if ( !User::QueryVersionSupported( currentVersion, aVersion ) )
|
|
291 |
{
|
|
292 |
User::Leave( KErrNotSupported );
|
|
293 |
}
|
|
294 |
|
|
295 |
// Create and return a new session
|
|
296 |
return CCbsSession::NewL( *( CCbsServer* ) this );
|
|
297 |
}
|
|
298 |
|
|
299 |
// -----------------------------------------------------------------------------
|
|
300 |
// CCbsServer::NewContainerL
|
|
301 |
// Creates a new session object container.
|
|
302 |
//
|
|
303 |
// It is the responsibility of the caller to delete the object
|
|
304 |
// container, when it is no longer used.
|
|
305 |
// (other items were commented in a header).
|
|
306 |
// -----------------------------------------------------------------------------
|
|
307 |
//
|
|
308 |
CObjectCon* CCbsServer::NewContainerL()
|
|
309 |
{
|
|
310 |
// Create the new container.
|
|
311 |
return iContainerIx->CreateL();
|
|
312 |
}
|
|
313 |
|
|
314 |
// -----------------------------------------------------------------------------
|
|
315 |
// CCbsServer::Database
|
|
316 |
// Returns a reference to the database.
|
|
317 |
// (other items were commented in a header).
|
|
318 |
// -----------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
CCbsDbImp& CCbsServer::Database()
|
|
321 |
{
|
|
322 |
return *iDatabase;
|
|
323 |
}
|
|
324 |
|
|
325 |
// -----------------------------------------------------------------------------
|
|
326 |
// CCbsServer::Receiver
|
|
327 |
// Returns a reference to the receiver.
|
|
328 |
// (other items were commented in a header).
|
|
329 |
// -----------------------------------------------------------------------------
|
|
330 |
//
|
|
331 |
CCbsRecEtel& CCbsServer::Receiver()
|
|
332 |
{
|
|
333 |
return *iReceiver;
|
|
334 |
}
|
|
335 |
|
|
336 |
// -----------------------------------------------------------------------------
|
|
337 |
// CCbsServer::TotalTopicsDetected
|
|
338 |
// Returns the total number of detected (via topic detection feature)
|
|
339 |
// topics and then clears the counter.
|
|
340 |
// (other items were commented in a header).
|
|
341 |
// -----------------------------------------------------------------------------
|
|
342 |
//
|
|
343 |
TInt CCbsServer::TotalTopicsDetected()
|
|
344 |
{
|
|
345 |
TInt count( iHelper->TopicsDetected() );
|
|
346 |
iHelper->ClearTopicsDetectedCounter();
|
|
347 |
return count;
|
|
348 |
}
|
|
349 |
|
|
350 |
// -----------------------------------------------------------------------------
|
|
351 |
// CCbsServer::PanicClient
|
|
352 |
// Panics the client.
|
|
353 |
// (other items were commented in a header).
|
|
354 |
// -----------------------------------------------------------------------------
|
|
355 |
//
|
|
356 |
void CCbsServer::PanicClient(
|
|
357 |
TInt aPanic ) const
|
|
358 |
{
|
|
359 |
__DEBUGGER(); // Debugger breakpoint in server's context.
|
|
360 |
Message().Panic( KCbsServerName, aPanic );
|
|
361 |
}
|
|
362 |
|
|
363 |
// -----------------------------------------------------------------------------
|
|
364 |
// CCbsServer::Shutdown
|
|
365 |
// Shuts down the server.
|
|
366 |
// (other items were commented in a header).
|
|
367 |
// -----------------------------------------------------------------------------
|
|
368 |
//
|
|
369 |
void CCbsServer::Shutdown()
|
|
370 |
{
|
|
371 |
CBSLOGSTRING("CBSSERVER: >>> CCbsServer::Shutdown()");
|
|
372 |
Cancel();
|
|
373 |
CActiveScheduler::Stop();
|
|
374 |
CBSLOGSTRING("CBSSERVER: <<< CCbsServer::Shutdown()");
|
|
375 |
}
|
|
376 |
|
|
377 |
// -----------------------------------------------------------------------------
|
|
378 |
// CCbsServer::ContainerIndex
|
|
379 |
// Returns the container index.
|
|
380 |
// (other items were commented in a header).
|
|
381 |
// -----------------------------------------------------------------------------
|
|
382 |
//
|
|
383 |
CObjectConIx& CCbsServer::ContainerIndex()
|
|
384 |
{
|
|
385 |
return *iContainerIx;
|
|
386 |
}
|
|
387 |
|
|
388 |
// -----------------------------------------------------------------------------
|
|
389 |
// CCbsServer::ServerMessage
|
|
390 |
// Returns the current IPC message.
|
|
391 |
// (other items were commented in a header).
|
|
392 |
// -----------------------------------------------------------------------------
|
|
393 |
//
|
|
394 |
const RMessage2 CCbsServer::ServerMessage() const
|
|
395 |
{
|
|
396 |
return Message();
|
|
397 |
}
|
|
398 |
|
|
399 |
// -----------------------------------------------------------------------------
|
|
400 |
// CCbsServer::ReturnObjectByHandle
|
|
401 |
// Returns a subsession object matching the given handle.
|
|
402 |
// (other items were commented in a header).
|
|
403 |
// -----------------------------------------------------------------------------
|
|
404 |
//
|
|
405 |
CCbsObject* CCbsServer::ReturnObjectByHandle(
|
|
406 |
TUint aHandle )
|
|
407 |
{
|
|
408 |
return ( CCbsObject* )iIndex->At( aHandle );
|
|
409 |
}
|
|
410 |
|
|
411 |
// -----------------------------------------------------------------------------
|
|
412 |
// CCbsServer::DeleteObjectByHandle
|
|
413 |
// Deletes a subsession
|
|
414 |
// (other items were commented in a header).
|
|
415 |
// -----------------------------------------------------------------------------
|
|
416 |
//
|
|
417 |
void CCbsServer::DeleteObjectByHandle(
|
|
418 |
TUint aHandle )
|
|
419 |
{
|
|
420 |
// Find object and then delete it
|
|
421 |
CCbsObject* object = ReturnObjectByHandle( aHandle );
|
|
422 |
|
|
423 |
if ( object )
|
|
424 |
{
|
|
425 |
// Remove from index (and it will delete the object)
|
|
426 |
iIndex->Remove( aHandle );
|
|
427 |
}
|
|
428 |
else
|
|
429 |
{
|
|
430 |
CbsServerPanic( EInvalidSessionObject );
|
|
431 |
}
|
|
432 |
}
|
|
433 |
|
|
434 |
// -----------------------------------------------------------------------------
|
|
435 |
// CCbsServer::Container
|
|
436 |
// Returns the object container
|
|
437 |
// (other items were commented in a header).
|
|
438 |
// -----------------------------------------------------------------------------
|
|
439 |
//
|
|
440 |
CObjectCon& CCbsServer::Container()
|
|
441 |
{
|
|
442 |
return *iContainer;
|
|
443 |
}
|
|
444 |
|
|
445 |
// -----------------------------------------------------------------------------
|
|
446 |
// CCbsServer::ObjectIx
|
|
447 |
// Returns the object index
|
|
448 |
// (other items were commented in a header).
|
|
449 |
// -----------------------------------------------------------------------------
|
|
450 |
//
|
|
451 |
CObjectIx& CCbsServer::ObjectIx()
|
|
452 |
{
|
|
453 |
return *iIndex;
|
|
454 |
}
|
|
455 |
|
|
456 |
// -----------------------------------------------------------------------------
|
|
457 |
// CCbsServer::InitReceiverL
|
|
458 |
// Initializes the receiver with values retrieved from the database.
|
|
459 |
// (other items were commented in a header).
|
|
460 |
// -----------------------------------------------------------------------------
|
|
461 |
//
|
|
462 |
void CCbsServer::InitReceiverL()
|
|
463 |
{
|
|
464 |
CBSLOGSTRING("CBSSERVER: >>> CCbsServer::InitReceiverL()");
|
|
465 |
|
|
466 |
// DB leave trapped.
|
|
467 |
TInt ignore( KErrNone );
|
|
468 |
TRAP( ignore, iReceiver->LoadSimTopicsL() );
|
|
469 |
CBSLOGSTRING2("CBSSERVER: CCbsServer::InitReceiverL(): LoadSimTopicsL() TRAPped error: %d", ignore);
|
|
470 |
|
|
471 |
iReceiver->ApplyStateChangesL();
|
|
472 |
|
|
473 |
CBSLOGSTRING("CBSSERVER: <<< CCbsServer::InitReceiverL()");
|
|
474 |
}
|
|
475 |
|
|
476 |
// -----------------------------------------------------------------------------
|
|
477 |
// CCbsServer::ReLoadSimTopicsL
|
|
478 |
// Initializes the receiver with values retrieved from the database.
|
|
479 |
// (other items were commented in a header).
|
|
480 |
// -----------------------------------------------------------------------------
|
|
481 |
//
|
|
482 |
void CCbsServer::ReLoadSimTopicsL()
|
|
483 |
{
|
|
484 |
CBSLOGSTRING("CBSSERVER: >>> CCbsServer::ReLoadSimTopicsL()");
|
|
485 |
|
|
486 |
TInt ignore( KErrNone );
|
|
487 |
|
|
488 |
TRAP( ignore, iReceiver->LoadSimTopicsL() );
|
|
489 |
CBSLOGSTRING2("CBSSERVER: CCbsServer::ReLoadSimTopicsL(): LoadSimTopicsL() TRAPped error: %d", ignore);
|
|
490 |
|
|
491 |
iReceiver->ApplyStateChangesL();
|
|
492 |
|
|
493 |
CBSLOGSTRING("CBSSERVER: <<< CCbsServer::ReLoadSimTopicsL()");
|
|
494 |
}
|
|
495 |
|
|
496 |
// ================= OTHER EXPORTED FUNCTIONS ==============
|
|
497 |
|
|
498 |
// -----------------------------------------------------------------------------
|
|
499 |
// E32Main
|
|
500 |
// E32Main implements the executable entry function.
|
|
501 |
// Creates a cleanup stack and runs the server.
|
|
502 |
// Returns: Zero
|
|
503 |
// -----------------------------------------------------------------------------
|
|
504 |
//
|
|
505 |
GLDEF_C TInt E32Main()
|
|
506 |
{
|
|
507 |
__UHEAP_MARK;
|
|
508 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
509 |
|
|
510 |
TRAPD( error, InitServerL() );
|
|
511 |
|
|
512 |
__ASSERT_ALWAYS( !error, User::Panic( KCbsServerName, error) );
|
|
513 |
delete cleanup;
|
|
514 |
__UHEAP_MARKEND;
|
|
515 |
return 0;
|
|
516 |
}
|
|
517 |
|
|
518 |
// ========================== OTHER EXPORTED FUNCTIONS =========================
|
|
519 |
// End of File
|