mtpdataproviders/mtppictbridgedp/src/cmtppictbridgeusbconnection.cpp
changeset 0 d0791faffa3f
child 18 453dfc402455
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include "s60dependency.h"
       
    18 #include "cmtppictbridgeusbconnection.h"
       
    19 #include "cmtppictbridgeprinter.h"
       
    20 #include "ptpdef.h"
       
    21 
       
    22 const TInt KNotAssigned=0;
       
    23 // --------------------------------------------------------------------------
       
    24 // 
       
    25 // 
       
    26 // --------------------------------------------------------------------------
       
    27 //
       
    28 CMTPPictBridgeUsbConnection* CMTPPictBridgeUsbConnection::NewL(CMTPPictBridgePrinter& aPrinter)
       
    29     {
       
    30     CMTPPictBridgeUsbConnection* self = new(ELeave) CMTPPictBridgeUsbConnection(aPrinter);
       
    31     CleanupStack::PushL(self);
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop();
       
    34     return self;
       
    35     }
       
    36 
       
    37 // --------------------------------------------------------------------------
       
    38 // 
       
    39 // 
       
    40 // --------------------------------------------------------------------------
       
    41 //    
       
    42 CMTPPictBridgeUsbConnection::CMTPPictBridgeUsbConnection(CMTPPictBridgePrinter& aPrinter) : CActive(EPriorityStandard),
       
    43     iPrinter(aPrinter)
       
    44     {
       
    45     CActiveScheduler::Add(this);    
       
    46     }
       
    47     
       
    48 
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // 
       
    52 // 
       
    53 // --------------------------------------------------------------------------
       
    54 //
       
    55 void CMTPPictBridgeUsbConnection::ConstructL()    
       
    56     {
       
    57     __FLOG_OPEN(KMTPSubsystem, KPtpServerLog);
       
    58     __FLOG(_L8("CMTPPictBridgeUsbConnection::ConstructL"));        
       
    59     User::LeaveIfError(iProperty.Attach(KPSUidUsbWatcher, KUsbWatcherSelectedPersonality));
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // 
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CMTPPictBridgeUsbConnection::~CMTPPictBridgeUsbConnection()
       
    67     {
       
    68     __FLOG(_L8(">> CMTPPictBridgeUsbConnection::~"));
       
    69     Cancel();
       
    70     iProperty.Close();
       
    71     __FLOG(_L8("<< CMTPPictBridgeUsbConnection::~"));
       
    72     __FLOG_CLOSE;
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // 
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 void CMTPPictBridgeUsbConnection::Listen()
       
    80     {
       
    81     iProperty.Subscribe(iStatus);
       
    82     SetActive();
       
    83     if(ConnectionClosed()) // we listen to the disconnection only if connected to the printer
       
    84         {
       
    85         iPrinter.ConnectionClosed();
       
    86         Cancel();    
       
    87         }
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // 
       
    92 // --------------------------------------------------------------------------
       
    93 //    
       
    94 TBool CMTPPictBridgeUsbConnection::ConnectionClosed()
       
    95     {
       
    96     TInt personality=KNotAssigned;
       
    97     TInt ret = RProperty::Get(KPSUidUsbWatcher, KUsbWatcherSelectedPersonality, personality);
       
    98 
       
    99     __FLOG_VA((_L8("CMTPPictBridgeUsbConnection::ConnectionClosed() current personality = %d, previous personality = %d"), personality, iPreviousPersonality));  
       
   100     if ((ret == KErrNone && 
       
   101         (personality == KUsbPersonalityIdMS || personality == KUsbPersonalityIdPTP))
       
   102        || (iPreviousPersonality != KNotAssigned && personality != iPreviousPersonality))
       
   103         { 
       
   104         __FLOG_VA((_L8("****WARNING!!! PTP server detects the USB connection closed!")));  
       
   105         return ETrue;
       
   106         }
       
   107 
       
   108     iPreviousPersonality = personality;
       
   109     return EFalse;
       
   110     }
       
   111 
       
   112 
       
   113     
       
   114 // --------------------------------------------------------------------------
       
   115 // 
       
   116 // --------------------------------------------------------------------------
       
   117 //
       
   118 void CMTPPictBridgeUsbConnection::DoCancel()
       
   119     {
       
   120     __FLOG(_L8("CMTPPictBridgeUsbConnection::DoCancel()"));
       
   121     iProperty.Cancel();
       
   122     }
       
   123 
       
   124 // --------------------------------------------------------------------------
       
   125 // 
       
   126 // --------------------------------------------------------------------------
       
   127 //    
       
   128 void CMTPPictBridgeUsbConnection::RunL()
       
   129     {
       
   130     __FLOG_VA((_L8(">>>CMTPPictBridgeUsbConnection::RunL %d"),iStatus.Int()));
       
   131 
       
   132     TBool closed = EFalse;    
       
   133     if( iStatus == KErrNone )
       
   134         {
       
   135         closed=ConnectionClosed();
       
   136         if(closed)
       
   137             {
       
   138             iPrinter.ConnectionClosed();                
       
   139             }
       
   140         }
       
   141 
       
   142     if(iStatus != KErrCancel && !closed) // if connection not closed, keep on listening
       
   143         {
       
   144         Listen();
       
   145         }
       
   146 
       
   147     __FLOG(_L8("<<<CMTPPictBridgeUsbConnection::RunL"));	
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // 
       
   152 // --------------------------------------------------------------------------
       
   153 //    
       
   154 #ifdef __FLOG_ACTIVE
       
   155 TInt CMTPPictBridgeUsbConnection::RunError(TInt aErr)
       
   156 #else
       
   157 TInt CMTPPictBridgeUsbConnection::RunError(TInt /*aErr*/)
       
   158 #endif
       
   159     {
       
   160     __FLOG_VA((_L8(">>>CMTPPictBridgeUsbConnection::RunError %d"), aErr));
       
   161     return KErrNone;
       
   162     }
       
   163