1 /* 2 * Copyright 2004-2013, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 * Jérôme Duval 8 * Marcus Overhagen 9 * John Scipione, jscipione@gmail.com 10 */ 11 #ifndef ADD_ON_MANAGER_H 12 #define ADD_ON_MANAGER_H 13 14 15 #include <InputServerDevice.h> 16 #include <InputServerFilter.h> 17 #include <InputServerMethod.h> 18 #include <Locker.h> 19 #include <Looper.h> 20 21 #include <AddOnMonitor.h> 22 #include <AddOnMonitorHandler.h> 23 24 #include "PathList.h" 25 26 27 using namespace BPrivate; 28 29 class AddOnManager : public AddOnMonitor { 30 public: 31 AddOnManager(); 32 ~AddOnManager(); 33 34 virtual void MessageReceived(BMessage* message); 35 36 void LoadState(); 37 void SaveState(); 38 39 status_t StartMonitoringDevice(DeviceAddOn* addOn, 40 const char* device); 41 status_t StopMonitoringDevice(DeviceAddOn* addOn, 42 const char* device); 43 44 private: 45 void _RegisterAddOns(); 46 void _UnregisterAddOns(); 47 48 status_t _RegisterAddOn(BEntry& entry); 49 status_t _UnregisterAddOn(BEntry& entry); 50 51 bool _IsDevice(const char* path) const; 52 bool _IsFilter(const char* path) const; 53 bool _IsMethod(const char* path) const; 54 55 status_t _RegisterDevice(BInputServerDevice* device, 56 const entry_ref& ref, image_id image); 57 status_t _RegisterFilter(BInputServerFilter* filter, 58 const entry_ref& ref, image_id image); 59 status_t _RegisterMethod(BInputServerMethod* method, 60 const entry_ref& ref, image_id image); 61 62 status_t _HandleFindDevices(BMessage* message, 63 BMessage* reply); 64 status_t _HandleWatchDevices(BMessage* message, 65 BMessage* reply); 66 status_t _HandleIsDeviceRunning(BMessage* message, 67 BMessage* reply); 68 status_t _HandleStartStopDevices(BMessage* message, 69 BMessage* reply); 70 status_t _HandleControlDevices(BMessage* message, 71 BMessage* reply); 72 status_t _HandleSystemShuttingDown(BMessage* message, 73 BMessage* reply); 74 status_t _HandleMethodReplicant(BMessage* message, 75 BMessage* reply); 76 void _HandleDeviceMonitor(BMessage* message); 77 78 void _LoadReplicant(); 79 void _UnloadReplicant(); 80 int32 _GetReplicantAt(BMessenger target, 81 int32 index) const; 82 status_t _GetReplicantName(BMessenger target, 83 int32 uid, BMessage* reply) const; 84 status_t _GetReplicantView(BMessenger target, int32 uid, 85 BMessage* reply) const; 86 87 status_t _AddDevicePath(DeviceAddOn* addOn, 88 const char* path, bool& newPath); 89 status_t _RemoveDevicePath(DeviceAddOn* addOn, 90 const char* path, bool& lastPath); 91 92 private: 93 class MonitorHandler; 94 friend class MonitorHandler; 95 96 template<typename T> struct add_on_info { 97 add_on_info() 98 : 99 image(-1), add_on(NULL) 100 { 101 } 102 103 ~add_on_info() 104 { 105 delete add_on; 106 if (image >= 0) 107 unload_add_on(image); 108 } 109 110 entry_ref ref; 111 image_id image; 112 T* add_on; 113 }; 114 typedef struct add_on_info<BInputServerDevice> device_info; 115 typedef struct add_on_info<BInputServerFilter> filter_info; 116 typedef struct add_on_info<BInputServerMethod> method_info; 117 118 BObjectList<device_info> fDeviceList; 119 BObjectList<filter_info> fFilterList; 120 BObjectList<method_info> fMethodList; 121 122 BObjectList<DeviceAddOn> fDeviceAddOns; 123 PathList fDevicePaths; 124 125 MonitorHandler* fHandler; 126 127 bool fSafeMode; 128 }; 129 130 #endif // ADD_ON_MANAGER_H 131