From d53035bc78b3fbbd640a6a7535b9cdf7ca0d9667 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 17 May 2012 22:16:02 +0000 Subject: Implement an NX interface to block flush message queues in multi-user mode. This is necessary to prevent stale window handles when a window is closed git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4745 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/libnxwidgets/include/ccallback.hxx | 77 ++++++++---- NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx | 25 ++++ .../libnxwidgets/include/cwindoweventhandler.hxx | 6 + .../include/cwindoweventhandlerlist.hxx | 6 + NxWidgets/libnxwidgets/src/ccallback.cxx | 140 +++++++++++++-------- .../libnxwidgets/src/cwindoweventhandlerlist.cxx | 11 ++ 6 files changed, 187 insertions(+), 78 deletions(-) (limited to 'NxWidgets') diff --git a/NxWidgets/libnxwidgets/include/ccallback.hxx b/NxWidgets/libnxwidgets/include/ccallback.hxx index 0e0d5de8b..ca3313a9b 100644 --- a/NxWidgets/libnxwidgets/include/ccallback.hxx +++ b/NxWidgets/libnxwidgets/include/ccallback.hxx @@ -99,16 +99,16 @@ namespace NXWidgets * either be the context of the owning thread or, in the case of multi- * user NX, the context of the NX event listener thread. * - * @param hWindow Handle to a specific NX window. - * @param pRect The rectangle that needs to be re-drawn (in window + * @param hwnd Handle to a specific NX window. + * @param rect The rectangle that needs to be re-drawn (in window * relative coordinates). * @param bMore true: More re-draw requests will follow. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ - static void redraw(NXHANDLE hWindow, FAR const struct nxgl_rect_s *pRect, - bool bMore, FAR void *pvArg); + static void redraw(NXHANDLE hwnd, FAR const struct nxgl_rect_s *rect, + bool bMore, FAR void *arg); /** * Position Callback. The new positional data is handled by @@ -118,19 +118,19 @@ namespace NXWidgets * either be the context of the owning thread or, in the case of multi- * user NX, the context of the NX event listener thread. * - * @param hWindow Handle to a specific NX window. - * @param pSize The size of the window. - * @param pPos The position of the upper left hand corner of the window on + * @param hwnd Handle to a specific NX window. + * @param size The size of the window. + * @param pos The position of the upper left hand corner of the window on * the overall display. - * @param pBounds The bounding rectangle that describes the entire display. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param bounds The bounding rectangle that describes the entire display. + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ - static void position(NXHANDLE hWindow, FAR const struct nxgl_size_s *pSize, - FAR const struct nxgl_point_s *pPos, - FAR const struct nxgl_rect_s *pBounds, - FAR void *pvArg); + static void position(NXHANDLE hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); /** * New mouse data is available for the window. The new mouse @@ -144,16 +144,17 @@ namespace NXWidgets * The GUI thread is probably sleeping a semaphore, waiting to be * awakened by a mouse or keyboard event. * - * @param hWindow Handle to a specific NX window. - * @param pPos The (x,y) position of the mouse. + * @param hwnd Handle to a specific NX window. + * @param pos The (x,y) position of the mouse. * @param buttons See NX_MOUSE_* definitions. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ #ifdef CONFIG_NX_MOUSE - static void newMouseEvent(NXHANDLE hWindow, FAR const struct nxgl_point_s *pPos, - uint8_t buttons, FAR void *pvArg); + static void newMouseEvent(NXHANDLE hwnd, + FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg); #endif /* CONFIG_NX_MOUSE */ /** @@ -168,27 +169,49 @@ namespace NXWidgets * The GUI thread is probably sleeping a semaphore, waiting to be * awakened by a mouse or keyboard event. * - * @param hWindow Handle to a specific NX window. - * @param nCh The number of characters that are available in pStr[]. - * @param pStr The array of characters. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param hwnd Handle to a specific NX window. + * @param nCh The number of characters that are available in str[]. + * @param str The array of characters. + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ #ifdef CONFIG_NX_KBD - static void newKeyboardEvent(NXHANDLE hWindow, uint8_t nCh, FAR const uint8_t *pStr, - FAR void *pvArg); + static void newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh, + FAR const uint8_t *str, FAR void *arg); #endif // CONFIG_NX_KBD + /** + * 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 + * that (1) there are no further pending callbacks and (2) that the + * window is now 'defunct' and will receive no further callbacks. + * + * This callback supports coordinated destruction of a window in multi- + * user mode. In multi-use mode, the client window logic must stay + * intact until all of the queued callbacks are processed. Then the + * window may be safely closed. Closing the window prior with pending + * callbacks can lead to bad behavior when the callback is executed. + * + * @param hwnd. Window handle of the blocked window + * @param arg. User provided argument (see nx_openwindow, nx_requestbkgd, + * nxtk_openwindow, or nxtk_opentoolbar) + */ + +#ifdef CONFIG_NX_MULTIUSER + static void windowBlocked(NXWINDOW hwnd, FAR void *arg); +#endif + public: /** * Constructor. * - * @param pWidgetControl Control object associated with this window + * @param widgetControl Control object associated with this window */ - CCallback(CWidgetControl *pWidgetControl); + CCallback(CWidgetControl *widgetControl); /** * Destructor. diff --git a/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx b/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx index 757dc1c5b..453cc1115 100644 --- a/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx +++ b/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx @@ -596,6 +596,31 @@ namespace NXWidgets void newKeyboardEvent(uint8_t nCh, FAR const uint8_t *pStr); #endif + /** + * This event 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 + * that (1) there are no further pending events and (2) that the + * window is now 'defunct' and will receive no further events. + * + * This event supports coordinated destruction of a window in multi- + * user mode. In multi-use mode, the client window logic must stay + * intact until all of the queued callbacks are processed. Then the + * window may be safely closed. Closing the window prior with pending + * callbacks can lead to bad behavior when the callback is executed. + * + * @param hwnd. Window handle of the blocked window + * @param arg. User provided argument (see nx_openwindow, nx_requestbkgd, + * nxtk_openwindow, or nxtk_opentoolbar) + */ + +#ifdef CONFIG_NX_MULTIUSER + inline void windowBlocked(void) + { + m_eventHandlers.raiseBlockedEvent(); + } +#endif + /** * This event means that cursor control data is available for the window. * diff --git a/NxWidgets/libnxwidgets/include/cwindoweventhandler.hxx b/NxWidgets/libnxwidgets/include/cwindoweventhandler.hxx index 1cea0ba68..c414abadb 100644 --- a/NxWidgets/libnxwidgets/include/cwindoweventhandler.hxx +++ b/NxWidgets/libnxwidgets/include/cwindoweventhandler.hxx @@ -105,6 +105,12 @@ namespace NXWidgets #ifdef CONFIG_NX_KBD virtual void handleKeyboardEvent(void) { } #endif + + /** + * Handle a NX window blocked event + */ + + virtual void handleBlockedEvent(void) { } }; } diff --git a/NxWidgets/libnxwidgets/include/cwindoweventhandlerlist.hxx b/NxWidgets/libnxwidgets/include/cwindoweventhandlerlist.hxx index 582805691..d9e17de09 100644 --- a/NxWidgets/libnxwidgets/include/cwindoweventhandlerlist.hxx +++ b/NxWidgets/libnxwidgets/include/cwindoweventhandlerlist.hxx @@ -160,6 +160,12 @@ namespace NXWidgets #ifdef CONFIG_NX_KBD void raiseKeyboardEvent(void); #endif + + /** + * Raise an NX window blocked event. + */ + + void raiseBlockedEvent(void); }; } diff --git a/NxWidgets/libnxwidgets/src/ccallback.cxx b/NxWidgets/libnxwidgets/src/ccallback.cxx index 25cb228b3..09dc53a5a 100644 --- a/NxWidgets/libnxwidgets/src/ccallback.cxx +++ b/NxWidgets/libnxwidgets/src/ccallback.cxx @@ -60,108 +60,113 @@ using namespace NXWidgets; /** * Constructor. * - * @param pWidgetControl Control object associated with this window + * @param widgetControl Control object associated with this window */ -CCallback::CCallback(CWidgetControl *pWidgetControl) +CCallback::CCallback(CWidgetControl *widgetControl) { // Initialize the callback vtable m_callbacks.redraw = redraw; m_callbacks.position = position; +#ifdef CONFIG_NX_MOUSE m_callbacks.mousein = newMouseEvent; +#endif +#ifdef CONFIG_NX_KBD m_callbacks.kbdin = newKeyboardEvent; +#endif + m_callbacks.blocked = windowBlocked; } /** * ReDraw Callback. The redraw action is handled by CWidgetControl:redrawEvent. * - * @param hWindow Handle to a specific NX window. - * @param pRect The rectangle that needs to be re-drawn (in window + * @param hwnd Handle to a specific NX window. + * @param rect The rectangle that needs to be re-drawn (in window * relative coordinates). * @param bMore true: More re-draw requests will follow. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ -void CCallback::redraw(NXHANDLE hWindow, - FAR const struct nxgl_rect_s *pRect, - bool bMore, FAR void *pvArg) +void CCallback::redraw(NXHANDLE hwnd, + FAR const struct nxgl_rect_s *rect, + bool bMore, FAR void *arg) { - gvdbg("hWindow=%p pRect={(%d,%d),(%d,%d)} bMore=%s\n", - hWindow, - pRect->pt1.x, pRect->pt1.y, pRect->pt2.x, pRect->pt2.y, + gvdbg("hwnd=%p rect={(%d,%d),(%d,%d)} bMore=%s\n", + hwnd, + rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, bMore ? "true" : "false"); // The argument must be the CWidgetControl instance - CWidgetControl *This = (CWidgetControl *)pvArg; + CWidgetControl *This = (CWidgetControl *)arg; // Just forward the callback to the CWidgetControl::redrawEvent method - This->redrawEvent(pRect, bMore); + This->redrawEvent(rect, bMore); } /** * Position Callback. The new positional data is handled by * CWidgetControl::geometryEvent. * - * @param hWindow Handle to a specific NX window. - * @param pSize The size of the window. - * @param pPos The position of the upper left hand corner of the window on + * @param hwnd Handle to a specific NX window. + * @param size The size of the window. + * @param pos The position of the upper left hand corner of the window on * the overall display. - * @param pBounds The bounding rectangle that describes the entire display. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param bounds The bounding rectangle that describes the entire display. + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ -void CCallback::position(NXHANDLE hWindow, - FAR const struct nxgl_size_s *pSize, - FAR const struct nxgl_point_s *pPos, - FAR const struct nxgl_rect_s *pBounds, - FAR void *pvArg) +void CCallback::position(NXHANDLE hwnd, + FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) { - gvdbg("hWindow=%p pSize=(%d,%d) pPos=(%d,%d) pBounds={(%d,%d),(%d,%d)} pvArg=%p\n", - hWindow, pSize->w, pSize->h, pPos->x, pPos->y, - pBounds->pt1.x, pBounds->pt1.y, pBounds->pt2.x, pBounds->pt2.y, - pvArg); + gvdbg("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)} arg=%p\n", + hwnd, size->w, size->h, pos->x, pos->y, + bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y, + arg); // The argument must be the CWidgetControl instance - CWidgetControl *This = (CWidgetControl *)pvArg; + CWidgetControl *This = (CWidgetControl *)arg; // Just forward the callback to the CWidgetControl::geometry method - This->geometryEvent(hWindow, pSize, pPos, pBounds); + This->geometryEvent(hwnd, size, pos, bounds); } /** * New mouse data is available for the window. The new mouse data is * handled by CWidgetControl::newMouseEvent. * - * @param hWindow Handle to a specific NX window. - * @param pPos The (x,y) position of the mouse. + * @param hwnd Handle to a specific NX window. + * @param pos The (x,y) position of the mouse. * @param buttons See NX_MOUSE_* definitions. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ - + #ifdef CONFIG_NX_MOUSE -void CCallback::newMouseEvent(NXHANDLE hWindow, - FAR const struct nxgl_point_s *pPos, - uint8_t buttons, FAR void *pvArg) +void CCallback::newMouseEvent(NXHANDLE hwnd, + FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg) { - gvdbg("hWindow=%p pPos=(%d,%d) buttons=%02x pvArg=%p\n", - hWindow, pPos->x, pPos->y, buttons, pvArg); + gvdbg("hwnd=%p pos=(%d,%d) buttons=%02x arg=%p\n", + hwnd, pos->x, pos->y, buttons, arg); // The argument must be the CWidgetControl instance - CWidgetControl *This = (CWidgetControl *)pvArg; + CWidgetControl *This = (CWidgetControl *)arg; // Just forward the callback to the CWidgetControl::newMouseEvent method - This->newMouseEvent(pPos, buttons); + This->newMouseEvent(pos, buttons); } #endif /* CONFIG_NX_MOUSE */ @@ -169,27 +174,60 @@ void CCallback::newMouseEvent(NXHANDLE hWindow, * New keyboard/keypad data is available for the window. The new keyboard * data is handled by CWidgetControl::newKeyboardEvent. * - * @param hWindow Handle to a specific NX window. - * @param nCh The number of characters that are available in pStr[]. - * @param pStr The array of characters. - * @param pvArg User provided argument (see nx_openwindow, nx_requestbg, + * @param hwnd Handle to a specific NX window. + * @param nCh The number of characters that are available in str[]. + * @param str The array of characters. + * @param arg User provided argument (see nx_openwindow, nx_requestbg, * nxtk_openwindow, or nxtk_opentoolbar). */ #ifdef CONFIG_NX_KBD -void CCallback::newKeyboardEvent(NXHANDLE hWindow, uint8_t nCh, - FAR const uint8_t *pStr, - FAR void *pvArg) +void CCallback::newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh, + FAR const uint8_t *str, + FAR void *arg) { - gvdbg("hWindow=%p nCh=%d pvArg=%p\n", - hWindow, nCh, pvArg); + gvdbg("hwnd=%p nCh=%d arg=%p\n", hwnd, nCh, arg); // The argument must be the CWidgetControl instance - CWidgetControl *This = (CWidgetControl *)pvArg; + CWidgetControl *This = (CWidgetControl *)arg; // Just forward the callback to the CWidgetControl::newKeyboardEvent method - This->newKeyboardEvent(nCh, pStr); + This->newKeyboardEvent(nCh, str); +} + +/** + * 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 + * that (1) there are no further pending callbacks and (2) that the + * window is now 'defunct' and will receive no further callbacks. + * + * This callback supports coordinated destruction of a window in multi- + * user mode. In multi-use more, the client window logic must stay + * intact until all of the queued callbacks are processed. Then the + * window may be safely closed. Closing the window prior with pending + * callbacks can lead to bad behavior when the callback is executed. + * + * @param hwnd. Window handle of the blocked window + * @param arg. User provided argument (see nx_openwindow, nx_requestbkgd, + * nxtk_openwindow, or nxtk_opentoolbar) + */ + +#ifdef CONFIG_NX_MULTIUSER +void CCallback::windowBlocked(NXWINDOW hwnd, FAR void *arg) +{ + gvdbg("hwnd=%p arg=%p\n", hwnd, arg); + + // The argument must be the CWidgetControl instance + + CWidgetControl *This = (CWidgetControl *)arg; + + // Just forward the callback to the CWidgetControl::windowBlocked method + + This->windowBlocked(); } +#endif + #endif // CONFIG_NX_KBD diff --git a/NxWidgets/libnxwidgets/src/cwindoweventhandlerlist.cxx b/NxWidgets/libnxwidgets/src/cwindoweventhandlerlist.cxx index 5f3048b63..15b2c65ff 100644 --- a/NxWidgets/libnxwidgets/src/cwindoweventhandlerlist.cxx +++ b/NxWidgets/libnxwidgets/src/cwindoweventhandlerlist.cxx @@ -160,3 +160,14 @@ void CWindowEventHandlerList::raiseKeyboardEvent(void) #endif } +/** + * Raise an NX window blocked event. + */ + +void CWindowEventHandlerList::raiseBlockedEvent(void) +{ + for (int i = 0; i < m_eventHandlers.size(); ++i) + { + m_eventHandlers.at(i)->handleBlockedEvent(); + } +} -- cgit v1.2.3