|
1 // Copyright (c) 2004-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 // The main startup of the AppArc server |
|
15 // |
|
16 // |
|
17 |
|
18 #include <apsserv.h> |
|
19 #include <fbs.h> |
|
20 |
|
21 #include "APASVST.H" |
|
22 #include "APAFLREC.H" |
|
23 |
|
24 #include <eikdll.h> |
|
25 |
|
26 NONSHARABLE_CLASS(CSvActiveScheduler) : public CActiveScheduler |
|
27 { |
|
28 public: |
|
29 static void NewLC(); |
|
30 virtual void Error(TInt anError) const; |
|
31 }; |
|
32 |
|
33 GLDEF_C void CSvActiveScheduler::NewLC() |
|
34 // |
|
35 // Create and install the active scheduler. |
|
36 // |
|
37 { |
|
38 CSvActiveScheduler* pA=new(ELeave) CSvActiveScheduler; |
|
39 CleanupStack::PushL(pA); |
|
40 CActiveScheduler::Install(pA); |
|
41 } |
|
42 |
|
43 GLDEF_C void CSvActiveScheduler::Error(TInt) const |
|
44 // |
|
45 // Called if any Run() method leaves. |
|
46 // |
|
47 { |
|
48 } |
|
49 |
|
50 static void CleanupRFbsSession(TAny*) |
|
51 { |
|
52 RFbsSession::Disconnect(); |
|
53 } |
|
54 |
|
55 static void RunServerL(MApaAppStarter* aAppStarter) |
|
56 // |
|
57 // Perform all server initialisation, in particular creation of the |
|
58 // scheduler and server and then run the scheduler |
|
59 // |
|
60 { |
|
61 MApaAppStarter* appStarter = aAppStarter; |
|
62 // create and install the active scheduler we need |
|
63 CSvActiveScheduler::NewLC(); |
|
64 // create a RFbsSession |
|
65 User::LeaveIfError(RFbsSession::Connect()); |
|
66 CleanupStack::PushL(TCleanupItem(CleanupRFbsSession, NULL)); |
|
67 // |
|
68 // create the server (leave it on the cleanup stack) |
|
69 CApaAppListServer* appListServer = CApaAppListServer::NewL(appStarter); |
|
70 CleanupStack::PushL(appListServer); |
|
71 // |
|
72 // Initialisation complete, now signal the client |
|
73 #ifdef APA_SERVER_IN_THREAD |
|
74 RThread::Rendezvous(KErrNone); |
|
75 #else |
|
76 if(aAppStarter) |
|
77 { |
|
78 // Launching in a thread within an existing process. |
|
79 RThread::Rendezvous(KErrNone); |
|
80 } |
|
81 else |
|
82 { |
|
83 RProcess::Rendezvous(KErrNone); |
|
84 } |
|
85 #endif |
|
86 // |
|
87 // Ready to run |
|
88 CActiveScheduler::Start(); |
|
89 // |
|
90 // Cleanup the server, RFbsSession and scheduler |
|
91 CleanupStack::PopAndDestroy(3); |
|
92 } |
|
93 |
|
94 static TInt RunServer(MApaAppStarter* aAppStarter) |
|
95 // |
|
96 // Main entry-point for the server thread |
|
97 // |
|
98 { |
|
99 __UHEAP_MARK; |
|
100 TInt r; |
|
101 // naming the server thread after the server helps to debug panics |
|
102 r=RThread::RenameMe(NameApaServServerThread()); |
|
103 // |
|
104 if (r == KErrNone) |
|
105 { |
|
106 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
107 r=KErrNoMemory; |
|
108 if (cleanup) |
|
109 { |
|
110 TRAP(r,RunServerL(aAppStarter)); |
|
111 REComSession::FinalClose(); |
|
112 delete cleanup; |
|
113 } |
|
114 } |
|
115 // |
|
116 __UHEAP_MARKEND; |
|
117 return r; |
|
118 } |
|
119 |
|
120 /** |
|
121 ApaServThreadStart |
|
122 |
|
123 @internalTechnology |
|
124 */ |
|
125 EXPORT_C TInt ApaServThreadStart(TAny* aAppStarter) |
|
126 // |
|
127 // thread entry-point function. |
|
128 // |
|
129 { |
|
130 MApaAppStarter* appStarter = reinterpret_cast<MApaAppStarter*>(aAppStarter); |
|
131 return RunServer(appStarter); |
|
132 } |