The Pedigree Project  0.1
InputManager.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef MACHINE_INPUT_MANAGER_H
21 #define MACHINE_INPUT_MANAGER_H
22 
23 #include "pedigree/kernel/Spinlock.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/process/Semaphore.h"
26 #include "pedigree/kernel/processor/types.h"
27 #include "pedigree/kernel/utilities/List.h"
28 #include "pedigree/kernel/utilities/new"
29 
30 class Thread;
31 
36 {
37  public:
40  const static int Key = 1;
41  const static int Mouse = 2;
42  const static int Joystick = 4;
43  const static int RawKey = 8;
44  const static int MachineKey = 16; // machine-specific key codes
45  const static int Unknown = 255;
46 
47  typedef int CallbackType;
48 
53  {
54  CallbackType type;
55  void *meta;
56 
57  union
58  {
59  struct
60  {
61  uint64_t key;
62  } key;
63  struct
64  {
65  ssize_t relx;
66  ssize_t rely;
67  ssize_t relz;
68 
69  bool buttons[64];
70  } pointy;
71  struct
72  {
75  uint8_t scancode;
76 
78  bool keyUp;
79  } rawkey;
80  struct
81  {
83  uint8_t scancode;
84 
86  bool keyUp;
87  } machinekey;
88  } data;
89  };
90 
92  typedef void (*callback_t)(InputNotification &);
93 
95  InputManager();
96 
98  virtual ~InputManager();
99 
101  void initialise();
102 
104  void shutdown();
105 
108  {
109  return m_Instance;
110  }
111 
113  void keyPressed(uint64_t key);
114 
117  void rawKeyUpdate(uint8_t scancode, bool bKeyUp);
118 
120  void machineKeyUpdate(uint8_t scancode, bool bKeyUp);
121 
123  void mouseUpdate(
124  ssize_t relX, ssize_t relY, ssize_t relZ, uint32_t buttonBitmap);
125 
127  void joystickUpdate(
128  ssize_t relX, ssize_t relY, ssize_t relZ, uint32_t buttonBitmap);
129 
131  void installCallback(
132  CallbackType filter, callback_t callback, void *meta = 0,
133  Thread *pThread = 0, uintptr_t param = 0);
134 
136  void
137  removeCallback(callback_t callback, void *meta = 0, Thread *pThread = 0);
138 
142  bool removeCallbackByThread(Thread *pThread);
143 
145  static int trampoline(void *ptr);
146 
148  void mainThread();
149 
151  bool isActive() const
152  {
153  return m_bActive;
154  }
155 
156  private:
159 
162  void putNotification(InputNotification *note);
163 
167  {
169  callback_t func;
170 
171 #ifdef THREADS
172  Thread *pThread;
176 #endif
177 
180  uintptr_t nParam;
181 
183  CallbackType filter;
184 
186  void *meta;
187  };
188 
191 
197 
200 
201 #ifdef THREADS
202  Semaphore m_InputQueueSize;
204 
207 #endif
208 
210  bool m_bActive;
211 };
212 
213 #endif
void * meta
Meta pointer for the InputNotifications we generate.
Definition: InputManager.h:186
static InputManager m_Instance
Static instance.
Definition: InputManager.h:158
Spinlock m_QueueLock
Definition: InputManager.h:196
bool isActive() const
Returns whether the instance is creating notifications.
Definition: InputManager.h:151
List< CallbackItem * > m_Callbacks
Callback list.
Definition: InputManager.h:199
List< InputNotification * > m_InputQueue
Input queue (for distribution to applications)
Definition: InputManager.h:190
Definition: List.h:64
bool keyUp
Whether this is a keyUp event or not.
Definition: InputManager.h:78
callback_t func
The handler function.
Definition: InputManager.h:169
Thread * m_pThread
Thread object for our worker thread.
Definition: InputManager.h:206
uint8_t scancode
Machine-specific scancode for the key.
Definition: InputManager.h:75
CallbackType filter
Filter for this callback.
Definition: InputManager.h:183
bool m_bActive
Are we active?
Definition: InputManager.h:210
static InputManager & instance()
Singleton design.
Definition: InputManager.h:107
Definition: Thread.h:54