1 /*****************************************************************************/ 2 // Haiku InputServer 3 // 4 // This is the InputServerDevice implementation 5 // 6 // This application and all source files used in its construction, except 7 // where noted, are licensed under the MIT License, and have been written 8 // and are: 9 // 10 // Copyright (c) 2002-2004 Haiku Project 11 // 12 // Permission is hereby granted, free of charge, to any person obtaining a 13 // copy of this software and associated documentation files (the "Software"), 14 // to deal in the Software without restriction, including without limitation 15 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 // and/or sell copies of the Software, and to permit persons to whom the 17 // Software is furnished to do so, subject to the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be included 20 // in all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 // DEALINGS IN THE SOFTWARE. 29 /*****************************************************************************/ 30 31 #include <Autolock.h> 32 #include <InputServerDevice.h> 33 #include "InputServer.h" 34 35 /** 36 * Method: BInputServerDevice::BInputServerDevice() 37 * Descr: 38 */ 39 BInputServerDevice::BInputServerDevice() 40 { 41 fOwner = new _BDeviceAddOn_(this); 42 } 43 44 45 /** 46 * Method: BInputServerDevice::~BInputServerDevice() 47 * Descr: 48 */ 49 BInputServerDevice::~BInputServerDevice() 50 { 51 CALLED(); 52 // Lock this section of code so that access to the device list 53 // is serialized. Be sure to release the lock before exitting. 54 // 55 InputServer::gInputDeviceListLocker.Lock(); 56 57 for (int i = InputServer::gInputDeviceList.CountItems() - 1; 58 i >= 0 && i < InputServer::gInputDeviceList.CountItems(); i--) { 59 60 PRINT(("%s Device #%d\n", __PRETTY_FUNCTION__, i)); 61 InputDeviceListItem* item = (InputDeviceListItem*) InputServer::gInputDeviceList.ItemAt(i); 62 if (NULL != item && this == item->mIsd) { 63 if (item->mStarted) { 64 input_device_ref dev = item->mDev; 65 PRINT((" Stopping: %s\n", dev.name)); 66 Stop(dev.name, dev.cookie); 67 } 68 InputServer::gInputDeviceList.RemoveItem(i++); 69 delete item; 70 } 71 } 72 73 InputServer::gInputDeviceListLocker.Unlock(); 74 75 delete fOwner; 76 } 77 78 79 /** 80 * Method: BInputServerDevice::InitCheck() 81 * Descr: 82 */ 83 status_t 84 BInputServerDevice::InitCheck() 85 { 86 return B_OK; 87 } 88 89 90 /** 91 * Method: BInputServerDevice::SystemShuttingDown() 92 * Descr: 93 */ 94 status_t 95 BInputServerDevice::SystemShuttingDown() 96 { 97 return B_OK; 98 } 99 100 101 /** 102 * Method: BInputServerDevice::Start() 103 * Descr: 104 */ 105 status_t 106 BInputServerDevice::Start(const char *device, 107 void *cookie) 108 { 109 return B_OK; 110 } 111 112 113 /** 114 * Method: BInputServerDevice::Stop() 115 * Descr: 116 */ 117 status_t 118 BInputServerDevice::Stop(const char *device, 119 void *cookie) 120 { 121 return B_OK; 122 } 123 124 125 /** 126 * Method: BInputServerDevice::Control() 127 * Descr: 128 */ 129 status_t 130 BInputServerDevice::Control(const char *device, 131 void *cookie, 132 uint32 code, 133 BMessage *message) 134 { 135 return B_OK; 136 } 137 138 139 /** 140 * Method: BInputServerDevice::RegisterDevices() 141 * Descr: 142 */ 143 status_t 144 BInputServerDevice::RegisterDevices(input_device_ref **devices) 145 { 146 CALLED(); 147 148 BAutolock lock(InputServer::gInputDeviceListLocker); 149 150 input_device_ref *device = NULL; 151 for (int i = 0; NULL != (device = devices[i]); i++) { 152 if (device->type != B_POINTING_DEVICE 153 && device->type != B_KEYBOARD_DEVICE 154 && device->type != B_UNDEFINED_DEVICE) 155 continue; 156 157 bool found = false; 158 for (int j = InputServer::gInputDeviceList.CountItems() - 1; j >= 0; j--) { 159 InputDeviceListItem* item = (InputDeviceListItem*)InputServer::gInputDeviceList.ItemAt(j); 160 if (!item) 161 continue; 162 163 if (strcmp(device->name, item->mDev.name) == 0) { 164 found = true; 165 break; 166 } 167 } 168 169 if (!found) { 170 PRINT(("RegisterDevices not found %s\n", device->name)); 171 InputServer::gInputDeviceList.AddItem(new InputDeviceListItem(this, *device) ); 172 InputServer::StartStopDevices(this, true); 173 } else { 174 PRINT(("RegisterDevices found %s\n", device->name)); 175 } 176 } 177 178 return B_OK; 179 } 180 181 182 /** 183 * Method: BInputServerDevice::UnregisterDevices() 184 * Descr: 185 */ 186 status_t 187 BInputServerDevice::UnregisterDevices(input_device_ref **devices) 188 { 189 CALLED(); 190 191 BAutolock lock(InputServer::gInputDeviceListLocker); 192 193 input_device_ref *device = NULL; 194 for (int i = 0; NULL != (device = devices[i]); i++) { 195 196 for (int j = InputServer::gInputDeviceList.CountItems() - 1; j >= 0; j--) { 197 InputDeviceListItem* item = (InputDeviceListItem*)InputServer::gInputDeviceList.ItemAt(j); 198 if (!item) 199 continue; 200 201 if (strcmp(device->name, item->mDev.name) == 0) { 202 Stop(item->mDev.name, item->mDev.cookie); 203 InputServer::gInputDeviceList.RemoveItem(j); 204 break; 205 } 206 } 207 } 208 209 return B_OK; 210 } 211 212 213 /** 214 * Method: BInputServerDevice::EnqueueMessage() 215 * Descr: 216 */ 217 status_t 218 BInputServerDevice::EnqueueMessage(BMessage *message) 219 { 220 return ((InputServer*)be_app)->EnqueueDeviceMessage(message); 221 } 222 223 224 /** 225 * Method: BInputServerDevice::StartMonitoringDevice() 226 * Descr: 227 */ 228 status_t 229 BInputServerDevice::StartMonitoringDevice(const char *device) 230 { 231 CALLED(); 232 PRINT(("StartMonitoringDevice %s\n", device)); 233 234 return InputServer::gDeviceManager.StartMonitoringDevice(fOwner, device); 235 } 236 237 238 /** 239 * Method: BInputServerDevice::StopMonitoringDevice() 240 * Descr: 241 */ 242 status_t 243 BInputServerDevice::StopMonitoringDevice(const char *device) 244 { 245 CALLED(); 246 return InputServer::gDeviceManager.StopMonitoringDevice(fOwner, device); 247 } 248 249 /** 250 ///////////////////////// Below this line is reserved functions ///////////////////////////// 251 */ 252 253 254 /** 255 * Method: BInputServerDevice::_ReservedInputServerDevice1() 256 * Descr: 257 */ 258 void 259 BInputServerDevice::_ReservedInputServerDevice1() 260 { 261 } 262 263 264 /** 265 * Method: BInputServerDevice::_ReservedInputServerDevice2() 266 * Descr: 267 */ 268 void 269 BInputServerDevice::_ReservedInputServerDevice2() 270 { 271 } 272 273 274 /** 275 * Method: BInputServerDevice::_ReservedInputServerDevice3() 276 * Descr: 277 */ 278 void 279 BInputServerDevice::_ReservedInputServerDevice3() 280 { 281 } 282 283 284 /** 285 * Method: BInputServerDevice::_ReservedInputServerDevice4() 286 * Descr: 287 */ 288 void 289 BInputServerDevice::_ReservedInputServerDevice4() 290 { 291 } 292 293 294