1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2003-2004, Niels S. Reedijk 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 22 #include "usb_p.h" 23 24 Transfer::Transfer( Pipe *pipe , bool synchronous ) 25 { 26 m_pipe = pipe; 27 m_buffer = 0; 28 m_bufferlength = 0; 29 m_actual_length = 0; 30 m_timeout = 0; 31 m_status = 0; 32 m_sem = B_ERROR; 33 m_hcpriv = 0; 34 35 if ( synchronous == true ) 36 { 37 m_sem = create_sem( 0 , "USB Transfer" ); 38 set_sem_owner ( m_sem , B_SYSTEM_TEAM ); 39 } 40 } 41 42 Transfer::~Transfer() 43 { 44 if ( m_sem > B_OK ) 45 delete_sem( m_sem ); 46 } 47 48 void Transfer::SetRequestData( usb_request_data *data ) 49 { 50 m_request = data; 51 } 52 53 void Transfer::SetBuffer( uint8 *buffer ) 54 { 55 m_buffer = buffer; 56 } 57 58 void Transfer::SetBufferLength( size_t length ) 59 { 60 m_bufferlength = length; 61 } 62 63 void Transfer::SetActualLength( size_t *actual_length ) 64 { 65 m_actual_length = actual_length; 66 }; 67 68 void Transfer::SetCallbackFunction( usb_callback_func callback ) 69 { 70 m_callback = callback; 71 } 72 73 void Transfer::SetHostPrivate( hostcontroller_priv *priv ) 74 { 75 m_hcpriv = priv; 76 } 77 78 void Transfer::WaitForFinish() 79 { 80 if ( m_sem > B_OK ) 81 acquire_sem( m_sem ); 82 } 83 84 void Transfer::TransferDone() 85 { 86 if ( m_sem > B_OK ) 87 release_sem( m_sem ); 88 } 89 90 void Transfer::Finish() 91 { 92 //If we are synchronous, release a sem 93 if ( m_sem > B_OK ) 94 release_sem( m_sem ); 95 } 96