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