xref: /haiku/src/servers/input/AddOnManager.h (revision 4a850ca730d8282b5b924e49e09b4ba4d6db7f54)
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 <set>
25 
26 #include "PathList.h"
27 
28 
29 using namespace BPrivate;
30 
31 class AddOnManager : public AddOnMonitor {
32 public:
33 								AddOnManager();
34 								~AddOnManager();
35 
36 	virtual	void 				MessageReceived(BMessage* message);
37 
38 			void				LoadState();
39 			void				SaveState();
40 
41 			status_t			StartMonitoringDevice(DeviceAddOn* addOn,
42 									const char* device);
43 			status_t			StopMonitoringDevice(DeviceAddOn* addOn,
44 									const char* device);
45 
46 private:
47 			void				_RegisterAddOns();
48 			void				_UnregisterAddOns();
49 
50 			status_t			_RegisterAddOn(BEntry& entry);
51 			status_t			_UnregisterAddOn(BEntry& entry);
52 
53 			bool				_IsDevice(const char* path) const;
54 			bool				_IsFilter(const char* path) const;
55 			bool				_IsMethod(const char* path) const;
56 
57 			status_t			_RegisterDevice(BInputServerDevice* device,
58 									const entry_ref& ref, image_id image);
59 			status_t			_RegisterFilter(BInputServerFilter* filter,
60 									const entry_ref& ref, image_id image);
61 			status_t			_RegisterMethod(BInputServerMethod* method,
62 									const entry_ref& ref, image_id image);
63 
64 			status_t			_HandleFindDevices(BMessage* message,
65 									BMessage* reply);
66 			status_t			_HandleWatchDevices(BMessage* message,
67 									BMessage* reply);
68 			status_t			_HandleNotifyDevice(BMessage* message,
69 									BMessage* reply);
70 			status_t			_HandleIsDeviceRunning(BMessage* message,
71 									BMessage* reply);
72 			status_t			_HandleStartStopDevices(BMessage* message,
73 									BMessage* reply);
74 			status_t			_HandleControlDevices(BMessage* message,
75 									BMessage* reply);
76 			status_t			_HandleSystemShuttingDown(BMessage* message,
77 									BMessage* reply);
78 			status_t			_HandleMethodReplicant(BMessage* message,
79 									BMessage* reply);
80 			void				_HandleDeviceMonitor(BMessage* message);
81 
82 			void				_LoadReplicant();
83 			void				_UnloadReplicant();
84 			int32				_GetReplicantAt(BMessenger target,
85 									int32 index) const;
86 			status_t			_GetReplicantName(BMessenger target,
87 									int32 uid, BMessage* reply) const;
88 			status_t			_GetReplicantView(BMessenger target, int32 uid,
89 									BMessage* reply) const;
90 
91 			status_t			_AddDevicePath(DeviceAddOn* addOn,
92 									const char* path, bool& newPath);
93 			status_t			_RemoveDevicePath(DeviceAddOn* addOn,
94 									const char* path, bool& lastPath);
95 
96 private:
97 	class MonitorHandler;
98 	friend class MonitorHandler;
99 
100 	template<typename T> struct add_on_info {
101 		add_on_info()
102 			:
103 			image(-1), add_on(NULL)
104 		{
105 		}
106 
107 		~add_on_info()
108 		{
109 			delete add_on;
110 			if (image >= 0)
111 				unload_add_on(image);
112 		}
113 
114 		entry_ref				ref;
115 		image_id				image;
116 		T*						add_on;
117 	};
118 	typedef struct add_on_info<BInputServerDevice> device_info;
119 	typedef struct add_on_info<BInputServerFilter> filter_info;
120 	typedef struct add_on_info<BInputServerMethod> method_info;
121 
122 			BObjectList<device_info> fDeviceList;
123 			BObjectList<filter_info> fFilterList;
124 			BObjectList<method_info> fMethodList;
125 
126 			BObjectList<DeviceAddOn> fDeviceAddOns;
127 			PathList			fDevicePaths;
128 
129 			MonitorHandler*		fHandler;
130 			std::set<BMessenger> fWatcherMessengerList;
131 
132 			bool				fSafeMode;
133 };
134 
135 #endif	// ADD_ON_MANAGER_H
136