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 17DeviceAddOn::DeviceAddOn(BInputServerDevice *device) 18 : 19 fDevice(device) 20{ 21} 22 23 24DeviceAddOn::~DeviceAddOn() 25{ 26 while (const char* path = fMonitoredPaths.PathAt(0)) { 27 gInputServer->AddOnManager()->StopMonitoringDevice(this, path); 28 } 29} 30 31 32bool 33DeviceAddOn::HasPath(const char* path) const 34{ 35 return fMonitoredPaths.HasPath(path); 36} 37 38 39status_t 40DeviceAddOn::AddPath(const char* path) 41{ 42 return fMonitoredPaths.AddPath(path); 43} 44 45 46status_t 47DeviceAddOn::RemovePath(const char* path) 48{ 49 return fMonitoredPaths.RemovePath(path); 50} 51 52 53int32 54DeviceAddOn::CountPaths() const 55{ 56 return fMonitoredPaths.CountPaths(); 57} 58 59 60// #pragma mark - 61 62 63BInputServerDevice::BInputServerDevice() 64{ 65 fOwner = new(std::nothrow) DeviceAddOn(this); 66} 67 68 69BInputServerDevice::~BInputServerDevice() 70{ 71 CALLED(); 72 73 gInputServer->UnregisterDevices(*this); 74 delete fOwner; 75} 76 77 78status_t 79BInputServerDevice::InitCheck() 80{ 81 if (fOwner == NULL) 82 return B_NO_MEMORY; 83 return B_OK; 84} 85 86 87status_t 88BInputServerDevice::SystemShuttingDown() 89{ 90 return B_OK; 91} 92 93 94status_t 95BInputServerDevice::Start(const char* device, void* cookie) 96{ 97 return B_OK; 98} 99 100 101status_t 102BInputServerDevice::Stop(const char* device, void* cookie) 103{ 104 return B_OK; 105} 106 107 108status_t 109BInputServerDevice::Control(const char* device, void* cookie, 110 uint32 code, BMessage* message) 111{ 112 return B_OK; 113} 114 115 116status_t 117BInputServerDevice::RegisterDevices(input_device_ref** devices) 118{ 119 CALLED(); 120 return gInputServer->RegisterDevices(*this, devices); 121} 122 123 124status_t 125BInputServerDevice::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 134status_t 135BInputServerDevice::EnqueueMessage(BMessage* message) 136{ 137 return gInputServer->EnqueueDeviceMessage(message); 138} 139 140 141status_t 142BInputServerDevice::StartMonitoringDevice(const char* device) 143{ 144 CALLED(); 145 PRINT(("StartMonitoringDevice %s\n", device)); 146 147 return gInputServer->AddOnManager()->StartMonitoringDevice(fOwner, device); 148} 149 150 151status_t 152BInputServerDevice::StopMonitoringDevice(const char* device) 153{ 154 return gInputServer->AddOnManager()->StopMonitoringDevice(fOwner, device); 155} 156 157 158status_t 159BInputServerDevice::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 185void BInputServerDevice::_ReservedInputServerDevice1() {} 186void BInputServerDevice::_ReservedInputServerDevice2() {} 187void BInputServerDevice::_ReservedInputServerDevice3() {} 188void BInputServerDevice::_ReservedInputServerDevice4() {} 189