usbclasses/pictbridgeengine/src/dpsconnectnotifier.cpp
changeset 0 1e05558e2206
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2006, 2007 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:  This class implements functions of the notification of the 
       
    15 *                PTP printer connction and disconnection. 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32debug.h>
       
    21 #include "dpsconnectnotifier.h"
       
    22 #include "dpsusbnotifier.h"
       
    23 
       
    24 #ifdef _DEBUG
       
    25 #	define IF_DEBUG(t) {RDebug::t;}
       
    26 #else
       
    27 #	define IF_DEBUG(t)
       
    28 #endif
       
    29 
       
    30 const TUint KUsbAllStates = 0xFFFFFFFF;
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // 
       
    34 // ---------------------------------------------------------------------------
       
    35 // 
       
    36 CDpsConnectNotifier* CDpsConnectNotifier::NewL(CDpsUsbNotifier* aParent)
       
    37     {
       
    38     IF_DEBUG(Print(_L("CDpsConnectNotifier::NewL")));
       
    39     CDpsConnectNotifier* self = new(ELeave) CDpsConnectNotifier(aParent);
       
    40     return self;	    
       
    41     }
       
    42     
       
    43 // ---------------------------------------------------------------------------
       
    44 // 
       
    45 // ---------------------------------------------------------------------------
       
    46 //     
       
    47 CDpsConnectNotifier::CDpsConnectNotifier(CDpsUsbNotifier* aParent) :
       
    48     CActive(EPriorityNormal), iNotifier(aParent) 
       
    49     {
       
    50     IF_DEBUG(Print(_L(">>>CDpsConnectNotifier::Ctor")));    
       
    51     CActiveScheduler::Add(this);
       
    52     IF_DEBUG(Print(_L("<<<CDpsConnectNotifier::Ctor")));    
       
    53     }
       
    54    
       
    55 // ---------------------------------------------------------------------------
       
    56 // 
       
    57 // ---------------------------------------------------------------------------
       
    58 //     
       
    59 CDpsConnectNotifier::~CDpsConnectNotifier()
       
    60     {
       
    61     IF_DEBUG(Print(_L(">>>CDpsConnectNotifier::~")));   
       
    62     Cancel();
       
    63     IF_DEBUG(Print(_L("<<<CDpsConnectNotifier::~")));   
       
    64     }
       
    65    
       
    66 // ---------------------------------------------------------------------------
       
    67 // 
       
    68 // ---------------------------------------------------------------------------
       
    69 //     
       
    70 void CDpsConnectNotifier::ConnectNotify()
       
    71     {
       
    72     IF_DEBUG(Print(_L(">>>CDpsConnectNotifier::ConnectNotify")));    
       
    73     if (!IsActive())
       
    74         {
       
    75 	    iNotifier->iUsbM.DeviceStateNotification(KUsbAllStates, 
       
    76 	                                             iNotifier->iConnectState, 
       
    77 	                                             iStatus);
       
    78         SetActive();			
       
    79         }
       
    80     IF_DEBUG(Print(_L("<<<CDpsConnectNotifier::ConnectNotify")));    	
       
    81     }
       
    82     
       
    83 // ---------------------------------------------------------------------------
       
    84 // 
       
    85 // ---------------------------------------------------------------------------
       
    86 // 
       
    87 void CDpsConnectNotifier::RunL()
       
    88     {
       
    89     IF_DEBUG(Print(_L
       
    90         (">>>CDpsConnectNotifier::RunL %x"), iNotifier->iConnectState));
       
    91     if (KErrNone == iStatus.Int())
       
    92         {
       
    93         
       
    94         // notify connect (by set personality)
       
    95         if (iNotifier->iConnectState == EUsbDeviceStateConfigured && 
       
    96             !iNotifier->iConfigured)
       
    97             {
       
    98             iNotifier->PtpNotify(KErrNone);
       
    99             }
       
   100         // Notify disconnect on cable disconnection and for compatible printer
       
   101         // also when other device state than configured or suspended is entered. 
       
   102         else if (  (iNotifier->iConnectState == EUsbDeviceStateUndefined) ||
       
   103                 ( iNotifier->IsConfigured() && 
       
   104                         (iNotifier->iConnectState != EUsbDeviceStateConfigured) &&
       
   105                         (iNotifier->iConnectState != EUsbDeviceStateSuspended) )  )
       
   106             {
       
   107             iNotifier->DisconnectNotify(iNotifier->iConnectState);
       
   108             } 
       
   109         else // not the state we are interested, keep on listening
       
   110             {
       
   111             iNotifier->iUsbM.DeviceStateNotification(KUsbAllStates, 
       
   112 	                                                 iNotifier->iConnectState, 
       
   113 	                                                 iStatus);
       
   114             SetActive();	                                             
       
   115             }
       
   116         
       
   117         }
       
   118     else
       
   119         {
       
   120         IF_DEBUG(Print(_L("\tthe iStatus is wrong!!!")));
       
   121         }    
       
   122     IF_DEBUG(Print(_L("<<<CDpsConnectNotifier::RunL")));    
       
   123     }
       
   124     
       
   125 // ---------------------------------------------------------------------------
       
   126 // 
       
   127 // ---------------------------------------------------------------------------
       
   128 // 
       
   129 void CDpsConnectNotifier::DoCancel()
       
   130     {
       
   131     IF_DEBUG(Print(_L(">>>CDpsConnectNotifier::DoCancel")));    
       
   132     iNotifier->iUsbM.DeviceStateNotificationCancel();
       
   133     IF_DEBUG(Print(_L("<<<CDpsConnectNotifier::DoCancel")));
       
   134     }
       
   135     
       
   136 // ---------------------------------------------------------------------------
       
   137 // 
       
   138 // ---------------------------------------------------------------------------
       
   139 // 
       
   140 TInt CDpsConnectNotifier::RunError(TInt aErr)
       
   141     {
       
   142     IF_DEBUG(Print(_L("CDpsConnectNotifier::RunError is %d"), aErr));    
       
   143     return aErr;
       
   144     }