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 _HandleNotifyDevice(BMessage* message, 67 BMessage* reply); 68 status_t _HandleIsDeviceRunning(BMessage* message, 69 BMessage* reply); 70 status_t _HandleStartStopDevices(BMessage* message, 71 BMessage* reply); 72 status_t _HandleControlDevices(BMessage* message, 73 BMessage* reply); 74 status_t _HandleSystemShuttingDown(BMessage* message, 75 BMessage* reply); 76 status_t _HandleMethodReplicant(BMessage* message, 77 BMessage* reply); 78 void _HandleDeviceMonitor(BMessage* message); 79 80 void _LoadReplicant(); 81 void _UnloadReplicant(); 82 int32 _GetReplicantAt(BMessenger target, 83 int32 index) const; 84 status_t _GetReplicantName(BMessenger target, 85 int32 uid, BMessage* reply) const; 86 status_t _GetReplicantView(BMessenger target, int32 uid, 87 BMessage* reply) const; 88 89 status_t _AddDevicePath(DeviceAddOn* addOn, 90 const char* path, bool& newPath); 91 status_t _RemoveDevicePath(DeviceAddOn* addOn, 92 const char* path, bool& lastPath); 93 94 private: 95 class MonitorHandler; 96 friend class MonitorHandler; 97 98 template<typename T> struct add_on_info { 99 add_on_info() 100 : 101 image(-1), add_on(NULL) 102 { 103 } 104 105 ~add_on_info() 106 { 107 delete add_on; 108 if (image >= 0) 109 unload_add_on(image); 110 } 111 112 entry_ref ref; 113 image_id image; 114 T* add_on; 115 }; 116 typedef struct add_on_info<BInputServerDevice> device_info; 117 typedef struct add_on_info<BInputServerFilter> filter_info; 118 typedef struct add_on_info<BInputServerMethod> method_info; 119 120 BObjectList<device_info> fDeviceList; 121 BObjectList<filter_info> fFilterList; 122 BObjectList<method_info> fMethodList; 123 124 BObjectList<DeviceAddOn> fDeviceAddOns; 125 PathList fDevicePaths; 126 127 MonitorHandler* fHandler; 128 BMessenger fWatcherMessenger; 129 130 bool fSafeMode; 131 }; 132 133 #endif // ADD_ON_MANAGER_H 134