dbgagents/trkagent/trkserver/toolsconnectionlistener.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 
       
    19 #include "toolsconnectionlistener.h"
       
    20 #include <e32debug.h>
       
    21 
       
    22 //
       
    23 //----------------------------------------------------
       
    24 // CToolsConnectionListener::NewL()
       
    25 // To create the instance
       
    26 //----------------------------------------------------
       
    27 //
       
    28 CToolsConnectionListener* CToolsConnectionListener :: NewL(MTrkUsbConnectionListener* aListener)
       
    29 {
       
    30     CToolsConnectionListener* self = new (ELeave) CToolsConnectionListener();
       
    31     CleanupStack::PushL(self);
       
    32     self->ConstructL(aListener);
       
    33     CleanupStack::Pop(self);
       
    34     return self;   
       
    35 }
       
    36 //
       
    37 //----------------------------------------------------
       
    38 // CToolsConnectionListener::ConstructL()
       
    39 // 2nd phase constructor
       
    40 //----------------------------------------------------
       
    41 //
       
    42 void CToolsConnectionListener::ConstructL(MTrkUsbConnectionListener* aListener)
       
    43 {
       
    44     User::LeaveIfError( iToolSession.Connect() );
       
    45     iConnectionListener = aListener;
       
    46 }
       
    47 //
       
    48 //----------------------------------------------------
       
    49 // CToolsConnectionListener::CToolsConnectionListener()
       
    50 // 1st phase constructor
       
    51 //----------------------------------------------------
       
    52 //
       
    53 CToolsConnectionListener::CToolsConnectionListener()
       
    54     : CActive(EPriorityStandard),
       
    55     iPackage(iConnStatus),
       
    56     iConnectionListener(NULL)
       
    57    
       
    58 {   
       
    59     CActiveScheduler::Add(this);
       
    60 }
       
    61 //
       
    62 //----------------------------------------------------
       
    63 // CToolsConnectionListener::~CToolsConnectionListener()
       
    64 // Desctructor
       
    65 //----------------------------------------------------
       
    66 //
       
    67 CToolsConnectionListener::~CToolsConnectionListener() 
       
    68 {   
       
    69     Cancel();
       
    70     iToolSession.Close();
       
    71 }
       
    72 //
       
    73 //----------------------------------------------------
       
    74 // CToolsConnectionListener::StartListening()
       
    75 // To issue the asynchronous request
       
    76 //----------------------------------------------------
       
    77 //
       
    78 
       
    79 void CToolsConnectionListener::StartListening()
       
    80 {
       
    81     iToolSession.UsbConnNotify(iPackage, iStatus);    
       
    82     SetActive();
       
    83 }
       
    84 //
       
    85 //----------------------------------------------------
       
    86 // CToolsConnectionListener::StartListening()
       
    87 // To stop the asynchronous request
       
    88 //----------------------------------------------------
       
    89 //
       
    90 void CToolsConnectionListener::StopListening()
       
    91 {
       
    92     DoCancel();  
       
    93     
       
    94 }
       
    95 //
       
    96 //----------------------------------------------------
       
    97 // CToolsConnectionListener::RunL()
       
    98 // RunL implementation
       
    99 //----------------------------------------------------
       
   100 //
       
   101 void CToolsConnectionListener::RunL()
       
   102 {
       
   103     if(iStatus==KErrNone)
       
   104     {
       
   105         switch(iConnStatus)
       
   106         {   
       
   107             case EUsbConnected:
       
   108             {  
       
   109                 if(iConnectionListener)
       
   110                     iConnectionListener->ConnectionAvailable();
       
   111                 break;
       
   112             }
       
   113             case EUsbNotConnected:
       
   114             {
       
   115                 if(iConnectionListener)
       
   116                     iConnectionListener->ConnectionUnAvailable();
       
   117                 break;
       
   118             }
       
   119                 
       
   120             default:
       
   121                 break;
       
   122             
       
   123          }
       
   124      }
       
   125     
       
   126     StartListening();
       
   127        
       
   128 }
       
   129 
       
   130 //
       
   131 //----------------------------------------------------
       
   132 // CToolsConnectionListener::DoCancel()
       
   133 // 
       
   134 //----------------------------------------------------
       
   135 //
       
   136 
       
   137 void CToolsConnectionListener::DoCancel()
       
   138 {
       
   139     iToolSession.UsbConnNotifyCancel();
       
   140 }
       
   141