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