xref: /haiku/src/add-ons/kernel/bus_managers/usb/Transfer.cpp (revision cd552c7a15cc10c36dae8d7439ba1d6c0bb168c5)
1 /*
2  * Copyright 2003-2006, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Niels S. Reedijk
7  */
8 
9 #include "usb_p.h"
10 
11 
12 Transfer::Transfer(Pipe *pipe, bool synchronous)
13 {
14 	fPipe = pipe;
15 	fBuffer = NULL;
16 	fBufferLength = 0;
17 	fActualLength = NULL;
18 	fTimeout = 0;
19 	fStatus = B_ERROR;
20 	fSem = -1;
21 	fHostPrivate = NULL;
22 
23 	if (synchronous) {
24 		fSem = create_sem(0, "USB Transfer");
25 		set_sem_owner(fSem, B_SYSTEM_TEAM);
26 	}
27 }
28 
29 
30 Transfer::~Transfer()
31 {
32 	if (fSem >= B_OK)
33 		delete_sem(fSem);
34 }
35 
36 
37 void
38 Transfer::SetRequestData(usb_request_data *data)
39 {
40 	fRequest = data;
41 }
42 
43 
44 void
45 Transfer::SetBuffer(uint8 *buffer)
46 {
47 	fBuffer = buffer;
48 }
49 
50 
51 void
52 Transfer::SetBufferLength(size_t length)
53 {
54 	fBufferLength = length;
55 }
56 
57 
58 void
59 Transfer::SetActualLength(size_t *actualLength)
60 {
61 	fActualLength = actualLength;
62 }
63 
64 
65 void
66 Transfer::SetCallbackFunction(usb_callback_func callback)
67 {
68 	fCallback = callback;
69 }
70 
71 
72 void
73 Transfer::SetHostPrivate(hostcontroller_priv *priv)
74 {
75 	fHostPrivate = priv;
76 }
77 
78 
79 void
80 Transfer::WaitForFinish()
81 {
82 	if (fSem > B_OK)
83 		acquire_sem(fSem);
84 	// ToDo: and otherwise?
85 }
86 
87 
88 void
89 Transfer::TransferDone()
90 {
91 	if (fSem > B_OK)
92 		release_sem(fSem);
93 }
94 
95 
96 void Transfer::Finish()
97 {
98 	// If we are synchronous, release a sem
99 	if (fSem > B_OK)
100 		release_sem(fSem);
101 }
102