sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Boilerplate code starts up server and exits the process when
|
sl@0
|
16 |
* the server has stopped.
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <scs/scsserver.h>
|
sl@0
|
26 |
#include <e32debug.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
NONSHARABLE_CLASS(CSystemActiveScheduler) : public CActiveScheduler
|
sl@0
|
29 |
{
|
sl@0
|
30 |
virtual void Error(TInt aError) const;
|
sl@0
|
31 |
};
|
sl@0
|
32 |
|
sl@0
|
33 |
void CSystemActiveScheduler::Error(TInt aError) const
|
sl@0
|
34 |
{
|
sl@0
|
35 |
// Ignore the error and continue...
|
sl@0
|
36 |
RDebug::Printf("SCS- Active object failed with code %d - IGNORED\n", aError);
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
static void RunServerL(TScsServerFactory aServerFactoryLC)
|
sl@0
|
40 |
/**
|
sl@0
|
41 |
Allocate and start the session counting server.
|
sl@0
|
42 |
|
sl@0
|
43 |
@param aServerFactoryLC Factory function defined in the implementation
|
sl@0
|
44 |
EXE, which allocates an instance of the server object
|
sl@0
|
45 |
and puts it on the cleanup stack.
|
sl@0
|
46 |
*/
|
sl@0
|
47 |
{
|
sl@0
|
48 |
CActiveScheduler* as = new(ELeave) CSystemActiveScheduler;
|
sl@0
|
49 |
CleanupStack::PushL(as);
|
sl@0
|
50 |
CActiveScheduler::Install(as);
|
sl@0
|
51 |
|
sl@0
|
52 |
// the server is started when it is allocated
|
sl@0
|
53 |
(void) aServerFactoryLC();
|
sl@0
|
54 |
|
sl@0
|
55 |
// tell launching process the server has started successfully
|
sl@0
|
56 |
RProcess::Rendezvous(KErrNone);
|
sl@0
|
57 |
|
sl@0
|
58 |
CActiveScheduler::Start();
|
sl@0
|
59 |
|
sl@0
|
60 |
// the active scheduler has been stopped here because there have
|
sl@0
|
61 |
// been no current sessions for the shutdown period.
|
sl@0
|
62 |
CleanupStack::PopAndDestroy(2, as);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
EXPORT_C TInt StartScsServer(TScsServerFactory aServerFactoryLC)
|
sl@0
|
66 |
/**
|
sl@0
|
67 |
This function must be called from the server executable's E32Main function.
|
sl@0
|
68 |
It sets up a cleanup stack and active scheduler before starting the server.
|
sl@0
|
69 |
|
sl@0
|
70 |
If the server is started successfully then this function does not return
|
sl@0
|
71 |
until the server shuts down.
|
sl@0
|
72 |
|
sl@0
|
73 |
@param aServerFactoryLC Factory function defined in the implementation
|
sl@0
|
74 |
EXE, which allocates an instance of the server object
|
sl@0
|
75 |
and puts it on the cleanup stack.
|
sl@0
|
76 |
@return Symbian OS error code. KErrNone indicates success,
|
sl@0
|
77 |
and any other value indicates failure.
|
sl@0
|
78 |
*/
|
sl@0
|
79 |
{
|
sl@0
|
80 |
__UHEAP_MARK;
|
sl@0
|
81 |
|
sl@0
|
82 |
// allocating a cleanup stack also installs it
|
sl@0
|
83 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
84 |
if (tc == 0)
|
sl@0
|
85 |
return KErrNoMemory;
|
sl@0
|
86 |
|
sl@0
|
87 |
TRAPD(r, RunServerL(aServerFactoryLC));
|
sl@0
|
88 |
|
sl@0
|
89 |
delete tc;
|
sl@0
|
90 |
|
sl@0
|
91 |
__UHEAP_MARKEND;
|
sl@0
|
92 |
|
sl@0
|
93 |
return r;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|