NXWidgets: cnxserver.hxx Source File

NXWidgets 1.19

cnxserver.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cnxserver.hxx
3 *
4 * Copyright (C) 2012 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 __INCLUDE_CNXSERVER_HXX
37 #define __INCLUDE_CNXSERVER_HXX
38
39 /****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43 #include <nuttx/config.h>
44
45 #include <stdint.h>
46 #include <stdbool.h>
47 #include <semaphore.h>
48
49 #include <nuttx/nx/nx.h>
50
51 #include "cnxwindow.hxx"
52 #include "cnxtkwindow.hxx"
53 #include "cbgwindow.hxx"
54
55 /****************************************************************************
56 * Pre-Processor Definitions
57 ****************************************************************************/
58
59 /****************************************************************************
60 * Implementation Classes
61 ****************************************************************************/
62
63 #if defined(__cplusplus)
64
65 namespace NXWidgets
66 {
67 /**
68 * Forward references
69 */
70
71 class CBgWindow;
72
73 /**
74 * This class represents the NX server. It includes methods to connect to
75 * and disconnect form the NX server, methods to manage the background, and
76 * "factory" methods to create window objects on the NX server. NXWidget
77 * objects them may be created on the window objects.
78 */
79
80 class CNxServer
81 {
82 private:
83 FAR NX_DRIVERTYPE *m_hDevice; /**< LCD/Framebuffer device handle */
84 NXHANDLE m_hNxServer; /**< NX server handle */
85 volatile bool m_running; /**< True: The listener thread is running */
86 volatile bool m_connected; /**< True: Connected to the server */
87 volatile bool m_stop; /**< True: Waiting for the listener thread to stop */
88 sem_t m_connsem; /**< Wait for server connection */
89 static uint8_t m_nServers; /**< The number of NX server instances */
90
91 /**
92 * NX listener thread. This is the entry point of a thread that listeners for and
93 * dispatches events from the NX server.
94 */
95
96 static FAR void *listener(FAR void *arg);
97
98 public:
99
100 /**
101 * CNXServer constructor. The CNxServer is a normally singleton. However, that
102 * not enforced: This constructor could run more than one in the situation where
103 * there are multiple physical displays. However, that configuration has never
104 * been texted.
105 */
106
107 CNxServer(void);
108
109 /**
110 * CNXServer destructor
111 */
112
113 ~CNxServer(void);
114
115 /**
116 * Connect to the NX Server
117 */
118
119 virtual bool connect(void);
120
121 /**
122 * Disconnect from the NX Server
123 */
124
125 virtual void disconnect(void);
126
127 /**
128 * Get the NX server handle
129 *
130 * @return The NX server handler (NULL is not connected)
131 */
132
133 inline NXHANDLE getServer(void)
134 {
135 return m_hNxServer;
136 }
137
138 /**
139 * Test if we are connected to the NX server.
140 *
141 * @return True is connected; false is not connected.
142 */
143
144 inline bool connected(void)
145 {
146 return m_connected;
147 }
148
149 /**
150 * Set the background color
151 */
152
153 inline bool setBackgroundColor(nxgl_mxpixel_t color)
154 {
155 return nx_setbgcolor(m_hNxServer, &color) == OK;
156 }
157
158 /**
159 * Get an instance of a raw NX window.
160 */
161
162 inline CNxWindow *createRawWindow(CWidgetControl *widgetControl)
163 {
164 return new CNxWindow(m_hNxServer, widgetControl);
165 }
166
167 /**
168 * Get an instance of the framed NX window.
169 */
170
171 inline CNxTkWindow *createFramedWindow(CWidgetControl *widgetControl)
172 {
173 return new CNxTkWindow(m_hNxServer, widgetControl);
174 }
175
176 /**
177 * Get an instance of the background window.
178 */
179
180 inline CBgWindow *getBgWindow(CWidgetControl *widgetControl)
181 {
182 return new CBgWindow(m_hNxServer, widgetControl);
183 }
184 };
185 }
186
187 #endif // __cplusplus
188
189 #endif // __INCLUDE_CNXSERVER_HXX
NXWidgets::CNxServer::~CNxServer
~CNxServer(void)
Definition: cnxserver.cxx:107
NXWidgets::CNxServer::getBgWindow
CBgWindow * getBgWindow(CWidgetControl *widgetControl)
Definition: cnxserver.hxx:180
NXWidgets::CWidgetControl
Definition: cwidgetcontrol.hxx:95
NXWidgets::CNxServer::m_stop
volatile bool m_stop
Definition: cnxserver.hxx:87
NXWidgets::CNxServer::getServer
NXHANDLE getServer(void)
Definition: cnxserver.hxx:133
NXWidgets::CNxServer::disconnect
virtual void disconnect(void)
Definition: cnxserver.cxx:231
NXWidgets::CNxServer::setBackgroundColor
bool setBackgroundColor(nxgl_mxpixel_t color)
Definition: cnxserver.hxx:153
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CNxServer::connect
virtual bool connect(void)
Definition: cnxserver.cxx:126
NXWidgets::CNxServer::listener
static FAR void * listener(FAR void *arg)
Definition: cnxserver.cxx:263
NXWidgets::CNxServer::m_connsem
sem_t m_connsem
Definition: cnxserver.hxx:88
NXWidgets::CNxServer::m_nServers
static uint8_t m_nServers
Definition: cnxserver.hxx:89
cnxwindow.hxx
NXWidgets::CNxServer::createFramedWindow
CNxTkWindow * createFramedWindow(CWidgetControl *widgetControl)
Definition: cnxserver.hxx:171
cbgwindow.hxx
NXWidgets::CNxServer::CNxServer
CNxServer(void)
Definition: cnxserver.cxx:81
NXWidgets::CNxServer::createRawWindow
CNxWindow * createRawWindow(CWidgetControl *widgetControl)
Definition: cnxserver.hxx:162
NXWidgets::CNxServer::m_running
volatile bool m_running
Definition: cnxserver.hxx:85
cnxtkwindow.hxx
NXWidgets::CNxServer::m_connected
volatile bool m_connected
Definition: cnxserver.hxx:86
NXWidgets::CNxTkWindow
Definition: cnxtkwindow.hxx:84
NXWidgets::CNxServer::connected
bool connected(void)
Definition: cnxserver.hxx:144
NXWidgets::CNxServer
Definition: cnxserver.hxx:80
NXWidgets::CBgWindow
Definition: cbgwindow.hxx:84
NXWidgets::CNxServer::m_hNxServer
NXHANDLE m_hNxServer
Definition: cnxserver.hxx:84
NXWidgets::CNxServer::m_hDevice
FAR NX_DRIVERTYPE * m_hDevice
Definition: cnxserver.hxx:83
NXWidgets::CNxWindow
Definition: cnxwindow.hxx:86