xref: /haiku/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2  * Copyright 2004-2008, Jérôme Duval. All rights reserved.
3  * Copyright 2008, Stephan Aßmus, superstippi@gmx.de.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef KEYBOARD_INPUT_DEVICE_H
7 #define KEYBOARD_INPUT_DEVICE_H
8 
9 
10 #include <Handler.h>
11 #include <InputServerDevice.h>
12 #include <Locker.h>
13 
14 #include <InputServerTypes.h>
15 #include <ObjectList.h>
16 
17 #include "Keymap.h"
18 #include "TeamMonitorWindow.h"
19 #include "kb_mouse_settings.h"
20 
21 
22 class KeyboardInputDevice;
23 
24 class KeyboardDevice : public BHandler {
25 public:
26 								KeyboardDevice(KeyboardInputDevice* owner,
27 									const char* path);
28 	virtual						~KeyboardDevice();
29 
30 	virtual	void				MessageReceived(BMessage* message);
31 			status_t			Start();
32 			void				Stop();
33 
34 			status_t			UpdateSettings(uint32 opcode = 0);
35 
36 			const char*			Path() const { return fPath; }
37 			input_device_ref*	DeviceRef() { return &fDeviceRef; }
38 
39 private:
40 	static	int32				_ControlThreadEntry(void* arg);
41 			int32				_ControlThread();
42 			void				_ControlThreadCleanup();
43 			void				_UpdateSettings(uint32 opcode);
44 			void				_UpdateLEDs();
45 			status_t			_EnqueueInlineInputMethod(int32 opcode,
46 									const char* string = NULL,
47 									bool confirmed = false,
48 									BMessage* keyDown = NULL);
49 
50 private:
51 			KeyboardInputDevice* fOwner;
52 			input_device_ref	fDeviceRef;
53 			char				fPath[B_PATH_NAME_LENGTH];
54 			int					fFD;
55 			thread_id			fThread;
56 			kb_settings			fSettings;
57 	volatile bool				fActive;
58 			bool				fIsAT;
59 	volatile bool				fInputMethodStarted;
60 			uint32				fModifiers;
61 			uint32				fCommandKey;
62 			uint32				fControlKey;
63 
64 	volatile bool				fUpdateSettings;
65 	volatile uint32				fSettingsCommand;
66 
67 			Keymap				fKeymap;
68 			BLocker				fKeymapLock;
69 };
70 
71 
72 class KeyboardInputDevice : public BInputServerDevice {
73 public:
74 								KeyboardInputDevice();
75 	virtual						~KeyboardInputDevice();
76 
77 	virtual	status_t			InitCheck();
78 
79 	virtual	status_t			Start(const char* name, void* cookie);
80 	virtual status_t			Stop(const char* name, void* cookie);
81 
82 	virtual status_t			Control(const char* name, void* cookie,
83 									uint32 command, BMessage* message);
84 
85 	virtual status_t			SystemShuttingDown();
86 
87 private:
88 	friend struct KeyboardDevice;
89 	// TODO: needed by the control thread to remove a dead device
90 	// find a better way...
91 
92 			status_t			_HandleMonitor(BMessage* message);
93 			void				_RecursiveScan(const char* directory);
94 
95 			KeyboardDevice*		_FindDevice(const char* path) const;
96 			status_t			_AddDevice(const char* path);
97 			status_t			_RemoveDevice(const char* path);
98 
99 			BObjectList<KeyboardDevice> fDevices;
100 			BLocker				fDeviceListLock;
101 			TeamMonitorWindow*	fTeamMonitorWindow;
102 };
103 
104 extern "C" BInputServerDevice* instantiate_input_device();
105 
106 #endif	// KEYBOARD_INPUT_DEVICE_H
107