xref: /haiku/src/add-ons/kernel/bus_managers/usb/Object.cpp (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2  * Copyright 2006-2020, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  */
8 
9 #include "usb_private.h"
10 
11 
12 Object::Object(Stack *stack, BusManager *bus)
13 	:	fParent(NULL),
14 		fBusManager(bus),
15 		fStack(stack),
16 		fUSBID(fStack->GetUSBID(this))
17 {
18 }
19 
20 
21 Object::Object(Object *parent)
22 	:	fParent(parent),
23 		fBusManager(parent->GetBusManager()),
24 		fStack(parent->GetStack()),
25 		fUSBID(fStack->GetUSBID(this))
26 {
27 }
28 
29 
30 Object::~Object()
31 {
32 	PutUSBID();
33 }
34 
35 
36 void
37 Object::PutUSBID(bool waitForIdle)
38 {
39 	if (fUSBID != UINT32_MAX) {
40 		fStack->PutUSBID(this);
41 		fUSBID = UINT32_MAX;
42 	}
43 
44 	if (waitForIdle)
45 		WaitForIdle();
46 }
47 
48 
49 void
50 Object::WaitForIdle()
51 {
52 	int32 retries = 20;
53 	while (CountReferences() != 1 && retries--)
54 		snooze(100);
55 	if (retries <= 0)
56 		panic("USB object did not become idle!");
57 }
58 
59 
60 status_t
61 Object::SetFeature(uint16 selector)
62 {
63 	// to be implemented in subclasses
64 	TRACE_ERROR("set feature called\n");
65 	return B_ERROR;
66 }
67 
68 
69 status_t
70 Object::ClearFeature(uint16 selector)
71 {
72 	// to be implemented in subclasses
73 	TRACE_ERROR("clear feature called\n");
74 	return B_ERROR;
75 }
76 
77 
78 status_t
79 Object::GetStatus(uint16 *status)
80 {
81 	// to be implemented in subclasses
82 	TRACE_ERROR("get status called\n");
83 	return B_ERROR;
84 }
85