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