1 /*****************************************************************************/ 2 // Keyboard input server device addon 3 // Written by Jérôme Duval 4 // 5 // KeyboardInputDevice.h 6 // 7 // Copyright (c) 2004 Haiku Project 8 // 9 // Permission is hereby granted, free of charge, to any person obtaining a 10 // copy of this software and associated documentation files (the "Software"), 11 // to deal in the Software without restriction, including without limitation 12 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 // and/or sell copies of the Software, and to permit persons to whom the 14 // Software is furnished to do so, subject to the following conditions: 15 // 16 // The above copyright notice and this permission notice shall be included 17 // in all copies or substantial portions of the Software. 18 // 19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 // DEALINGS IN THE SOFTWARE. 26 /*****************************************************************************/ 27 #ifndef __KEYBOARDINPUTDEVICE_H 28 #define __KEYBOARDINPUTDEVICE_H 29 30 #include "Keymap.h" 31 #include "TMWindow.h" 32 #include <InputServerDevice.h> 33 #include <List.h> 34 #include <stdio.h> 35 #include "kb_mouse_settings.h" 36 37 class KeyboardInputDevice; 38 39 struct keyboard_device { 40 keyboard_device(const char *path); 41 ~keyboard_device(); 42 43 KeyboardInputDevice *owner; 44 input_device_ref device_ref; 45 char path[B_PATH_NAME_LENGTH]; 46 int fd; 47 thread_id device_watcher; 48 kb_settings settings; 49 volatile bool active; 50 bool isAT; 51 uint32 modifiers; 52 }; 53 54 55 class KeyboardInputDevice : public BInputServerDevice { 56 public: 57 KeyboardInputDevice(); 58 ~KeyboardInputDevice(); 59 60 virtual status_t InitCheck(); 61 62 virtual status_t Start(const char *name, void *cookie); 63 virtual status_t Stop(const char *name, void *cookie); 64 65 virtual status_t Control(const char *name, void *cookie, 66 uint32 command, BMessage *message); 67 68 virtual status_t SystemShuttingDown(); 69 #ifdef DEBUG 70 static FILE *sLogFile; 71 #endif 72 private: 73 status_t HandleMonitor(BMessage *message); 74 status_t InitFromSettings(void *cookie, uint32 opcode = 0); 75 void RecursiveScan(const char *directory); 76 77 status_t AddDevice(const char *path); 78 status_t RemoveDevice(const char *path); 79 80 static int32 DeviceWatcher(void *arg); 81 82 void SetLeds(keyboard_device *device); 83 84 BList fDevices; 85 Keymap fKeymap; 86 TMWindow *fTMWindow; 87 }; 88 89 extern "C" BInputServerDevice *instantiate_input_device(); 90 91 #if DEBUG 92 inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \ 93 fputs(buf, KeyboardInputDevice::sLogFile); fflush(KeyboardInputDevice::sLogFile); } 94 #define LOG_ERR(text...) LOG(text) 95 #else 96 #define LOG(text...) 97 #define LOG_ERR(text...) fprintf(stderr, text) 98 #endif 99 100 #define CALLED() LOG("%s\n", __PRETTY_FUNCTION__) 101 102 #endif 103 104