mtptransports/mtpusbtransport/usbsic_imp/src/cmtpusbepcontrol.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include "cmtpusbconnection.h"
       
    22 #include "cmtpusbepcontrol.h"
       
    23 #include "mtpusbpanic.h"
       
    24 #include "mtpusbtransportconstants.h"
       
    25 
       
    26 // Class constants.
       
    27 __FLOG_STMT(_LIT8(KComponent,"UsbEpControl");)
       
    28 
       
    29 /**
       
    30 USB MTP device class control endpoint data transfer controller factory method.
       
    31 @param aId The internal endpoint identifier of the endpoint.
       
    32 @param aConnection USB MTP device class transport connection which controls 
       
    33 the endpoint.
       
    34 @return A pointer to an USB MTP device class control endpoint data transfer 
       
    35 controller. Ownership IS transfered.
       
    36 @leave One of the system wide error codes, if a processing failure occurs.
       
    37 */
       
    38 CMTPUsbEpControl* CMTPUsbEpControl::NewL(TUint aId, CMTPUsbConnection& aConnection)
       
    39     {
       
    40     CMTPUsbEpControl* self = new(ELeave) CMTPUsbEpControl(aId, aConnection);
       
    41     CleanupStack::PushL(self);
       
    42     
       
    43 #ifdef __FLOG_ACTIVE    
       
    44     self->ConstructL(KComponent);
       
    45 #else
       
    46     self->ConstructL();
       
    47 #endif
       
    48 
       
    49     CleanupStack::Pop(self);
       
    50     return self;    
       
    51     }
       
    52 
       
    53 /**
       
    54 Destructor.
       
    55 */
       
    56 CMTPUsbEpControl::~CMTPUsbEpControl()
       
    57     {
       
    58     __FLOG(_L8("~CMTPUsbEpControl - Entry"));
       
    59     __FLOG(_L8("~CMTPUsbEpControl - Exit"));
       
    60     }
       
    61 
       
    62 /**
       
    63 Initiates an USB MTP device class specific request data receive sequence.
       
    64 @param aData The control request data sink buffer.
       
    65 @leave One of the system wide error codes, if a processing failure occurs.
       
    66 */
       
    67 void CMTPUsbEpControl::ReceiveControlRequestDataL(MMTPType& aData)
       
    68     {
       
    69     __FLOG(_L8("ReceiveControlRequestDataL - Entry"));
       
    70     __FLOG_VA((_L8("CMTPUsbEpControl state on entry = %d"), iState));
       
    71     __ASSERT_DEBUG((iState == EControlRequestSetupComplete), Panic(EMTPUsbBadState));
       
    72     
       
    73     // Pass the bulk data sink buffer to the base class and update state..
       
    74     ReceiveDataL(aData);
       
    75     SetState(EControlRequestDataReceive);
       
    76     
       
    77     __FLOG_VA((_L8("CMTPUsbEpControl state on entry = %d"), iState));
       
    78     __FLOG(_L8("ReceiveControlRequestDataL - Exit"));
       
    79     }
       
    80 
       
    81 /**
       
    82 Initiates an USB MTP device class specific request request processing sequence.
       
    83 @param aData The control request setup data sink buffer.
       
    84 @leave One of the system wide error codes, if a processing failure occurs.
       
    85 */
       
    86 void CMTPUsbEpControl::ReceiveControlRequestSetupL(MMTPType& aData)
       
    87     {
       
    88     __FLOG(_L8("ReceiveControlRequestSetupL - Entry"));
       
    89     __FLOG_VA((_L8("CMTPUsbEpControl state on entry = %d"), iState));
       
    90     __ASSERT_DEBUG((iState == EIdle), Panic(EMTPUsbBadState));
       
    91     
       
    92     // Pass the bulk data sink buffer to the base class and update state.
       
    93     ReceiveDataL(aData);
       
    94     SetState(EControlRequestSetupPending);
       
    95     
       
    96     __FLOG_VA((_L8("CMTPUsbEpControl state on entry = %d"), iState));
       
    97     __FLOG(_L8("ReceiveControlRequestSetupL - Exit"));
       
    98     }
       
    99 
       
   100 /**
       
   101 Initiates an USB MTP device class specific request data send sequence.
       
   102 @param aData The control request data source buffer.
       
   103 @leave One of the system wide error codes, if a processing failure occurs.
       
   104 */
       
   105 void CMTPUsbEpControl::SendControlRequestDataL(const MMTPType& aData)
       
   106     {
       
   107     __FLOG(_L8("SendControlRequestDataL - Entry"));
       
   108     __ASSERT_DEBUG((iState == EControlRequestSetupComplete), Panic(EMTPUsbBadState));
       
   109     
       
   110     // Pass the bulk data source buffer to the base class and update state.
       
   111     SendDataL(aData);
       
   112     SetState(EControlRequestDataSend);
       
   113     
       
   114     __FLOG(_L8("SendControlRequestDataL - Exit"));
       
   115     }
       
   116 
       
   117 /**
       
   118 Concludes an USB MTP device class specific request request processing sequence.
       
   119 */
       
   120 void CMTPUsbEpControl::SendControlRequestStatus()
       
   121     {
       
   122     __FLOG(_L8("SendControlRequestStatus - Entry"));
       
   123     __FLOG_VA((_L8("CMTPUsbEpControl state on entry = %d"), iState));
       
   124     __ASSERT_DEBUG(((iState == EControlRequestStatusSend) || (iState == EControlRequestSetupComplete)), Panic(EMTPUsbBadState));
       
   125     TInt ret = Connection().Ldd().SendEp0StatusPacket();
       
   126     __FLOG_VA((_L8("SendEp0StatusPacket result = %d."), ret));
       
   127     SetState(EIdle);
       
   128     __FLOG_VA((_L8("CMTPUsbEpControl state on exit = %d"), iState));
       
   129     __FLOG(_L8("SendControlRequestStatus - Exit"));
       
   130     }
       
   131     
       
   132 void CMTPUsbEpControl::ReceiveDataCompleteL(TInt aError, MMTPType& aSink)
       
   133     {
       
   134     __FLOG(_L8("ReceiveDataCompleteL - Entry"));
       
   135     __FLOG_VA((_L8("CMTPUsbEpControl state on entry = %d"), iState));
       
   136     switch (iState)
       
   137         {
       
   138     case EControlRequestSetupPending:
       
   139         SetState(EControlRequestSetupComplete);
       
   140         Connection().ReceiveControlRequestSetupCompleteL(aError, aSink);
       
   141         break;          
       
   142         
       
   143     case EControlRequestDataReceive:
       
   144         SetState(EControlRequestStatusSend);
       
   145         Connection().ReceiveControlRequestDataCompleteL(aError, aSink);
       
   146         break;  
       
   147     
       
   148     case EIdle:
       
   149     	// State will be EIdle if CancelReceive is called
       
   150     	break;
       
   151     	
       
   152     case EControlRequestSetupComplete:
       
   153     case EControlRequestDataSend:
       
   154     case EControlRequestStatusSend:
       
   155     default:
       
   156         __DEBUG_ONLY(Panic(EMTPUsbBadState));
       
   157         break;          
       
   158         }
       
   159     if(aError != KErrNone)
       
   160 	    {
       
   161 	    // Reset the internal state to idle.
       
   162 	    SetState(EIdle);
       
   163 	    }
       
   164     __FLOG_VA((_L8("CMTPUsbEpControl state on exit = %d"), iState));
       
   165     __FLOG(_L8("ReceiveDataCompleteL - Exit"));
       
   166     }
       
   167     
       
   168 void CMTPUsbEpControl::SendDataCompleteL(TInt aError, const MMTPType& aSource)
       
   169     {
       
   170     __FLOG(_L8("SendDataCompleteL - Entry"));
       
   171     __FLOG_VA((_L8("CMTPUsbEpControl state on entry = %d"), iState));
       
   172     __ASSERT_DEBUG((iState == EControlRequestDataSend), Panic(EMTPUsbBadState));
       
   173     SetState(EIdle);
       
   174     Connection().SendControlRequestDataCompleteL(aError, aSource);        
       
   175     __FLOG_VA((_L8("CMTPUsbEpControl state on exit = %d"), iState));
       
   176     __FLOG(_L8("SendDataCompleteL - Exit"));
       
   177     }    
       
   178     
       
   179 /**
       
   180 Constructor.
       
   181 @param aId The internal endpoint identifier of the endpoint.
       
   182 @param aConnection USB MTP device class transport connection which controls 
       
   183 the endpoint.
       
   184 */
       
   185 CMTPUsbEpControl::CMTPUsbEpControl(TUint aId, CMTPUsbConnection& aConnection) :
       
   186     CMTPUsbEpBase(aId, EPriorityStandard, aConnection)
       
   187     {
       
   188 
       
   189     }
       
   190 
       
   191 /**
       
   192 Sets the endpoint data send/receive state variable.
       
   193 @param aState The new data stream state.
       
   194 */
       
   195 void CMTPUsbEpControl::SetState(TUint aState)
       
   196     {
       
   197     __FLOG(_L8("SetState - Entry"));
       
   198     iState = aState;
       
   199     __FLOG_VA((_L8("State set to %d"), iState));
       
   200     __FLOG(_L8("SetState - Exit"));
       
   201     }
       
   202 /**
       
   203 Overide this method derived from base class.
       
   204 reset the state.
       
   205 */      
       
   206 void CMTPUsbEpControl::DoCancel()
       
   207 	{
       
   208 	__FLOG(_L8("DoCancel - Entry"));
       
   209 	CMTPUsbEpBase::DoCancel();
       
   210 	SetState(EIdle);
       
   211 	__FLOG(_L8("DoCancel - Exit"));
       
   212 	}
       
   213 	
       
   214