usbengines/usbdevcon/src/cep0writer.cpp
changeset 0 1e05558e2206
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 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:  EP0 Writer 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cep0writer.h"
       
    20 #include "cstatemachine.h"
       
    21 #include "cusbdevcon.h"
       
    22 #include "debug.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Two-phase construction
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CEP0Writer* CEP0Writer::NewL(CStateMachine& aObserver, RDevUsbcClient& aLdd)
       
    29     {
       
    30     
       
    31     FLOG( _L( "[USBDEVCON]\tCEP0Writer::NewL" ) );
       
    32     
       
    33     CEP0Writer* self = new (ELeave) CEP0Writer(aObserver, aLdd);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;    
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Default construction
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CEP0Writer::CEP0Writer(CStateMachine& aObserver, RDevUsbcClient& aLdd) :
       
    45                                                             CActive(EPriorityMore),
       
    46                                                             iObserver(aObserver),
       
    47                                                             iLdd(aLdd)
       
    48     {
       
    49     CActiveScheduler::Add(this);
       
    50     }
       
    51         
       
    52 // ---------------------------------------------------------------------------
       
    53 // Two-phase construction
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CEP0Writer::ConstructL()
       
    57     {
       
    58     
       
    59     FLOG( _L( "[USBDEVCON]\tCEP0Writer::ConstructL" ) );
       
    60     
       
    61     iBuffer.CreateL(0); // later will be set with needed size
       
    62     }
       
    63     
       
    64 // ---------------------------------------------------------------------------
       
    65 // Destruction
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CEP0Writer::~CEP0Writer()
       
    69     {
       
    70     Cancel(); 
       
    71            
       
    72     iBuffer.Close();
       
    73         
       
    74     }   
       
    75     
       
    76 // ---------------------------------------------------------------------------
       
    77 // Cancellation
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CEP0Writer::DoCancel()
       
    81     {
       
    82     iLdd.WriteCancel(EEndpoint0);
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Data has been wrote to EP0 
       
    87 // ---------------------------------------------------------------------------
       
    88 //  
       
    89 void CEP0Writer::RunL()
       
    90     {
       
    91 
       
    92     FLOG( _L( "[USBDEVCON]\tCEP0Writer::RunL" ) );
       
    93 
       
    94     iObserver.WroteEP0(iStatus);
       
    95     }
       
    96     
       
    97 // ----------------------------------------------------------------------------
       
    98 // Standard active object error function.
       
    99 // ----------------------------------------------------------------------------
       
   100 //
       
   101 TInt CEP0Writer::RunError( TInt /*aError*/ )
       
   102     {
       
   103     return KErrNone;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Issue request to write data
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CEP0Writer::Write(const RBuf8& aBuffer, TUint aDataLength)
       
   111     {
       
   112 
       
   113     FLOG( _L( "[USBDEVCON]\tCEP0Writer::Write" ) );
       
   114 
       
   115     if(IsActive())
       
   116         {
       
   117         return;
       
   118         }
       
   119     
       
   120     FTRACE(FPrint(
       
   121             _L("[USBDEVCON]\tCEP0Writer::Write. aBuffer Length = %d aDataLength = %d" ),aBuffer.Length(), aDataLength));
       
   122 
       
   123     iBuffer.Close();
       
   124     iBuffer.Create(aBuffer, aDataLength);   
       
   125     
       
   126     iLdd.Write(iStatus, EEndpoint0, iBuffer, aDataLength, ETrue);
       
   127     SetActive();
       
   128     
       
   129     }
       
   130 
       
   131