|
1 /* |
|
2 * Copyright (c) 2006 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 #include <e32base.h> |
|
20 #include <w32std.h> |
|
21 #include <apgcli.h> |
|
22 #include "WidgetRegistryConstants.h" |
|
23 #include "widgetregistryserver.h" |
|
24 #include "widgetregistrysession.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CWidgetRegistryServer::CWidgetRegistryServer |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CWidgetRegistryServer::CWidgetRegistryServer() : |
|
36 CPolicyServer(0,widgetRegistryPolicy,ESharableSessions) |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CWidgetRegistryServer::ConstructL |
|
42 // Symbian 2nd phase constructor can leave. |
|
43 // |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CWidgetRegistryServer::ConstructL() |
|
47 { |
|
48 StartL( KWidgetRegistryName ); |
|
49 iShutDown.ConstructL(); |
|
50 iShutDown.Start(); |
|
51 } |
|
52 |
|
53 CWidgetRegistryServer::~CWidgetRegistryServer() |
|
54 { |
|
55 } |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CWidgetRegistryServer::NewL |
|
58 // Two-phased constructor. |
|
59 // |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CServer2* CWidgetRegistryServer::NewLC() |
|
63 { |
|
64 CWidgetRegistryServer* self = new ( ELeave ) CWidgetRegistryServer; |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CWidgetRegistryServer::NewSessionL |
|
72 // Creates a new widgetregistry server session |
|
73 // |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CSession2* CWidgetRegistryServer::NewSessionL( |
|
77 const TVersion& /*aVersion*/, |
|
78 const RMessage2& aMessage ) const |
|
79 { |
|
80 CWidgetRegistryServerSession* session = CWidgetRegistryServerSession::NewL( |
|
81 const_cast<CWidgetRegistryServer&>( *this ),aMessage ); |
|
82 return session; |
|
83 } |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CWidgetRegistryServer::AddSession |
|
88 // Cancel the shutdown timer now, the new session is connected |
|
89 // |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CWidgetRegistryServer::AddSession() |
|
93 { |
|
94 ++iSessionCount; |
|
95 iShutDown.Cancel(); // Cancel any outstanding shutdown timer |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CWidgetRegistryServer::RemoveSession |
|
100 // Decrement the session counter and start the shutdown timer if the last client |
|
101 // has disconnected |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CWidgetRegistryServer::RemoveSession() |
|
105 { |
|
106 if ( --iSessionCount == 0 ) |
|
107 { |
|
108 iShutDown.Start(); |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CWidgetRegistryServer::RunServerL |
|
114 // Initialize and run the server |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CWidgetRegistryServer::RunServerL() |
|
119 { |
|
120 // We need to tell the app list server about widgets, this happens |
|
121 // during installing a widget but if a widget is already installed |
|
122 // (say on a memory card) then the app list server should already |
|
123 // know about widgets |
|
124 RApaLsSession apparcSession; |
|
125 if ( KErrNone == apparcSession.Connect() ) |
|
126 { |
|
127 TRAP_IGNORE( |
|
128 apparcSession.RegisterNonNativeApplicationTypeL( |
|
129 KUidWidgetLauncher, KLauncherApp())); |
|
130 apparcSession.Close(); |
|
131 } |
|
132 |
|
133 // First create and install the active scheduler |
|
134 CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler; |
|
135 CleanupStack::PushL(scheduler); |
|
136 |
|
137 CActiveScheduler::Install(scheduler); |
|
138 |
|
139 // create the server |
|
140 CWidgetRegistryServer::NewLC(); |
|
141 |
|
142 // Naming the server thread after the server helps to debug panics |
|
143 User::LeaveIfError( RThread().RenameMe( KWidgetRegistryName ) ); |
|
144 |
|
145 RProcess::Rendezvous(KErrNone); |
|
146 |
|
147 // Enter the wait loop |
|
148 CActiveScheduler::Start(); |
|
149 |
|
150 // Exited - cleanup the server and scheduler |
|
151 |
|
152 CleanupStack::PopAndDestroy( 2, scheduler ); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // Server process entry-point |
|
157 // |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 TInt E32Main() |
|
161 { |
|
162 __UHEAP_MARK; // Heap checking |
|
163 |
|
164 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
165 TInt r = KErrNoMemory; |
|
166 |
|
167 if ( cleanup ) |
|
168 { |
|
169 TRAP( r, CWidgetRegistryServer::RunServerL() ); |
|
170 delete cleanup; |
|
171 } |
|
172 |
|
173 __UHEAP_MARKEND; |
|
174 return r; |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CShutdown::RunServerL |
|
179 // Initiates server exit when the timer expires |
|
180 // |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CShutdown::RunL() |
|
184 { |
|
185 CActiveScheduler::Stop(); |
|
186 } |
|
187 |
|
188 // End of File |