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
12Object::Object(Stack *stack, BusManager *bus)
13	:	fParent(NULL),
14		fBusManager(bus),
15		fStack(stack),
16		fUSBID(fStack->GetUSBID(this)),
17		fBusy(0)
18{
19}
20
21
22Object::Object(Object *parent)
23	:	fParent(parent),
24		fBusManager(parent->GetBusManager()),
25		fStack(parent->GetStack()),
26		fUSBID(fStack->GetUSBID(this)),
27		fBusy(0)
28{
29}
30
31
32Object::~Object()
33{
34	PutUSBID();
35}
36
37
38void
39Object::PutUSBID(bool waitForUnbusy)
40{
41	if (fUSBID != UINT32_MAX) {
42		fStack->PutUSBID(this);
43		fUSBID = UINT32_MAX;
44	}
45
46	if (waitForUnbusy)
47		WaitForUnbusy();
48}
49
50
51void
52Object::WaitForUnbusy()
53{
54	int32 retries = 20;
55	while (atomic_get(&fBusy) != 0 && retries--)
56		snooze(100);
57	if (retries <= 0)
58		panic("USB object did not become unbusy!");
59}
60
61
62status_t
63Object::SetFeature(uint16 selector)
64{
65	// to be implemented in subclasses
66	TRACE_ERROR("set feature called\n");
67	return B_ERROR;
68}
69
70
71status_t
72Object::ClearFeature(uint16 selector)
73{
74	// to be implemented in subclasses
75	TRACE_ERROR("clear feature called\n");
76	return B_ERROR;
77}
78
79
80status_t
81Object::GetStatus(uint16 *status)
82{
83	// to be implemented in subclasses
84	TRACE_ERROR("get status called\n");
85	return B_ERROR;
86}
87