xref: /haiku/src/add-ons/input_server/devices/wacom/MasterServerDevice.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 /*
2  * Copyright 2005-2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  */
5 #ifndef MASTER_SERVER_DEVICE_H
6 #define MASTER_SERVER_DEVICE_H
7 
8 #include <stdio.h>
9 
10 #include <add-ons/input_server/InputServerDevice.h>
11 #include <List.h>
12 #include <Locker.h>
13 #include <String.h>
14 
15 // export this for the input_server
16 extern "C" _EXPORT BInputServerDevice* instantiate_input_device();
17 
18 class MasterServerDevice : public BInputServerDevice {
19  public:
20 							MasterServerDevice();
21 	virtual					~MasterServerDevice();
22 
23 							// BInputServerDevice
24 	virtual status_t		InitCheck();
25 	virtual status_t		SystemShuttingDown();
26 
27 	virtual status_t		Start(const char* device, void* cookie);
28 	virtual	status_t		Stop(const char* device, void* cookie);
29 	virtual status_t		Control(const char	*device,
30 									void		*cookie,
31 									uint32		code,
32 									BMessage	*message);
33 
34 							// MasterServerDevice
35 			bigtime_t		DoubleClickSpeed() const
36 								{ return fDblClickSpeed; }
37 			const float*	AccelerationTable() const
38 								{ return fAccelerationTable; }
39 
40 private:
41 			void			_SearchDevices();
42 
43 			void			_StopAll();
44 			void			_AddDevice(const char* path);
45 			void			_HandleNodeMonitor(BMessage* message);
46 
47 			void			_CalculateAccelerationTable();
48 
49 							// thread function for watching
50 							// the status of master device
51 //	static	int32			_ps2_disabler(void* cookie);
52 //			void			_StartPS2DisablerThread();
53 //			void			_StopPS2DisablerThread();
54 
55 			bool			_LockDevices();
56 			void			_UnlockDevices();
57 
58 			// list of mice objects
59 			BList			fDevices;
60 	volatile bool			fActive;
61 
62 			// global stuff for all mice objects
63 			int32			fSpeed;
64 			int32			fAcceleration;
65 			bigtime_t		fDblClickSpeed;
66 			float			fAccelerationTable[256];
67 
68 			// support halting the PS/2 mouse thread as long as we exist
69 			thread_id		fPS2DisablerThread;
70 			BLocker			fDeviceLock;
71 };
72 
73 #ifndef DEBUG
74 #	define DEBUG 0
75 #endif
76 
77 #if DEBUG
78 #	undef PRINT
79 	inline void _iprint(const char* fmt, ...) {
80 		FILE* log = fopen("/var/log/wacom.log", "a");
81 		va_list ap;
82 		va_start(ap, fmt);
83 		vfprintf(log, fmt, ap);
84 		va_end(ap);
85 		fflush(log);
86 		fclose(log);
87        }
88 #	define PRINT(x)	_iprint x
89 #else
90 #	define PRINT(x)
91 #endif
92 
93 
94 #endif	// MASTER_SERVER_DEVICE_H
95