cbs/CbsServer/McnClientSrc/Rmcnsubsession.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:  Implementation of the class RMcnSubSession.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CbsServerConstants.h"
       
    21 #include <cbsmcnpanic.h>
       
    22 #include <rcbsmcnsession.h>
       
    23 #include <rmcnsubsession.h>
       
    24 #include <ccbsmcnlistener.h>
       
    25 #include <cmcntopicarray.h>
       
    26 #include "CbsLogger.h"
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // RMcnSubSession::RMcnSubSession
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 RMcnSubSession::RMcnSubSession()
       
    37     : iConnected( EFalse )
       
    38     {    //lint !e1928    
       
    39     }
       
    40 
       
    41 // Destructor
       
    42 RMcnSubSession::~RMcnSubSession()
       
    43     {
       
    44     Close();
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // RMcnSubSession::Open
       
    49 // Creates a MCN subsession to CbsServer.
       
    50 // (other items were commented in a header).
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 TInt RMcnSubSession::Open( 
       
    54     RCbsMcnSession& aMcnSession )
       
    55     {
       
    56     CBSLOGSTRING("CBSMCNCLIENT: >>> RMcnSubSession::Open()");
       
    57 
       
    58     if ( !iConnected )
       
    59         {
       
    60         const TIpcArgs args( TIpcArgs::ENothing );
       
    61         TInt result( CreateSubSession( aMcnSession, EMcnCreateSubsession, args ) );
       
    62 
       
    63         if ( result == KErrNone )
       
    64             {            
       
    65             CBSLOGSTRING2("CBSMCNCLIENT: RMcnSubSession::Open(): Subsession created, result: %d", result );
       
    66             iConnected = ETrue;
       
    67             } 
       
    68         else
       
    69             {
       
    70             iConnected = EFalse;
       
    71             }
       
    72         CBSLOGSTRING2("CBSMCNCLIENT: RMcnSubSession::Open(), returning %d.", result );        
       
    73         return result;
       
    74         }
       
    75     CBSLOGSTRING("CBSMCNCLIENT: <<< RMcnSubSession::Open(), returning KErrGeneral.");    
       
    76     return KErrGeneral;       
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // RMcnSubSession::Close
       
    81 // Closes the subsession.
       
    82 // (other items were commented in a header).
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 TInt RMcnSubSession::Close()
       
    86     {
       
    87     CBSLOGSTRING("CBSMCNCLIENT: >>> RMcnSubSession::Close()");
       
    88 
       
    89     if ( iConnected ) 
       
    90         {
       
    91         RSubSessionBase::CloseSubSession( EMcnCloseSubsession );
       
    92         iConnected = EFalse;
       
    93         }
       
    94     CBSLOGSTRING("CBSMCNCLIENT: <<< RMcnSubSession::Close()");
       
    95     return KErrNone;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // RMcnSubSession::ReadMcnMessage
       
   100 // Request next subscribed MCN message to be delivered to this session.
       
   101 // (other items were commented in a header).
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void RMcnSubSession::ReadMcnMessage( 
       
   105     TRequestStatus& aStatus, 
       
   106     TPckg<TCbsMcnMessage>& aMcnPckg )
       
   107     {
       
   108     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );    
       
   109     const TIpcArgs args( &aMcnPckg );
       
   110 
       
   111     SendReceive( EMcnNotifyOnChange, args, aStatus );  // asynchronous
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // RMcnSubSession::ReadMcnMessageCancel
       
   116 // Cancels an outstanding request.
       
   117 // (other items were commented in a header).
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TInt RMcnSubSession::ReadMcnMessageCancel() 
       
   121     {
       
   122     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
   123     const TIpcArgs args( TIpcArgs::ENothing );
       
   124     return SendReceive( EMcnNotifyOnChangeCancel, args );
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // RMcnSubSession::RegisterL
       
   129 // Subscribes topics given in aArray.
       
   130 // (other items were commented in a header).
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void RMcnSubSession::RegisterL( 
       
   134     const CMcnTopicArray& aArray )
       
   135     {
       
   136     CBSLOGSTRING("CBSMCNCLIENT: >>> RMcnSubSession::RegisterL()");
       
   137 
       
   138     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
   139     // Store topic numbers into a descriptor.
       
   140     TUint entries( 0 );
       
   141     aArray.EnumerateEntries( entries );
       
   142     TUint number( 0 );
       
   143 
       
   144     // Request registration, pass topic numbers one at time to server-side.
       
   145     
       
   146     for( TUint i = 0; i < entries; i++ )
       
   147         {
       
   148         aArray.GetTopicNumber( i, number );
       
   149         const TIpcArgs args( number );        
       
   150 
       
   151         CBSLOGSTRING2("CBSMCNCLIENT: RMcnSubSession::RegisterL(): Passing topic number to server: %d", number );
       
   152         User::LeaveIfError( SendReceive( EMcnSubscribeTopic, args ) );        
       
   153         CBSLOGSTRING("CBSMCNCLIENT: RMcnSubSession::RegisterL(): Topic number passed to server OK." );
       
   154         }
       
   155 
       
   156     // Tell the server this was enough.
       
   157     const TIpcArgs args2( TIpcArgs::ENothing );
       
   158     User::LeaveIfError( SendReceive( EMcnNoMoreSubscriptions, args2 ) );
       
   159 
       
   160     CBSLOGSTRING("CBSMCNCLIENT: <<< RMcnSubSession::RegisterL()");
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // RMcnSubSession::ClearSubscriptionsL
       
   165 // Clears topic subscriptions of this session in CbsServer
       
   166 // (other items were commented in a header).
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void RMcnSubSession::ClearSubscriptionsL()
       
   170     {
       
   171     CBSLOGSTRING("CBSMCNCLIENT: >>> RMcnSubSession::ClearSubscriptionsL()");
       
   172 
       
   173     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
   174     const TIpcArgs args( TIpcArgs::ENothing );
       
   175     User::LeaveIfError( SendReceive( EMcnClearSubscriptions, args ) );
       
   176 
       
   177     CBSLOGSTRING("CBSMCNCLIENT: <<< RMcnSubSession::ClearSubscriptionsL(), cleared OK.");    
       
   178     }
       
   179 
       
   180 //  End of File