diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-28 18:48:11 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-28 18:48:11 +0000 |
commit | a63f8bb684d01a23bfe1ee85b1d7faf983b9d1ea (patch) | |
tree | 3f51cea039f16c0a9b0b8e05550fe9112d72d824 /NxWidgets/nxwm | |
parent | f1b1e3ba11994bcbb0a1ddad9f8e686a6a9ae475 (diff) | |
download | px4-nuttx-a63f8bb684d01a23bfe1ee85b1d7faf983b9d1ea.tar.gz px4-nuttx-a63f8bb684d01a23bfe1ee85b1d7faf983b9d1ea.tar.bz2 px4-nuttx-a63f8bb684d01a23bfe1ee85b1d7faf983b9d1ea.zip |
NxWidgets/NxWM updates from Petteri Aimonen (Patches 0007-0013)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5689 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'NxWidgets/nxwm')
-rw-r--r-- | NxWidgets/nxwm/include/cstartwindow.hxx | 1 | ||||
-rw-r--r-- | NxWidgets/nxwm/include/cwindowmessenger.hxx | 25 | ||||
-rw-r--r-- | NxWidgets/nxwm/src/capplicationwindow.cxx | 22 | ||||
-rw-r--r-- | NxWidgets/nxwm/src/cstartwindow.cxx | 153 | ||||
-rw-r--r-- | NxWidgets/nxwm/src/ctaskbar.cxx | 18 | ||||
-rw-r--r-- | NxWidgets/nxwm/src/cwindowmessenger.cxx | 116 |
6 files changed, 100 insertions, 235 deletions
diff --git a/NxWidgets/nxwm/include/cstartwindow.hxx b/NxWidgets/nxwm/include/cstartwindow.hxx index 52a67fbd4..250d5068c 100644 --- a/NxWidgets/nxwm/include/cstartwindow.hxx +++ b/NxWidgets/nxwm/include/cstartwindow.hxx @@ -119,7 +119,6 @@ namespace NxWM CApplicationWindow *m_window; /**< Reference to the application window */ TNxArray<struct SStartWindowSlot> m_slots; /**< List of apps in the start window */ struct nxgl_size_s m_iconSize; /**< A box big enough to hold the largest icon */ - pid_t m_taskId; /**< ID of the start window task */ /** * This is the start window task. This function receives window events from diff --git a/NxWidgets/nxwm/include/cwindowmessenger.hxx b/NxWidgets/nxwm/include/cwindowmessenger.hxx index 11a48645b..a30010fd8 100644 --- a/NxWidgets/nxwm/include/cwindowmessenger.hxx +++ b/NxWidgets/nxwm/include/cwindowmessenger.hxx @@ -1,7 +1,7 @@ /**************************************************************************** * NxWidgets/nxwm/include/cwindowmessenger.hxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -39,12 +39,12 @@ /**************************************************************************** * Included Files ****************************************************************************/ - + #include <nuttx/config.h> #include <sys/types.h> -#include <mqueue.h> +#include <nuttx/wqueue.h> #include <nuttx/nx/nxtk.h> #include <nuttx/nx/nxconsole.h> @@ -83,9 +83,20 @@ namespace NxWM public NXWidgets::CWidgetControl { private: - mqd_t m_mqd; /**< Message queue descriptor used to commincate with the - ** start window thread. */ - + /** Structure that stores data for the work queue callback. */ + + struct work_state_t + { + work_s work; + CWindowMessenger *windowMessenger; + void *instance; + }; + + /** Work queue callback functions */ + + static void inputWorkCallback(FAR void *arg); + static void destroyWorkCallback(FAR void *arg); + /** * Handle an NX window mouse input event. * @@ -109,7 +120,7 @@ namespace NxWM * * @param arg - User provided argument (see nx_block or nxtk_block) */ - + void handleBlockedEvent(FAR void *arg); public: diff --git a/NxWidgets/nxwm/src/capplicationwindow.cxx b/NxWidgets/nxwm/src/capplicationwindow.cxx index d2e044298..77d196d07 100644 --- a/NxWidgets/nxwm/src/capplicationwindow.cxx +++ b/NxWidgets/nxwm/src/capplicationwindow.cxx @@ -1,7 +1,7 @@ /******************************************************************************************** * NxWidgets/nxwm/src/capplicationwindow.cxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -54,6 +54,18 @@ * Pre-Processor Definitions ********************************************************************************************/ +#ifdef CONFIG_NXWM_STOP_BITMAP +extern const struct NXWidgets::SRlePaletteBitmap CONFIG_NXWM_STOP_BITMAP; +#else +# define CONFIG_NXWM_STOP_BITMAP g_stopBitmap +#endif + +#ifdef CONFIG_NXWM_MINIMIZE_BITMAP +extern const struct NXWidgets::SRlePaletteBitmap CONFIG_NXWM_MINIMIZE_BITMAP; +#else +# define CONFIG_NXWM_MINIMIZE_BITMAP g_minimizeBitmap +#endif + /******************************************************************************************** * CApplicationWindow Method Implementations ********************************************************************************************/ @@ -192,7 +204,7 @@ bool CApplicationWindow::open(void) { // Create STOP bitmap container - m_stopBitmap = new NXWidgets::CRlePaletteBitmap(&g_stopBitmap); + m_stopBitmap = new NXWidgets::CRlePaletteBitmap(&CONFIG_NXWM_STOP_BITMAP); if (!m_stopBitmap) { return false; @@ -244,7 +256,7 @@ bool CApplicationWindow::open(void) #ifndef CONFIG_NXWM_DISABLE_MINIMIZE // Create MINIMIZE application bitmap container - m_minimizeBitmap = new NXWidgets::CRlePaletteBitmap(&g_minimizeBitmap); + m_minimizeBitmap = new NXWidgets::CRlePaletteBitmap(&CONFIG_NXWM_MINIMIZE_BITMAP); if (!m_minimizeBitmap) { return false; @@ -375,7 +387,7 @@ void CApplicationWindow::redraw(void) m_minimizeImage->redraw(); m_minimizeImage->setRaisesEvents(true); } - + // And finally draw the window label m_windowLabel->enableDrawing(); @@ -406,7 +418,7 @@ void CApplicationWindow::hide(void) m_minimizeImage->disableDrawing(); m_minimizeImage->setRaisesEvents(false); } - + // Disable the window label m_windowLabel->disableDrawing(); diff --git a/NxWidgets/nxwm/src/cstartwindow.cxx b/NxWidgets/nxwm/src/cstartwindow.cxx index bc7b747f8..1b56094ec 100644 --- a/NxWidgets/nxwm/src/cstartwindow.cxx +++ b/NxWidgets/nxwm/src/cstartwindow.cxx @@ -1,7 +1,7 @@ /******************************************************************************************** * NxWidgets/nxwm/src/cstartwindow.cxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -44,8 +44,6 @@ #include <csched> #include <cerrno> -#include <mqueue.h> - #include "cwidgetcontrol.hxx" #include "nxwmconfig.hxx" @@ -66,7 +64,7 @@ */ FAR const char *NxWM::g_startWindowMqName = CONFIG_NXWM_STARTWINDOW_MQNAME; - + /******************************************************************************************** * CStartWindow Method Implementations ********************************************************************************************/ @@ -89,10 +87,6 @@ CStartWindow::CStartWindow(CTaskbar *taskbar, CApplicationWindow *window) m_taskbar = taskbar; m_window = window; - // The start window task is not running - - m_taskId = -1; - // Add our personalized window label NXWidgets::CNxString myName = getName(); @@ -169,24 +163,7 @@ NXWidgets::CNxString CStartWindow::getName(void) bool CStartWindow::run(void) { - // Some sanity checking - - if (m_taskId >= 0) - { - // The start window task is already running??? - - return false; - } - - // Start the start window task - - m_taskId = TASK_CREATE("StartWindow", CONFIG_NXWM_STARTWINDOW_PRIO, - CONFIG_NXWM_STARTWINDOW_STACKSIZE, startWindow, - (FAR char * const *)0); - - // Did we successfully start the NxConsole task? - - return m_taskId >= 0; + return true; } /** @@ -195,21 +172,8 @@ bool CStartWindow::run(void) void CStartWindow::stop(void) { - // Delete the start window task --- what are we doing? This should never - // happen because the start window task is persistent! - - if (m_taskId >= 0) - { - // Call task_delete(), possibly stranding resources - - pid_t pid = m_taskId; - m_taskId = -1; - - // Then delete the NSH task - - task_delete(pid); - } } + /** * Destroy the application and free all of its resources. This method * will initiate blocking of messages from the NX server. The server @@ -532,7 +496,7 @@ void CStartWindow::getIconBounds(void) void CStartWindow::removeAllApplications(void) { - // Stop all applications and remove them from the start window. Clearly, there + // Stop all applications and remove them from the start window. Clearly, there // are some ordering issues here... On an orderly system shutdown, disconnection // should really occur priority to deleting instances @@ -543,7 +507,7 @@ void CStartWindow::removeAllApplications(void) IApplicationFactory *app = m_slots.at(0).app; // Now, delete the image and the application - + delete app; delete m_slots.at(0).image; @@ -596,108 +560,3 @@ void CStartWindow::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) } } -/** - * This is the start window task. This function receives window events from - * the NX listener threads indirectly through this sequence: - * - * 1. NX listener thread receives a windows event. This may be a - * positional change notification, a redraw request, or mouse or - * keyboard input. - * 2. The NX listener thread performs the callback by calling a - * NXWidgets::CCallback method associated with the window. - * 3. NXWidgets::CCallback calls into NXWidgets::CWidgetControl to process - * the event. - * 4. NXWidgets::CWidgetControl records the new state data and raises a - * window event. - * 5. NXWidgets::CWindowEventHandlerList will give the event to - * NxWM::CWindowMessenger. - * 6. NxWM::CWindowMessenger will send the a message on a well-known message - * queue. - * 7. This CStartWindow::startWindow task will receive and process that - * message. - */ - -int CStartWindow::startWindow(int argc, char *argv[]) -{ - /* Open a well-known message queue for reading */ - - struct mq_attr attr; - attr.mq_maxmsg = CONFIG_NXWM_STARTWINDOW_MXMSGS; - attr.mq_msgsize = sizeof(struct SStartWindowMessage); - attr.mq_flags = 0; - - mqd_t mqd = mq_open(g_startWindowMqName, O_RDONLY|O_CREAT, 0666, &attr); - if (mqd == (mqd_t)-1) - { - gdbg("ERROR: mq_open(%s) failed: %d\n", g_startWindowMqName, errno); - return EXIT_FAILURE; - } - - // Now loop forever, receiving and processing messages. Ultimately, all - // widget driven events (button presses, etc.) are driven by this logic - // on this thread. - - for (;;) - { - // Receive the next message - - struct SStartWindowMessage msg; - ssize_t nbytes = mq_receive(mqd, &msg, sizeof(struct SStartWindowMessage), 0); - if (nbytes < 0) - { - int errval = errno; - - // EINTR is not an error. The wait was interrupted by a signal and - // we just need to try reading again. - - if (errval != EINTR) - { - gdbg("ERROR: mq_receive failed: %d\n", errval); - } - else - { - gdbg("mq_receive interrupted by signal\n"); - } - - continue; - } - - gvdbg("Received msgid=%d nbytes=%d\n", msg.msgId, nbytes); - DEBUGASSERT(nbytes = sizeof(struct SStartWindowMessage) && msg.instance); - - // Dispatch the message to the appropriate CWidgetControl and to the - // appropriate CWidgetControl method - - switch (msg.msgId) - { - break; - - case MSGID_MOUSE_INPUT: // New mouse input is available - case MSGID_KEYBOARD_INPUT: // New keyboard input is available - { - // Handle all new window input events by calling the CWidgetControl::pollEvents() method - - NXWidgets::CWidgetControl *control = (NXWidgets::CWidgetControl *)msg.instance; - control->pollEvents(); - } - break; - - case MSGID_DESTROY_APP: // Destroy the application - { - // Handle all destroy application events - - gdbg("Deleting app=%p\n", msg.instance); - IApplication *app = (IApplication *)msg.instance; - delete app; - } - break; - - case MSGID_POSITIONAL_CHANGE: // Change in window positional data (not used) - case MSGID_REDRAW_REQUEST: // Request to redraw a portion of the window (not used) - default: - gdbg("ERROR: Unrecognized or unsupported msgId: %d\n", (int)msg.msgId); - break; - } - } -} - diff --git a/NxWidgets/nxwm/src/ctaskbar.cxx b/NxWidgets/nxwm/src/ctaskbar.cxx index 031edbf3a..93c38ed98 100644 --- a/NxWidgets/nxwm/src/ctaskbar.cxx +++ b/NxWidgets/nxwm/src/ctaskbar.cxx @@ -1,7 +1,7 @@ /******************************************************************************************** * NxWidgets/nxwm/src/ctaskbar.cxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -456,11 +456,21 @@ bool CTaskbar::startApplication(IApplication *app, bool minimized) NXWidgets::IBitmap *bitmap = app->getIcon(); - // Create a CImage instance to manage the applications icon + // Create a CImage instance to manage the applications icon. Assume the + // minimum size in case no bitmap is provided (bitmap == NULL) + + int w = 1; + int h = 1; + + if (bitmap) + { + w = bitmap->getWidth(); + h = bitmap->getHeight(); + } NXWidgets::CImage *image = - new NXWidgets::CImage(control, 0, 0, bitmap->getWidth(), - bitmap->getHeight(), bitmap, 0); + new NXWidgets::CImage(control, 0, 0, w, h, bitmap, 0); + if (!image) { return false; diff --git a/NxWidgets/nxwm/src/cwindowmessenger.cxx b/NxWidgets/nxwm/src/cwindowmessenger.cxx index 032dd1bf2..114690838 100644 --- a/NxWidgets/nxwm/src/cwindowmessenger.cxx +++ b/NxWidgets/nxwm/src/cwindowmessenger.cxx @@ -1,7 +1,7 @@ /******************************************************************************************** * NxWidgets/nxwm/src/cwindowmessenger.cxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -69,20 +69,6 @@ using namespace NxWM; CWindowMessenger::CWindowMessenger(FAR const NXWidgets::CWidgetStyle *style) : NXWidgets::CWidgetControl(style) { - // Open a message queue to communicate with the start window task. We need to create - // the message queue if it does not exist. - - struct mq_attr attr; - attr.mq_maxmsg = CONFIG_NXWM_STARTWINDOW_MXMSGS; - attr.mq_msgsize = sizeof(struct SStartWindowMessage); - attr.mq_flags = 0; - - m_mqd = mq_open(g_startWindowMqName, O_WRONLY|O_CREAT, 0666, &attr); - if (m_mqd == (mqd_t)-1) - { - gdbg("ERROR: mq_open(%s) failed: %d\n", g_startWindowMqName, errno); - } - // Add ourself to the list of window event handlers addWindowEventHandler(this); @@ -97,10 +83,6 @@ CWindowMessenger::~CWindowMessenger(void) // Remove ourself from the list of the window event handlers removeWindowEventHandler(this); - - // Close the message queue - - (void)mq_close(m_mqd); } /** @@ -120,8 +102,8 @@ void CWindowMessenger::handleMouseEvent(void) // 3. The NX server will determine which window gets the mouse input // and send a window event message to the NX listener thread. // 4. The NX listener thread receives a windows event. The NX listener thread - // which is part of CTaskBar and was created when NX server connection was - // established). This event may be a positional change notification, a + // is part of CTaskBar and was created when NX server connection was + // established. This event may be a positional change notification, a // redraw request, or mouse or keyboard input. In this case, mouse input. // 5. The NX listener thread handles the message by calling nx_eventhandler(). // nx_eventhandler() dispatches the message by calling a method in the @@ -133,20 +115,18 @@ void CWindowMessenger::handleMouseEvent(void) // window event. // 8. NXWidgets::CWindowEventHandlerList will give the event to this method // NxWM::CWindowMessenger. - // 9. This NxWM::CWindowMessenger method will send the a message on a well- - // known message queue. - // 10. This CStartWindow::startWindow task will receive and process that - // message by calling CWidgetControl::pollEvents() + // 9. This NxWM::CWindowMessenger method will schedule an entry on the work + // queue. + // 10. The work queue callback will finally call pollEvents() to execute whatever + // actions the input event should trigger. - struct SStartWindowMessage outmsg; - outmsg.msgId = MSGID_MOUSE_INPUT; - outmsg.instance = (FAR void *)static_cast<CWidgetControl*>(this); + work_state_t *state = new work_state_t; + state->windowMessenger = this; - int ret = mq_send(m_mqd, &outmsg, sizeof(struct SStartWindowMessage), - CONFIG_NXWM_STARTWINDOW_MXMPRIO); + int ret = work_queue(USRWORK, &state->work, &inputWorkCallback, state, 0); if (ret < 0) { - gdbg("ERROR: mq_send failed: %d\n", errno); + gdbg("ERROR: work_queue failed: %d\n", ret); } } #endif @@ -158,41 +138,13 @@ void CWindowMessenger::handleMouseEvent(void) #ifdef CONFIG_NX_KBD void CWindowMessenger::handleKeyboardEvent(void) { - // The logic path here is tortuous but flexible: - // - // 1. A listener thread receives keyboard input and injects that into NX - // via nx_kbdin. - // 2. In the multi-user mode, this will send a message to the NX server - // 3. The NX server will determine which window gets the keyboard input - // and send a window event message to the NX listener thread. - // 4. The NX listener thread receives a windows event. The NX listener thread - // which is part of CTaskBar and was created when NX server connection was - // established). This event may be a positional change notification, a - // redraw request, or mouse or keyboard input. In this case, keyboard input. - // 5. The NX listener thread handles the message by calling nx_eventhandler(). - // nx_eventhandler() dispatches the message by calling a method in the - // NXWidgets::CCallback instance associated with the window. - // NXWidgets::CCallback is a part of the CWidgetControl. - // 6. NXWidgets::CCallback calls into NXWidgets::CWidgetControl to process - // the event. - // 7. NXWidgets::CWidgetControl records the new state data and raises a - // window event. - // 8. NXWidgets::CWindowEventHandlerList will give the event to this method - // NxWM::CWindowMessenger. - // 9. This NxWM::CWindowMessenger method will send the a message on a well- - // known message queue. - // 10. This CStartWindow::startWindow task will receive and process that - // message by calling CWidgetControl::pollEvents() - - struct SStartWindowMessage outmsg; - outmsg.msgId = MSGID_KEYBOARD_INPUT; - outmsg.instance = (FAR void *)static_cast<CWidgetControl*>(this); + work_state_t *state = new work_state_t; + state->windowMessenger = this; - int ret = mq_send(m_mqd, &outmsg, sizeof(struct SStartWindowMessage), - CONFIG_NXWM_STARTWINDOW_MXMPRIO); + int ret = work_queue(USRWORK, &state->work, &inputWorkCallback, state, 0); if (ret < 0) { - gdbg("ERROR: mq_send failed: %d\n", errno); + gdbg("ERROR: work_queue failed: %d\n", ret); } } #endif @@ -213,18 +165,40 @@ void CWindowMessenger::handleKeyboardEvent(void) void CWindowMessenger::handleBlockedEvent(FAR void *arg) { - // Send a message to destroy the window isntance at a later time + // Send a message to destroy the window instance. - struct SStartWindowMessage outmsg; - outmsg.msgId = MSGID_DESTROY_APP; - outmsg.instance = arg; + work_state_t *state = new work_state_t; + state->windowMessenger = this; + state->instance = arg; - gdbg("Sending MSGID_DESTROY_APP with instance=%p\n", arg); - int ret = mq_send(m_mqd, &outmsg, sizeof(struct SStartWindowMessage), - CONFIG_NXWM_STARTWINDOW_MXMPRIO); + int ret = work_queue(USRWORK, &state->work, &destroyWorkCallback, state, 0); if (ret < 0) { - gdbg("ERROR: mq_send failed: %d\n", errno); + gdbg("ERROR: work_queue failed: %d\n", ret); } } +/** Work queue callback functions */ + +void CWindowMessenger::inputWorkCallback(FAR void *arg) +{ + work_state_t *state = (work_state_t*)arg; + state->windowMessenger->pollEvents(); + delete state; +} + +void CWindowMessenger::destroyWorkCallback(FAR void *arg) +{ + work_state_t *state = (work_state_t*)arg; + + // First make sure any pending input events have been handled. + + state->windowMessenger->pollEvents(); + + // Then release the memory. + + gdbg("Deleting app=%p\n", state->instance); + IApplication *app = (IApplication *)state->instance; + delete app; + delete state; +} |