1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 // |
7 // |
8 // Initial Contributors: |
8 // Initial Contributors: |
9 // Nokia Corporation - initial contribution. |
9 // Nokia Corporation - initial contribution. |
11 // Contributors: |
11 // Contributors: |
12 // |
12 // |
13 // Description: |
13 // Description: |
14 // Client access to the AppArc server |
14 // Client access to the AppArc server |
15 // |
15 // |
|
16 // apscli.cpp |
16 // |
17 // |
|
18 |
|
19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
20 #if !defined(__APA_INTERNAL_H__) |
|
21 #include "apainternal.h" |
|
22 #endif |
|
23 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
17 |
24 |
18 #include <e32base.h> |
25 #include <e32base.h> |
19 #include <e32svr.h> |
26 #include <e32svr.h> |
20 #include <e32math.h> |
27 #include <e32math.h> |
21 #include <apasvst.h> |
28 #include <apasvst.h> |
22 #include <apsserv.h> |
|
23 #include <e32uid.h> |
29 #include <e32uid.h> |
24 |
30 |
25 _LIT(KNameApaImage,"APSEXE"); |
31 _LIT(KNameApaImage,"APSEXE"); |
26 const TUid KServerUid3 = { 0x10003A3F }; |
32 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 |
33 |
30 EXPORT_C TInt StartupApaServer(MApaAppStarter& aAppStarter) |
|
31 /** |
34 /** |
32 Start the server in a thread, using the supplied app starter. |
35 StartupApaServerProcess |
|
36 Start the server in a process. Simultaneous launching of two such processes |
|
37 should be detected when the second one attempts to create the server object, |
|
38 failing with KErrAlreadyExists. |
33 |
39 |
34 @internalTechnology |
40 @publishedPartner |
|
41 @released |
35 */ |
42 */ |
|
43 EXPORT_C TInt StartupApaServerProcess() |
36 { |
44 { |
37 RThread server; |
45 const TUidType uidType(KNullUid, KNullUid, KServerUid3); |
38 TInt r=server.Create(NameApaServServerThread(),ApaServThreadStart,KApaServThreadStackSize,KMinHeapSize,KApaServThreadMaxHeapSize,&aAppStarter,EOwnerThread); |
46 TInt r=KErrNone; |
|
47 |
|
48 // On ARM or any EKA2 target, the server is an EXE. |
|
49 // Create a process from it. |
|
50 RProcess server; |
|
51 r=server.Create(KNameApaImage,KNullDesC,uidType); |
|
52 |
39 if (r!=KErrNone) |
53 if (r!=KErrNone) |
40 return r; |
54 return r; |
41 TRequestStatus stat; |
55 TRequestStatus stat; |
42 server.Rendezvous(stat); |
56 server.Rendezvous(stat); |
43 if (stat!=KRequestPending) |
57 if (stat!=KRequestPending) |
47 User::WaitForRequest(stat); // wait for start or death |
61 User::WaitForRequest(stat); // wait for start or death |
48 server.Close(); |
62 server.Close(); |
49 return stat.Int(); |
63 return stat.Int(); |
50 } |
64 } |
51 |
65 |
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 } |
|