messagingapp/msgappfw/client/src/rcssession.cpp
changeset 31 ebfee66fde93
child 44 36f374c67aa8
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     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     User::LeaveIfError (SendReceive(EShutdown, args));
       
   129     PRINT ( _L("RCsSession::ShutdownServerL - ServerShutDown") );
       
   130 }
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // RCsSession::GetConversationListL
       
   134 // This function sends the request to conversation server
       
   135 // to get Recent Conversation Entry list with display name and contact link
       
   136 // for all stored conversation entry IDs.
       
   137 // ----------------------------------------------------------------------------
       
   138 void RCsSession::GetConversationListL(TPtr8 aResultsBuffer,
       
   139                                       TRequestStatus& aStatus)
       
   140 {
       
   141     PRINT( _L("Enter RCsSession::GetConversationEntryListL") );
       
   142 
       
   143     // Hold the pointer to buffers till the async request is complete
       
   144     iListResultsBufferPtr.Set(aResultsBuffer);
       
   145 
       
   146     TIpcArgs args(TIpcArgs::ENothing, &iListResultsBufferPtr);
       
   147 
       
   148     // Initiate the request
       
   149     SendReceive(EGetConversationList, args, aStatus);
       
   150     PRINT( _L("End RCsSession::GetConversationEntryListL") );
       
   151 }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // RCsSession::GetConversationUnreadListL
       
   155 // This function sends the request to conversation server
       
   156 // to get Recent unread Conversation Entry list with display name and contact link
       
   157 // for all stored conversation entry IDs.
       
   158 // ----------------------------------------------------------------------------
       
   159 void RCsSession::GetConversationUnreadListL(TPtr8 aOverflow, TPtr8 aResultsBuffer)
       
   160   {
       
   161   PRINT( _L("Enter RCsSession::GetConversationEntryListL") );
       
   162 
       
   163   TIpcArgs args(&aOverflow, &aResultsBuffer);
       
   164   // Initiate the request
       
   165   User::LeaveIfError (SendReceive(EGetConversationUnreadList, args));
       
   166   PRINT( _L("End RCsSession::GetConversationEntryListL") );
       
   167   }
       
   168 
       
   169 // ----------------------------------------------------------------------------
       
   170 // RCsSession::GetConversationsL
       
   171 // This function sends the request to conversation server
       
   172 // to get Conversation Entry list for given Conversation Entry ID.
       
   173 // ----------------------------------------------------------------------------
       
   174 void RCsSession::GetConversationsL(const TDes8& aClientConversation,
       
   175                                    TPtr8 aResultsBuffer,
       
   176                                    TRequestStatus& aStatus)
       
   177 {
       
   178     PRINT( _L("Enter RCsSession::GetConversationsL") );
       
   179 
       
   180     // Hold the pointer to buffers till the async request is complete
       
   181     iRequestBufferPtr.Set(aClientConversation);
       
   182     iConvResultsBufferPtr.Set(aResultsBuffer);
       
   183 
       
   184     TIpcArgs args(&iRequestBufferPtr, &iConvResultsBufferPtr);
       
   185 
       
   186     // Initiate the request
       
   187     SendReceive(EGetConversations, args, aStatus);
       
   188     PRINT( _L("End RCsSession::GetConversationsL") );
       
   189 }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // RCsSession::SendNewBufferGetConversationL
       
   193 // This function sends the request to conversation server
       
   194 // to get whole conversation again for the new buffer size
       
   195 //
       
   196 // ----------------------------------------------------------------------------
       
   197 void RCsSession::SendNewBufferGetConversationL(TPtr8 aResultsBuffer,
       
   198                                                TRequestStatus& aStatus)
       
   199 {
       
   200     PRINT( _L("Enter RCsSession::SendNewBufferGetConversationL") );
       
   201 
       
   202     // Hold the pointer to buffers till the async request is complete
       
   203     iConvResultsBufferPtr.Set(aResultsBuffer);
       
   204 
       
   205     TIpcArgs args(TIpcArgs::ENothing, &iConvResultsBufferPtr);
       
   206 
       
   207     // Initiate the request
       
   208     SendReceive(EGetConversations, args, aStatus);
       
   209 }
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // RCsSession::GetCachingStatusL
       
   213 // This function sends the request to conversation server
       
   214 // to get caching status.
       
   215 // ----------------------------------------------------------------------------
       
   216 void RCsSession::GetCachingStatusL(TPtr8 aResultsBuffer)
       
   217 {
       
   218     TIpcArgs args(TIpcArgs::ENothing, &aResultsBuffer);
       
   219     // Initiate the request
       
   220     User::LeaveIfError (SendReceive(EGetCachingStatus, args));
       
   221 }
       
   222 
       
   223 // ----------------------------------------------------------------------------
       
   224 // RCsSession::GetTotalUnreadCountL
       
   225 // This function sends the request to conversation server
       
   226 // to get caching status.
       
   227 // ----------------------------------------------------------------------------
       
   228 void RCsSession::GetTotalUnreadCountL(TPtr8 aResultsBuffer)
       
   229     {
       
   230     TIpcArgs args(TIpcArgs::ENothing, &aResultsBuffer);
       
   231     // Initiate the request
       
   232     User::LeaveIfError (SendReceive(EGetTotalUnreadCount, args));
       
   233     }
       
   234 
       
   235 // ----------------------------------------------------------------------------
       
   236 // RCsSession::SetConversationListChangeObserverL
       
   237 // This function sends the request to conversation server
       
   238 // to set conversation list change observer flag.
       
   239 // ----------------------------------------------------------------------------
       
   240 void RCsSession::SetConversationListChangeObserverL()
       
   241 {
       
   242     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing);
       
   243 
       
   244     // Initiate the request
       
   245     User::LeaveIfError ( SendReceive(ESetConversationListChangeObserver, args));
       
   246 
       
   247   
       
   248 }
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // RCsSession::ResetConversationListChangeObserverL
       
   252 // This function sends the request to conversation server
       
   253 // to reset conversation list change observer flag.
       
   254 // ----------------------------------------------------------------------------
       
   255 void RCsSession::ResetConversationListChangeObserverL()
       
   256 {
       
   257     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing);
       
   258     // Initiate the request
       
   259     User::LeaveIfError ( SendReceive(EResetConversationListChangeObserver, args));
       
   260 }
       
   261 
       
   262 // ----------------------------------------------------------------------------
       
   263 // RCsSession::SetConversationChangeObserverL
       
   264 // This function sends the request to conversation server
       
   265 // to set conversation change observer flag for given
       
   266 // client conversation
       
   267 // ----------------------------------------------------------------------------
       
   268 void RCsSession::SetConversationChangeObserverL(
       
   269                                                 const TDes8& aClientConversation)
       
   270 {
       
   271     TIpcArgs args(&aClientConversation);
       
   272     // Initiate the request
       
   273     User::LeaveIfError (SendReceive(ESetConversationChangeObserver, args));
       
   274 }
       
   275 
       
   276 // ----------------------------------------------------------------------------
       
   277 // RCsSession::ResetConversationChangeObserverL
       
   278 // This function sends the request to conversation server
       
   279 // to reset conversation change observer flag for given
       
   280 // client conversation
       
   281 // ----------------------------------------------------------------------------
       
   282 void RCsSession::ResetConversationChangeObserverL(
       
   283                                                   const TDes8& aClientConversation)
       
   284 {
       
   285     TIpcArgs args(&aClientConversation);
       
   286     // Initiate the request
       
   287     User::LeaveIfError (SendReceive(EResetConversationChangeObserver, args));
       
   288 }
       
   289 
       
   290 // ----------------------------------------------------------------------------
       
   291 // RCsSession::SetCachingStatusObserverL
       
   292 // This function sends the request to conversation server
       
   293 // to set caching status observer flag.
       
   294 // ----------------------------------------------------------------------------
       
   295 void RCsSession::SetCachingStatusObserverL()
       
   296 {
       
   297     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing);
       
   298 
       
   299     // Initiate the request
       
   300     User::LeaveIfError (SendReceive(ESetCachingStatusObserver, args));
       
   301 }
       
   302 
       
   303 // ----------------------------------------------------------------------------
       
   304 // RCsSession::ResetConversationListChangeObserverL
       
   305 // This function sends the request to conversation server
       
   306 // to reset caching status observer flag.
       
   307 // ----------------------------------------------------------------------------
       
   308 void RCsSession::ResetCachingStatusObserverL()
       
   309 {
       
   310     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing);
       
   311 
       
   312     // Initiate the request
       
   313     User::LeaveIfError (SendReceive(EResetCachingStatusObserver, args));
       
   314 }
       
   315 
       
   316 // ----------------------------------------------------------------------------
       
   317 // RCsSession::RequestChangeEventL
       
   318 // This function sends the request to conversation server
       
   319 // to register for any cache change event.
       
   320 // ----------------------------------------------------------------------------
       
   321 void RCsSession::RequestChangeEventL(TInt aLastReqID, TPtr8 aNextReqIDBuffer,
       
   322                                      TPtr8 aResultsBuffer,
       
   323                                      TRequestStatus& aStatus)
       
   324 {
       
   325     // Hold the pointer to buffers till the async request is complete
       
   326     iNotifyRequestBufferPtr.Set(aNextReqIDBuffer);
       
   327     iNotifyResultsBufferPtr.Set(aResultsBuffer);
       
   328 
       
   329     TIpcArgs args(&iNotifyRequestBufferPtr,
       
   330                   &iNotifyResultsBufferPtr,
       
   331                   aLastReqID);
       
   332 
       
   333     // Initiate the request
       
   334     SendReceive(ERequestChangeEvent, args, aStatus);
       
   335 }
       
   336 
       
   337 // ----------------------------------------------------------------------------
       
   338 // RCsSession::RemoveChangeEventL
       
   339 // This function sends the request to conversation server
       
   340 // to deregister for for any cache change event.
       
   341 // ----------------------------------------------------------------------------
       
   342 void RCsSession::RemoveChangeEventL()
       
   343 {
       
   344     TIpcArgs args(TIpcArgs::ENothing, TIpcArgs::ENothing);
       
   345 
       
   346     // Initiate the request
       
   347     User::LeaveIfError ( SendReceive(ERemoveChangeEvent, args));
       
   348 }
       
   349 
       
   350 // ----------------------------------------------------------------------------
       
   351 // RCsSession::DeleteConversationL
       
   352 // ----------------------------------------------------------------------------
       
   353 void RCsSession::DeleteConversationL(TInt aConversationId)
       
   354 {
       
   355     PRINT( _L("Enter RCsSession::DeleteConversationL") );
       
   356 
       
   357     TRequestStatus status;
       
   358     TIpcArgs args(aConversationId);
       
   359 
       
   360     // Initiate the request
       
   361     SendReceive(EUserDeleteConversation, args, status);
       
   362 
       
   363     User::WaitForRequest(status);
       
   364 
       
   365     PRINT( _L("End RCsSession::DeleteConversationL") );
       
   366 }
       
   367 
       
   368 // ----------------------------------------------------------------------------
       
   369 // RCsSession::GetConversationIdL
       
   370 // ----------------------------------------------------------------------------
       
   371 void RCsSession::GetConversationIdL(TInt aContactId, TPtr8 aResultsBuffer)
       
   372     {
       
   373     PRINT( _L("Enter RCsSession::GetConversationIdL") );
       
   374 
       
   375 
       
   376     TIpcArgs args(aContactId, &aResultsBuffer);
       
   377 
       
   378     // Initiate the request
       
   379     User::LeaveIfError (SendReceive(EGetConversationId, args) );
       
   380     PRINT( _L("End RCsSession::GetConversationIdL") );
       
   381     }
       
   382 
       
   383 // ----------------------------------------------------------------------------
       
   384 // RCsSession::GetConversationIdFromAddressL
       
   385 // ----------------------------------------------------------------------------
       
   386 void RCsSession::GetConversationIdFromAddressL(TDesC& aContactAddress, TPtr8 aResultsBuffer)
       
   387     {
       
   388     PRINT( _L("Enter RCsSession::GetConversationIdFromAddressL") );
       
   389 
       
   390     TIpcArgs args(&aContactAddress, &aResultsBuffer);
       
   391 
       
   392     // Initiate the request
       
   393     User::LeaveIfError (SendReceive(EGetConversationIdFromAddress,
       
   394             args ));
       
   395 
       
   396     PRINT( _L("End RCsSession::GetConversationIdFromAddressL") );
       
   397     }
       
   398 	
       
   399 // ----------------------------------------------------------------------------
       
   400 // RCsSession::GetConversationFromMessageIdL
       
   401 // ----------------------------------------------------------------------------
       
   402 void RCsSession::GetConversationFromMessageIdL(TInt aMessageId, TPtr8 aResultsBuffer)
       
   403     {
       
   404     PRINT( _L("Enter RCsSession::GetConversationFromMessageIdL") );
       
   405     
       
   406     TIpcArgs args(aMessageId, &aResultsBuffer);
       
   407 
       
   408     // Initiate the request
       
   409     User::LeaveIfError (SendReceive(EGetConversationFromMessageId, args ) );
       
   410     PRINT( _L("End RCsSession::GetConversationFromMessageIdL") );
       
   411     }
       
   412 	
       
   413 // ----------------------------------------------------------------------------
       
   414 // RCsSession::MarkConversationReadL
       
   415 // ----------------------------------------------------------------------------
       
   416 void RCsSession::MarkConversationReadL(TInt aConversationId)
       
   417     {
       
   418     PRINT( _L("Enter RCsSession::MarkConversationReadL") );
       
   419 
       
   420     TRequestStatus status;
       
   421     TIpcArgs args(aConversationId);
       
   422 
       
   423     // Initiate the request
       
   424     SendReceive(EUserMarkReadConversation,
       
   425             args,
       
   426             status );
       
   427 
       
   428     User::WaitForRequest(status);
       
   429 
       
   430     PRINT( _L("End RCsSession::MarkConversationReadL") );
       
   431     }
       
   432 
       
   433 // End of File