summaryrefslogtreecommitdiff
path: root/NxWidgets/nxwm/src/cwindowmessenger.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'NxWidgets/nxwm/src/cwindowmessenger.cxx')
-rw-r--r--NxWidgets/nxwm/src/cwindowmessenger.cxx116
1 files changed, 45 insertions, 71 deletions
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;
+}