cbs/CbsServer/ClientSrc/RCbsTopicList.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 RCbsTopicList class 
       
    15                  member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "CbsServerConstants.h"
       
    24 #include "RCbs.h"
       
    25 #include "RCbsTopicList.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // RCbsTopicList::RCbsTopicList
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 RCbsTopicList::RCbsTopicList()
       
    36     : iNotifyEventPtr( NULL, 0, 0 ), 
       
    37     iNotifyHandlePtr( NULL, 0, 0 )
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // RCbsTopicList::Open
       
    43 // Creates a subsession to the server.
       
    44 // (other items were commented in a header).
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 TInt RCbsTopicList::Open( 
       
    48     RCbs& aServer )
       
    49     {
       
    50     const TIpcArgs args( TIpcArgs::ENothing );
       
    51     return CreateSubSession( aServer, ECbsCreateTopicListSubsession, args );
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // RCbsTopicList::Close
       
    56 // Closes the subsession and connection to the server.
       
    57 // (other items were commented in a header).
       
    58 // -----------------------------------------------------------------------------
       
    59 //  
       
    60 TInt RCbsTopicList::Close()
       
    61     {
       
    62     // Close the subsession.
       
    63     RSubSessionBase::CloseSubSession( ECbsCloseTopicListSubsession );
       
    64     return KErrNone;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // RCbsTopicList::GetTopicCount
       
    69 // Returns the total amount of topics the topic list contains.
       
    70 // (other items were commented in a header).
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void RCbsTopicList::GetTopicCount( 
       
    74     TInt& aCount )
       
    75     {
       
    76     // Send request to the server. Get the total amount of topics.
       
    77     aCount = 0;
       
    78     TPckgBuf< TInt > pckg( aCount );
       
    79     const TIpcArgs args( &pckg );
       
    80 
       
    81     TInt result = SendReceive( ECbsGetTopicCount, args );
       
    82     // In case everything went just fine update the parameter!
       
    83     if ( result == KErrNone )
       
    84         {
       
    85         aCount = pckg();
       
    86         }
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // RCbsTopicList::GetTopic
       
    91 // Returns information about a topic from the topic list.
       
    92 // (other items were commented in a header).
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 TInt RCbsTopicList::GetTopic( 
       
    96     const TInt aIndex, 
       
    97     TCbsTopic& aTopic )
       
    98     {
       
    99     TPckgBuf< TCbsTopic > pckgTopic;
       
   100     const TIpcArgs args( aIndex, &pckgTopic );
       
   101 
       
   102     TInt result = SendReceive( ECbsGetTopic, args );
       
   103 
       
   104     // Update if everything went just fine
       
   105     if ( result == KErrNone )
       
   106         {
       
   107         aTopic = pckgTopic();
       
   108         }
       
   109 
       
   110     return result;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // RCbsTopicList::FindTopicByNumber
       
   115 // Finds the topic by given number.
       
   116 // (other items were commented in a header).
       
   117 // -----------------------------------------------------------------------------
       
   118 //  
       
   119 TInt RCbsTopicList::FindTopicByNumber( 
       
   120     TCbsTopicNumber aNumber, 
       
   121     TCbsTopic& aTopic )
       
   122     {
       
   123     TPckgBuf< TCbsTopic > pckgTopic;
       
   124     const TIpcArgs args( aNumber, &pckgTopic );
       
   125 
       
   126     TInt result = SendReceive( ECbsFindTopicByNumber, args );
       
   127 
       
   128     // Update aTopic if everything went just fine.
       
   129     if ( result == KErrNone )
       
   130         {
       
   131         aTopic = pckgTopic();
       
   132         }
       
   133 
       
   134     return result;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // RCbsTopicList::DeleteTopic
       
   139 // Deletes an existing topic.
       
   140 // (other items were commented in a header).
       
   141 // -----------------------------------------------------------------------------
       
   142 //  
       
   143 TInt RCbsTopicList::DeleteTopic( 
       
   144     TCbsTopicNumber aNumber )
       
   145     {
       
   146     // Send request to the server to delete a topic by handle    
       
   147     const TIpcArgs args( aNumber );
       
   148     return SendReceive( ECbsDeleteTopic, args );
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // RCbsTopicList::DeleteAllTopics
       
   153 // Delete all topics.
       
   154 // (other items were commented in a header).
       
   155 // -----------------------------------------------------------------------------
       
   156 //  
       
   157 TInt RCbsTopicList::DeleteAllTopics()
       
   158     {
       
   159     const TIpcArgs args( TIpcArgs::ENothing );
       
   160     return SendReceive( ECbsDeleteAll, args );
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // RCbsTopicList::AddTopic
       
   165 // Adds a new topic.
       
   166 // (other items were commented in a header).
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 TInt RCbsTopicList::AddTopic( 
       
   170     TCbsTopic& aTopic )
       
   171     {
       
   172     // Send request to add a topic to the list.
       
   173     TPckgBuf< TCbsTopic > pckgTopic( aTopic );
       
   174     const TIpcArgs args( &pckgTopic );
       
   175 
       
   176     TInt result = SendReceive( ECbsAddTopic, args );
       
   177 
       
   178     if ( result == KErrNone )
       
   179         {
       
   180         // Update the topic information (only handle).
       
   181         aTopic = pckgTopic();    
       
   182         }
       
   183 
       
   184     return result;
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // RCbsTopicList::ChangeTopicNameAndNumber
       
   189 // Changes the name and number of the existing topic.
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 TInt RCbsTopicList::ChangeTopicNameAndNumber( 
       
   194     TCbsTopicNumber aOldNumber, 
       
   195     TCbsTopicNumber aNewNumber, 
       
   196     const TCbsTopicName& aName )
       
   197     {
       
   198     // Send request to the server
       
   199     const TIpcArgs args( aOldNumber, aNewNumber, &aName );
       
   200     return SendReceive( ECbsChangeTopicNameAndNumber, args );
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // RCbsTopicList::ChangeTopicSubscriptionStatus
       
   205 // Changes topic subscription status.
       
   206 // (other items were commented in a header).
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt RCbsTopicList::ChangeTopicSubscriptionStatus( 
       
   210      TCbsTopicNumber aNumber, 
       
   211      TBool aNewStatus )
       
   212     {
       
   213     // Send request to the server
       
   214     TPckgBuf< TBool > pckgStatus( aNewStatus );
       
   215     const TIpcArgs args( aNumber, &pckgStatus );
       
   216     return SendReceive( ECbsChangeTopicSubscriptionStatus, args );
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // RCbsTopicList::ChangeTopicHotmarkStatus
       
   221 // Changes topic hotmark status.
       
   222 // (other items were commented in a header).
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 TInt RCbsTopicList::ChangeTopicHotmarkStatus( 
       
   226      TCbsTopicNumber aNumber, 
       
   227      TBool aNewStatus )
       
   228     {
       
   229     // Send request to the server
       
   230     TPckgBuf< TBool > pckgStatus( aNewStatus );
       
   231     const TIpcArgs args( aNumber, &pckgStatus );
       
   232     return SendReceive( ECbsChangeTopicHotmarkStatus, args );
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // RCbsTopicList::NotifyOnEvent
       
   237 // Requests the server to notify the client whenever an event occurs that 
       
   238 // changes the information of the topics.
       
   239 // (other items were commented in a header).
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 void RCbsTopicList::NotifyOnEvent( 
       
   243     TRequestStatus& aStatus, 
       
   244     const TInt aRequested, 
       
   245     TCbsTopicListEvent& aEvent, 
       
   246     TCbsTopicNumber& aHandle )
       
   247     {
       
   248     // Send request for the notify
       
   249     iNotifyEventPtr.Set( reinterpret_cast< TText8* >( &aEvent ), 
       
   250                          sizeof( TCbsTopicListEvent ),
       
   251                          sizeof( TCbsTopicListEvent ) );
       
   252     iNotifyHandlePtr.Set( reinterpret_cast< TText8* >( &aHandle ), 
       
   253                          sizeof( TCbsTopicNumber ),
       
   254                          sizeof( TCbsTopicNumber ) );
       
   255 
       
   256     const TIpcArgs args( aRequested, &iNotifyEventPtr, &iNotifyHandlePtr );
       
   257     SendReceive( ECbsNotifyOnEvent, args, aStatus );
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // RCbsTopicList::NotifyOnEventCancel
       
   262 // Cancels the pending notify request.
       
   263 // (other items were commented in a header).
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void RCbsTopicList::NotifyOnEventCancel()
       
   267     {
       
   268     const TIpcArgs args( TIpcArgs::ENothing );
       
   269     SendReceive( ECbsNotifyOnEventCancel, args );
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // RCbsTopicList::GetNewTopicsCount
       
   274 // Returns the number of session-specific new topics and resets the counter.
       
   275 // (other items were commented in a header).
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 TInt RCbsTopicList::GetNewTopicsCount( 
       
   279     TInt& aCount )
       
   280     {
       
   281     // Send request to the server to get the total amount of new topics
       
   282     aCount = 0;
       
   283     TPckgBuf<TInt> pckg( aCount );
       
   284     const TIpcArgs args( &pckg );
       
   285 
       
   286     TInt result( SendReceive( ECbsGetNewTopicsCount, args ) );
       
   287 
       
   288     if ( result == KErrNone )
       
   289         {
       
   290         aCount = pckg();
       
   291         }
       
   292 
       
   293     return result;
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // RCbsTopicList::GetLatestTopicNumber
       
   298 // Returns the latest topic's number.
       
   299 // (other items were commented in a header).
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 TInt RCbsTopicList::GetLatestTopicNumber( 
       
   303     TCbsTopicNumber& aNumber )
       
   304     {
       
   305     aNumber = 0;
       
   306     TPckgBuf<TCbsTopicNumber> pckg( aNumber );
       
   307     const TIpcArgs args( &pckg );
       
   308 
       
   309     TInt result( SendReceive( ECbsGetLatestTopicNumber, args ) );
       
   310 
       
   311     if ( result == KErrNone )
       
   312         {
       
   313         aNumber = pckg();
       
   314         }
       
   315     return result;
       
   316     }
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // RCbsTopicList::GetUnreadMessageCount
       
   320 // Returns the total amount of unread messages.
       
   321 // (other items were commented in a header).
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void RCbsTopicList::GetUnreadMessageCount( 
       
   325     TInt& aCount )
       
   326     {
       
   327     // Send request to the server to get the total amount of unread messages
       
   328     TPckgBuf<TInt> pckg( aCount );
       
   329     const TIpcArgs args( &pckg );
       
   330 
       
   331     TInt result = SendReceive( ECbsGetUnreadMessageCount, args );
       
   332 
       
   333     // In case everything went just fine update the parameter
       
   334     if ( result == KErrNone )
       
   335         {
       
   336         aCount = pckg();
       
   337         }
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // RCbsTopicList::GetHotmarkedMessageHandle
       
   342 // Returns the handle to the latest hotmarked message that has been
       
   343 // received after the system has started up.
       
   344 // (other items were commented in a header).
       
   345 // -----------------------------------------------------------------------------
       
   346 // 
       
   347 void RCbsTopicList::GetHotmarkedMessageHandle( 
       
   348     TCbsMessageHandle& aMessage )
       
   349     {
       
   350     // Send request to the server to get the handle to the hotmarked message
       
   351     TPckgBuf<TCbsMessageHandle> pckgMessageHandle( aMessage );
       
   352     const TIpcArgs args( &pckgMessageHandle );
       
   353 
       
   354     TInt result = SendReceive( ECbsGetHotmarkedMessageHandle, args );
       
   355 
       
   356     if ( result == KErrNone )
       
   357         {
       
   358         aMessage = pckgMessageHandle();
       
   359         }
       
   360     else
       
   361         {
       
   362         aMessage = 0;
       
   363         }
       
   364     }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // RCbsTopicList::NumberOfUnreadHotmarkedMessages
       
   368 // Returns the number of unread messages in hotmarked topics.
       
   369 // (other items were commented in a header).
       
   370 // -----------------------------------------------------------------------------
       
   371 // 
       
   372 TInt RCbsTopicList::NumberOfUnreadHotmarkedMessages() 
       
   373     {
       
   374     TInt hotMsgCount( 0 );
       
   375     TPckgBuf<TInt> pckgHotMsgCount;    
       
   376     const TIpcArgs args( &pckgHotMsgCount );
       
   377 
       
   378     if ( SendReceive( ECbsGetUnreadHotmarkedMessageCount, args ) == KErrNone )
       
   379         {
       
   380         hotMsgCount = pckgHotMsgCount();
       
   381         }
       
   382 
       
   383     return hotMsgCount;
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // RCbsTopicList::GetNextAndPrevTopicNumber
       
   388 // Returns the numbers of topics that precede and succeed the given 
       
   389 // topic in server-side topic list.
       
   390 // (other items were commented in a header).
       
   391 // -----------------------------------------------------------------------------
       
   392 // 
       
   393 TInt RCbsTopicList::GetNextAndPrevTopicNumber( 
       
   394 	const TCbsTopicNumber& aCurrentTopicNumber,
       
   395 	TCbsTopicNumber& aPrevTopicNumber,
       
   396 	TCbsTopicNumber& aNextTopicNumber,
       
   397 	TInt& aPosition )
       
   398     {
       
   399     TPckgBuf<TCbsTopicNumber> pckgCurrentTopic( aCurrentTopicNumber );
       
   400     TPckgBuf<TCbsNextPrevTopicAndPosition> pckgResults;
       
   401 
       
   402     const TIpcArgs args( &pckgCurrentTopic, &pckgResults );
       
   403 
       
   404     TInt result( SendReceive( ECbsGetNextAndPrevTopicNumber, args ) );
       
   405     if ( result == KErrNone )
       
   406         {
       
   407         aPrevTopicNumber = pckgResults().iPrevTopic;
       
   408         aNextTopicNumber = pckgResults().iNextTopic;
       
   409         aPosition = pckgResults().iPosition;
       
   410         }
       
   411     return result;
       
   412     }
       
   413 
       
   414 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   415 
       
   416 //  End of File