|
1 /* |
|
2 * Copyright (c) 2006-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file tinterpretsisserver.cpp |
|
21 */ |
|
22 |
|
23 #include "tinterpretsisserver.h" |
|
24 #include "tinterpretsisstep.h" |
|
25 |
|
26 _LIT(KServerName, "tinterpretsis"); |
|
27 CInterpretsisServer* CInterpretsisServer::NewL() |
|
28 /** |
|
29 * @return - Instance of the test server |
|
30 * Called inside the Mail() function to create and start the |
|
31 * CTestServer derived server |
|
32 * |
|
33 */ |
|
34 { |
|
35 CInterpretsisServer* server = new (ELeave) CInterpretsisServer(); |
|
36 CleanupStack::PushL(server); |
|
37 server->StartL(KServerName); |
|
38 CleanupStack::Pop(server); |
|
39 return server; |
|
40 } |
|
41 |
|
42 |
|
43 CTestStep* CInterpretsisServer::CreateTestStep(const TDesC& aStepName) |
|
44 /** |
|
45 * @return - A CTestStep derived instance |
|
46 * Implementation of CTestServer pure virtual |
|
47 */ |
|
48 { |
|
49 CTestStep* testStep = NULL; |
|
50 if(aStepName == KInterpretsisStep) |
|
51 testStep = new CInterpretsisStep(); |
|
52 return testStep; |
|
53 } |
|
54 |
|
55 #if (!defined EKA2) |
|
56 LOCAL_C void MainL() |
|
57 /** |
|
58 * REQUIRES semaphore to sync with client as the Rendezvous() |
|
59 * calls are not available |
|
60 */ |
|
61 { |
|
62 CActiveScheduler* sched=NULL; |
|
63 sched=new(ELeave) CActiveScheduler; |
|
64 CleanupStack::PushL(sched); |
|
65 CActiveScheduler::Install(sched); |
|
66 // __EDIT_ME__ Your server name here |
|
67 CInterpretsisServer* server = NULL; |
|
68 // Create the CTestServer derived server . __EDIT_ME__ Your server |
|
69 TRAPD(err,server = CInterpretsisServer::NewL()); |
|
70 if(!err) |
|
71 { |
|
72 CleanupStack::PushL(server); |
|
73 RSemaphore sem; |
|
74 // The client API will already have created the semaphore |
|
75 User::LeaveIfError(sem.OpenGlobal(KServerName)); |
|
76 CleanupStack::Pop(server); |
|
77 // Sync with the client then enter the active scheduler |
|
78 sem.Signal(); |
|
79 sem.Close(); |
|
80 sched->Start(); |
|
81 } |
|
82 CleanupStack::Pop(sched); |
|
83 delete server; |
|
84 delete sched; |
|
85 } |
|
86 #else |
|
87 // EKA2 much simpler |
|
88 // Just an E32Main and a MainL() |
|
89 LOCAL_C void MainL() |
|
90 /** |
|
91 * Much simpler, uses the new Rendezvous() call to sync with the client |
|
92 */ |
|
93 { |
|
94 // Leave the hooks in for platform security |
|
95 #if (defined __DATA_CAGING__) |
|
96 RProcess().DataCaging(RProcess::EDataCagingOn); |
|
97 RProcess().SecureApi(RProcess::ESecureApiOn); |
|
98 #endif |
|
99 CActiveScheduler* sched=NULL; |
|
100 sched=new(ELeave) CActiveScheduler; |
|
101 CActiveScheduler::Install(sched); |
|
102 // __EDIT_ME__ Your server name |
|
103 CInterpretsisServer* server = NULL; |
|
104 // Create the CTestServer derived server |
|
105 // __EDIT_ME__ Your server name |
|
106 TRAPD(err,server = CInterpretsisServer::NewL()); |
|
107 if(!err) |
|
108 { |
|
109 // Sync with the client and enter the active scheduler |
|
110 RProcess::Rendezvous(KErrNone); |
|
111 sched->Start(); |
|
112 } |
|
113 delete server; |
|
114 delete sched; |
|
115 } |
|
116 #endif |
|
117 |
|
118 GLDEF_C TInt E32Main() |
|
119 /** |
|
120 * @return - Standard Epoc error code on exit |
|
121 */ |
|
122 { |
|
123 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
124 if(cleanup == NULL) |
|
125 { |
|
126 return KErrNoMemory; |
|
127 } |
|
128 TRAP_IGNORE(MainL()); |
|
129 delete cleanup; |
|
130 return KErrNone; |
|
131 } |
|
132 |
|
133 // Create a thread in the calling process |
|
134 // Emulator typhoon and earlier |
|
135 #if (defined __WINS__ && !defined EKA2) |
|
136 TInt ThreadFunc (TAny* /*aParam*/) |
|
137 /** |
|
138 * @return - Server exit code |
|
139 * @param - unused |
|
140 * Server Thread function. Guts of the code in the MainL() function |
|
141 */ |
|
142 { |
|
143 return E32Main(); |
|
144 } |
|
145 |
|
146 EXPORT_C TInt WinsMain() |
|
147 /** |
|
148 * @return - Standard Epoc error codes |
|
149 * 1st and only ordinal, called by the client API to initialise the server |
|
150 */ |
|
151 { |
|
152 _LIT(KThread,"Thread"); |
|
153 RThread thread; |
|
154 // __EDIT_ME__ - Make sure the TBuf is large enough |
|
155 TBuf<KMaxTestExecuteNameLength> threadName(KServerName); |
|
156 // Create a hopefully unique thread name and use the ThreadFunc |
|
157 threadName.Append(KThread); |
|
158 const TInt KMaxHeapSize = 0x1000000; ///< Allow a 1Mb max heap |
|
159 TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize, |
|
160 KMinHeapSize, KMaxHeapSize, |
|
161 NULL, EOwnerProcess); |
|
162 if(err) |
|
163 return err; |
|
164 thread.Resume(); |
|
165 thread.Close(); |
|
166 return KErrNone; |
|
167 } |
|
168 |
|
169 GLDEF_C TInt E32Dll(enum TDllReason) |
|
170 { |
|
171 return 0; |
|
172 } |
|
173 |
|
174 #endif |