cbs/CbsServer/McnClientSrc/Rcbsmcnsession.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     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 RCbsMcnSession.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "CbsServerConstants.h"
       
    22 #include "CbsMcnPanic.h"
       
    23 #include "CMcn.h"
       
    24 #include "RCbsMcnSession.h"
       
    25 #include "CCbsMcnListener.h"
       
    26 #include "CMcnTopicArray.h"
       
    27 #include "CbsLogger.h"
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // RCbsMcnSession::RCbsMcnSession
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 RCbsMcnSession::RCbsMcnSession()
       
    38     : iConnected( EFalse )
       
    39     { //lint !e1928 !e1926
       
    40     }                               
       
    41     
       
    42 // Destructor
       
    43 RCbsMcnSession::~RCbsMcnSession()
       
    44     {
       
    45     Close();
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // RCbsMcnSession::GetCellInfo
       
    50 // Retrieves the current MCN message from CBS server.
       
    51 // (other items were commented in a header).
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 TInt RCbsMcnSession::GetCellInfo( 
       
    55     TDes& aMcnMessage ) const
       
    56     {
       
    57     return GetInfoMessage( aMcnMessage, KCellInfoTopic );
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // RCbsMcnSession::GetInfoMessage
       
    62 // Retrieves the current HomeZone message from CBS server.
       
    63 // (other items were commented in a header).
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 TInt RCbsMcnSession::GetInfoMessage( 
       
    67     TDes& aMessage, 
       
    68     const TInt aTopicNumber ) const
       
    69     {
       
    70     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
    71 
       
    72     const TIpcArgs args( &aMessage, aTopicNumber );
       
    73     TInt result( SendReceive( EMcnGetInfoMessage, args ) );
       
    74     return result;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // RCbsMcnSession::ReadMcnMessage
       
    79 // Request next subscribed MCN message to be delivered to this session.
       
    80 // (other items were commented in a header).
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void RCbsMcnSession::ReadMcnMessage( 
       
    84     TRequestStatus& aStatus, 
       
    85     TPckg<TCbsMcnMessage>& aMcnPckg ) 
       
    86     {
       
    87     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
    88     iSubSession.ReadMcnMessage( aStatus, aMcnPckg );
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // RCbsMcnSession::ReadMcnMessageCancel
       
    93 // Cancels an outstanding request. Passed to the subsession object.
       
    94 // (other items were commented in a header).
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 TInt RCbsMcnSession::ReadMcnMessageCancel() 
       
    98     {
       
    99     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
   100     return iSubSession.ReadMcnMessageCancel();
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // RCbsMcnSession::RegisterL
       
   105 // Subscribes topics given in aArray.
       
   106 // (other items were commented in a header).
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void RCbsMcnSession::RegisterL( 
       
   110     const CMcnTopicArray& aArray )
       
   111     {
       
   112     CBSLOGSTRING("CBSMCNCLIENT: >>> RCbsMcnSession::RegisterL()");
       
   113 
       
   114     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
   115     iSubSession.RegisterL( aArray );
       
   116     
       
   117     CBSLOGSTRING("CBSMCNCLIENT: <<< RCbsMcnSession::RegisterL()");
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // RCbsMcnSession::ClearSubscriptionsL
       
   122 // Clears all topic subscriptions of this session in CbsServer.
       
   123 // (other items were commented in a header).
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void RCbsMcnSession::ClearSubscriptionsL()
       
   127     {
       
   128     CBSLOGSTRING("CBSMCNCLIENT: >>> RCbsMcnSession::ClearSubscriptionsL()");
       
   129 
       
   130     __ASSERT_DEBUG( iConnected, CbsMcnPanic( EMcnNotConnected ) );
       
   131     iSubSession.ClearSubscriptionsL();
       
   132 
       
   133     CBSLOGSTRING("CBSMCNCLIENT: <<< RCbsMcnSession::ClearSubscriptionsL()");
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // RCbsMcnSession::Connect
       
   138 // Establishes a connection with CbsServer.
       
   139 // (other items were commented in a header).
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 TInt RCbsMcnSession::Connect()
       
   143     {
       
   144     CBSLOGSTRING("CBSMCNCLIENT: >>> RCbsMcnSession::Connect()");
       
   145 
       
   146     // Create a session to the server.
       
   147     TInt result = CreateSession( KCbsServerName,
       
   148        Version(), KCbsServerDefaultSlots );
       
   149 
       
   150     CBSLOGSTRING2("CBSMCNCLIENT: RCbsMcnSession::Connect(): CreateSession() result: %d", result );    
       
   151 
       
   152     if ( result == KErrNone )
       
   153         {
       
   154         TInt error = iSubSession.Open( *this );
       
   155         if ( !error )
       
   156             {
       
   157             iConnected = ETrue;
       
   158             CBSLOGSTRING("CBSMCNCLIENT: RCbsMcnSession::Connect(): Subsession opened.");            
       
   159             }        
       
   160         CBSLOGSTRING2("CBSMCNCLIENT: RCbsMcnSession::Connect(): Subsession opening failed, error: %d", error );        
       
   161         } 
       
   162     else
       
   163         {
       
   164         iConnected = EFalse;
       
   165         CBSLOGSTRING2("CBSMCNCLIENT: RCbsMcnSession::Connect(): CreateSession failed, errorCode: %d", result );
       
   166         }
       
   167 
       
   168     CBSLOGSTRING2("CBSMCNCLIENT: <<< RCbsMcnSession::Connect(), iConnected: %d", iConnected );    
       
   169     return result;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // RCbsMcnSession::Close
       
   174 // Closes the connection with CbsServer.
       
   175 // (other items were commented in a header).
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void RCbsMcnSession::Close()
       
   179     {
       
   180     CBSLOGSTRING("CBSMCNCLIENT: >>> RCbsMcnSession::Close()");
       
   181 
       
   182     if ( iConnected ) 
       
   183         {
       
   184         iSubSession.Close();
       
   185 
       
   186         const TIpcArgs args( TIpcArgs::ENothing );
       
   187         SendReceive( EMcnCloseSession, args );
       
   188         RSessionBase::Close();
       
   189         iConnected = EFalse;
       
   190 
       
   191         CBSLOGSTRING("CBSMCNCLIENT: RCbsMcnSession::Close(): Connected -> subsession closed.");        
       
   192         }
       
   193     CBSLOGSTRING("CBSMCNCLIENT: <<< RCbsMcnSession::Close()");
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // RCbsMcnSession::Version
       
   198 // Returns version information of this dll.
       
   199 // (other items were commented in a header).
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TVersion RCbsMcnSession::Version() const
       
   203     {
       
   204     // Create version and return it.
       
   205     return TVersion( KCbsServerVersionMajor,
       
   206                      KCbsServerVersionMinor,
       
   207                      KCbsServerVersionBuild );
       
   208     }
       
   209     
       
   210 //  End of File