NXWidgets: ckeyboard.hxx Source File

NXWidgets 1.19

ckeyboard.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/nxwm/include/keyboard.hxx
3 *
4 * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
5 * Author: Gregory Nutt <gnutt@nuttx.org>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18 * me be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36 #ifndef __NXWM_INCLUDE_CKEYBOARD_HXX
37 #define __NXWM_INCLUDE_CKEYBOARD_HXX
38
39 /****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43 #include <nuttx/nx/nxglib.h>
44
45 #include <semaphore.h>
46 #include <pthread.h>
47
48 #include <nuttx/input/touchscreen.h>
49
50 #include "cnxserver.hxx"
51 #include "ccalibration.hxx"
52
53 /****************************************************************************
54 * Pre-processor Definitions
55 ****************************************************************************/
56
57 /****************************************************************************
58 * Implementation Classes
59 ****************************************************************************/
60
61 namespace NxWM
62 {
63 /**
64 * The CKeyboard class provides the the calibration window and obtains
65 * callibration data.
66 */
67
68 class CKeyboard
69 {
70 private:
71 /**
72 * The state of the listener thread.
73 */
74
75 enum EListenerState
76 {
77 LISTENER_NOTRUNNING = 0, /**< The listener thread has not yet been started */
78 LISTENER_STARTED, /**< The listener thread has been started, but is not yet running */
79 LISTENER_RUNNING, /**< The listener thread is running normally */
80 LISTENER_STOPREQUESTED, /**< The listener thread has been requested to stop */
81 LISTENER_TERMINATED, /**< The listener thread terminated normally */
82 LISTENER_FAILED /**< The listener thread terminated abnormally */
83 };
84
85 /**
86 * CKeyboard state data
87 */
88
89 NXWidgets::CNxServer *m_server; /**< The current NX server */
90 int m_kbdFd; /**< File descriptor of the opened keyboard device */
91 pthread_t m_thread; /**< The listener thread ID */
92 volatile enum EListenerState m_state; /**< The state of the listener thread */
93 sem_t m_waitSem; /**< Used to synchronize with the listener thread */
94
95 /**
96 * Open the keyboard device. Not very interesting for the case of
97 * standard device but much more interesting for a USB keyboard device
98 * that may disappear when the keyboard is disconnect but later reappear
99 * when the keyboard is reconnected. In this case, this function will
100 * not return until the keyboard device was successfully opened (or
101 * until an irrecoverable error occurs.
102 *
103 * Opens the keyboard device specified by CONFIG_NXWM_KEYBOARD_DEVPATH.
104 *
105 * @return On success, then method returns a valid file descriptor that
106 * can be used to redirect stdin. A negated errno value is returned
107 * if an irrecoverable error occurs.
108 */
109
110 inline int open(void);
111
112 /**
113 * This is the heart of the keyboard listener thread. It contains the
114 * actual logic that listeners for and dispatches keyboard events to the
115 * NX server.
116 *
117 * @return If the session terminates gracefully (i.e., because >m_state
118 * is no longer equal to LISTENER_RUNNING, then method returns OK. A
119 * negated errno value is returned if an error occurs while reading from
120 * the keyboard device. A read error, depending upon the type of the
121 * error, may simply indicate that a USB keyboard was removed and we
122 * should wait for the keyboard to be connected.
123 */
124
125 inline int session(void);
126
127 /**
128 * The keyboard listener thread. This is the entry point of a thread
129 * that listeners for and dispatches keyboard events to the NX server.
130 * It simply opens the keyboard device (using CKeyboard::open()) and
131 * executes the session (via CKeyboard::session()).
132 *
133 * If an errors while reading from the keyboard device AND we are
134 * configured to use a USB keyboard, then this function will wait for
135 * the USB keyboard to be re-connected.
136 *
137 * @param arg. The CKeyboard 'this' pointer cast to a void*.
138 * @return This function normally does not return but may return NULL on
139 * error conditions.
140 */
141
142 static FAR void *listener(FAR void *arg);
143
144 public:
145
146 /**
147 * CKeyboard Constructor
148 *
149 * @param server. An instance of the NX server. This will be needed for
150 * injecting mouse data.
151 */
152
153 CKeyboard(NXWidgets::CNxServer *server);
154
155 /**
156 * CKeyboard Destructor
157 */
158
159 ~CKeyboard(void);
160
161 /**
162 * Start the keyboard listener thread.
163 *
164 * @return True if the keyboard listener thread was correctly started.
165 */
166
167 bool start(void);
168 };
169 }
170
171 #endif // __NXWM_INCLUDE_CKEYBOARD_HXX
NxWM::CKeyboard::LISTENER_NOTRUNNING
Definition: ckeyboard.hxx:77
NxWM::CKeyboard::m_state
enum EListenerState m_state
Definition: ckeyboard.hxx:92
NxWM::CKeyboard::CKeyboard
CKeyboard(NXWidgets::CNxServer *server)
Definition: ckeyboard.cxx:71
NxWM::CKeyboard::EListenerState
EListenerState
Definition: ckeyboard.hxx:75
NxWM::CKeyboard::session
int session(void)
Definition: ckeyboard.cxx:247
NxWM::CKeyboard
Definition: ckeyboard.hxx:68
NxWM::CKeyboard::LISTENER_FAILED
Definition: ckeyboard.hxx:82
NxWM
Definition: capplicationwindow.hxx:66
NxWM::CKeyboard::LISTENER_STOPREQUESTED
Definition: ckeyboard.hxx:80
NxWM::CKeyboard::listener
static FAR void * listener(FAR void *arg)
Definition: ckeyboard.cxx:325
NxWM::CKeyboard::~CKeyboard
~CKeyboard(void)
Definition: ckeyboard.cxx:86
NxWM::CKeyboard::start
bool start(void)
Definition: ckeyboard.cxx:112
NxWM::CKeyboard::m_server
NXWidgets::CNxServer * m_server
Definition: ckeyboard.hxx:89
NxWM::CKeyboard::open
int open(void)
Definition: ckeyboard.cxx:174
NxWM::CKeyboard::m_waitSem
sem_t m_waitSem
Definition: ckeyboard.hxx:93
NxWM::CKeyboard::LISTENER_STARTED
Definition: ckeyboard.hxx:78
NxWM::CKeyboard::m_kbdFd
int m_kbdFd
Definition: ckeyboard.hxx:90
cnxserver.hxx
NxWM::CKeyboard::LISTENER_TERMINATED
Definition: ckeyboard.hxx:81
NxWM::CKeyboard::m_thread
pthread_t m_thread
Definition: ckeyboard.hxx:91
NxWM::CKeyboard::LISTENER_RUNNING
Definition: ckeyboard.hxx:79
NXWidgets::CNxServer
Definition: cnxserver.hxx:80
ccalibration.hxx