dbgagents/trkagent/app/common/trkconnstatelistener.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32std.h>                      
       
    20 
       
    21 #include "trksrvclisession.h"
       
    22 #include "trkconnstatelistener.h" 
       
    23                    
       
    24 // LOCAL FUNCTION PROTOTYPES
       
    25 
       
    26 // LOCAL CONSTANTS
       
    27 
       
    28 //
       
    29 // CTrkConnStateListener::CTrkConnStateListener
       
    30 // Constructor
       
    31 //
       
    32 CTrkConnStateListener::CTrkConnStateListener (RTrkSrvCliSession& aTrkSrvSession, MTrkServerEventCallback *aTrkServerEventCallback) 
       
    33               :CTrkServerEventListener(aTrkSrvSession, aTrkServerEventCallback, CActive::EPriorityStandard), iConnMsg(KNullDesC), iConnState(iConnStatus)
       
    34 {
       
    35     iConnStatus = ETrkNotConnected;
       
    36     iTrkSrvSession.GetDebugConnStatus(iConnStatus, iConnMsg);
       
    37     CActiveScheduler::Add( this ); 
       
    38 }
       
    39 
       
    40 //
       
    41 // CTrkConnStateListener::~CTrkConnStateListener
       
    42 // Destructor
       
    43 //
       
    44 CTrkConnStateListener::~CTrkConnStateListener()
       
    45 {
       
    46     Cancel();   // Ensure that any outstanding requests are cancelled
       
    47     Deque();
       
    48 }
       
    49 
       
    50 //
       
    51 // CTrkConnStateListener::ListenL
       
    52 // Starts listening for usb connection status notifications..
       
    53 //
       
    54 void CTrkConnStateListener::ListenL()
       
    55 {       
       
    56     IssueRequestL();        
       
    57 }
       
    58 
       
    59 
       
    60 
       
    61 //
       
    62 // CTrkConnStateListener::StopListening
       
    63 // Cancel any pending requests for connection status notifications.
       
    64 //
       
    65 void CTrkConnStateListener::StopListening()
       
    66 {
       
    67     Cancel();   
       
    68 }
       
    69 
       
    70 //
       
    71 // CTrkConnStateListener::IssueRequestL
       
    72 //
       
    73 TBool CTrkConnStateListener::IsConnected()
       
    74 {       
       
    75    iTrkSrvSession.GetDebugConnStatus(iConnStatus, iConnMsg);
       
    76    return (iConnStatus==ETrkConnected);
       
    77 }
       
    78 
       
    79 //
       
    80 // CTrkConnStateListener::IssueRequestL
       
    81 //
       
    82 void CTrkConnStateListener::IssueRequestL()
       
    83 {       
       
    84     if (IsActive()) //already listening, just return...
       
    85         return;
       
    86     iTrkSrvSession.DebugConnStatusNotify(iConnState, iConnMsg, iStatus);
       
    87     
       
    88     SetActive();    
       
    89 }
       
    90 
       
    91 //
       
    92 // CTrkConnStateListener::DoCancel
       
    93 // This method gets called from CActive::Cancel();
       
    94 //
       
    95 void CTrkConnStateListener::DoCancel()
       
    96 {
       
    97     iTrkSrvSession.DebugConnStatusNotifyCancel();   
       
    98 }
       
    99 
       
   100 //
       
   101 // CTrkConnStateListener::RunL
       
   102 // This method gets called whenever there is a change in the connection status.
       
   103 //
       
   104 void CTrkConnStateListener::RunL()
       
   105 {
       
   106     User::LeaveIfError( iStatus.Int() );
       
   107     if (iTrkServerEventCallback)
       
   108         iTrkServerEventCallback->ConnectionStateChanged(iConnStatus);
       
   109     
       
   110     IssueRequestL();
       
   111 }