wvuing/IMPSConnectionUI/ServiceSrc/CCnUiClientStatusHandler.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Concrete client login status handler.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32std.h>
       
    20 #include "CCnUiClientStatusHandler.h"
       
    21 
       
    22 /**
       
    23 * Channel value for no logged
       
    24 * in clients. Logged in clients are
       
    25 * logically orred channel value.
       
    26 * @since 2.1
       
    27 */
       
    28 const TInt KCnUiNoLoggedInClients = 0;
       
    29 
       
    30 
       
    31 
       
    32 // ================= GLOBAL FUNCTIONS =======================
       
    33 // -----------------------------------------------------------------------------
       
    34 // CreateClientStatusHandlerLC()
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 GLREF_C MCnUiClientStatusHandler* CreateClientStatusHandlerLC()
       
    38     {
       
    39     return CCnUiClientStatusHandler::NewLC();
       
    40     }
       
    41 
       
    42 
       
    43 
       
    44 // ================= MEMBER FUNCTIONS =======================
       
    45 // Two-phased constructor.
       
    46 CCnUiClientStatusHandler* CCnUiClientStatusHandler::NewLC()
       
    47     {
       
    48     CCnUiClientStatusHandler* self = new ( ELeave ) CCnUiClientStatusHandler;
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL();
       
    51     return self;
       
    52     }
       
    53 
       
    54 
       
    55 // Destructor
       
    56 CCnUiClientStatusHandler::~CCnUiClientStatusHandler()
       
    57     {
       
    58     delete iLoginStastusChannel;
       
    59     }
       
    60 
       
    61 // C++ default constructor can NOT contain any code, that
       
    62 // might leave.
       
    63 //
       
    64 CCnUiClientStatusHandler::CCnUiClientStatusHandler()
       
    65     {
       
    66     }
       
    67 
       
    68 
       
    69 // Symbian OS default constructor can leave.
       
    70 void CCnUiClientStatusHandler::ConstructL()
       
    71     {
       
    72     iLoginStastusChannel = CCnUiGroupChannel::NewL( ECnUiGlobalGroup,
       
    73                                                     ECnUiClientLoginLogoutStateChannel,
       
    74                                                     EFalse ); //permanent data
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CCnUiClientStatusHandler::AnyClientLoggedIn()
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TBool CCnUiClientStatusHandler::AnyClientLoggedIn()
       
    83     {
       
    84     TInt statusWord = KCnUiNoLoggedInClients;
       
    85     iLoginStastusChannel->Read( statusWord );
       
    86 
       
    87     //any client logged in
       
    88     if ( statusWord != 0 )
       
    89         {
       
    90         return ETrue;
       
    91         }
       
    92 
       
    93     return EFalse;
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CCnUiClientStatusHandler::ClientLoggedIn()
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 TBool CCnUiClientStatusHandler::ClientLoggedIn( TIMPSConnectionClient aClient )
       
   102     {
       
   103     TInt statusWord = KCnUiNoLoggedInClients;
       
   104     iLoginStastusChannel->Read( statusWord );
       
   105 
       
   106     //Is the asked client logged in
       
   107     if ( statusWord & ( TInt ) aClient )
       
   108         {
       
   109         return ETrue;
       
   110         }
       
   111 
       
   112     return EFalse;
       
   113     }
       
   114 
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CCnUiClientStatusHandler::SetNoClientsLoggedInL()
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CCnUiClientStatusHandler::SetNoClientsLoggedInL()
       
   121     {
       
   122     iLoginStastusChannel->WriteL( KCnUiNoLoggedInClients );
       
   123     }
       
   124 
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CCnUiClientStatusHandler::SetClientLoggedInL()
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CCnUiClientStatusHandler::SetClientLoggedInL( TIMPSConnectionClient aClient )
       
   131     {
       
   132     TInt existingClients = KCnUiNoLoggedInClients;
       
   133     iLoginStastusChannel->Read( existingClients );
       
   134 
       
   135     //this client is among the other ones
       
   136     TInt loggedInClients = existingClients | ( TInt ) aClient;
       
   137     iLoginStastusChannel->WriteL( loggedInClients );
       
   138     }
       
   139 
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CCnUiClientStatusHandler::SetClientLoggedOutL()
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CCnUiClientStatusHandler::SetClientLoggedOutL( TIMPSConnectionClient aClient )
       
   146     {
       
   147     TInt existingClients = KCnUiNoLoggedInClients;
       
   148     iLoginStastusChannel->Read( existingClients );
       
   149 
       
   150 
       
   151     TInt loggedInClients = existingClients & ~( TInt ) aClient;
       
   152     iLoginStastusChannel->WriteL( loggedInClients );
       
   153     }
       
   154 
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CCnUiClientStatusHandler::NotifyClientStatusChangesL()
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CCnUiClientStatusHandler::NotifyClientLoginStatusChangesL(
       
   162     MCnUiClientStatusObserver* aObserver,
       
   163     TIMPSConnectionClient aClientToNotify )
       
   164     {
       
   165     __ASSERT_ALWAYS( !iClntStatusObserver, User::Leave( KErrInUse ) );
       
   166     __ASSERT_ALWAYS( aObserver, User::Leave( KErrArgument ) );
       
   167 
       
   168     //start the notifier
       
   169     iLoginStastusChannel->ListenL( this );
       
   170 
       
   171     //store observer information
       
   172     iClntStatusObserver = aObserver;
       
   173     iObservedClient = aClientToNotify;
       
   174     }
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CCnUiClientStatusHandler::CancelClientStatusNotify()
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CCnUiClientStatusHandler::CancelClientStatusNotify()
       
   182     {
       
   183     iLoginStastusChannel->CancelListen();
       
   184     iClntStatusObserver = NULL;
       
   185     }
       
   186 
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CCnUiClientStatusHandler::HandleNotifyL()
       
   190 // from MSharedDataNotifyHandler
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CCnUiClientStatusHandler::HandleChannelMsg( TInt /*aGroupId*/,
       
   194                                                  TGCChannelID /*aChannelId*/,
       
   195                                                  TInt aRetMsg )
       
   196     {
       
   197     TBool clientNowLoggedIn = EFalse;
       
   198     //Is the asked client logged in
       
   199     if ( aRetMsg & ( TInt ) iObservedClient )
       
   200         {
       
   201         clientNowLoggedIn = ETrue;
       
   202         }
       
   203 
       
   204     iClntStatusObserver->HandleClientLoginStatusChange( iObservedClient, clientNowLoggedIn );
       
   205     }
       
   206 
       
   207 //  End of File