mtptransports/mtpcontroller/src/cmtpoperator.cpp
changeset 0 d0791faffa3f
child 6 ef55b168cedb
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2007-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 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include "cmtpoperator.h"
       
    24 
       
    25 __FLOG_STMT( _LIT8( KComponent, "mtpoperator" ); )
       
    26 
       
    27 CMTPOperator* CMTPOperator::NewL( MMTPOperatorNotifier& aNotifier )
       
    28     {
       
    29     CMTPOperator* self = new( ELeave ) CMTPOperator( aNotifier );
       
    30     self->ConstructL();
       
    31     return self;
       
    32     }
       
    33 
       
    34 CMTPOperator::~CMTPOperator()
       
    35     {
       
    36     Cancel();
       
    37     iPendingOperations.Reset();
       
    38     iPendingOperations.Close();
       
    39     iMTPClient.Close();
       
    40     __FLOG( _L8("+/-Dtor") );
       
    41     __FLOG_CLOSE;
       
    42     }
       
    43 
       
    44 void CMTPOperator::StartTransport( TUid aTransport )
       
    45     {
       
    46     __FLOG_1( _L8("+/-StartTransport( 0x%08X )"), aTransport.iUid );
       
    47     TInt err = AppendOperation( EStartTransport, aTransport );
       
    48     if ( KErrNone != err )
       
    49         {
       
    50         iNotifier.HandleStartTrasnportCompleteL( err );
       
    51         }
       
    52     }
       
    53 
       
    54 void CMTPOperator::StopTransport( TUid aTransport )
       
    55     {
       
    56     __FLOG_1( _L8("+/-StopTransport( 0x%08X )"), aTransport.iUid );
       
    57     TInt err = AppendOperation( EStopTransport, aTransport );
       
    58     if ( KErrNone != err )
       
    59         {
       
    60         iNotifier.HandleStartTrasnportCompleteL( err );
       
    61         }
       
    62     }
       
    63 
       
    64 void CMTPOperator::DoCancel()
       
    65     {
       
    66     __FLOG( _L8("+/-DoCancel") );
       
    67     }
       
    68 
       
    69 void CMTPOperator::RunL()
       
    70     {
       
    71     __FLOG( _L8("+RunL") );
       
    72     
       
    73     TInt count = iPendingOperations.Count();
       
    74     if ( count > 0 )
       
    75         {
       
    76         TOperation& operation = iPendingOperations[0];
       
    77         TRAP_IGNORE( HandleOperationL( operation ) );
       
    78         iPendingOperations.Remove( 0 );
       
    79         }
       
    80     
       
    81     __FLOG( _L8("-RunL") );
       
    82     }
       
    83 
       
    84 CMTPOperator::CMTPOperator( MMTPOperatorNotifier& aNotifier ):
       
    85     CActive( EPriorityStandard ),
       
    86     iNotifier( aNotifier )
       
    87     {
       
    88     __FLOG_OPEN( KMTPSubsystem, KComponent );
       
    89     __FLOG( _L8("+/-Ctor") );
       
    90     }
       
    91 
       
    92 void CMTPOperator::ConstructL()
       
    93     {
       
    94     __FLOG( _L8("+ConstructL") );
       
    95     CActiveScheduler::Add( this );
       
    96     User::LeaveIfError( iMTPClient.Connect() );
       
    97     __FLOG( _L8("-ConstructL") );
       
    98     }
       
    99 
       
   100 TInt CMTPOperator::AppendOperation( TOperationType aType, TUid aTransport )
       
   101     {
       
   102     TOperation operation = { aType, aTransport };
       
   103     TInt err = iPendingOperations.Append( operation );
       
   104     if ( ( KErrNone == err ) && !IsActive() )
       
   105         {
       
   106         Schedule( KErrNone );
       
   107         }
       
   108     __FLOG_1( _L8("+/-AppendOperation returns %d"), err );
       
   109     return err;
       
   110     }
       
   111 
       
   112 void CMTPOperator::Schedule( TInt aError )
       
   113     {
       
   114     __FLOG_1( _L8("+/-Schedule( %d )"), aError );
       
   115     TRequestStatus* status = &iStatus;
       
   116     User::RequestComplete( status, aError );
       
   117     SetActive();
       
   118     }
       
   119 
       
   120 void CMTPOperator::HandleOperationL( const TOperation& aOperation )
       
   121     {
       
   122     __FLOG_2( _L8("+HandleOperationL( 0x%08X, 0x%08X )"), aOperation.iTransport.iUid, aOperation.iType );
       
   123     TInt err = KErrNone;
       
   124     switch ( aOperation.iType )
       
   125         {
       
   126         case EStartTransport:
       
   127             err = iMTPClient.StartTransport( aOperation.iTransport );
       
   128             iNotifier.HandleStartTrasnportCompleteL( err );
       
   129             break;
       
   130         default:
       
   131             __ASSERT_DEBUG( ( EStopTransport == aOperation.iType ), User::Invariant() );
       
   132             err = iMTPClient.StopTransport( aOperation.iTransport );
       
   133             iNotifier.HandleStopTrasnportCompleteL( err );
       
   134             break;
       
   135         }
       
   136     __FLOG( _L8("-HandleOperationL") );
       
   137     }
       
   138