|
1 /* |
|
2 * Copyright (c) 2002 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 "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: Provides methods for client session implementation of calendar server. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarui_debug.h" |
|
22 |
|
23 #include "CalSvrClient.h" |
|
24 #include "CalSvrInitializer.h" |
|
25 |
|
26 #include "CalSvrDef.h" |
|
27 #include "CalServerSignaller.h" |
|
28 |
|
29 #include <e32base.h> |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // ?classname::?member_function |
|
33 // ?implementation_description |
|
34 // (other items were commented in a header). |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 static TInt StartCalendarServer() |
|
38 { |
|
39 TRACE_ENTRY_POINT; |
|
40 |
|
41 TRequestStatus started; |
|
42 TCalServerStart start( started ); |
|
43 |
|
44 const TUidType serverUid( KNullUid, KNullUid, KNullUid ); |
|
45 |
|
46 // |
|
47 // EPOC is easy, we just create a new server process. Simultaneous |
|
48 // launching of two such processes should be detected when the |
|
49 // second one attempts to create the server object, failing with |
|
50 // KErrAlreadyExists. |
|
51 // |
|
52 RProcess server; |
|
53 const TInt ret=server.Create( KCalSvrServerExe, start.AsCommand(), serverUid ); |
|
54 |
|
55 // Did we manage to create the thread/process? |
|
56 if(ret != KErrNone) |
|
57 { |
|
58 TRACE_EXIT_POINT; |
|
59 return ret; |
|
60 } |
|
61 |
|
62 // Wait to see if the thread/process died during construction |
|
63 TRequestStatus serverDiedRequestStatus; |
|
64 server.Rendezvous(serverDiedRequestStatus); |
|
65 |
|
66 // do we have to abort? |
|
67 if(serverDiedRequestStatus != KRequestPending) |
|
68 { |
|
69 server.Kill(0); // abort the sartup here |
|
70 } |
|
71 else |
|
72 { |
|
73 server.Resume(); // start server |
|
74 } |
|
75 |
|
76 User::WaitForRequest(serverDiedRequestStatus); |
|
77 |
|
78 // determine the reason for the server exit |
|
79 const TInt exitReason =(server.ExitType()==EExitPanic) ? KErrGeneral : serverDiedRequestStatus.Int(); |
|
80 server.Close(); |
|
81 |
|
82 TRACE_EXIT_POINT; |
|
83 return exitReason; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // ?classname::?member_function |
|
88 // ?implementation_description |
|
89 // (other items were commented in a header). |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C RCalSvrSession::RCalSvrSession() |
|
93 :RSessionBase(), iListenerCallback(NULL), iInitializer(NULL) |
|
94 { |
|
95 TRACE_ENTRY_POINT; |
|
96 TRACE_EXIT_POINT; |
|
97 } |
|
98 |
|
99 // open/close |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // ?classname::?member_function |
|
103 // ?implementation_description |
|
104 // (other items were commented in a header). |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C void RCalSvrSession::ConnectL() |
|
108 { |
|
109 TRACE_ENTRY_POINT; |
|
110 |
|
111 // connect to server |
|
112 TInt err( KErrNone ); |
|
113 |
|
114 for( TInt tries(0); tries < 2; tries++ ) |
|
115 { |
|
116 err = CreateSession( KCalendarServerName, TVersion(0,0,0) ); |
|
117 |
|
118 if( !err ) |
|
119 { |
|
120 // connected to existing server - ok |
|
121 break; |
|
122 } |
|
123 |
|
124 if( err != KErrNotFound && err != KErrServerTerminated ) |
|
125 { |
|
126 // problems other than server not here - propagate error |
|
127 break; |
|
128 } |
|
129 |
|
130 err = StartCalendarServer(); |
|
131 |
|
132 if( !err || (err==KErrAlreadyExists) ) |
|
133 { |
|
134 // if server launched ok, try again to connect |
|
135 // OR |
|
136 // if someone else got there first, try again to connect |
|
137 continue; |
|
138 } |
|
139 |
|
140 break; // server not launched: don't cycle round again |
|
141 } |
|
142 |
|
143 User::LeaveIfError( err ); |
|
144 |
|
145 CleanupClosePushL( *this ); // Close if next operation leaves |
|
146 |
|
147 iInitializer = new( ELeave )CCalSvrInitializer( *this ); |
|
148 |
|
149 CleanupStack::Pop( this ); |
|
150 |
|
151 TRACE_EXIT_POINT; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // ?classname::?member_function |
|
156 // ?implementation_description |
|
157 // (other items were commented in a header). |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 EXPORT_C void RCalSvrSession::Close() |
|
161 { |
|
162 TRACE_ENTRY_POINT; |
|
163 |
|
164 delete iInitializer; |
|
165 iInitializer = NULL; |
|
166 RSessionBase::Close(); |
|
167 |
|
168 TRACE_EXIT_POINT; |
|
169 } |
|
170 |
|
171 /////////////////////////////// |
|
172 // These are high-level client interface functions |
|
173 /////////////////////////////// |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // ?classname::?member_function |
|
177 // ?implementation_description |
|
178 // (other items were commented in a header). |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 EXPORT_C void RCalSvrSession::Initialize(MCalSvrAgendaUpdateListener& aListener) |
|
182 { |
|
183 TRACE_ENTRY_POINT; |
|
184 |
|
185 __ASSERT_ALWAYS(!iInitializer->IsActive(), User::Invariant()); |
|
186 if(!iInitializer->IsActive()) |
|
187 { |
|
188 iInitializer->Initialize(&aListener); |
|
189 } |
|
190 |
|
191 TRACE_EXIT_POINT; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // ?classname::?member_function |
|
196 // ?implementation_description |
|
197 // (other items were commented in a header). |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 EXPORT_C void RCalSvrSession::StopInitialization() |
|
201 { |
|
202 TRACE_ENTRY_POINT; |
|
203 |
|
204 iInitializer->Cancel(); |
|
205 |
|
206 TRACE_EXIT_POINT; |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // ?classname::?member_function |
|
211 // ?implementation_description |
|
212 // (other items were commented in a header). |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void RCalSvrSession::Uninitialize() |
|
216 { |
|
217 TRACE_ENTRY_POINT; |
|
218 |
|
219 if(iInitializer->IsActive()) |
|
220 { |
|
221 iInitializer->Cancel(); |
|
222 } |
|
223 SendReceive(ECalSvrUninitialize, TIpcArgs()); |
|
224 |
|
225 TRACE_EXIT_POINT; |
|
226 } |
|
227 |
|
228 |
|
229 /////////////////////////////// |
|
230 // These are low-level functions talking to server |
|
231 ////////////////////////////// |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // ?classname::?member_function |
|
235 // ?implementation_description |
|
236 // (other items were commented in a header). |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 void RCalSvrSession::Initialize(TRequestStatus& aStatus) |
|
240 { |
|
241 TRACE_ENTRY_POINT; |
|
242 |
|
243 SendReceive(ECalSvrInitialize, TIpcArgs(), aStatus); |
|
244 |
|
245 TRACE_EXIT_POINT; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // ?classname::?member_function |
|
250 // ?implementation_description |
|
251 // (other items were commented in a header). |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void RCalSvrSession::CancelInitialize() |
|
255 { |
|
256 TRACE_ENTRY_POINT; |
|
257 |
|
258 SendReceive(ECalSvrCancelInitialize, TIpcArgs()); |
|
259 |
|
260 TRACE_EXIT_POINT; |
|
261 } |
|
262 |
|
263 |
|
264 // End of File |