1 /*
2 * Copyright 2002-2008, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include <InputServerDevice.h>
8
9 #include <new>
10
11 #include <Directory.h>
12 #include <Path.h>
13
14 #include "InputServer.h"
15
16
DeviceAddOn(BInputServerDevice * device)17 DeviceAddOn::DeviceAddOn(BInputServerDevice *device)
18 :
19 fDevice(device)
20 {
21 }
22
23
~DeviceAddOn()24 DeviceAddOn::~DeviceAddOn()
25 {
26 while (const char* path = fMonitoredPaths.PathAt(0)) {
27 gInputServer->AddOnManager()->StopMonitoringDevice(this, path);
28 }
29 }
30
31
32 bool
HasPath(const char * path) const33 DeviceAddOn::HasPath(const char* path) const
34 {
35 return fMonitoredPaths.HasPath(path);
36 }
37
38
39 status_t
AddPath(const char * path)40 DeviceAddOn::AddPath(const char* path)
41 {
42 return fMonitoredPaths.AddPath(path);
43 }
44
45
46 status_t
RemovePath(const char * path)47 DeviceAddOn::RemovePath(const char* path)
48 {
49 return fMonitoredPaths.RemovePath(path);
50 }
51
52
53 int32
CountPaths() const54 DeviceAddOn::CountPaths() const
55 {
56 return fMonitoredPaths.CountPaths();
57 }
58
59
60 // #pragma mark -
61
62
BInputServerDevice()63 BInputServerDevice::BInputServerDevice()
64 {
65 fOwner = new(std::nothrow) DeviceAddOn(this);
66 }
67
68
~BInputServerDevice()69 BInputServerDevice::~BInputServerDevice()
70 {
71 CALLED();
72
73 gInputServer->UnregisterDevices(*this);
74 delete fOwner;
75 }
76
77
78 status_t
InitCheck()79 BInputServerDevice::InitCheck()
80 {
81 if (fOwner == NULL)
82 return B_NO_MEMORY;
83 return B_OK;
84 }
85
86
87 status_t
SystemShuttingDown()88 BInputServerDevice::SystemShuttingDown()
89 {
90 return B_OK;
91 }
92
93
94 status_t
Start(const char * device,void * cookie)95 BInputServerDevice::Start(const char* device, void* cookie)
96 {
97 return B_OK;
98 }
99
100
101 status_t
Stop(const char * device,void * cookie)102 BInputServerDevice::Stop(const char* device, void* cookie)
103 {
104 return B_OK;
105 }
106
107
108 status_t
Control(const char * device,void * cookie,uint32 code,BMessage * message)109 BInputServerDevice::Control(const char* device, void* cookie,
110 uint32 code, BMessage* message)
111 {
112 return B_OK;
113 }
114
115
116 status_t
RegisterDevices(input_device_ref ** devices)117 BInputServerDevice::RegisterDevices(input_device_ref** devices)
118 {
119 CALLED();
120 return gInputServer->RegisterDevices(*this, devices);
121 }
122
123
124 status_t
UnregisterDevices(input_device_ref ** devices)125 BInputServerDevice::UnregisterDevices(input_device_ref** devices)
126 {
127 CALLED();
128 // TODO: is this function supposed to remove devices that do not belong to this object?
129 // (at least that's what the previous implementation allowed for)
130 return gInputServer->UnregisterDevices(*this, devices);
131 }
132
133
134 status_t
EnqueueMessage(BMessage * message)135 BInputServerDevice::EnqueueMessage(BMessage* message)
136 {
137 return gInputServer->EnqueueDeviceMessage(message);
138 }
139
140
141 status_t
StartMonitoringDevice(const char * device)142 BInputServerDevice::StartMonitoringDevice(const char* device)
143 {
144 CALLED();
145 PRINT(("StartMonitoringDevice %s\n", device));
146
147 return gInputServer->AddOnManager()->StartMonitoringDevice(fOwner, device);
148 }
149
150
151 status_t
StopMonitoringDevice(const char * device)152 BInputServerDevice::StopMonitoringDevice(const char* device)
153 {
154 return gInputServer->AddOnManager()->StopMonitoringDevice(fOwner, device);
155 }
156
157
158 status_t
AddDevices(const char * path)159 BInputServerDevice::AddDevices(const char* path)
160 {
161 BDirectory directory;
162 status_t status = directory.SetTo(path);
163 if (status != B_OK)
164 return status;
165
166 BEntry entry;
167 while (directory.GetNextEntry(&entry) == B_OK) {
168 BPath entryPath(&entry);
169
170 if (entry.IsDirectory()) {
171 AddDevices(entryPath.Path());
172 } else {
173 BMessage added(B_NODE_MONITOR);
174 added.AddInt32("opcode", B_ENTRY_CREATED);
175 added.AddString("path", entryPath.Path());
176
177 Control(NULL, NULL, B_INPUT_DEVICE_ADDED, &added);
178 }
179 }
180
181 return B_OK;
182 }
183
184
_ReservedInputServerDevice1()185 void BInputServerDevice::_ReservedInputServerDevice1() {}
_ReservedInputServerDevice2()186 void BInputServerDevice::_ReservedInputServerDevice2() {}
_ReservedInputServerDevice3()187 void BInputServerDevice::_ReservedInputServerDevice3() {}
_ReservedInputServerDevice4()188 void BInputServerDevice::_ReservedInputServerDevice4() {}
189