cbs/CbsServer/ClientSrc/RCbsTopicCollection.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 RCbsTopicCollection class 
       
    15                  member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "CbsServerConstants.h"
       
    23 #include "RCbs.h"
       
    24 #include "RCbsTopicCollection.h"
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // RCbsTopicCollection::RCbsTopicCollection
       
    30 // C++ default constructor can NOT contain any code, that
       
    31 // might leave.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 RCbsTopicCollection::RCbsTopicCollection() 
       
    35     : iIterator( 0 )
       
    36     {   
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // RCbsTopicCollection::Open
       
    41 // Creates a subsession to the server.
       
    42 // (other items were commented in a header).
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 TInt RCbsTopicCollection::Open( 
       
    46     RCbs& aServer  )
       
    47     {
       
    48     // Open the subsession.
       
    49     const TIpcArgs args( TIpcArgs::ENothing );
       
    50     return CreateSubSession( aServer, ECbsCreateTopicCollectionSubsession, args );
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // RCbsTopicCollection::Close
       
    55 // Closes a subsession to the server.
       
    56 // (other items were commented in a header).
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 TInt RCbsTopicCollection::Close()
       
    60     {
       
    61     // Close the subsession
       
    62     RSubSessionBase::CloseSubSession( ECbsCloseTopicCollectionSubsession );
       
    63     return KErrNone;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // RCbsTopicCollection::GetTopicCount
       
    68 // Returns the total amount of topic information the topic collection
       
    69 // contains.
       
    70 // (other items were commented in a header).
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void RCbsTopicCollection::GetTopicCount( 
       
    74     TInt& aCount )
       
    75     {
       
    76     // Get the topic count from the server
       
    77     TPckgBuf< TInt > pckgCount;
       
    78     const TIpcArgs args( &pckgCount );
       
    79     SendReceive( ECbsGetTopicInfoCount, args );
       
    80     aCount = pckgCount();
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // RCbsTopicCollection::GetTopicInfo
       
    85 // Returns a topic information structure.
       
    86 // (other items were commented in a header).
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TInt RCbsTopicCollection::GetTopicInfo( 
       
    90     TInt aIndex, 
       
    91     TCbsTopicInfo& aInfo )
       
    92     {
       
    93     // Get topic information from the server
       
    94     TPckgBuf< TCbsTopicInfo > pckgInfo( aInfo );
       
    95     const TIpcArgs args( aIndex, &pckgInfo );
       
    96     TInt result( SendReceive( ECbsGetTopicInfo, args ) );
       
    97 
       
    98     if ( result == KErrNone )
       
    99         {
       
   100         aInfo = pckgInfo();
       
   101         }
       
   102     return result;    
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // RCbsTopicCollection::NotifyOnChange
       
   107 // Notifies the client next time when topic collection changes.
       
   108 // (other items were commented in a header).
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void RCbsTopicCollection::NotifyOnChange( 
       
   112     TRequestStatus& aStatus )
       
   113     {
       
   114     // Send notification on change
       
   115     const TIpcArgs args( TIpcArgs::ENothing );
       
   116     SendReceive( ECbsNotifyOnChange, args, aStatus );
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // RCbsTopicCollection::NotifyOnChangeCancel
       
   121 // Cancels the pending request to notify.
       
   122 // (other items were commented in a header).
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void RCbsTopicCollection::NotifyOnChangeCancel()
       
   126     {
       
   127     // Cancel pending notification request.
       
   128     const TIpcArgs args( TIpcArgs::ENothing );
       
   129     SendReceive( ECbsNotifyOnChangeCancel, args );
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // RCbsTopicCollection::Start
       
   134 // Interface for topic collection browsing. Resets the iterator.
       
   135 // (other items were commented in a header).
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void RCbsTopicCollection::Start()
       
   139     {
       
   140     iIterator = 0;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // RCbsTopicCollection::HasNextTopic
       
   145 // Returns ETrue, if the topic collection has topic identities 
       
   146 // unaccessed with NextTopic().
       
   147 // (other items were commented in a header).
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 TBool RCbsTopicCollection::HasNextTopic()
       
   151     {
       
   152     TInt count( 0 );
       
   153     TInt result( KErrNone );
       
   154     TBool inList( EFalse );
       
   155 
       
   156     GetTopicCount( count );
       
   157     for ( ; iIterator < count; iIterator++ )
       
   158         {
       
   159         // Check if the current topic is in the topic list.
       
   160         result = TopicInList( iIterator, inList );
       
   161         if ( result != KErrNone )
       
   162             {
       
   163             return EFalse;
       
   164             }
       
   165         else if ( !inList )  
       
   166             {
       
   167             return ETrue;   // this topic is not in the list; 
       
   168             }
       
   169         }
       
   170 
       
   171     return EFalse;
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // RCbsTopicCollection::NextTopic
       
   176 // Returns the next topic identity if one exists.
       
   177 // (other items were commented in a header).
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TInt RCbsTopicCollection::NextTopic( 
       
   181     TCbsTopicInfo& aInfo )
       
   182     {
       
   183     // iIterator points to the next unlisted topic: return the topic 
       
   184     // and error code.
       
   185     TInt result( KErrNone );
       
   186     result = GetTopicInfo( iIterator, aInfo );
       
   187     if ( result == KErrNone )
       
   188         {
       
   189         iIterator++;    // advance to the next topic
       
   190         }
       
   191     return result;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // RCbsTopicCollection::TopicInList
       
   196 // Returns information whether the topic was in topic list.
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TInt RCbsTopicCollection::TopicInList( 
       
   201     TInt aIndex, 
       
   202     TBool& aInList )
       
   203     {
       
   204     // value returned by the server gets stored here
       
   205     TPckgBuf< TBool > pckgInList;
       
   206     const TIpcArgs args( aIndex, &pckgInList );
       
   207 
       
   208     TInt result = SendReceive( ECbsTopicInList, args );
       
   209     if ( result == KErrNone )
       
   210         {
       
   211         aInList = pckgInList();
       
   212         }
       
   213     
       
   214     return result;
       
   215     }
       
   216 
       
   217 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   218 
       
   219 //  End of File