From fccb66a0beb3ebafaadb9ee63fbf9adf53f9463b Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 29 Nov 2008 18:12:17 +0000 Subject: [PATCH] Add nx_eventnotify.c git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1349 42af7a65-404d-4744-a932-0658087f49c3 --- graphics/nxmu/Make.defs | 2 +- graphics/nxmu/nx_eventnotify.c | 109 +++++++++++++++++++++++++++++++++ include/nuttx/nx.h | 48 ++++++++++++--- 3 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 graphics/nxmu/nx_eventnotify.c diff --git a/graphics/nxmu/Make.defs b/graphics/nxmu/Make.defs index dc9b6bae62..d7d8086718 100644 --- a/graphics/nxmu/Make.defs +++ b/graphics/nxmu/Make.defs @@ -35,7 +35,7 @@ NX_ASRCS = NXAPI_CSRCS = nx_bitmap.c nx_closewindow.c nx_connect.c nx_disconnect.c \ - nx_eventhandler.c nx_fill.c nx_filltrapezoid.c \ + nx_eventhandler.c nx_eventnotify.c nx_fill.c nx_filltrapezoid.c \ nx_getposition.c nx_kbdchin.c nx_kbdin.c nx_lower.c \ nx_mousein.c nx_move.c nx_openwindow.c nx_raise.c \ nx_releasebkgd.c nx_requestbkgd.c nx_setsize.c \ diff --git a/graphics/nxmu/nx_eventnotify.c b/graphics/nxmu/nx_eventnotify.c new file mode 100644 index 0000000000..9432f3361e --- /dev/null +++ b/graphics/nxmu/nx_eventnotify.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * graphics/nxmu/nx_eventnotify.c + * + * Copyright (C) 2008 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 "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. + * + * 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/include/nuttx/nx.h b/include/nuttx/nx.h index 2831eb783b..e54d0f06b3 100644 --- a/include/nuttx/nx.h +++ b/include/nuttx/nx.h @@ -321,24 +321,56 @@ EXTERN void nx_close(NXHANDLE handle); * 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 will never return until the host is disconnected. + * 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: - * >0: The length of the message received in msgbuffer - * 0: No message was received - * <0: 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 not longer - * be used. + * 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. * ****************************************************************************/ #ifdef CONFIG_NX_MULTIUSER EXTERN int nx_eventhandler(NXHANDLE handle); +#else +# define nx_eventhandler(handle) (OK) +#endif + +/**************************************************************************** + * 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. + * + * 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 + * + ****************************************************************************/ + +#if defined(CONFIG_NX_MULTIUSER) && !defined(CONFIG_DISABLE_SIGNALS) +EXTERN int nx_eventnotify(NXHANDLE handle, int signo); +#else +# define nx_eventnotify(handle, signo) (OK) #endif /****************************************************************************