|
1 /* |
|
2 * Copyright (c) 2010 Sun Microsystems, Inc. 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 Contributor: |
|
10 * Maximilian Odendahl |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: provides a client API for Caldav server |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "caldavclient.h" |
|
19 #include "caldavserver.h" |
|
20 #include "caldavutils.h" |
|
21 |
|
22 const TUint KDefaultMessageSlots = 4; |
|
23 |
|
24 // testing ************ |
|
25 #include <e32base.h> |
|
26 #include <e32cons.h> |
|
27 #include <e32cmn.h> |
|
28 |
|
29 /** |
|
30 * RCalDavServer::RCalDavServer |
|
31 * default constructor |
|
32 */ |
|
33 EXPORT_C RCalDavServer::RCalDavServer() |
|
34 { |
|
35 } |
|
36 |
|
37 /** |
|
38 * RCalDavServer::Connect |
|
39 * connect to server |
|
40 */ |
|
41 EXPORT_C TInt RCalDavServer::Connect() |
|
42 { |
|
43 TInt retry = 2; |
|
44 for (;;) |
|
45 { |
|
46 TInt r = CreateSession(KCalDavServerName, Version(), |
|
47 KDefaultMessageSlots); |
|
48 |
|
49 if ((KErrNotFound != r) && (KErrServerTerminated != r)) |
|
50 return (r); |
|
51 |
|
52 if (--retry == 0) |
|
53 return (r); |
|
54 |
|
55 r = StartServer(); |
|
56 if ((KErrNone != r) && (KErrAlreadyExists != r)) |
|
57 return (r); |
|
58 } |
|
59 } |
|
60 |
|
61 /** |
|
62 * RCalDavServer::Enable |
|
63 * enable Caldav sync |
|
64 */ |
|
65 EXPORT_C TInt RCalDavServer::Enable(const TDesC &aCalendar) |
|
66 { |
|
67 TIpcArgs args(&aCalendar); |
|
68 return SendReceive(ECalDavEnable, args); |
|
69 } |
|
70 |
|
71 /** |
|
72 * RCalDavServer::Disable |
|
73 * disable Caldav sync |
|
74 */ |
|
75 EXPORT_C TInt RCalDavServer::Disable(const TDesC &aCalendar) |
|
76 { |
|
77 TIpcArgs args(&aCalendar); |
|
78 return SendReceive(ECalDavDisable, args); |
|
79 } |
|
80 |
|
81 /** |
|
82 * RCalDavServer::EnabledSync |
|
83 * check for enabled sync |
|
84 */ |
|
85 EXPORT_C TInt RCalDavServer::EnabledSync(const TDesC &aCalendar, |
|
86 TBool &aEnabled) |
|
87 { |
|
88 TPckg<TBool> enabled(aEnabled); |
|
89 TIpcArgs args(&aCalendar, &enabled); |
|
90 return (SendReceive(ECalDavEnabled, args)); |
|
91 } |
|
92 |
|
93 /** |
|
94 * RCalDavServer::Sync |
|
95 * sync now a specific calendar |
|
96 */ |
|
97 EXPORT_C TInt RCalDavServer::Sync(const TDesC &aCalendar) |
|
98 { |
|
99 TIpcArgs args(&aCalendar); |
|
100 return SendReceive(ECalDavSync, args); |
|
101 } |
|
102 |
|
103 /** |
|
104 * RCalDavServer::SyncAll |
|
105 * sync now all calendars |
|
106 */ |
|
107 EXPORT_C TInt RCalDavServer::SyncAll() |
|
108 { |
|
109 return SendReceive(ECalDavSyncAll); |
|
110 } |
|
111 |
|
112 /** |
|
113 * RCalDavServer::Url |
|
114 * get caldav sync url |
|
115 */ |
|
116 EXPORT_C TInt RCalDavServer::Url(const TDesC &aCalendar, TDes8 &aUrl) |
|
117 { |
|
118 TIpcArgs args(&aCalendar, &aUrl); |
|
119 return SendReceive(ECalDavUrl, args); |
|
120 } |
|
121 |
|
122 /** |
|
123 * RCalDavServer::SetUrl |
|
124 * set url |
|
125 */ |
|
126 EXPORT_C TInt RCalDavServer::SetUrl(const TDesC &aCalendar, const TDesC8 &aUrl) |
|
127 { |
|
128 TIpcArgs args(&aCalendar, &aUrl); |
|
129 return SendReceive(ECalDavSetUrl, args); |
|
130 } |
|
131 |
|
132 /** |
|
133 * RCalDavServer::Username |
|
134 * get username |
|
135 */ |
|
136 EXPORT_C TInt RCalDavServer::Username(const TDesC &aCalendar, TDes8 &aUsername) |
|
137 { |
|
138 TIpcArgs args(&aCalendar, &aUsername); |
|
139 return SendReceive(ECalDavUsername, args); |
|
140 } |
|
141 |
|
142 /** |
|
143 * RCalDavServer::SetUsername |
|
144 * set username |
|
145 */ |
|
146 EXPORT_C TInt RCalDavServer::SetUsername(const TDesC &aCalendar, |
|
147 const TDesC8 &aUsername) |
|
148 { |
|
149 TIpcArgs args(&aCalendar, &aUsername); |
|
150 return SendReceive(ECalDavSetUsername, args); |
|
151 } |
|
152 |
|
153 /** |
|
154 * RCalDavServer::Password |
|
155 * get password |
|
156 */ |
|
157 EXPORT_C TInt RCalDavServer::Password(const TDesC &aCalendar, TDes8 &aPassword) |
|
158 { |
|
159 TIpcArgs args(&aCalendar, &aPassword); |
|
160 return SendReceive(ECalDavPassword, args); |
|
161 } |
|
162 |
|
163 /** |
|
164 * RCalDavServer::SetPassword |
|
165 * set password |
|
166 */ |
|
167 EXPORT_C TInt RCalDavServer::SetPassword(const TDesC &aCalendar, |
|
168 const TDesC8 &aPassword) |
|
169 { |
|
170 TIpcArgs args(&aCalendar, &aPassword); |
|
171 return SendReceive(ECalDavSetPassword, args); |
|
172 } |
|
173 |
|
174 /** |
|
175 * RCalDavServer::SyncInterval |
|
176 * get SyncInterval |
|
177 */ |
|
178 EXPORT_C TInt RCalDavServer::SyncInterval(const TDesC &aCalendar, |
|
179 TTimeIntervalMinutes& aSyncInterval) |
|
180 { |
|
181 TPckg<TTimeIntervalMinutes> syncinterval(aSyncInterval); |
|
182 TIpcArgs args(&aCalendar, &syncinterval); |
|
183 return (SendReceive(ECalDavSyncInterval, args)); |
|
184 } |
|
185 |
|
186 /** |
|
187 * RCalDavServer::SetSyncInterval |
|
188 * set SyncInterval |
|
189 */ |
|
190 EXPORT_C TInt RCalDavServer::SetSyncInterval(const TDesC &aCalendar, |
|
191 TTimeIntervalMinutes aSyncInterval) |
|
192 { |
|
193 TPckg<TTimeIntervalMinutes> syncinterval(aSyncInterval); |
|
194 TIpcArgs args(&aCalendar, &syncinterval); |
|
195 return (SendReceive(ECalDavSetSyncInterval, args)); |
|
196 } |
|
197 |
|
198 /** |
|
199 * RCalDavServer::PastDays |
|
200 * get past days |
|
201 */ |
|
202 EXPORT_C TInt RCalDavServer::PastDays(const TDesC &aCalendar, |
|
203 TTimeIntervalDays &aDays) |
|
204 { |
|
205 TPckg<TTimeIntervalDays> pastdays(aDays); |
|
206 TIpcArgs args(&aCalendar, &pastdays); |
|
207 return (SendReceive(ECalDavPastDays, args)); |
|
208 } |
|
209 |
|
210 /** |
|
211 * RCalDavServer::SetPastDays |
|
212 * set past days |
|
213 */ |
|
214 EXPORT_C TInt RCalDavServer::SetPastDays(const TDesC &aCalendar, |
|
215 TTimeIntervalDays aDays) |
|
216 { |
|
217 TPckg<TTimeIntervalDays> pastdays(aDays); |
|
218 TIpcArgs args(&aCalendar, &pastdays); |
|
219 return (SendReceive(ECalDavSetPastDays, args)); |
|
220 } |
|
221 |
|
222 /** |
|
223 * RCalDavServer::ImmediateSync |
|
224 * get Immediate Sync |
|
225 */ |
|
226 EXPORT_C TInt RCalDavServer::ImmediateSync(const TDesC &aCalendar, |
|
227 TBool &aImmediateSyc) |
|
228 { |
|
229 TPckg<TBool> syncimmediate(aImmediateSyc); |
|
230 TIpcArgs args(&aCalendar, &syncimmediate); |
|
231 return (SendReceive(ECalDavImmediateSync, args)); |
|
232 } |
|
233 |
|
234 /** |
|
235 * RCalDavServer::SetImmediateSync |
|
236 * set immediate Sync |
|
237 */ |
|
238 EXPORT_C TInt RCalDavServer::SetImmediateSync(const TDesC &aCalendar, |
|
239 TBool aImmediateSyc) |
|
240 { |
|
241 TPckg<TBool> syncimmediate(aImmediateSyc); |
|
242 TIpcArgs args(&aCalendar, &syncimmediate); |
|
243 return SendReceive(ECalDavSetImmediateSync, args); |
|
244 } |
|
245 |
|
246 /** |
|
247 * RCalDavServer::KeepServerEntry |
|
248 * get KeepServerEntry |
|
249 */ |
|
250 EXPORT_C TInt RCalDavServer::KeepServerEntry(const TDesC &aCalendar, |
|
251 TBool &aKeepServerEntry) |
|
252 { |
|
253 TPckg<TBool> keepserverentry(aKeepServerEntry); |
|
254 TIpcArgs args(&aCalendar, &keepserverentry); |
|
255 return SendReceive(ECalDavKeepServer, args); |
|
256 } |
|
257 |
|
258 /** |
|
259 * RCalDavServer::SetKeepServerEntry |
|
260 * set KeepServerEntry |
|
261 */ |
|
262 EXPORT_C TInt RCalDavServer::SetKeepServerEntry(const TDesC &aCalendar, |
|
263 TBool aKeepServerEntry) |
|
264 { |
|
265 TPckg<TBool> keepserverentry(aKeepServerEntry); |
|
266 TIpcArgs args(&aCalendar, &keepserverentry); |
|
267 return SendReceive(ECalDavSetKeepServer, args); |
|
268 } |
|
269 |
|
270 /** |
|
271 * RCalDavServer::Version |
|
272 * get version |
|
273 */ |
|
274 TVersion RCalDavServer::Version(void) const |
|
275 { |
|
276 return (TVersion(KCalDavServerMajorVersionNumber, |
|
277 KCalDavServerMinorVersionNumber, KCalDavServerBuildVersionNumber)); |
|
278 } |
|
279 |
|
280 /** |
|
281 * RCalDavServer::UnsupportedRequest() |
|
282 * A server request to stop the server. |
|
283 * This is a request that is NOT implemented by the server; it is here to show |
|
284 * the handling of non-implemented requests. |
|
285 */ |
|
286 TInt RCalDavServer::UnsupportedRequest() |
|
287 { |
|
288 return SendReceive(ECalDavUnsupportedRequest); |
|
289 } |
|
290 |
|
291 /** |
|
292 * RCalDavServer::BadRequest() |
|
293 * A request that the server knows nothing about. |
|
294 */ |
|
295 void RCalDavServer::BadRequest() |
|
296 { |
|
297 SendReceive(9999); |
|
298 } |
|
299 |
|
300 static TInt StartServer() |
|
301 { |
|
302 RProcess server; |
|
303 TInt r = server.Create(KCalDavServerFilename, KNullDesC); |
|
304 if (r != KErrNone) |
|
305 return r; |
|
306 |
|
307 TRequestStatus stat; |
|
308 server.Rendezvous(stat); |
|
309 |
|
310 if (stat != KRequestPending) |
|
311 server.Kill(0); // abort startup |
|
312 else |
|
313 server.Resume(); // logon OK - start the server |
|
314 |
|
315 User::WaitForRequest(stat); // wait for start or death |
|
316 |
|
317 // Check the exit type. |
|
318 // We can't use the 'exit reason' because if the server panicked this |
|
319 // is set to the panic 'reason' (which may be '0' and cannot thus be distinguished |
|
320 // from KErrNone) |
|
321 r = server.ExitType(); |
|
322 if (EExitPanic == r) |
|
323 r = KErrGeneral; |
|
324 else |
|
325 r = stat.Int(); |
|
326 |
|
327 server.Close(); // This is no longer needed |
|
328 return r; |
|
329 } |