From 500e0bf8574e8257e709d4a45a2d8b6c84b9a8c4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 29 Dec 2013 08:48:06 -0600 Subject: Move more files from graphics/nxmu to libnx/nxmu --- nuttx/ChangeLog | 1 + nuttx/Documentation/NXGraphicsSubsystem.html | 11 +- nuttx/graphics/nxmu/Make.defs | 1 - nuttx/graphics/nxmu/nx_eventhandler.c | 262 --------------------------- nuttx/graphics/nxmu/nx_eventnotify.c | 111 ------------ nuttx/graphics/nxsu/nx_constructwindow.c | 8 +- nuttx/graphics/nxsu/nx_openwindow.c | 2 +- nuttx/include/nuttx/nx/nx.h | 24 +-- nuttx/libnx/nxmu/Make.defs | 2 +- nuttx/libnx/nxmu/nx_eventhandler.c | 262 +++++++++++++++++++++++++++ nuttx/libnx/nxmu/nx_eventnotify.c | 111 ++++++++++++ 11 files changed, 397 insertions(+), 398 deletions(-) delete mode 100644 nuttx/graphics/nxmu/nx_eventhandler.c delete mode 100644 nuttx/graphics/nxmu/nx_eventnotify.c create mode 100644 nuttx/libnx/nxmu/nx_eventhandler.c create mode 100644 nuttx/libnx/nxmu/nx_eventnotify.c diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 75e8cbe78..a8d5ffa68 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -6331,4 +6331,5 @@ * Move graphics/nxfonts to libnx/nxfonts (2013-12-28). * Move graphics/nxtk to libnx/nxtk (2013-12-28). * syscalls: Need to add sem_timedwait() (2013-12-28) + * Move more files from graphics/nxmu to libnx/nxmu (2013-12-29). diff --git a/nuttx/Documentation/NXGraphicsSubsystem.html b/nuttx/Documentation/NXGraphicsSubsystem.html index 744607154..7d9c2d64e 100644 --- a/nuttx/Documentation/NXGraphicsSubsystem.html +++ b/nuttx/Documentation/NXGraphicsSubsystem.html @@ -3170,7 +3170,7 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height, It contains most of the important window management logic: clipping, window controls, window drawing, etc. -
graphics/nxsu +
graphics/nxsu1
This is the NX single user front end. When combined with the generic back-end (nxbe), it implements a single threaded, single user windowing system. @@ -3179,11 +3179,6 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height, The single user front-end is selected when CONFIG_NX_MULTIUSER is not defined in the NuttX configuration file. -
- NOTE: There is no nxsu sub-directory in nuttx/libnx. - That is because this separation of interfaces is only required in the kernel build mode and only the multi-user interfaces can be used with the kernel build. -
-
graphics/nxmu and libnx/nxmu
This is the NX multi user front end. When combined with the generic back-end (nxbe), it implements a @@ -3213,6 +3208,10 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
The NxConsole driver is built on top of NX and works with either the single-user or multi-user NX version. See include/nuttx/nx/nxconsole.h. +

+ 1There is no nxsu sub-directory in nuttx/libnx. + That is because this separation of interfaces is only required in the kernel build mode and only the multi-user interfaces can be used with the kernel build. +

diff --git a/nuttx/graphics/nxmu/Make.defs b/nuttx/graphics/nxmu/Make.defs index 41a660ba1..2f443c20f 100644 --- a/nuttx/graphics/nxmu/Make.defs +++ b/nuttx/graphics/nxmu/Make.defs @@ -35,7 +35,6 @@ NX_ASRCS = -NX_CSRCS = nx_eventhandler.c nx_eventnotify.c NX_CSRCS += nxmu_kbdin.c nxmu_mouse.c nxmu_openwindow.c nxmu_redrawreq.c NX_CSRCS += nxmu_releasebkgd.c nxmu_requestbkgd.c nxmu_reportposition.c NX_CSRCS += nxmu_sendclient.c nxmu_sendclientwindow.c nxmu_server.c diff --git a/nuttx/graphics/nxmu/nx_eventhandler.c b/nuttx/graphics/nxmu/nx_eventhandler.c deleted file mode 100644 index 815f9f583..000000000 --- a/nuttx/graphics/nxmu/nx_eventhandler.c +++ /dev/null @@ -1,262 +0,0 @@ -/**************************************************************************** - * graphics/nxmu/nx_eventhandler.c - * - * Copyright (C) 2008-2009, 2011-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "nxfe.h" - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nx_connected - * - * Description: - * The server has completed the connection and is ready. - * - ****************************************************************************/ - -static inline void nx_connected(FAR struct nxfe_conn_s *conn) -{ - DEBUGASSERT(conn->state == NX_CLISTATE_NOTCONNECTED); - conn->state = NX_CLISTATE_CONNECTED; -} - -/**************************************************************************** - * Name: nx_disconnected - ****************************************************************************/ - -static inline void nx_disconnected(FAR struct nxfe_conn_s *conn) -{ - /* Close the server and client MQs */ - - (void)mq_close(conn->cwrmq); - (void)mq_close(conn->crdmq); - - /* And free the client structure */ - - kfree(conn); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nx_eventhandler - * - * Description: - * The client code must call this function periodically to process - * incoming messages from the server. If CONFIG_NX_BLOCKING is defined, - * then this function not return until a server message is received. - * - * When CONFIG_NX_BLOCKING is not defined, the client must exercise - * caution in the looping to assure that it does not eat up all of - * the CPU bandwidth calling nx_eventhandler repeatedly. nx_eventnotify - * may be called to get a signal event whenever a new incoming server - * event is avaiable. - * - * Input Parameters: - * handle - the handle returned by nx_connect - * - * Return: - * OK: No errors occurred. If CONFIG_NX_BLOCKING is defined, then - * one or more server message was processed. - * ERROR: An error occurred and errno has been set appropriately. Of - * particular interest, it will return errno == EHOSTDOWN when the - * server is disconnected. After that event, the handle can no - * longer be used. - * - ****************************************************************************/ - -int nx_eventhandler(NXHANDLE handle) -{ - FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; - struct nxsvrmsg_s *msg; - struct nxbe_window_s *wnd; - uint8_t buffer[NX_MXCLIMSGLEN]; - int nbytes; - - /* Get the next message from our incoming message queue */ - - do - { - nbytes = mq_receive(conn->crdmq, buffer, NX_MXCLIMSGLEN, 0); - if (nbytes < 0) - { - /* EINTR is not an error. The wait was interrupted by a signal and - * we just need to try reading again. - */ - - if (errno != EINTR) - { - if (errno == EAGAIN) - { - /* EAGAIN is not an error. It occurs because the MQ is opened with - * O_NONBLOCK and there is no message available now. - */ - - return OK; - } - else - { - gdbg("mq_receive failed: %d\n", errno); - return ERROR; - } - } - } - } - while (nbytes < 0); - - DEBUGASSERT(nbytes >= sizeof(struct nxclimsg_s)); - - /* Dispatch the message appropriately */ - - msg = (struct nxsvrmsg_s *)buffer; - gvdbg("Received msgid=%d\n", msg->msgid); - switch (msg->msgid) - { - case NX_CLIMSG_CONNECTED: - nx_connected(conn); - break; - - case NX_CLIMSG_DISCONNECTED: - nx_disconnected(conn); - errno = EHOSTDOWN; - return ERROR; - - case NX_CLIMSG_REDRAW: - { - FAR struct nxclimsg_redraw_s *redraw = (FAR struct nxclimsg_redraw_s *)buffer; - wnd = redraw->wnd; - DEBUGASSERT(wnd); - if (wnd->cb->redraw) - { - wnd->cb->redraw((NXWINDOW)wnd, &redraw->rect, redraw->more, wnd->arg); - } - } - break; - - case NX_CLIMSG_NEWPOSITION: - { - FAR struct nxclimsg_newposition_s *postn = (FAR struct nxclimsg_newposition_s *)buffer; - wnd = postn->wnd; - DEBUGASSERT(wnd); - if (wnd->cb->position) - { - wnd->cb->position((NXWINDOW)wnd, &postn->size, &postn->pos, &postn->bounds, wnd->arg); - } - } - break; - -#ifdef CONFIG_NX_MOUSE - case NX_CLIMSG_MOUSEIN: - { - FAR struct nxclimsg_mousein_s *mouse = (FAR struct nxclimsg_mousein_s *)buffer; - wnd = mouse->wnd; - DEBUGASSERT(wnd); - if (wnd->cb->mousein) - { - wnd->cb->mousein((NXWINDOW)wnd, &mouse->pos, mouse->buttons, wnd->arg); - } - } - break; -#endif - -#ifdef CONFIG_NX_KBD - case NX_CLIMSG_KBDIN: - { - FAR struct nxclimsg_kbdin_s *kbd = (FAR struct nxclimsg_kbdin_s *)buffer; - wnd = kbd->wnd; - DEBUGASSERT(wnd); - if (wnd->cb->kbdin) - { - wnd->cb->kbdin((NXWINDOW)wnd, kbd->nch, kbd->ch, wnd->arg); - } - } - break; -#endif - - case NX_CLIMSG_BLOCKED: - { - FAR struct nxclimsg_blocked_s *blocked = (FAR struct nxclimsg_blocked_s *)buffer; - wnd = blocked->wnd; - DEBUGASSERT(wnd); - if (wnd->cb->blocked) - { - wnd->cb->blocked((NXWINDOW)wnd, wnd->arg, blocked->arg); - } - } - break; - - default: - gdbg("Unrecognized message opcode: %d\n", ((FAR struct nxsvrmsg_s *)buffer)->msgid); - break; - } - - return OK; -} - diff --git a/nuttx/graphics/nxmu/nx_eventnotify.c b/nuttx/graphics/nxmu/nx_eventnotify.c deleted file mode 100644 index 556c9fa93..000000000 --- a/nuttx/graphics/nxmu/nx_eventnotify.c +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * graphics/nxmu/nx_eventnotify.c - * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include "nxfe.h" - -#ifndef CONFIG_DISABLE_SIGNALS - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nx_eventnotify - * - * Description: - * Rather than calling nx_eventhandler periodically, the client may - * register to receive a signal when a server event is available. The - * client can then call nv_eventhandler() only when incoming events are - * available. - * - * Only one such event is issued. Upon receipt of the signal, if the client - * wishes further notifications, it must call nx_eventnotify again. - * - * Input Parameters: - * handle - the handle returned by nx_connect - * - * Return: - * OK: No errors occurred. If CONFIG_NX_BLOCKING is defined, then - * one or more server message was processed. - * ERROR: An error occurred and errno has been set appropriately - * - ****************************************************************************/ - -int nx_eventnotify(NXHANDLE handle, int signo) -{ - FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; - struct sigevent se; - - se.sigev_notify = SIGEV_SIGNAL; - se.sigev_signo = signo; - se.sigev_value.sival_ptr = (FAR void *)handle; - - return mq_notify(conn->crdmq, &se); -} - -#endif /* CONFIG_DISABLE_SIGNALS */ diff --git a/nuttx/graphics/nxsu/nx_constructwindow.c b/nuttx/graphics/nxsu/nx_constructwindow.c index 0703ab644..6a0595181 100644 --- a/nuttx/graphics/nxsu/nx_constructwindow.c +++ b/nuttx/graphics/nxsu/nx_constructwindow.c @@ -83,10 +83,10 @@ * inheritance: The caller's window structure may include extensions that * are not visible to NX. * - * NOTE: hwnd must have been allocated using kmalloc() (or related allocators) - * Once provided to nx_constructwindow() that memory is owned and managed - * by NX. On certain error conditions or when the window is closed, NX will - * free the window. + * NOTE: hwnd must have been allocated using a user-space allocator that + * permits user access to the window. Once provided to nx_constructwindow() + * that memory is owned and managed by NX. On certain error conditions or + * when the window is closed, NX will free the window. * * Input Parameters: * handle - The handle returned by nx_connect diff --git a/nuttx/graphics/nxsu/nx_openwindow.c b/nuttx/graphics/nxsu/nx_openwindow.c index 773210853..b1e632937 100644 --- a/nuttx/graphics/nxsu/nx_openwindow.c +++ b/nuttx/graphics/nxsu/nx_openwindow.c @@ -80,7 +80,7 @@ * * Input Parameters: * handle - The handle returned by nx_connect - * cb - Callbacks used to process windo events + * cb - Callbacks used to process window events * arg - User provided value that will be returned with NX callbacks. * * Return: diff --git a/nuttx/include/nuttx/nx/nx.h b/nuttx/include/nuttx/nx/nx.h index b8eed9204..e1357a342 100644 --- a/nuttx/include/nuttx/nx/nx.h +++ b/nuttx/include/nuttx/nx/nx.h @@ -99,7 +99,7 @@ struct nx_callback_s /************************************************************************** * Name: redraw * - * Descripton: + * Description: * NX requests that the client re-draw the portion of the window within * with rectangle. * @@ -122,7 +122,7 @@ struct nx_callback_s /************************************************************************** * Name: position * - * Descripton: + * Description: * The size or position of the window has changed (or the window was * just created with zero size. * @@ -149,7 +149,7 @@ struct nx_callback_s /************************************************************************** * Name: mousein * - * Descripton: + * Description: * New mouse data is available for the window. * * Input Parameters: @@ -172,7 +172,7 @@ struct nx_callback_s /************************************************************************** * Name: kbdin * - * Descripton: + * Description: * New keyboard/keypad data is available for the window * * Input Parameters: @@ -194,7 +194,7 @@ struct nx_callback_s /************************************************************************** * Name: blocked * - * Descripton: + * Description: * This callback is the response from nx_block (or nxtk_block). Those * blocking interfaces are used to assure that no further messages are * directed to the window. Receipt of the blocked callback signifies @@ -332,7 +332,7 @@ NXHANDLE nx_open(FAR NX_DRIVERTYPE *dev); * * Description: * Disconnect a client from the NX server and/or free resources reserved - * by nx_connect/nx_connectinstance. nx_disconnect is muliti-user equivalent + * by nx_connect/nx_connectinstance. nx_disconnect is multi-user equivalent * of nx_close. * * Multiple user mode only! @@ -382,7 +382,7 @@ void nx_close(NXHANDLE handle); * caution in the looping to assure that it does not eat up all of * the CPU bandwidth calling nx_eventhandler repeatedly. nx_eventnotify * may be called to get a signal event whenever a new incoming server - * event is avaiable. + * event is available. * * Input Parameters: * handle - the handle returned by nx_connect @@ -511,7 +511,7 @@ int nx_block(NXWINDOW hwnd, FAR void *arg); * background window in the following conditions: * * - If you want to implement a windowless solution. The single screen - * can be used to creat a truly simple graphic environment. In this + * can be used to create a truly simple graphic environment. In this * case, you should probably also de-select CONFIG_NX_MULTIUSER as well. * - When you want more on the background than a solid color. For * example, if you want an image in the background, or animations in the @@ -930,10 +930,10 @@ void nx_redrawreq(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect); * inheritance: The caller's window structure may include extensions that * are not visible to NX. * - * NOTE: wnd must have been allocated using kmalloc() (or related allocators) - * Once provided to nx_constructwindow() that memory is owned and managed - * by NX. On certain error conditions or when the window is closed, NX will - * free the window. + * NOTE: hwnd must have been allocated using a user-space allocator that + * permits user access to the window. Once provided to nx_constructwindow() + * that memory is owned and managed by NX. On certain error conditions or + * when the window is closed, NX will free the window. * * Input Parameters: * handle - The handle returned by nx_connect diff --git a/nuttx/libnx/nxmu/Make.defs b/nuttx/libnx/nxmu/Make.defs index ebf9c4f65..ac99b7cb1 100644 --- a/nuttx/libnx/nxmu/Make.defs +++ b/nuttx/libnx/nxmu/Make.defs @@ -41,7 +41,7 @@ ifeq ($(CONFIG_NX),y) ifeq ($(CONFIG_NX_MULTIUSER),y) CSRCS += nxmu_sendserver.c nx_connect.c nx_disconnect.c -CSRCS += nxmu_semtake.c nx_block.c +CSRCS += nx_eventhandler.c nx_eventnotify.c nxmu_semtake.c nx_block.c CSRCS += nx_kbdchin.c nx_kbdin.c nx_mousein.c CSRCS += nx_releasebkgd.c nx_requestbkgd.c nx_setbgcolor.c diff --git a/nuttx/libnx/nxmu/nx_eventhandler.c b/nuttx/libnx/nxmu/nx_eventhandler.c new file mode 100644 index 000000000..26d7f9dee --- /dev/null +++ b/nuttx/libnx/nxmu/nx_eventhandler.c @@ -0,0 +1,262 @@ +/**************************************************************************** + * libnx/nxmu/nx_eventhandler.c + * + * Copyright (C) 2008-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "nxcontext.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_connected + * + * Description: + * The server has completed the connection and is ready. + * + ****************************************************************************/ + +static inline void nx_connected(FAR struct nxfe_conn_s *conn) +{ + DEBUGASSERT(conn->state == NX_CLISTATE_NOTCONNECTED); + conn->state = NX_CLISTATE_CONNECTED; +} + +/**************************************************************************** + * Name: nx_disconnected + ****************************************************************************/ + +static inline void nx_disconnected(FAR struct nxfe_conn_s *conn) +{ + /* Close the server and client MQs */ + + (void)mq_close(conn->cwrmq); + (void)mq_close(conn->crdmq); + + /* And free the client structure */ + + lib_free(conn); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_eventhandler + * + * Description: + * The client code must call this function periodically to process + * incoming messages from the server. If CONFIG_NX_BLOCKING is defined, + * then this function not return until a server message is received. + * + * When CONFIG_NX_BLOCKING is not defined, the client must exercise + * caution in the looping to assure that it does not eat up all of + * the CPU bandwidth calling nx_eventhandler repeatedly. nx_eventnotify + * may be called to get a signal event whenever a new incoming server + * event is available. + * + * Input Parameters: + * handle - the handle returned by nx_connect + * + * Return: + * OK: No errors occurred. If CONFIG_NX_BLOCKING is defined, then + * one or more server message was processed. + * ERROR: An error occurred and errno has been set appropriately. Of + * particular interest, it will return errno == EHOSTDOWN when the + * server is disconnected. After that event, the handle can no + * longer be used. + * + ****************************************************************************/ + +int nx_eventhandler(NXHANDLE handle) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_s *msg; + struct nxbe_window_s *wnd; + uint8_t buffer[NX_MXCLIMSGLEN]; + int nbytes; + + /* Get the next message from our incoming message queue */ + + do + { + nbytes = mq_receive(conn->crdmq, buffer, NX_MXCLIMSGLEN, 0); + if (nbytes < 0) + { + /* EINTR is not an error. The wait was interrupted by a signal and + * we just need to try reading again. + */ + + if (errno != EINTR) + { + if (errno == EAGAIN) + { + /* EAGAIN is not an error. It occurs because the MQ is opened with + * O_NONBLOCK and there is no message available now. + */ + + return OK; + } + else + { + gdbg("mq_receive failed: %d\n", errno); + return ERROR; + } + } + } + } + while (nbytes < 0); + + DEBUGASSERT(nbytes >= sizeof(struct nxclimsg_s)); + + /* Dispatch the message appropriately */ + + msg = (struct nxsvrmsg_s *)buffer; + gvdbg("Received msgid=%d\n", msg->msgid); + switch (msg->msgid) + { + case NX_CLIMSG_CONNECTED: + nx_connected(conn); + break; + + case NX_CLIMSG_DISCONNECTED: + nx_disconnected(conn); + set_errno(EHOSTDOWN); + return ERROR; + + case NX_CLIMSG_REDRAW: + { + FAR struct nxclimsg_redraw_s *redraw = (FAR struct nxclimsg_redraw_s *)buffer; + wnd = redraw->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->redraw) + { + wnd->cb->redraw((NXWINDOW)wnd, &redraw->rect, redraw->more, wnd->arg); + } + } + break; + + case NX_CLIMSG_NEWPOSITION: + { + FAR struct nxclimsg_newposition_s *postn = (FAR struct nxclimsg_newposition_s *)buffer; + wnd = postn->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->position) + { + wnd->cb->position((NXWINDOW)wnd, &postn->size, &postn->pos, &postn->bounds, wnd->arg); + } + } + break; + +#ifdef CONFIG_NX_MOUSE + case NX_CLIMSG_MOUSEIN: + { + FAR struct nxclimsg_mousein_s *mouse = (FAR struct nxclimsg_mousein_s *)buffer; + wnd = mouse->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->mousein) + { + wnd->cb->mousein((NXWINDOW)wnd, &mouse->pos, mouse->buttons, wnd->arg); + } + } + break; +#endif + +#ifdef CONFIG_NX_KBD + case NX_CLIMSG_KBDIN: + { + FAR struct nxclimsg_kbdin_s *kbd = (FAR struct nxclimsg_kbdin_s *)buffer; + wnd = kbd->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->kbdin) + { + wnd->cb->kbdin((NXWINDOW)wnd, kbd->nch, kbd->ch, wnd->arg); + } + } + break; +#endif + + case NX_CLIMSG_BLOCKED: + { + FAR struct nxclimsg_blocked_s *blocked = (FAR struct nxclimsg_blocked_s *)buffer; + wnd = blocked->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->blocked) + { + wnd->cb->blocked((NXWINDOW)wnd, wnd->arg, blocked->arg); + } + } + break; + + default: + gdbg("Unrecognized message opcode: %d\n", ((FAR struct nxsvrmsg_s *)buffer)->msgid); + break; + } + + return OK; +} diff --git a/nuttx/libnx/nxmu/nx_eventnotify.c b/nuttx/libnx/nxmu/nx_eventnotify.c new file mode 100644 index 000000000..37f2b1591 --- /dev/null +++ b/nuttx/libnx/nxmu/nx_eventnotify.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * libnx/nxmu/nx_eventnotify.c + * + * Copyright (C) 2008-2009, 2011, 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#ifndef CONFIG_DISABLE_SIGNALS + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_eventnotify + * + * Description: + * Rather than calling nx_eventhandler periodically, the client may + * register to receive a signal when a server event is available. The + * client can then call nv_eventhandler() only when incoming events are + * available. + * + * Only one such event is issued. Upon receipt of the signal, if the client + * wishes further notifications, it must call nx_eventnotify again. + * + * Input Parameters: + * handle - the handle returned by nx_connect + * + * Return: + * OK: No errors occurred. If CONFIG_NX_BLOCKING is defined, then + * one or more server message was processed. + * ERROR: An error occurred and errno has been set appropriately + * + ****************************************************************************/ + +int nx_eventnotify(NXHANDLE handle, int signo) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct sigevent se; + + se.sigev_notify = SIGEV_SIGNAL; + se.sigev_signo = signo; + se.sigev_value.sival_ptr = (FAR void *)handle; + + return mq_notify(conn->crdmq, &se); +} + +#endif /* CONFIG_DISABLE_SIGNALS */ -- cgit v1.2.3