xref: /haiku/src/system/kernel/device_manager/AbstractModuleDevice.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 
8 #include "AbstractModuleDevice.h"
9 
10 
11 AbstractModuleDevice::AbstractModuleDevice()
12 	:
13 	fNode(NULL),
14 	fInitialized(0),
15 	fDeviceModule(NULL),
16 	fDeviceData(NULL)
17 {
18 }
19 
20 
21 AbstractModuleDevice::~AbstractModuleDevice()
22 {
23 }
24 
25 
26 bool
27 AbstractModuleDevice::HasSelect() const
28 {
29 	return Module()->select != NULL;
30 }
31 
32 
33 bool
34 AbstractModuleDevice::HasDeselect() const
35 {
36 	return Module()->deselect != NULL;
37 }
38 
39 
40 bool
41 AbstractModuleDevice::HasRead() const
42 {
43 	return Module()->read != NULL;
44 }
45 
46 
47 bool
48 AbstractModuleDevice::HasWrite() const
49 {
50 	return Module()->write != NULL;
51 }
52 
53 
54 bool
55 AbstractModuleDevice::HasIO() const
56 {
57 	return Module()->io != NULL;
58 }
59 
60 
61 status_t
62 AbstractModuleDevice::Open(const char* path, int openMode, void** _cookie)
63 {
64 	return Module()->open(Data(), path, openMode, _cookie);
65 }
66 
67 
68 status_t
69 AbstractModuleDevice::Read(void* cookie, off_t pos, void* buffer, size_t* _length)
70 {
71 	if (Module()->read == NULL)
72 		return BaseDevice::Read(cookie, pos, buffer, _length);
73 	return Module()->read(cookie, pos, buffer, _length);
74 }
75 
76 
77 status_t
78 AbstractModuleDevice::Write(void* cookie, off_t pos, const void* buffer, size_t* _length)
79 {
80 	if (Module()->write == NULL)
81 		return BaseDevice::Write(cookie, pos, buffer, _length);
82 	return Module()->write(cookie, pos, buffer, _length);
83 }
84 
85 
86 status_t
87 AbstractModuleDevice::IO(void* cookie, io_request* request)
88 {
89 	if (Module()->io == NULL)
90 		return BaseDevice::IO(cookie, request);
91 	return Module()->io(cookie, request);
92 }
93 
94 
95 status_t
96 AbstractModuleDevice::Control(void* cookie, int32 op, void* buffer, size_t length)
97 {
98 	if (Module()->control == NULL)
99 		return BaseDevice::Control(cookie, op, buffer, length);
100 	return Module()->control(cookie, op, buffer, length);
101 }
102 
103 
104 status_t
105 AbstractModuleDevice::Select(void* cookie, uint8 event, selectsync* sync)
106 {
107 	if (Module()->select == NULL)
108 		return BaseDevice::Select(cookie, event, sync);
109 	return Module()->select(cookie, event, sync);
110 }
111 
112 
113 status_t
114 AbstractModuleDevice::Deselect(void* cookie, uint8 event, selectsync* sync)
115 {
116 	if (Module()->deselect == NULL)
117 		return BaseDevice::Deselect(cookie, event, sync);
118 	return Module()->deselect(cookie, event, sync);
119 }
120 
121 
122 status_t
123 AbstractModuleDevice::Close(void* cookie)
124 {
125 	return Module()->close(cookie);
126 }
127 
128 
129 status_t
130 AbstractModuleDevice::Free(void* cookie)
131 {
132 	return Module()->free(cookie);
133 }
134