usbengines/usbdevcon/src/cep0reader.cpp
changeset 0 1e05558e2206
child 87 18fe5224f0dc
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 Reader 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cep0reader.h"
       
    20 #include "cstatemachine.h"
       
    21 #include "cusbdevcon.h"
       
    22 #include "debug.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Two-phase construction
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CEP0Reader* CEP0Reader::NewL(CStateMachine& aObserver, RDevUsbcClient& aLdd)
       
    29     {
       
    30     
       
    31     FLOG( _L( "[USBDEVCON]\tCEP0Reader::NewL" ) );
       
    32     
       
    33     CEP0Reader* self = new (ELeave) CEP0Reader(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 CEP0Reader::CEP0Reader(CStateMachine& aObserver, RDevUsbcClient& aLdd) :
       
    45                                                             CActive(EPriorityMore),
       
    46                                                             iLdd(aLdd),
       
    47                                                             iObserver(aObserver)
       
    48                                                             
       
    49     {
       
    50     CActiveScheduler::Add(this);
       
    51     }
       
    52         
       
    53 // ---------------------------------------------------------------------------
       
    54 // Two-phase construction
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CEP0Reader::ConstructL()
       
    58     {
       
    59     
       
    60     FLOG( _L( "[USBDEVCON]\tCEP0Reader::ConstructL" ) );
       
    61     
       
    62     iBuffer.CreateL(0); // later will be reallocated with required size
       
    63     }
       
    64     
       
    65 // ---------------------------------------------------------------------------
       
    66 // Destruction
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CEP0Reader::~CEP0Reader()
       
    70     {
       
    71     Cancel();
       
    72            
       
    73     iBuffer.Close();
       
    74     }   
       
    75     
       
    76 // ---------------------------------------------------------------------------
       
    77 // Cancellation of outstanding request
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CEP0Reader::DoCancel()
       
    81     {
       
    82     iLdd.ReadCancel(EEndpoint0);
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // Standard active object error function.
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 TInt CEP0Reader::RunError( TInt /*aError*/ )
       
    90     {
       
    91     return KErrNone;
       
    92     }
       
    93         
       
    94 // ---------------------------------------------------------------------------
       
    95 // Data has been read from EP0
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CEP0Reader::RunL()
       
    99     {
       
   100 
       
   101     FLOG( _L( "[USBDEVCON]\tCEP0Reader::RunL Data received:" ) );
       
   102     
       
   103     iObserver.ReadEP0(iBuffer, iStatus);
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Issue request to read setup packet
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CEP0Reader::ReadSetupPacket()
       
   111     {
       
   112     
       
   113     FLOG( _L( "[USBDEVCON]\tCEP0Reader::ReadSetupPacket" ) );
       
   114 
       
   115     if(IsActive())
       
   116         {
       
   117         return;
       
   118         }
       
   119     
       
   120     iBuffer.Close();
       
   121     iBuffer.Create(KSetupPacketLength);
       
   122     
       
   123     iLdd.ReadPacket(iStatus, EEndpoint0, iBuffer, KSetupPacketLength);
       
   124     SetActive();
       
   125     
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Issue request to read data
       
   130 // ---------------------------------------------------------------------------
       
   131 //  
       
   132 void CEP0Reader::Read(TUint aDataLength)
       
   133     {
       
   134     
       
   135     FLOG( _L( "[USBDEVCON]\tCEP0Reader::Read" ) );
       
   136 
       
   137     if(IsActive())
       
   138         {
       
   139         return;
       
   140         }
       
   141     
       
   142     iBuffer.Close();
       
   143     iBuffer.Create(aDataLength);    
       
   144         
       
   145     iLdd.Read(iStatus, EEndpoint0, iBuffer, aDataLength);
       
   146     SetActive();
       
   147     
       
   148     }
       
   149