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