cbs/CbsServer/ClientSrc/RCbs.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     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 module contains the implementation of RCbs class 
       
    15                  member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  INCLUDES
       
    21 #include "RCbs.h"
       
    22 #include "CbsCommon.h"
       
    23 #include "CbsServerConstants.h"
       
    24 #include <data_caging_path_literals.hrh>
       
    25 
       
    26 // CONSTANTS 
       
    27 // Server name
       
    28 _LIT( KCbsServerExe, "CbsServer.exe");
       
    29 
       
    30 // How many microseconds to wait for server
       
    31 const TInt KWaitForServerRetries = 10;
       
    32 const TInt KWaitForServerTime = 500000;
       
    33 
       
    34 // ==================== LOCAL FUNCTIONS ====================
       
    35 
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // RCbs::RCbs
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 EXPORT_C RCbs::RCbs()   //lint -e1926
       
    46                         //lint -e1928
       
    47     : iConnected( EFalse )    
       
    48     {
       
    49     }                   //lint +e1926
       
    50                         //lint +e1928
       
    51     
       
    52 // Destructor
       
    53 EXPORT_C RCbs::~RCbs() 
       
    54     {
       
    55     // Close subsession and session.
       
    56     Close();
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // RCbs::Connect
       
    61 // Creates connection to the server.
       
    62 // (other items were commented in a header).
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C TInt RCbs::Connect()
       
    66     {
       
    67     TInt result( KErrNone );
       
    68 
       
    69     if ( !iConnected )
       
    70         {
       
    71         // Start the server if it isn't already started
       
    72         StartServer();
       
    73 
       
    74         // Create a session to the server.
       
    75         result = CreateSession( KCbsServerName,
       
    76                                 Version(), 
       
    77                                 KCbsServerDefaultSlots );
       
    78     
       
    79         if ( result == KErrNone )
       
    80             {
       
    81             // Create a settings subsession
       
    82             result = iSettings.Open( *this );
       
    83             }                        
       
    84         if ( result == KErrNone )
       
    85             {
       
    86             // Create a topic list subsession
       
    87             result = iTopicList.Open( *this );
       
    88             }        
       
    89         if ( result == KErrNone )
       
    90             {
       
    91             // Create a topic messages subsession
       
    92             result = iTopicMessages.Open( *this );
       
    93             }                        
       
    94         if ( result == KErrNone )
       
    95             {
       
    96             // Create a topic collection subsession     
       
    97             result = iTopicCollection.Open( *this );            
       
    98             if ( result == KErrNone )
       
    99                 {
       
   100                 iConnected = ETrue;
       
   101                 }
       
   102             else
       
   103                 {
       
   104                 iConnected = EFalse;
       
   105                 }
       
   106             }        
       
   107         }
       
   108     // Return the result code           
       
   109     return result; 
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // RCbs::Close
       
   114 // Closes the session to the server.
       
   115 // (other items were commented in a header).
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C void RCbs::Close()
       
   119     {
       
   120     if ( iConnected )
       
   121         {
       
   122         // First close all subsessions.
       
   123         iTopicCollection.Close();
       
   124         iTopicMessages.Close();
       
   125         iTopicList.Close();
       
   126         iSettings.Close();
       
   127 
       
   128         // Then close the server session.
       
   129 
       
   130         // Try to tell the server we've closed the session.
       
   131         // Just ignore if that fails.
       
   132         const TIpcArgs args( TIpcArgs::ENothing );
       
   133         SendReceive( ECbsCloseSession, args );
       
   134 
       
   135         RHandleBase::Close();
       
   136         iConnected = EFalse;
       
   137         }
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // RCbs::Version
       
   142 // Returns the version of CbsClient.
       
   143 // (other items were commented in a header).
       
   144 // -----------------------------------------------------------------------------
       
   145 //  
       
   146 EXPORT_C TVersion RCbs::Version() const
       
   147     {
       
   148     // Create version and return it.
       
   149     return TVersion( KCbsServerVersionMajor,
       
   150                      KCbsServerVersionMinor,
       
   151                      KCbsServerVersionBuild );
       
   152     }
       
   153 
       
   154 // Settings-related methods
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // RCbs::GetReceptionStatus
       
   158 // Requests the reception status from the server.
       
   159 // (other items were commented in a header).
       
   160 // -----------------------------------------------------------------------------
       
   161 // 
       
   162 EXPORT_C void RCbs::GetReceptionStatus( 
       
   163     TBool& aStatus )
       
   164     {
       
   165     iSettings.GetReceptionStatus( aStatus );
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // RCbs::SetReceptionStatus
       
   170 // Changes the reception status to aStatus.
       
   171 // (other items were commented in a header).
       
   172 // -----------------------------------------------------------------------------
       
   173 // 
       
   174 EXPORT_C TInt RCbs::SetReceptionStatus( 
       
   175     TBool aStatus )
       
   176     {    
       
   177     // Change the reception status
       
   178     return iSettings.SetReceptionStatus( aStatus );
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // RCbs::GetTopicDetectionStatus
       
   183 // Requests the current topic detection status.
       
   184 // (other items were commented in a header).
       
   185 // -----------------------------------------------------------------------------
       
   186 // 
       
   187 EXPORT_C void RCbs::GetTopicDetectionStatus( 
       
   188     TBool& aStatus )
       
   189     {
       
   190     iSettings.GetTopicDetectionStatus( aStatus );
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // RCbs::SetTopicDetectionStatus
       
   195 // Changes the topic detection status to aStatus.
       
   196 // (other items were commented in a header).
       
   197 // -----------------------------------------------------------------------------
       
   198 //  
       
   199 EXPORT_C TInt RCbs::SetTopicDetectionStatus( 
       
   200     TBool aStatus )
       
   201     {
       
   202     return iSettings.SetTopicDetectionStatus( aStatus );
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // RCbs::GetLanguages
       
   207 // Requests for the current language settings from the server.
       
   208 // (other items were commented in a header).
       
   209 // -----------------------------------------------------------------------------
       
   210 // 
       
   211 EXPORT_C void RCbs::GetLanguages( 
       
   212     TCbsSettingsLanguages& aLanguages )
       
   213     {
       
   214     iSettings.GetLanguages( aLanguages );
       
   215     }
       
   216 // -----------------------------------------------------------------------------
       
   217 // RCbs::SetLanguages
       
   218 // Sets a new set of languages to the server.
       
   219 // (other items were commented in a header).
       
   220 // -----------------------------------------------------------------------------
       
   221 // 
       
   222 EXPORT_C TInt RCbs::SetLanguages( 
       
   223     const TCbsSettingsLanguages& aLanguages )
       
   224     {
       
   225     return iSettings.SetLanguages( aLanguages );
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // RCbs::NotifySettingsChanged
       
   230 // Requests the server to notify the client whenever any settings will be 
       
   231 // changed.
       
   232 // (other items were commented in a header).
       
   233 // -----------------------------------------------------------------------------
       
   234 // 
       
   235 EXPORT_C void RCbs::NotifySettingsChanged( 
       
   236     TRequestStatus& aStatus, 
       
   237     TCbsSettingsEvent& aEvent )
       
   238     {    
       
   239     iSettings.NotifySettingsChanged( aStatus, aEvent );
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // RCbs::NotifySettingsChangedCancel
       
   244 // Cancels the request to notify the client.
       
   245 // (other items were commented in a header).
       
   246 // -----------------------------------------------------------------------------
       
   247 // 
       
   248 EXPORT_C void RCbs::NotifySettingsChangedCancel()
       
   249     {
       
   250     iSettings.NotifySettingsChangedCancel();
       
   251     }
       
   252 
       
   253 // Topic Collection -related methods
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // RCbs::StartCollectionBrowsing
       
   257 // Resets the iterator.
       
   258 // (other items were commented in a header).
       
   259 // -----------------------------------------------------------------------------
       
   260 // 
       
   261 EXPORT_C void RCbs::StartCollectionBrowsing()
       
   262     {
       
   263     iTopicCollection.Start();
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // RCbs::HasNextCollectionTopic
       
   268 // Returns ETrue, if there is a topic not accessed with NextTopic()
       
   269 // (other items were commented in a header).
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 EXPORT_C TBool RCbs::HasNextCollectionTopic()
       
   273     {
       
   274     return iTopicCollection.HasNextTopic();
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // RCbs::NextCollectionTopic
       
   279 // Returns the next topic identity if one exists.
       
   280 // (other items were commented in a header).
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 EXPORT_C TInt RCbs::NextCollectionTopic( 
       
   284     TCbsTopicInfo& aInfo )
       
   285     {
       
   286     return iTopicCollection.NextTopic( aInfo );
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // RCbs::GetTopicCount
       
   291 // Returns the total amount of topics the topic list contains. 
       
   292 // (other items were commented in a header).
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 EXPORT_C void RCbs::GetTopicCount( 
       
   296     TInt& aCount )
       
   297     {
       
   298     iTopicList.GetTopicCount( aCount );
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // RCbs::GetTopic
       
   303 // Returns information about a topic from the topic list.
       
   304 // (other items were commented in a header).
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 EXPORT_C TInt RCbs::GetTopic( 
       
   308     const TInt aIndex, 
       
   309     TCbsTopic& aTopic )
       
   310     {
       
   311     return iTopicList.GetTopic( aIndex, aTopic ); 
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // RCbs::FindTopicByNumber
       
   316 // Finds the topic by the given number.
       
   317 // (other items were commented in a header).
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 EXPORT_C TInt RCbs::FindTopicByNumber( 
       
   321     TCbsTopicNumber aNumber, 
       
   322     TCbsTopic& aTopic )
       
   323     {
       
   324     return iTopicList.FindTopicByNumber( aNumber, aTopic );
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // RCbs::DeleteTopic
       
   329 // Deletes an existing topic.
       
   330 // (other items were commented in a header).
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 EXPORT_C TInt RCbs::DeleteTopic( 
       
   334     TCbsTopicNumber aNumber )
       
   335     {
       
   336     return iTopicList.DeleteTopic( aNumber );
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // RCbs::DeleteAllTopics
       
   341 // Delete all topics.
       
   342 // (other items were commented in a header).
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 EXPORT_C TInt RCbs::DeleteAllTopics()
       
   346     {
       
   347     return iTopicList.DeleteAllTopics();
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // RCbs::AddTopic
       
   352 // Adds a new topic.
       
   353 // (other items were commented in a header).
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 EXPORT_C TInt RCbs::AddTopic( 
       
   357     TCbsTopic& aTopic )
       
   358     {
       
   359     return iTopicList.AddTopic( aTopic );
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // RCbs::ChangeTopicNameAndNumber
       
   364 // Changes the name and number of the existing topic.
       
   365 // (other items were commented in a header).
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 EXPORT_C TInt RCbs::ChangeTopicNameAndNumber( 
       
   369     TCbsTopicNumber aOldNumber,
       
   370     TCbsTopicNumber aNewNumber, 
       
   371     const TCbsTopicName& aName )
       
   372     {
       
   373     return iTopicList.ChangeTopicNameAndNumber( 
       
   374         aOldNumber, aNewNumber, aName );
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // RCbs::ChangeTopicSubscriptionStatus
       
   379 // Changes topic subscription status.
       
   380 // (other items were commented in a header).
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 EXPORT_C TInt RCbs::ChangeTopicSubscriptionStatus( 
       
   384     TCbsTopicNumber aNumber,
       
   385     TBool aNewStatus )
       
   386     {
       
   387     return iTopicList.ChangeTopicSubscriptionStatus( aNumber, aNewStatus );
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // RCbs::ChangeTopicHotmarkStatus
       
   392 // Changes topic hotmark status.
       
   393 // (other items were commented in a header).
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 EXPORT_C TInt RCbs::ChangeTopicHotmarkStatus( 
       
   397     TCbsTopicNumber aNumber,
       
   398     TBool aNewStatus )
       
   399     {
       
   400     return iTopicList.ChangeTopicHotmarkStatus( aNumber, aNewStatus );
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // RCbs::NotifyOnTopicListEvent
       
   405 // Requests the server to notify the client whenever an event occurs 
       
   406 // that changes the information of the topics.
       
   407 // (other items were commented in a header).
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 EXPORT_C void RCbs::NotifyOnTopicListEvent( 
       
   411     TRequestStatus& aStatus, 
       
   412     const TInt aRequested, 
       
   413     TCbsTopicListEvent& aEvent, 
       
   414     TCbsTopicNumber& aNumber )
       
   415     {
       
   416     iTopicList.NotifyOnEvent( aStatus, aRequested, aEvent, aNumber );
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // RCbs::NotifyOnTopicListEventCancel
       
   421 // Cancels the pending notify request.
       
   422 // (other items were commented in a header).
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 EXPORT_C void RCbs::NotifyOnTopicListEventCancel()
       
   426     {
       
   427     iTopicList.NotifyOnEventCancel();
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // RCbs::GetNewTopicsCount
       
   432 // Returns the number of topics added since last GetNewTopicsCount()
       
   433 // by the topic detection feature.
       
   434 // (other items were commented in a header).
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C TInt RCbs::GetNewTopicsCount( 
       
   438     TInt& aCount )
       
   439     {
       
   440     return iTopicList.GetNewTopicsCount( aCount );
       
   441     }
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 // RCbs::GetLatestTopicNumber
       
   445 // Returns the number of the topic which was last added 
       
   446 // to topic list.
       
   447 // (other items were commented in a header).
       
   448 // -----------------------------------------------------------------------------
       
   449 //
       
   450 EXPORT_C TInt RCbs::GetLatestTopicNumber( 
       
   451     TCbsTopicNumber& aNumber )
       
   452     {
       
   453     return iTopicList.GetLatestTopicNumber( aNumber );
       
   454     }
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // RCbs::GetUnreadMessageCount
       
   458 // Returns the total amount of unread messages.
       
   459 // (other items were commented in a header).
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 EXPORT_C void RCbs::GetUnreadMessageCount( 
       
   463     TInt& aCount )
       
   464     {
       
   465     iTopicList.GetUnreadMessageCount( aCount );
       
   466     }
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // RCbs::GetHotmarkedMessageHandle
       
   470 // Returns the handle to the latest hotmarked message that has been
       
   471 // received after the system has started up.
       
   472 // (other items were commented in a header).
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 EXPORT_C void RCbs::GetHotmarkedMessageHandle( 
       
   476     TCbsMessageHandle& aMessage )
       
   477     {
       
   478     iTopicList.GetHotmarkedMessageHandle( aMessage );
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // RCbs::GetHotmarkedMessageHandle
       
   483 // Returns the number of unread messages in hotmarked topics.
       
   484 // (other items were commented in a header).
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 EXPORT_C TInt RCbs::NumberOfUnreadHotmarkedMessages() 
       
   488     {
       
   489     return iTopicList.NumberOfUnreadHotmarkedMessages();
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // RCbs::GetNextAndPrevTopicNumber
       
   494 // Returns the numbers of topics that precede and succeed the given 
       
   495 // topic in server-side topic list.
       
   496 // (other items were commented in a header).
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 EXPORT_C TInt RCbs::GetNextAndPrevTopicNumber( 
       
   500         const TCbsTopicNumber& aCurrentTopicNumber,
       
   501         TCbsTopicNumber& aPrevTopicNumber,
       
   502         TCbsTopicNumber& aNextTopicNumber,
       
   503         TInt& aPosition )
       
   504     {
       
   505     return iTopicList.GetNextAndPrevTopicNumber(
       
   506         aCurrentTopicNumber,
       
   507         aPrevTopicNumber,
       
   508         aNextTopicNumber,
       
   509         aPosition);
       
   510     }
       
   511 
       
   512 
       
   513 // Topic Messages-related methods
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // RCbs::GetMessageCount
       
   517 // Returns the total amount of messages the topic contains. 
       
   518 // (other items were commented in a header).
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 EXPORT_C TInt RCbs::GetMessageCount( 
       
   522     TCbsTopicNumber aNumber,
       
   523     TInt& aCount )
       
   524     {
       
   525     return iTopicMessages.GetMessageCount( aNumber, aCount );
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // RCbs::GetMessage
       
   530 // Returns message information. 
       
   531 // (other items were commented in a header).
       
   532 // -----------------------------------------------------------------------------
       
   533 // 
       
   534 EXPORT_C TInt RCbs::GetMessage( 
       
   535     TCbsTopicNumber aNumber, 
       
   536     TInt aIndex, 
       
   537     TCbsMessage& aMessage )
       
   538     {
       
   539     return iTopicMessages.GetMessage( aNumber, aIndex, aMessage );
       
   540     }
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // RCbs::FindMessageByHandle
       
   544 // Finds a message by given handle.
       
   545 // (other items were commented in a header).
       
   546 // -----------------------------------------------------------------------------
       
   547 // 
       
   548 EXPORT_C TInt RCbs::FindMessageByHandle( 
       
   549     const TCbsMessageHandle& aHandle, 
       
   550     TCbsMessage& aMessage )
       
   551     {
       
   552     return iTopicMessages.FindMessageByHandle( aHandle, aMessage );
       
   553     }
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // RCbs::GetMessageIndexByHandle
       
   557 // Returns the index of a message with given handle in topic.
       
   558 // (other items were commented in a header).
       
   559 // -----------------------------------------------------------------------------
       
   560 //    
       
   561 EXPORT_C TInt RCbs::GetMessageIndexByHandle( 
       
   562     const TCbsMessageHandle& aHandle, 
       
   563     TInt& aIndex )
       
   564     {
       
   565     return iTopicMessages.GetMessageIndexByHandle( aHandle, aIndex );
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // RCbs::DeleteMessage
       
   570 // Deletes an existing message.
       
   571 // (other items were commented in a header).
       
   572 // -----------------------------------------------------------------------------
       
   573 // 
       
   574 EXPORT_C TInt RCbs::DeleteMessage( 
       
   575     const TCbsMessageHandle& aHandle )
       
   576     {
       
   577     return iTopicMessages.DeleteMessage( aHandle );
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // RCbs::SaveMessage
       
   582 // Saves a message (the saved message won't be deleted to make 
       
   583 // room for new messages).
       
   584 // (other items were commented in a header).
       
   585 // -----------------------------------------------------------------------------
       
   586 // 
       
   587 EXPORT_C TInt RCbs::SaveMessage( 
       
   588     const TCbsMessageHandle& aHandle )
       
   589     {
       
   590     return iTopicMessages.SaveMessage( aHandle );
       
   591     }
       
   592 
       
   593 // -----------------------------------------------------------------------------
       
   594 // RCbs::LockMessage
       
   595 // Locks the message.
       
   596 // (other items were commented in a header).
       
   597 // -----------------------------------------------------------------------------
       
   598 // 
       
   599 EXPORT_C TInt RCbs::LockMessage( 
       
   600     const TCbsMessageHandle& aHandle )
       
   601     {
       
   602     return iTopicMessages.LockMessage( aHandle );   
       
   603     }
       
   604 
       
   605 // -----------------------------------------------------------------------------
       
   606 // RCbs::ReadMessage
       
   607 // Sets the message as read.
       
   608 // (other items were commented in a header).
       
   609 // -----------------------------------------------------------------------------
       
   610 // 
       
   611 EXPORT_C TInt RCbs::ReadMessage( 
       
   612     const TCbsMessageHandle& aHandle )
       
   613     {
       
   614     return iTopicMessages.ReadMessage( aHandle );
       
   615     }
       
   616 
       
   617 // -----------------------------------------------------------------------------
       
   618 // RCbs::GetMessageContents
       
   619 // Returns the message contents.
       
   620 // (other items were commented in a header).
       
   621 // -----------------------------------------------------------------------------
       
   622 // 
       
   623 EXPORT_C TInt RCbs::GetMessageContents( 
       
   624     const TCbsMessageHandle& aHandle, 
       
   625     TDes& aBuffer )
       
   626     {
       
   627     return iTopicMessages.GetMessageContents( aHandle, aBuffer );
       
   628     }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // RCbs::GetNextAndPrevMessageHandle
       
   632 // Returns the handles of messages that precede and succeed the 
       
   633 // given message in server-side list of topic messages.
       
   634 // (other items were commented in a header).
       
   635 // -----------------------------------------------------------------------------
       
   636 // 
       
   637 EXPORT_C TInt RCbs::GetNextAndPrevMessageHandle(
       
   638         const TCbsMessageHandle& aCurrentMsgHandle,
       
   639         TCbsMessageHandle& aPrevMsgHandle,
       
   640         TCbsMessageHandle& aNextMsgHandle,
       
   641         TInt& aPosition )
       
   642     {
       
   643     return iTopicMessages.GetNextAndPrevMessageHandle(
       
   644         aCurrentMsgHandle,
       
   645         aPrevMsgHandle,
       
   646         aNextMsgHandle,
       
   647         aPosition );
       
   648     }
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // RCbs::Connected
       
   652 // Returns ETrue if CbsServer session has been established.
       
   653 // (other items were commented in a header).
       
   654 // -----------------------------------------------------------------------------
       
   655 // 
       
   656 EXPORT_C TBool RCbs::Connected() const 
       
   657     {
       
   658     return iConnected;
       
   659     }
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // RCbs::Shutdown
       
   663 // Forces the server to shut down.
       
   664 // (other items were commented in a header).
       
   665 // -----------------------------------------------------------------------------
       
   666 // 
       
   667 EXPORT_C void RCbs::Shutdown() const
       
   668     {
       
   669     const TIpcArgs args( TIpcArgs::ENothing );
       
   670     SendReceive( ECbsShutdown, args );
       
   671     }
       
   672 
       
   673 // -----------------------------------------------------------------------------
       
   674 // RCbs::StartServer
       
   675 // Starts the server.
       
   676 // (other items were commented in a header).
       
   677 // -----------------------------------------------------------------------------
       
   678 // 
       
   679 TInt RCbs::StartServer()
       
   680     {	
       
   681     TInt errorCode( KErrNone );
       
   682     RMutex serverStartMutex;
       
   683 
       
   684     if ( !IsServerStarted() )
       
   685         {
       
   686         TInt mutexExists( serverStartMutex.CreateGlobal( _L("CBSSERVERMTX") ) );
       
   687         if ( mutexExists )
       
   688             {
       
   689             TInt openErr( serverStartMutex.OpenGlobal( _L("CBSSERVERMTX") ) );
       
   690             if ( openErr )
       
   691                 {
       
   692                 return openErr;
       
   693                 }
       
   694             }
       
   695         // Mutex exists, wait until server is finished with it's tasks
       
   696         if ( mutexExists == KErrAlreadyExists )
       
   697             {
       
   698             serverStartMutex.Wait();
       
   699             }
       
   700 
       
   701         // Create and start a new process.
       
   702 	    TBuf<1> arguments;
       
   703 	    RProcess p;
       
   704 
       
   705 	    #ifdef __WINS__
       
   706         errorCode = p.Create( KCbsServerExe, arguments );        
       
   707         #else
       
   708         // Use the correct path depending on whether using data caging or not
       
   709 	    // Use path \sys\bin
       
   710 	    TBuf<64> fullPath;
       
   711 	    fullPath = KDC_PROGRAMS_DIR;
       
   712         fullPath.Append( KCbsServerExe );	    	  
       
   713 	    errorCode = p.Create( fullPath, arguments );	    
       
   714         #endif
       
   715 
       
   716         if ( errorCode == KErrNone )
       
   717             {
       
   718 	        p.Resume();
       
   719 	        p.Close();
       
   720 
       
   721             TInt i( 0 );
       
   722             for ( i = 0; i < KWaitForServerRetries; i++ )
       
   723                 {
       
   724                 if ( IsServerStarted() )
       
   725                     {
       
   726                     break; 
       
   727                     }
       
   728 
       
   729                 User::After( KWaitForServerTime );
       
   730                 }            
       
   731             }
       
   732         // Finished with startup sequence, release the mutex
       
   733         if ( mutexExists == KErrAlreadyExists )
       
   734             {
       
   735             serverStartMutex.Signal();
       
   736             }
       
   737         serverStartMutex.Close();
       
   738         }    
       
   739     return errorCode;
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // RCbs::IsServerStarted
       
   744 // Checks if the server is already started.
       
   745 // (other items were commented in a header).
       
   746 // -----------------------------------------------------------------------------
       
   747 // 
       
   748 TBool RCbs::IsServerStarted()
       
   749     {
       
   750 	TFindServer findServer( KCbsServerName );
       
   751 	TFullName name;
       
   752 	return ( findServer.Next( name ) == KErrNone );
       
   753     }
       
   754 
       
   755 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   756 
       
   757 //  End of File