|         |      1 /* | 
|         |      2  * Copyright (c) 2007 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 is the CS server client side interface implementation. | 
|         |     15  * | 
|         |     16  */ | 
|         |     17  | 
|         |     18 // INCLUDE FILES | 
|         |     19  | 
|         |     20 // SYSTEM INCLUDES | 
|         |     21 #include <rcssession.h> | 
|         |     22  | 
|         |     23 // USER INCLUDES | 
|         |     24 #include "ccsdebug.h" | 
|         |     25  | 
|         |     26 // ---------------------------------------------------------------------------- | 
|         |     27 // StartServer | 
|         |     28 // Starts the server. Used only when the server is implemented as a transient. | 
|         |     29 // ---------------------------------------------------------------------------- | 
|         |     30 TInt StartServer() | 
|         |     31 { | 
|         |     32     PRINT ( _L("Enter RCsSession->StartServer") ); | 
|         |     33  | 
|         |     34     RProcess server; | 
|         |     35     TInt err = server.Create(KCsServerExeName, KNullDesC); | 
|         |     36     if (err != KErrNone) | 
|         |     37     { | 
|         |     38         return err; | 
|         |     39     } | 
|         |     40  | 
|         |     41     TRequestStatus status; | 
|         |     42     server.Rendezvous(status); | 
|         |     43  | 
|         |     44     if (status != KRequestPending) | 
|         |     45     { | 
|         |     46         server.Kill(0); | 
|         |     47         server.Close(); | 
|         |     48         return KErrGeneral; | 
|         |     49     } | 
|         |     50     else | 
|         |     51     { | 
|         |     52         server.Resume(); | 
|         |     53     } | 
|         |     54  | 
|         |     55     User::WaitForRequest(status); | 
|         |     56  | 
|         |     57     if (status != KErrNone) | 
|         |     58     { | 
|         |     59         server.Close(); | 
|         |     60         return status.Int(); | 
|         |     61     } | 
|         |     62  | 
|         |     63     PRINT ( _L("End RCsSession->StartServer") ); | 
|         |     64  | 
|         |     65     return KErrNone; | 
|         |     66 } | 
|         |     67 // ============================== MEMBER FUNCTIONS ============================ | 
|         |     68  | 
|         |     69 // ---------------------------------------------------------------------------- | 
|         |     70 // RCsSession::RCsSession | 
|         |     71 // Constructor | 
|         |     72 // ---------------------------------------------------------------------------- | 
|         |     73 RCsSession::RCsSession() : RSessionBase(), | 
|         |     74 iListResultsBufferPtr (0, 0), | 
|         |     75 iConvResultsBufferPtr (0, 0), | 
|         |     76 iRequestBufferPtr (0, 0), | 
|         |     77 iNotifyResultsBufferPtr (0, 0), | 
|         |     78 iNotifyRequestBufferPtr (0, 0){ | 
|         |     79 } | 
|         |     80  | 
|         |     81 // ---------------------------------------------------------------------------- | 
|         |     82 // RCsSession::Connects to the conversation server | 
|         |     83 // Returns the version number | 
|         |     84 // ---------------------------------------------------------------------------- | 
|         |     85 TInt RCsSession::Connect() | 
|         |     86 { | 
|         |     87     TInt err = CreateSession(KCsServerName, Version()); | 
|         |     88  | 
|         |     89     if (err != KErrNone) | 
|         |     90     { | 
|         |     91         PRINT ( _L("conversation server not running. Trying to start") ); | 
|         |     92  | 
|         |     93         err = StartServer(); | 
|         |     94  | 
|         |     95         if (err != KErrNone) | 
|         |     96         { | 
|         |     97             PRINT ( _L("Conversation server startup failed") ); | 
|         |     98             PRINT1 ( _L("End RCsSession::Connect. Error code = %d"), err ); | 
|         |     99             return err; | 
|         |    100         } | 
|         |    101  | 
|         |    102         PRINT ( _L("Conversation server startup successful") ); | 
|         |    103  | 
|         |    104         err = CreateSession(KCsServerName, Version()); | 
|         |    105     } | 
|         |    106  | 
|         |    107     return err; | 
|         |    108 } | 
|         |    109  | 
|         |    110 // ---------------------------------------------------------------------------- | 
|         |    111 // RCsSession::Version | 
|         |    112 // Returns the version number | 
|         |    113 // ---------------------------------------------------------------------------- | 
|         |    114 TVersion RCsSession::Version() const | 
|         |    115 { | 
|         |    116     return (TVersion(KCsServerMajorVersionNumber, | 
|         |    117                      KCsServerMinorVersionNumber, | 
|         |    118                      KCsServerBuildVersionNumber)); | 
|         |    119 } | 
|         |    120  | 
|         |    121 // ---------------------------------------------------------------------------- | 
|         |    122 // RCsSession::ShutdownServerL | 
|         |    123 // Shutsdown the CS Server. Synchronous. | 
|         |    124 // ---------------------------------------------------------------------------- | 
|         |    125 void RCsSession::ShutdownServerL() | 
|         |    126 { | 
|         |    127     TIpcArgs args; | 
|         |    128     TRequestStatus status; | 
|         |    129     SendReceive(EShutdown, args, status); | 
|         |    130     User::WaitForRequest(status); | 
|         |    131  | 
|         |    132     PRINT ( _L("RCsSession::ShutdownServerL - ServerShutDown") ); | 
|         |    133 } | 
|         |    134  | 
|         |    135 // ---------------------------------------------------------------------------- | 
|         |    136 // RCsSession::GetConversationListL | 
|         |    137 // This function sends the request to conversation server | 
|         |    138 // to get Recent Conversation Entry list with display name and contact link | 
|         |    139 // for all stored conversation entry IDs. | 
|         |    140 // ---------------------------------------------------------------------------- | 
|         |    141 void RCsSession::GetConversationListL(TPtr8 aResultsBuffer, | 
|         |    142                                       TRequestStatus& aStatus) | 
|         |    143 { | 
|         |    144     PRINT( _L("Enter RCsSession::GetConversationEntryListL") ); | 
|         |    145  | 
|         |    146     // Hold the pointer to buffers till the async request is complete | 
|         |    147     iListResultsBufferPtr.Set(aResultsBuffer); | 
|         |    148  | 
|         |    149     TIpcArgs args(TIpcArgs::ENothing, &iListResultsBufferPtr); | 
|         |    150  | 
|         |    151     // Initiate the request | 
|         |    152     SendReceive(EGetConversationList, args, aStatus); | 
|         |    153     PRINT( _L("End RCsSession::GetConversationEntryListL") ); | 
|         |    154 } | 
|         |    155  | 
|         |    156 // ---------------------------------------------------------------------------- | 
|         |    157 // RCsSession::GetConversationUnreadListL | 
|         |    158 // This function sends the request to conversation server | 
|         |    159 // to get Recent unread Conversation Entry list with display name and contact link | 
|         |    160 // for all stored conversation entry IDs. | 
|         |    161 // ---------------------------------------------------------------------------- | 
|         |    162 void RCsSession::GetConversationUnreadListL(TPtr8 aOverflow, TPtr8 aResultsBuffer) | 
|         |    163   { | 
|         |    164   PRINT( _L("Enter RCsSession::GetConversationEntryListL") ); | 
|         |    165  | 
|         |    166   TIpcArgs args(&aOverflow, &aResultsBuffer); | 
|         |    167  | 
|         |    168   TRequestStatus status; | 
|         |    169  | 
|         |    170   // Initiate the request | 
|         |    171   SendReceive(EGetConversationUnreadList, args, status); | 
|         |    172  | 
|         |    173   User::WaitForRequest(status); | 
|         |    174  | 
|         |    175   PRINT( _L("End RCsSession::GetConversationEntryListL") ); | 
|         |    176   } | 
|         |    177  | 
|         |    178 // ---------------------------------------------------------------------------- | 
|         |    179 // RCsSession::GetConversationsL | 
|         |    180 // This function sends the request to conversation server | 
|         |    181 // to get Conversation Entry list for given Conversation Entry ID. | 
|         |    182 // ---------------------------------------------------------------------------- | 
|         |    183 void RCsSession::GetConversationsL(const TDes8& aClientConversation, | 
|         |    184                                    TPtr8 aResultsBuffer, | 
|         |    185                                    TRequestStatus& aStatus) | 
|         |    186 { | 
|         |    187     PRINT( _L("Enter RCsSession::GetConversationsL") ); | 
|         |    188  | 
|         |    189     // Hold the pointer to buffers till the async request is complete | 
|         |    190     iRequestBufferPtr.Set(aClientConversation); | 
|         |    191     iConvResultsBufferPtr.Set(aResultsBuffer); | 
|         |    192  | 
|         |    193     TIpcArgs args(&iRequestBufferPtr, &iConvResultsBufferPtr); | 
|         |    194  | 
|         |    195     // Initiate the request | 
|         |    196     SendReceive(EGetConversations, args, aStatus); | 
|         |    197     PRINT( _L("End RCsSession::GetConversationsL") ); | 
|         |    198 } | 
|         |    199  | 
|         |    200 // ---------------------------------------------------------------------------- | 
|         |    201 // RCsSession::SendNewBufferGetConversationL | 
|         |    202 // This function sends the request to conversation server | 
|         |    203 // to get whole conversation again for the new buffer size | 
|         |    204 // | 
|         |    205 // ---------------------------------------------------------------------------- | 
|         |    206 void RCsSession::SendNewBufferGetConversationL(TPtr8 aResultsBuffer, | 
|         |    207                                                TRequestStatus& aStatus) | 
|         |    208 { | 
|         |    209     PRINT( _L("Enter RCsSession::SendNewBufferGetConversationL") ); | 
|         |    210  | 
|         |    211     // Hold the pointer to buffers till the async request is complete | 
|         |    212     iConvResultsBufferPtr.Set(aResultsBuffer); | 
|         |    213  | 
|         |    214     TIpcArgs args(TIpcArgs::ENothing, &iConvResultsBufferPtr); | 
|         |    215  | 
|         |    216     // Initiate the request | 
|         |    217     SendReceive(EGetConversations, args, aStatus); | 
|         |    218 } | 
|         |    219  | 
|         |    220 // ---------------------------------------------------------------------------- | 
|         |    221 // RCsSession::GetCachingStatusL | 
|         |    222 // This function sends the request to conversation server | 
|         |    223 // to get caching status. | 
|         |    224 // ---------------------------------------------------------------------------- | 
|         |    225 void RCsSession::GetCachingStatusL(TPtr8 aResultsBuffer) | 
|         |    226 { | 
|         |    227     TIpcArgs args(TIpcArgs::ENothing, &aResultsBuffer); | 
|         |    228  | 
|         |    229     TRequestStatus status; | 
|         |    230  | 
|         |    231     // Initiate the request | 
|         |    232     SendReceive(EGetCachingStatus, args, status); | 
|         |    233  | 
|         |    234     User::WaitForRequest(status); | 
|         |    235 } | 
|         |    236  | 
|         |    237 // ---------------------------------------------------------------------------- | 
|         |    238 // RCsSession::GetTotalUnreadCountL | 
|         |    239 // This function sends the request to conversation server | 
|         |    240 // to get caching status. | 
|         |    241 // ---------------------------------------------------------------------------- | 
|         |    242 void RCsSession::GetTotalUnreadCountL(TPtr8 aResultsBuffer) | 
|         |    243     { | 
|         |    244     TIpcArgs args(TIpcArgs::ENothing, &aResultsBuffer); | 
|         |    245  | 
|         |    246     TRequestStatus status; | 
|         |    247  | 
|         |    248     // Initiate the request | 
|         |    249     SendReceive(EGetTotalUnreadCount, args, status); | 
|         |    250  | 
|         |    251     User::WaitForRequest(status); | 
|         |    252     } | 
|         |    253  | 
|         |    254 // ---------------------------------------------------------------------------- | 
|         |    255 // RCsSession::SetConversationListChangeObserverL | 
|         |    256 // This function sends the request to conversation server | 
|         |    257 // to set conversation list change observer flag. | 
|         |    258 // ---------------------------------------------------------------------------- | 
|         |    259 void RCsSession::SetConversationListChangeObserverL() | 
|         |    260 { | 
|         |    261     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing); | 
|         |    262  | 
|         |    263     TRequestStatus status; | 
|         |    264  | 
|         |    265     // Initiate the request | 
|         |    266     SendReceive(ESetConversationListChangeObserver, args, status); | 
|         |    267  | 
|         |    268     User::WaitForRequest(status); | 
|         |    269 } | 
|         |    270  | 
|         |    271 // ---------------------------------------------------------------------------- | 
|         |    272 // RCsSession::ResetConversationListChangeObserverL | 
|         |    273 // This function sends the request to conversation server | 
|         |    274 // to reset conversation list change observer flag. | 
|         |    275 // ---------------------------------------------------------------------------- | 
|         |    276 void RCsSession::ResetConversationListChangeObserverL() | 
|         |    277 { | 
|         |    278     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing); | 
|         |    279  | 
|         |    280     TRequestStatus status; | 
|         |    281  | 
|         |    282     // Initiate the request | 
|         |    283     SendReceive(EResetConversationListChangeObserver, args, status); | 
|         |    284  | 
|         |    285     User::WaitForRequest(status); | 
|         |    286 } | 
|         |    287  | 
|         |    288 // ---------------------------------------------------------------------------- | 
|         |    289 // RCsSession::SetConversationChangeObserverL | 
|         |    290 // This function sends the request to conversation server | 
|         |    291 // to set conversation change observer flag for given | 
|         |    292 // client conversation | 
|         |    293 // ---------------------------------------------------------------------------- | 
|         |    294 void RCsSession::SetConversationChangeObserverL( | 
|         |    295                                                 const TDes8& aClientConversation) | 
|         |    296 { | 
|         |    297     TIpcArgs args(&aClientConversation); | 
|         |    298  | 
|         |    299     TRequestStatus status; | 
|         |    300  | 
|         |    301     // Initiate the request | 
|         |    302     SendReceive(ESetConversationChangeObserver, args, status); | 
|         |    303  | 
|         |    304     User::WaitForRequest(status); | 
|         |    305 } | 
|         |    306  | 
|         |    307 // ---------------------------------------------------------------------------- | 
|         |    308 // RCsSession::ResetConversationChangeObserverL | 
|         |    309 // This function sends the request to conversation server | 
|         |    310 // to reset conversation change observer flag for given | 
|         |    311 // client conversation | 
|         |    312 // ---------------------------------------------------------------------------- | 
|         |    313 void RCsSession::ResetConversationChangeObserverL( | 
|         |    314                                                   const TDes8& aClientConversation) | 
|         |    315 { | 
|         |    316     TIpcArgs args(&aClientConversation); | 
|         |    317  | 
|         |    318     TRequestStatus status; | 
|         |    319  | 
|         |    320     // Initiate the request | 
|         |    321     SendReceive(EResetConversationChangeObserver, args, status); | 
|         |    322  | 
|         |    323     User::WaitForRequest(status); | 
|         |    324 } | 
|         |    325  | 
|         |    326 // ---------------------------------------------------------------------------- | 
|         |    327 // RCsSession::SetCachingStatusObserverL | 
|         |    328 // This function sends the request to conversation server | 
|         |    329 // to set caching status observer flag. | 
|         |    330 // ---------------------------------------------------------------------------- | 
|         |    331 void RCsSession::SetCachingStatusObserverL() | 
|         |    332 { | 
|         |    333     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing); | 
|         |    334  | 
|         |    335     TRequestStatus status; | 
|         |    336  | 
|         |    337     // Initiate the request | 
|         |    338     SendReceive(ESetCachingStatusObserver, args, status); | 
|         |    339  | 
|         |    340     User::WaitForRequest(status); | 
|         |    341 } | 
|         |    342  | 
|         |    343 // ---------------------------------------------------------------------------- | 
|         |    344 // RCsSession::ResetConversationListChangeObserverL | 
|         |    345 // This function sends the request to conversation server | 
|         |    346 // to reset caching status observer flag. | 
|         |    347 // ---------------------------------------------------------------------------- | 
|         |    348 void RCsSession::ResetCachingStatusObserverL() | 
|         |    349 { | 
|         |    350     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing); | 
|         |    351  | 
|         |    352     TRequestStatus status; | 
|         |    353  | 
|         |    354     // Initiate the request | 
|         |    355     SendReceive(EResetCachingStatusObserver, args, status); | 
|         |    356  | 
|         |    357     User::WaitForRequest(status); | 
|         |    358 } | 
|         |    359  | 
|         |    360 // ---------------------------------------------------------------------------- | 
|         |    361 // RCsSession::RequestChangeEventL | 
|         |    362 // This function sends the request to conversation server | 
|         |    363 // to register for any cache change event. | 
|         |    364 // ---------------------------------------------------------------------------- | 
|         |    365 void RCsSession::RequestChangeEventL(TInt aLastReqID, TPtr8 aNextReqIDBuffer, | 
|         |    366                                      TPtr8 aResultsBuffer, | 
|         |    367                                      TRequestStatus& aStatus) | 
|         |    368 { | 
|         |    369     // Hold the pointer to buffers till the async request is complete | 
|         |    370     iNotifyRequestBufferPtr.Set(aNextReqIDBuffer); | 
|         |    371     iNotifyResultsBufferPtr.Set(aResultsBuffer); | 
|         |    372  | 
|         |    373     TIpcArgs args(&iNotifyRequestBufferPtr, | 
|         |    374                   &iNotifyResultsBufferPtr, | 
|         |    375                   aLastReqID); | 
|         |    376  | 
|         |    377     // Initiate the request | 
|         |    378     SendReceive(ERequestChangeEvent, args, aStatus); | 
|         |    379 } | 
|         |    380  | 
|         |    381 // ---------------------------------------------------------------------------- | 
|         |    382 // RCsSession::RemoveChangeEventL | 
|         |    383 // This function sends the request to conversation server | 
|         |    384 // to deregister for for any cache change event. | 
|         |    385 // ---------------------------------------------------------------------------- | 
|         |    386 void RCsSession::RemoveChangeEventL() | 
|         |    387 { | 
|         |    388     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing); | 
|         |    389  | 
|         |    390     TRequestStatus status; | 
|         |    391  | 
|         |    392     // Initiate the request | 
|         |    393     SendReceive(ERemoveChangeEvent, args, status); | 
|         |    394  | 
|         |    395     User::WaitForRequest(status); | 
|         |    396 } | 
|         |    397  | 
|         |    398 // ---------------------------------------------------------------------------- | 
|         |    399 // RCsSession::DeleteConversationL | 
|         |    400 // ---------------------------------------------------------------------------- | 
|         |    401 void RCsSession::DeleteConversationL(TInt aConversationId) | 
|         |    402 { | 
|         |    403     PRINT( _L("Enter RCsSession::DeleteConversationL") ); | 
|         |    404  | 
|         |    405     TRequestStatus status; | 
|         |    406     TIpcArgs args(aConversationId); | 
|         |    407  | 
|         |    408     // Initiate the request | 
|         |    409     SendReceive(EUserDeleteConversation, args, status); | 
|         |    410  | 
|         |    411     User::WaitForRequest(status); | 
|         |    412  | 
|         |    413     PRINT( _L("End RCsSession::DeleteConversationL") ); | 
|         |    414 } | 
|         |    415  | 
|         |    416 // ---------------------------------------------------------------------------- | 
|         |    417 // RCsSession::GetConversationIdL | 
|         |    418 // ---------------------------------------------------------------------------- | 
|         |    419 void RCsSession::GetConversationIdL(TInt aContactId, TPtr8 aResultsBuffer) | 
|         |    420     { | 
|         |    421     PRINT( _L("Enter RCsSession::GetConversationIdL") ); | 
|         |    422  | 
|         |    423     TRequestStatus status; | 
|         |    424     TIpcArgs args(aContactId, &aResultsBuffer); | 
|         |    425  | 
|         |    426     // Initiate the request | 
|         |    427     SendReceive(EGetConversationId, | 
|         |    428             args, | 
|         |    429             status ); | 
|         |    430  | 
|         |    431     User::WaitForRequest(status); | 
|         |    432  | 
|         |    433     PRINT( _L("End RCsSession::GetConversationIdL") ); | 
|         |    434     } | 
|         |    435  | 
|         |    436 // ---------------------------------------------------------------------------- | 
|         |    437 // RCsSession::GetConversationIdFromAddressL | 
|         |    438 // ---------------------------------------------------------------------------- | 
|         |    439 void RCsSession::GetConversationIdFromAddressL(TDesC& aContactAddress, TPtr8 aResultsBuffer) | 
|         |    440     { | 
|         |    441     PRINT( _L("Enter RCsSession::GetConversationIdFromAddressL") ); | 
|         |    442  | 
|         |    443     TRequestStatus status; | 
|         |    444     TIpcArgs args(&aContactAddress, &aResultsBuffer); | 
|         |    445  | 
|         |    446     // Initiate the request | 
|         |    447     SendReceive(EGetConversationIdFromAddress, | 
|         |    448             args, | 
|         |    449             status ); | 
|         |    450  | 
|         |    451     User::WaitForRequest(status); | 
|         |    452  | 
|         |    453     PRINT( _L("End RCsSession::GetConversationIdFromAddressL") ); | 
|         |    454     } | 
|         |    455 // ---------------------------------------------------------------------------- | 
|         |    456 // RCsSession::MarkConversationReadL | 
|         |    457 // ---------------------------------------------------------------------------- | 
|         |    458 void RCsSession::MarkConversationReadL(TInt aConversationId) | 
|         |    459     { | 
|         |    460     PRINT( _L("Enter RCsSession::MarkConversationReadL") ); | 
|         |    461  | 
|         |    462     TRequestStatus status; | 
|         |    463     TIpcArgs args(aConversationId); | 
|         |    464  | 
|         |    465     // Initiate the request | 
|         |    466     SendReceive(EUserMarkReadConversation, | 
|         |    467             args, | 
|         |    468             status ); | 
|         |    469  | 
|         |    470     User::WaitForRequest(status); | 
|         |    471  | 
|         |    472     PRINT( _L("End RCsSession::MarkConversationReadL") ); | 
|         |    473     } | 
|         |    474  | 
|         |    475 // End of File |