|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Client access to the AppArc server |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32svr.h> |
|
20 #include <e32math.h> |
|
21 #include <apasvst.h> |
|
22 #include <apsserv.h> |
|
23 #include <e32uid.h> |
|
24 |
|
25 _LIT(KNameApaImage,"APSEXE"); |
|
26 const TUid KServerUid3 = { 0x10003A3F }; |
|
27 const TInt KApaServThreadMaxHeapSize = 0x100000; // 1Mb |
|
28 const TInt KApaServThreadStackSize = 0x3000; // Apparc server need extra stack as it has a lot of filenames and parse objects on stack from time to time |
|
29 |
|
30 EXPORT_C TInt StartupApaServer(MApaAppStarter& aAppStarter) |
|
31 /** |
|
32 Start the server in a thread, using the supplied app starter. |
|
33 |
|
34 @internalTechnology |
|
35 */ |
|
36 { |
|
37 RThread server; |
|
38 TInt r=server.Create(NameApaServServerThread(),ApaServThreadStart,KApaServThreadStackSize,KMinHeapSize,KApaServThreadMaxHeapSize,&aAppStarter,EOwnerThread); |
|
39 if (r!=KErrNone) |
|
40 return r; |
|
41 TRequestStatus stat; |
|
42 server.Rendezvous(stat); |
|
43 if (stat!=KRequestPending) |
|
44 server.Kill(0); // abort startup |
|
45 else |
|
46 server.Resume(); // logon OK - start the server |
|
47 User::WaitForRequest(stat); // wait for start or death |
|
48 server.Close(); |
|
49 return stat.Int(); |
|
50 } |
|
51 |
|
52 EXPORT_C TInt StartupApaServerProcess() |
|
53 /** |
|
54 StartupApaServerProcess |
|
55 Start the server in a process, (or thread in EKA1 WINS). Simultaneous launching |
|
56 of two such processes should be detected when the second one attempts to |
|
57 create the server object, failing with KErrAlreadyExists. |
|
58 |
|
59 @publishedPartner |
|
60 */ |
|
61 { |
|
62 const TUidType uidType(KNullUid, KNullUid, KServerUid3); |
|
63 TInt r=KErrNone; |
|
64 |
|
65 #ifdef APA_SERVER_IN_THREAD |
|
66 // In WINS the server is a DLL, the exported entrypoint returns a TInt |
|
67 // which represents the real entry-point for the server thread |
|
68 RLibrary lib; |
|
69 r=lib.Load(KNameApaImage,uidType); |
|
70 if (r!=KErrNone) |
|
71 return r; |
|
72 TLibraryFunction ordinal1=lib.Lookup(1); |
|
73 TThreadFunction serverFunc=reinterpret_cast<TThreadFunction>(ordinal1()); |
|
74 // To deal with the unique thread (+semaphore!) naming in EPOC, and that we may |
|
75 // be trying to restart a server that has just exited we attempt to create a |
|
76 // unique thread name for the server. |
|
77 // This uses Math::Random() to generate a 32-bit random number for the name |
|
78 TName name(NameApaServServerThread()); |
|
79 name.AppendNum(Math::Random(),EHex); |
|
80 RThread server; |
|
81 r=server.Create(name, serverFunc, KApaServThreadStackSize, NULL, &lib, NULL, KMinHeapSize,KApaServThreadMaxHeapSize, EOwnerProcess); |
|
82 lib.Close(); |
|
83 #else |
|
84 // On ARM or any EKA2 target, the server is an EXE. |
|
85 // Create a process from it. |
|
86 RProcess server; |
|
87 r=server.Create(KNameApaImage,KNullDesC,uidType); |
|
88 #endif |
|
89 |
|
90 if (r!=KErrNone) |
|
91 return r; |
|
92 TRequestStatus stat; |
|
93 server.Rendezvous(stat); |
|
94 if (stat!=KRequestPending) |
|
95 server.Kill(0); // abort startup |
|
96 else |
|
97 server.Resume(); // logon OK - start the server |
|
98 User::WaitForRequest(stat); // wait for start or death |
|
99 server.Close(); |
|
100 return stat.Int(); |
|
101 } |