1 /* |
|
2 * Copyright (c) 2003 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: This file contains the header file of the RCbs class. |
|
15 * |
|
16 * The client of the CBS Server is required to import this header file |
|
17 * into project. The connection to the server is made with Connect() |
|
18 * and closed with Close(). |
|
19 * |
|
20 * RCbs provides the interface to CBS clients for accessing the |
|
21 * CBS server. It uses subsession classes RCbsSettings, RCbsTopicList, |
|
22 * RCbsTopicMessages and RCbsTopicCollection to actually carry out |
|
23 * the required ITC between client and server threads. |
|
24 * |
|
25 * |
|
26 */ |
|
27 |
|
28 |
|
29 |
|
30 #ifndef RCBS_H |
|
31 #define RCBS_H |
|
32 |
|
33 // INCLUDES |
|
34 #include <e32base.h> |
|
35 #include "CbsCommon.h" |
|
36 #include "RCbsSettings.h" |
|
37 #include "RCbsTopicCollection.h" |
|
38 #include "RCbsTopicList.h" |
|
39 #include "RCbsTopicMessages.h" |
|
40 |
|
41 // CLASS DECLARATION |
|
42 |
|
43 /** |
|
44 * This represents the client-side session to the cbs server. |
|
45 * |
|
46 * Every client must have an instance of the class to be able to communicate |
|
47 * with the server. |
|
48 * |
|
49 * Note that both client and server must use the same versions of the API. |
|
50 * Otherwise the server will terminate the client process. |
|
51 * |
|
52 * - The server does not buffer events. This must be taken into |
|
53 * account when using notifications. |
|
54 * - There can only be one pending notification request per subsession object. |
|
55 * The behaviour is undefined, if you try to make several for only one |
|
56 * subsession. |
|
57 */ |
|
58 class RCbs |
|
59 : public RSessionBase |
|
60 { |
|
61 public: // New functions |
|
62 /** |
|
63 * Constructor. |
|
64 */ |
|
65 IMPORT_C RCbs(); |
|
66 |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 IMPORT_C ~RCbs(); |
|
71 |
|
72 /** |
|
73 * Creates connection to the server. |
|
74 * |
|
75 * Note that the method must be called before calling any other |
|
76 * methods. The method returns an error code and, therefore, |
|
77 * the caller is responsible of checking that everything went just |
|
78 * fine. |
|
79 * |
|
80 * @return Error code. |
|
81 */ |
|
82 IMPORT_C TInt Connect(); |
|
83 |
|
84 /** |
|
85 * Closes the session to the server. |
|
86 */ |
|
87 IMPORT_C void Close(); |
|
88 |
|
89 /** |
|
90 * Returns the version of CbsClient. |
|
91 * |
|
92 * CbsServer and CbsClient must be of same version. |
|
93 * |
|
94 * @return Returns the version of CbsClient. |
|
95 */ |
|
96 IMPORT_C TVersion Version() const; |
|
97 |
|
98 // === Settings-related methods |
|
99 |
|
100 /** |
|
101 * Returns the reception status in aStatus, which is ETrue if the reception is |
|
102 * on. Otherwise it is EFalse. |
|
103 * |
|
104 * @param aStatus The method returns the reception status in this parameter. |
|
105 */ |
|
106 IMPORT_C void GetReceptionStatus( TBool& aStatus ); |
|
107 |
|
108 /** |
|
109 * Changes the reception status to aStatus. |
|
110 * |
|
111 * @param aStatus It contains the new reception status. |
|
112 * @return KErrNone if succeeded. |
|
113 */ |
|
114 IMPORT_C TInt SetReceptionStatus( TBool aStatus ); |
|
115 |
|
116 /** |
|
117 * Returns the topic detection status in aStatus, which is ETrue if the detection |
|
118 * is on. Otherwise it is EFalse. |
|
119 * |
|
120 * @param aStatus The method returns the topic detection status in this parameter. |
|
121 */ |
|
122 IMPORT_C void GetTopicDetectionStatus( TBool& aStatus ); |
|
123 |
|
124 /** |
|
125 * Changes the topic detection status to aStatus. |
|
126 * |
|
127 * @param aStatus It contains the new topic detection status. |
|
128 * @return KErrNone if succeeded. |
|
129 */ |
|
130 IMPORT_C TInt SetTopicDetectionStatus( TBool aStatus ); |
|
131 |
|
132 /** |
|
133 * Returns the preferred languages in aLanguages. |
|
134 * |
|
135 * @param aLanguages The method returns the languages in this parameter. |
|
136 */ |
|
137 IMPORT_C void GetLanguages( TCbsSettingsLanguages& aLanguages ); |
|
138 |
|
139 /** |
|
140 * Changes the preferred languages to aLanguages. |
|
141 * |
|
142 * @param aLanguages It contains the new preferred languages. |
|
143 * @return KErrNone if succeeded. |
|
144 */ |
|
145 IMPORT_C TInt SetLanguages( const TCbsSettingsLanguages& aLanguages ); |
|
146 |
|
147 /** |
|
148 * Requests the server to notify the client whenever any settings will be |
|
149 * changed. |
|
150 * |
|
151 * Note that for each subsession only one this kind of request can be pending. Each |
|
152 * client is responsible of assuring this. |
|
153 * |
|
154 * @param aStatus It is the variable that the server will modify |
|
155 * whenever an event occurs. |
|
156 * @param aEvent The server will store the type of occurred event |
|
157 * to this variable. |
|
158 */ |
|
159 IMPORT_C void NotifySettingsChanged( TRequestStatus& aStatus, |
|
160 TCbsSettingsEvent& aEvent ); |
|
161 |
|
162 /** |
|
163 * Cancels the request to notify the client. |
|
164 */ |
|
165 IMPORT_C void NotifySettingsChangedCancel(); |
|
166 |
|
167 // === Topic Collection-related methods |
|
168 |
|
169 /** |
|
170 * Resets the iterator. Must be called prior any call to HasNextTopic() |
|
171 * or NextTopic()! |
|
172 */ |
|
173 IMPORT_C void StartCollectionBrowsing(); |
|
174 |
|
175 /** |
|
176 * Returns ETrue, if there is a topic not accessed with NextTopic() |
|
177 * |
|
178 * @return ETrue, if there is a topic. EFalse if the end of the collection |
|
179 * has been reached. |
|
180 */ |
|
181 IMPORT_C TBool HasNextCollectionTopic(); |
|
182 |
|
183 /** |
|
184 * Returns the next topic in the topic collection skipping all topics with |
|
185 * a topic number matching a topic already listed in the current topic list. |
|
186 * This function will return KErrNotFound if the collection is tried to |
|
187 * access beyond the end of the list. Otherwise the error code will be |
|
188 * the same returned by GetTopicInfo(). |
|
189 * |
|
190 * @param aInfo The topic information will be stored here. |
|
191 * @return The error code. KErrNotFound if there are no topics left. |
|
192 */ |
|
193 IMPORT_C TInt NextCollectionTopic( TCbsTopicInfo& aInfo ); |
|
194 |
|
195 // === Topic list-related methods |
|
196 |
|
197 /** |
|
198 * Returns the total amount of topics the topic list contains. |
|
199 * |
|
200 * @param aCount It will contain the total amount of topics. |
|
201 */ |
|
202 IMPORT_C void GetTopicCount( TInt& aCount ); |
|
203 |
|
204 /** |
|
205 * Returns information about a topic from the topic list. |
|
206 * |
|
207 * Return values: |
|
208 * KErrArgument Topic was not found. |
|
209 * |
|
210 * Rest of return values indicate a file error. |
|
211 * |
|
212 * @param aIndex It is the index to the topic. |
|
213 * @param aTopic It will contain the topic information. |
|
214 * @return Error code. |
|
215 */ |
|
216 IMPORT_C TInt GetTopic( const TInt aIndex, TCbsTopic& aTopic ); |
|
217 |
|
218 /** |
|
219 * Finds the topic by the given number. |
|
220 * |
|
221 * Return values: |
|
222 * KErrNone Topic returned in parameter aTopic. |
|
223 * KErrNotFound Topic was not found. |
|
224 * |
|
225 * @param aNumber Number of the topic |
|
226 * @param aTopic Return: contains the topic information |
|
227 * @return Error code |
|
228 */ |
|
229 IMPORT_C TInt FindTopicByNumber( TCbsTopicNumber aNumber, |
|
230 TCbsTopic& aTopic ); |
|
231 |
|
232 /** |
|
233 * Deletes an existing topic. |
|
234 * |
|
235 * @param aNumber Number of the topic to be deleted |
|
236 * @return Error code |
|
237 */ |
|
238 IMPORT_C TInt DeleteTopic( TCbsTopicNumber aNumber ); |
|
239 |
|
240 /** |
|
241 * Delete all topics. |
|
242 * |
|
243 * @return Error code. |
|
244 */ |
|
245 IMPORT_C TInt DeleteAllTopics(); |
|
246 |
|
247 /** |
|
248 * Adds a new topic. The handle assigned to the topic will be returned |
|
249 * in aTopic. |
|
250 * |
|
251 * Return values: |
|
252 * KErrNone Topic was successfully added. |
|
253 * KErrAlreadyExists A topic of the same number already exists in DB |
|
254 * KErrArgument Topic number given was not in a proper range. |
|
255 * KErrDiskFull Topic not added - FFS out of space |
|
256 * |
|
257 * Note that the number of the new topic must be unused. |
|
258 * |
|
259 * @param aTopic Contains the information of the new topic. |
|
260 * On return, aTopic also contains the topic |
|
261 * handle. |
|
262 * @return Error code. |
|
263 */ |
|
264 IMPORT_C TInt AddTopic( TCbsTopic& aTopic ); |
|
265 |
|
266 /** |
|
267 * Changes the name and number of the existing topic. |
|
268 * |
|
269 * Note that the changing fails in case there is another topic with |
|
270 * the new topic number. It also fails if the topic is protected. |
|
271 * |
|
272 * Return values: |
|
273 * KErrNone Topic name and number successfully changed. |
|
274 * KErrDiskFull Topic information not changed - FFS out of space |
|
275 * |
|
276 * @param aOldNumber Number of the topic to be changed |
|
277 * @param aNewNumber Number to be given for the topic |
|
278 * @param aName Name to be given for the topic |
|
279 * @return Error code |
|
280 */ |
|
281 IMPORT_C TInt ChangeTopicNameAndNumber( |
|
282 TCbsTopicNumber aOldNumber, |
|
283 TCbsTopicNumber aNewNumber, |
|
284 const TCbsTopicName& aName ); |
|
285 |
|
286 /** |
|
287 * Changes topic subscription status. |
|
288 * |
|
289 * @param aNumber Number of the topic |
|
290 * @param aNewStatus New subscription status |
|
291 * @return Error code |
|
292 */ |
|
293 IMPORT_C TInt ChangeTopicSubscriptionStatus( |
|
294 TCbsTopicNumber aNumber, TBool aNewStatus ); |
|
295 |
|
296 /** |
|
297 * Changes topic hotmark status. |
|
298 * |
|
299 * @param aNumber Number of the topic |
|
300 * @param aNewStatus New hotmark status |
|
301 * @return Error code |
|
302 */ |
|
303 IMPORT_C TInt ChangeTopicHotmarkStatus( TCbsTopicNumber aNumber, |
|
304 TBool aNewStatus ); |
|
305 |
|
306 /** |
|
307 * Requests the server to notify the client whenever an event occurs |
|
308 * that changes the information of the topics. |
|
309 * |
|
310 * Note that the client may select what kind of events it is |
|
311 * interested in. Note also that there can be at most one pending |
|
312 * request per instance of the class. |
|
313 * |
|
314 * @param aStatus The variable that the server will modify |
|
315 * whenever an event occurs. |
|
316 * @param aRequested Events the client is interested in |
|
317 * @param aEvent Indicates the variable that will contain the |
|
318 * type of event that occured. |
|
319 * @param aNumber Indicates the variable that will contain the |
|
320 * topic number that was changed in event. |
|
321 */ |
|
322 IMPORT_C void NotifyOnTopicListEvent( |
|
323 TRequestStatus& aStatus, |
|
324 const TInt aRequested, |
|
325 TCbsTopicListEvent& aEvent, |
|
326 TCbsTopicNumber& aNumber ); |
|
327 |
|
328 /** |
|
329 * Cancels the pending notify request. |
|
330 */ |
|
331 IMPORT_C void NotifyOnTopicListEventCancel(); |
|
332 |
|
333 /** |
|
334 * Returns the number of topics added since last GetNewTopicsCount() |
|
335 * by the topic detection feature. |
|
336 * |
|
337 * @param aCount It will contain the amount of new topics. |
|
338 * @return TInt Result code. |
|
339 */ |
|
340 IMPORT_C TInt GetNewTopicsCount( TInt& aCount ); |
|
341 |
|
342 /** |
|
343 * Returns the number of the topic which was last added |
|
344 * to topic list. |
|
345 * |
|
346 * Note: if a topic list cache is maintained by the client |
|
347 * (as CBS UI application does), this function has to |
|
348 * be called BEFORE calling GetTopicCount() and GetTopic() |
|
349 * to make sure that no topic is added in between |
|
350 * GetTopic() and GetLatestTopicHandle() calls. If this |
|
351 * happens, GetLatestTopicHandle() will return a handle |
|
352 * to a topic that is not cached client-side. |
|
353 * |
|
354 * Return codes: |
|
355 * KErrNone aNumber is a valid topic number. |
|
356 * KErrNotFound No topic added since server start, |
|
357 * aNumber is not valid. |
|
358 * |
|
359 * @param aNumber Returns: number of the topic last added |
|
360 * @return Result code |
|
361 */ |
|
362 IMPORT_C TInt GetLatestTopicNumber( TCbsTopicNumber& aNumber ); |
|
363 |
|
364 /** |
|
365 * Returns the total amount of unread messages. |
|
366 * |
|
367 * @param aCount Return: number of unread messages |
|
368 */ |
|
369 IMPORT_C void GetUnreadMessageCount( TInt& aCount ); |
|
370 |
|
371 /** |
|
372 * Returns the handle to the latest hotmarked message that has been |
|
373 * received after the system has started up. |
|
374 * |
|
375 * @param aMessage Handle to the message |
|
376 */ |
|
377 IMPORT_C void GetHotmarkedMessageHandle( TCbsMessageHandle& aMessage ); |
|
378 |
|
379 /** |
|
380 * Returns the number of unread messages in hotmarked topics. |
|
381 * |
|
382 * This function is to used by the client when deciding whether |
|
383 * the message or topic list view should be opened to display |
|
384 * a hotmarked message(s). |
|
385 * |
|
386 * @return Number of unread hotmarked messages |
|
387 */ |
|
388 IMPORT_C TInt NumberOfUnreadHotmarkedMessages(); |
|
389 |
|
390 /** |
|
391 * Returns the numbers of topics that precede and succeed the given |
|
392 * topic in server-side topic list. |
|
393 * |
|
394 * If the given topic is the first topic in list, aPosition has |
|
395 * ECbsHead bit up. If the given topic is the last topic in list, |
|
396 * aPosition has ECbsTail bit up. |
|
397 * |
|
398 * Return code values: |
|
399 * KErrNone aPrevTopicNumber, aNextTopicNumber and aPosition |
|
400 * contain valid values. |
|
401 * KErrNotFound aCurrentTopicNumber specified a topic that was not |
|
402 * on topic list. |
|
403 * |
|
404 * @param aCurrentTopicNumber Number that specifies the topic |
|
405 * whose surroundings are returned |
|
406 * @param aPrevTopicNumber Returns: number of topic preceding |
|
407 * the given topic |
|
408 * @param aNextTopicNumber Returns: number of topic succeeding |
|
409 * the given topic |
|
410 * @param aPosition Returns: position of current |
|
411 * topic in list. |
|
412 * @return Result code |
|
413 */ |
|
414 IMPORT_C TInt GetNextAndPrevTopicNumber( |
|
415 const TCbsTopicNumber& aCurrentTopicNumber, |
|
416 TCbsTopicNumber& aPrevTopicNumber, |
|
417 TCbsTopicNumber& aNextTopicNumber, |
|
418 TInt& aPosition ); |
|
419 |
|
420 // === Topic Messages-related methods |
|
421 |
|
422 /** |
|
423 * Returns the total amount of messages the topic contains. |
|
424 * |
|
425 * Return codes: |
|
426 * KErrNotFound Invalid handle. |
|
427 * KErrNone aCount contains the number of messages |
|
428 * in topic |
|
429 * |
|
430 * @param aNumber Number of the topic. |
|
431 * @param aCount Number of messages in given topic. |
|
432 * @return Result code |
|
433 */ |
|
434 IMPORT_C TInt GetMessageCount( TCbsTopicNumber aNumber, |
|
435 TInt& aCount ); |
|
436 |
|
437 /** |
|
438 * Returns message information. |
|
439 * |
|
440 * Return codes: |
|
441 * KErrNotFound Topic or message not found. |
|
442 * KErrNone aMessage contains the message information. |
|
443 * |
|
444 * @param aNumber Number of the topic |
|
445 * @param aIndex Index to the message in topic. |
|
446 * @param aMessage Returns: the message information |
|
447 * @return Error code |
|
448 */ |
|
449 IMPORT_C TInt GetMessage( TCbsTopicNumber aNumber, TInt aIndex, |
|
450 TCbsMessage& aMessage ); |
|
451 |
|
452 /** |
|
453 * Finds a message by given handle. |
|
454 * |
|
455 * @param aHandle Handle to the message. |
|
456 * @param aMessage Return: contains the message information. |
|
457 * @return Error code. |
|
458 */ |
|
459 IMPORT_C TInt FindMessageByHandle( |
|
460 const TCbsMessageHandle& aHandle, |
|
461 TCbsMessage& aMessage ); |
|
462 |
|
463 /** |
|
464 * Returns the index of a message with given handle in topic. |
|
465 * |
|
466 * Result code KErrNotFound indicates that no message was found with |
|
467 * the given handle. |
|
468 * |
|
469 * @param aHandle Handle of the message |
|
470 * @param aIndex Return: index of the message in message topic |
|
471 * @return Result code |
|
472 */ |
|
473 IMPORT_C TInt GetMessageIndexByHandle( |
|
474 const TCbsMessageHandle& aHandle, TInt& aIndex ); |
|
475 |
|
476 /** |
|
477 * Deletes an existing message. |
|
478 * |
|
479 * Note that it does not care a lot about the status of the message. |
|
480 * |
|
481 * Please check also the description of LockMessage(). |
|
482 * |
|
483 * @param aHandle It is handle to the message. |
|
484 * @return Error code. |
|
485 */ |
|
486 IMPORT_C TInt DeleteMessage( const TCbsMessageHandle& aHandle ); |
|
487 |
|
488 /** |
|
489 * Saves a message (the saved message won't be deleted to make |
|
490 * room for new messages). |
|
491 * |
|
492 * Return codes: |
|
493 * KErrNone Message is saved. |
|
494 * KErrGeneral Message not saved -- total maximum of saved |
|
495 * messages reached. |
|
496 * KErrNotFound Message not saved -- no message associated |
|
497 * with the given handle. |
|
498 * KErrDiskFull Message not saved -- FFS out of space. |
|
499 * |
|
500 * @param aHandle Handle to the message to be saved. |
|
501 * @return Return code. |
|
502 */ |
|
503 IMPORT_C TInt SaveMessage( const TCbsMessageHandle& aHandle ); |
|
504 |
|
505 /** |
|
506 * Locks the message. |
|
507 * |
|
508 * Note that a single topic messages subsession can have at most one locked |
|
509 * message. |
|
510 * |
|
511 * Message can be unlocked by trying to lock a null message. Locked message |
|
512 * will also be automatically unlocked when subsession is closed. If a message |
|
513 * is locked, then it will not be deleted from the database. Thus, deleting a |
|
514 * message or trying to delete a topic that contains such a message will fail. |
|
515 * |
|
516 * Locking a message does not prevent to save the message nor read the message. |
|
517 * |
|
518 * @param aHandle It is handle to the message to be locked. |
|
519 * @return Error code. |
|
520 */ |
|
521 IMPORT_C TInt LockMessage( const TCbsMessageHandle& aHandle ); |
|
522 |
|
523 /** |
|
524 * Sets the message as read. |
|
525 * |
|
526 * @param aHandle It is handle to the message to be set read. |
|
527 * @return Error code. |
|
528 */ |
|
529 IMPORT_C TInt ReadMessage( const TCbsMessageHandle& aHandle ); |
|
530 |
|
531 /** |
|
532 * Returns the message contents. |
|
533 * |
|
534 * @param aHandle It is handle to the message. |
|
535 * @param aBuffer It will contain the contents (as much as it fits). |
|
536 * @return Error code. |
|
537 */ |
|
538 IMPORT_C TInt GetMessageContents( |
|
539 const TCbsMessageHandle& aHandle, |
|
540 TDes& aBuffer ); |
|
541 |
|
542 /** |
|
543 * Returns the handles of messages that precede and succeed the |
|
544 * given message in server-side list of topic messages. |
|
545 * |
|
546 * Topic is resolved from the given message handle |
|
547 * |
|
548 * If the given handle specifies the first message in topic, |
|
549 * aPosition has ECbsHead bit up. If the given handle specifies |
|
550 * the last message in topic, aPosition has ECbsTail bit up. |
|
551 * |
|
552 * Return code values: |
|
553 * KErrNone aPrevMsgHandle, aNextMsgHandle and aPosition |
|
554 * contain valid values. |
|
555 * KErrNotFound aCurrentMsgHandle specified a message that was not |
|
556 * found. |
|
557 * |
|
558 * @param aCurrentMsgHandle Handle that specifies the message |
|
559 * whose surroundings are returned |
|
560 * @param aPrevMsgHandle Returns: handle of message |
|
561 * preceding the given message |
|
562 * @param aNextMsgHandle Returns: handle of message |
|
563 * succeeding the given topic |
|
564 * @param aPosition Returns: position of current topic |
|
565 * in list |
|
566 * @return Result code |
|
567 */ |
|
568 IMPORT_C TInt GetNextAndPrevMessageHandle( |
|
569 const TCbsMessageHandle& aCurrentMsgHandle, |
|
570 TCbsMessageHandle& aPrevMsgHandle, |
|
571 TCbsMessageHandle& aNextMsgHandle, |
|
572 TInt& aPosition ); |
|
573 |
|
574 // Other methods |
|
575 |
|
576 /** |
|
577 * Returns ETrue if CbsServer session has been established. |
|
578 * |
|
579 * @return ETrue, if session open. |
|
580 */ |
|
581 IMPORT_C TBool Connected() const; |
|
582 |
|
583 /** |
|
584 * Forces the server to shut down. |
|
585 * |
|
586 */ |
|
587 IMPORT_C void Shutdown() const; |
|
588 |
|
589 private: // starting server |
|
590 /** |
|
591 * Starts the server. |
|
592 */ |
|
593 TInt StartServer(); |
|
594 |
|
595 /** |
|
596 * Checks if the server is already started. |
|
597 */ |
|
598 TBool IsServerStarted(); |
|
599 |
|
600 private: |
|
601 |
|
602 // Copy constructor |
|
603 RCbs( const RCbs& ); |
|
604 |
|
605 // Assignment operator |
|
606 RCbs& operator=( const RCbs& ); |
|
607 |
|
608 private: |
|
609 // Settings subsession |
|
610 RCbsSettings iSettings; |
|
611 |
|
612 // Topic list subsession |
|
613 RCbsTopicList iTopicList; |
|
614 |
|
615 // Topic messages subsession |
|
616 RCbsTopicMessages iTopicMessages; |
|
617 |
|
618 // Collection subsession |
|
619 RCbsTopicCollection iTopicCollection; |
|
620 |
|
621 // ETrue, if the session has been established |
|
622 TBool iConnected; |
|
623 }; |
|
624 |
|
625 #endif // RCbs_H |
|
626 |
|
627 // End of File |
|
628 |
|
629 |
|