|
1 /* |
|
2 * Copyright (c) 2004 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 calendar session for a client thread on the server-side. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarui_debug.h" |
|
22 |
|
23 #include "CalSvrSession.h" |
|
24 |
|
25 #include "CalenServer.h" |
|
26 #include "CalSvrDef.h" |
|
27 |
|
28 |
|
29 /** |
|
30 * CCalSvrSession |
|
31 **/ |
|
32 |
|
33 // construct/destruct |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // ?classname::?member_function |
|
37 // ?implementation_description |
|
38 // (other items were commented in a header). |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CCalSvrSession::CCalSvrSession() |
|
42 { |
|
43 TRACE_ENTRY_POINT; |
|
44 TRACE_EXIT_POINT; |
|
45 } |
|
46 |
|
47 // FIXME: this is never called ! Correct would have been createL |
|
48 // ----------------------------------------------------------------------------- |
|
49 // ?classname::?member_function |
|
50 // ?implementation_description |
|
51 // (other items were commented in a header). |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CCalSvrSession::ConstructL(CCalenServer& /*aServer*/) |
|
55 { |
|
56 TRACE_ENTRY_POINT; |
|
57 TRACE_EXIT_POINT; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // ?classname::?member_function |
|
62 // ?implementation_description |
|
63 // (other items were commented in a header). |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CCalSvrSession::~CCalSvrSession() |
|
67 { |
|
68 TRACE_ENTRY_POINT; |
|
69 |
|
70 PIM_TRAPD_HANDLE( DoDestructL() ); |
|
71 |
|
72 TRACE_EXIT_POINT; |
|
73 } |
|
74 |
|
75 void CCalSvrSession::DoDestructL() |
|
76 { |
|
77 TRACE_ENTRY_POINT; |
|
78 |
|
79 CancelInitializeL(); |
|
80 |
|
81 if( iRegistered ) // if still registered |
|
82 { |
|
83 Server()->UnregisterUserL(*this); |
|
84 iRegistered = EFalse; |
|
85 } |
|
86 |
|
87 TRACE_EXIT_POINT; |
|
88 } |
|
89 // ----------------------------------------------------------------------------- |
|
90 // ?classname::?member_function |
|
91 // ?implementation_description |
|
92 // (other items were commented in a header). |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CCalenServer* CCalSvrSession::Server() const |
|
96 { |
|
97 TRACE_ENTRY_POINT; |
|
98 /** |
|
99 * Return the Calendar server. |
|
100 * |
|
101 * This deliberately hides the CSession2 version of this |
|
102 * function, to prevent lots of ugly casts around the code. |
|
103 **/ |
|
104 CCalenServer* server = const_cast<CCalenServer*>(static_cast<const CCalenServer*>(CSession2::Server())); |
|
105 |
|
106 TRACE_EXIT_POINT; |
|
107 return server; |
|
108 } |
|
109 |
|
110 // service dispatcher - from CSession2 |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // ?classname::?member_function |
|
114 // ?implementation_description |
|
115 // (other items were commented in a header). |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CCalSvrSession::ServiceL(const RMessage2& aMessage) |
|
119 { |
|
120 TRACE_ENTRY_POINT; |
|
121 |
|
122 switch (aMessage.Function()) |
|
123 { |
|
124 case ECalSvrInitialize: |
|
125 { |
|
126 InitializeL(aMessage); |
|
127 // Asynchronous service, message completion not done here |
|
128 } |
|
129 break; |
|
130 |
|
131 case ECalSvrUninitialize: |
|
132 { |
|
133 UninitializeL(); |
|
134 aMessage.Complete(KErrNone); |
|
135 } |
|
136 break; |
|
137 |
|
138 case ECalSvrCancelInitialize: |
|
139 { |
|
140 CancelInitializeL(); |
|
141 aMessage.Complete(KErrNone); |
|
142 } |
|
143 break; |
|
144 |
|
145 default: |
|
146 Server()->PanicClient(aMessage, EBadRequest); |
|
147 |
|
148 } |
|
149 |
|
150 TRACE_EXIT_POINT; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // ?classname::?member_function |
|
155 // ?implementation_description |
|
156 // (other items were commented in a header). |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CCalSvrSession::CancelInitializeL() |
|
160 { |
|
161 TRACE_ENTRY_POINT; |
|
162 |
|
163 if(!iInitActive) |
|
164 { |
|
165 TRACE_EXIT_POINT; |
|
166 return; |
|
167 } |
|
168 |
|
169 Server()->UnregisterUserL(*this); |
|
170 iRegistered = EFalse; |
|
171 |
|
172 iInitMessage.Complete(KErrCancel); |
|
173 iInitActive = EFalse; |
|
174 |
|
175 TRACE_EXIT_POINT; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // ?classname::?member_function |
|
180 // ?implementation_description |
|
181 // (other items were commented in a header). |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CCalSvrSession::InitializeL(const RMessage2& aMessage) |
|
185 { |
|
186 TRACE_ENTRY_POINT; |
|
187 |
|
188 __ASSERT_DEBUG(!iInitActive, User::Panic(_L("CalSvrSession::InitializeL"), 0)); |
|
189 __ASSERT_DEBUG(!iRegistered, User::Panic(_L("CalSvrSession::InitializeL"), 1)); |
|
190 iInitMessage = aMessage; |
|
191 iInitActive = ETrue; |
|
192 iRegistered = ETrue; |
|
193 Server()->RegisterUserL(*this); |
|
194 |
|
195 TRACE_EXIT_POINT; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // ?classname::?member_function |
|
200 // ?implementation_description |
|
201 // (other items were commented in a header). |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 void CCalSvrSession::UninitializeL() |
|
205 { |
|
206 TRACE_ENTRY_POINT; |
|
207 |
|
208 __ASSERT_DEBUG(iRegistered, User::Panic(_L("CalSvrSession::UninitializeL"), 0)); |
|
209 CancelInitializeL(); // this will unregister if init active |
|
210 if (iRegistered) // if still registered |
|
211 { |
|
212 Server()->UnregisterUserL(*this); |
|
213 iRegistered = EFalse; |
|
214 } |
|
215 |
|
216 TRACE_EXIT_POINT; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // ?classname::?member_function |
|
221 // ?implementation_description |
|
222 // (other items were commented in a header). |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CCalSvrSession::DatabaseOpened() |
|
226 { |
|
227 TRACE_ENTRY_POINT; |
|
228 |
|
229 HandleInitReady(); |
|
230 |
|
231 TRACE_EXIT_POINT; |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // ?classname::?member_function |
|
236 // ?implementation_description |
|
237 // (other items were commented in a header). |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CCalSvrSession::DatabaseTemporarilyClosed() |
|
241 { |
|
242 TRACE_ENTRY_POINT; |
|
243 |
|
244 // Do not do anything here. |
|
245 // Client doesn't need to know anything about database being temporarily |
|
246 // closed, because initialize/uninitialize mechanism is meant for |
|
247 // optimization only. From client perspective, it is not real connection |
|
248 // to agenda database, but "a guarantee" that someone is holding open |
|
249 // connection to agenda database, so that subsequent connections from |
|
250 // clients are cheaper. |
|
251 // |
|
252 // After restoring is completed, we need to be sure that there are |
|
253 // no unnecessary notifications to clients. |
|
254 // When we get DatabaseOpened after DatabaseTemporarilyClosed, |
|
255 // there are two options: |
|
256 // 1) Client has been already notified in HandleInitReady. |
|
257 // In this case iInitActive is EFalse, and we don't inform |
|
258 // client. Everything is ok. |
|
259 // 2) Client has been notified yet, i.e. restore started in middle of |
|
260 // CalenSvrDBManager opening connection to database. In this case |
|
261 // we want client to be notified. And this happens as iInitActive |
|
262 // is still ETrue. |
|
263 TRACE_EXIT_POINT; |
|
264 } |
|
265 |
|
266 /** |
|
267 * Called by server when agenda observer notifies of change |
|
268 **/ |
|
269 // ----------------------------------------------------------------------------- |
|
270 // ?classname::?member_function |
|
271 // ?implementation_description |
|
272 // (other items were commented in a header). |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CCalSvrSession::HandleInitReady() |
|
276 { |
|
277 TRACE_ENTRY_POINT; |
|
278 |
|
279 if(iInitActive) |
|
280 { |
|
281 iInitMessage.Complete(KErrNone); |
|
282 iInitActive = EFalse; |
|
283 } |
|
284 |
|
285 TRACE_EXIT_POINT; |
|
286 } |
|
287 |
|
288 |
|
289 // End of File |