33
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2007 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: General functions
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <data_caging_path_literals.hrh>
|
|
21 |
#include "SatServerFactory.h"
|
|
22 |
#include "CSatSScheduler.h"
|
|
23 |
#include "SatSPanic.h"
|
|
24 |
#include "SatLog.h"
|
|
25 |
|
|
26 |
const TInt8 KInitServerPop( 2 );
|
|
27 |
_LIT( KSatServerMtx, "SATSERVERMTX" );
|
|
28 |
|
|
29 |
// ======== LOCAL FUNCTIONS ========
|
|
30 |
|
|
31 |
// -----------------------------------------------------------------------------
|
|
32 |
// PanicServer
|
|
33 |
// Panics the SatServer.
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
void PanicServer(
|
|
37 |
TSatSPanicCode aPanicCode ) // Panic code
|
|
38 |
{
|
|
39 |
LOG( SIMPLE, "SATSERVER: PanicServer" )
|
|
40 |
User::Panic( KSatServerPanic, aPanicCode );
|
|
41 |
}
|
|
42 |
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
// InitServerL
|
|
45 |
// Initialises the SatServer.
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
LOCAL_C void InitServerL()
|
|
49 |
{
|
|
50 |
LOG( SIMPLE, "SATSERVER: InitServerL calling" )
|
|
51 |
|
|
52 |
RMutex serverStartMutex;
|
|
53 |
TInt createErr( serverStartMutex.CreateGlobal( KSatServerMtx ) );
|
|
54 |
if ( createErr )
|
|
55 |
{
|
|
56 |
TInt openErr( serverStartMutex.OpenGlobal( KSatServerMtx ) );
|
|
57 |
User::LeaveIfError( openErr );
|
|
58 |
LOG( SIMPLE, "SATSERVER: Opened SATSERVERMTX" )
|
|
59 |
}
|
|
60 |
|
|
61 |
LOG( SIMPLE, "SATSERVER: Asking ownership of SATSERVERMTX" )
|
|
62 |
serverStartMutex.Wait();
|
|
63 |
LOG( SIMPLE, "SATSERVER: Got ownership of SATSERVERMTX" )
|
|
64 |
|
|
65 |
// create server - if one of this name does not already exist
|
|
66 |
TFindServer findSatServer( KSatServerName );
|
|
67 |
TFullName pathName;
|
|
68 |
|
|
69 |
// Search for the server.
|
|
70 |
if ( KErrNone != findSatServer.Next( pathName ) )
|
|
71 |
{
|
|
72 |
// We don't already exist.
|
|
73 |
// Start scheduler and server.
|
|
74 |
CSatSScheduler* scheduler = new ( ELeave ) CSatSScheduler;
|
|
75 |
__ASSERT_ALWAYS( scheduler !=
|
|
76 |
NULL, PanicServer( ESatSMainSchedulerError ) );
|
|
77 |
|
|
78 |
CleanupStack::PushL( scheduler );
|
|
79 |
CActiveScheduler::Install( scheduler );
|
|
80 |
|
|
81 |
// Rename the thread.
|
|
82 |
User::RenameThread( KSatServerName );
|
|
83 |
|
|
84 |
// Create the server and connect to external interfaces.
|
|
85 |
CSatSServer* server = CreateSatServerL();
|
|
86 |
CleanupStack::PushL( server );
|
|
87 |
|
|
88 |
// The scheduler needs access to the server instance.
|
|
89 |
//lint -e{613} scheduler cannot be null, due assertion in creation.
|
|
90 |
scheduler->SetServer( server );
|
|
91 |
|
|
92 |
// Call Rendezvous to improve startup time
|
|
93 |
RProcess::Rendezvous( KErrNone );
|
|
94 |
|
|
95 |
LOG( SIMPLE,
|
|
96 |
"SATSERVER: Releasing ownership of SATSERVERMTX, Starting.." )
|
|
97 |
serverStartMutex.Signal();
|
|
98 |
|
|
99 |
// start fielding requests from clients
|
|
100 |
CActiveScheduler::Start();
|
|
101 |
|
|
102 |
// finished when the scheduler stops
|
|
103 |
CleanupStack::PopAndDestroy( KInitServerPop ); // scheduler, server
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
LOG( SIMPLE,
|
|
108 |
"SATSERVER: Releasing ownership of SATSERVERMTX, Already started" )
|
|
109 |
serverStartMutex.Signal();
|
|
110 |
}
|
|
111 |
serverStartMutex.Close();
|
|
112 |
LOG( SIMPLE, "SATSERVER: InitServerL exiting" )
|
|
113 |
}
|
|
114 |
|
|
115 |
// ======== GLOBAL FUNCTIONS ========
|
|
116 |
|
|
117 |
// -----------------------------------------------------------------------------
|
|
118 |
// E32Main implements the executable entry function.
|
|
119 |
// Target type of the SATServer module is EXE.
|
|
120 |
// Creates a cleanup stack and runs the server.
|
|
121 |
// -----------------------------------------------------------------------------
|
|
122 |
//
|
|
123 |
GLDEF_C TInt E32Main()
|
|
124 |
{
|
|
125 |
__UHEAP_MARK;
|
|
126 |
|
|
127 |
// Get a new clean-up stack.
|
|
128 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
129 |
|
|
130 |
// Initialize and run the server.
|
|
131 |
TRAPD( error, InitServerL() );
|
|
132 |
__ASSERT_ALWAYS( !error, User::Panic( KSatSInitError, error ) );
|
|
133 |
|
|
134 |
// Destroy clean-up stack.
|
|
135 |
delete cleanup;
|
|
136 |
|
|
137 |
__UHEAP_MARKEND;
|
|
138 |
// Not called unless server is already running. This server is always on
|
|
139 |
LOG( SIMPLE, "SATSERVER: E32Main exiting" )
|
|
140 |
return KErrAlreadyExists;
|
|
141 |
}
|