Browse Source

Update echo-msg window from the thread that owns the window

Change the way echo-msg window is update (thread safety).
When new echo-msg content is available for display, update the window
from the thread owning it by sending a message to it.
A blocking SendMessage (with a timeout) is used, as the window
needs access to the config's echo-msg buffer which is cleared
on return from this this call.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/392/head
Selva Nair 4 years ago
parent
commit
e4fba0c003
  1. 37
      echo.c
  2. 1
      main.h

37
echo.c

@ -259,20 +259,12 @@ echo_msg_display(connection_t *c, time_t timestamp, const char *title, int type)
}
if (type == ECHO_MSG_WINDOW)
{
HWND h = echo_msg_window;
if (h)
DWORD_PTR res;
UINT timeout = 5000; /* msec */
if (echo_msg_window
&& SendMessageTimeout(echo_msg_window, WM_OVPN_ECHOMSG, 0, (LPARAM) c, SMTO_BLOCK, timeout, &res) == 0)
{
wchar_t from[256];
_sntprintf_0(from, L"From: %s %s", c->config_name, _wctime(&timestamp));
/* strip \n added by _wctime */
if (wcslen(from) > 0)
from[wcslen(from)-1] = L'\0';
AddMessageBoxText(h, c->echo_msg.text, c->echo_msg.title, from);
SetForegroundWindow(h);
ShowWindow(h, SW_SHOW);
WriteStatusLog(c, L"GUI> Failed to display echo message: ", c->echo_msg.title, false);
}
}
else /* notify */
@ -537,6 +529,25 @@ MessageDialogFunc(HWND hwnd, UINT msg, UNUSED WPARAM wParam, LPARAM lParam)
}
break;
/* Must be sent with lParam = connection pointer
* Adds the current echo message and shows the window.
*/
case WM_OVPN_ECHOMSG:
{
connection_t *c = (connection_t *) lParam;
wchar_t from[256];
_sntprintf_0(from, L"From: %s %s", c->config_name, _wctime(&c->echo_msg.fp.timestamp));
/* strip \n added by _wctime */
if (wcslen(from) > 0)
from[wcslen(from)-1] = L'\0';
AddMessageBoxText(hwnd, c->echo_msg.text, c->echo_msg.title, from);
SetForegroundWindow(hwnd);
ShowWindow(hwnd, SW_SHOW);
}
break;
case WM_NOTIFY:
nmh = (NMHDR*) lParam;
/* We handle only EN_LINK messages */

1
main.h

@ -60,6 +60,7 @@
#define WM_OVPN_SILENT (WM_APP + 18)
#define WM_OVPN_IMPORT (WM_APP + 20)
#define WM_OVPN_RESCAN (WM_APP + 21)
#define WM_OVPN_ECHOMSG (WM_APP + 22)
/* bool definitions */
#define bool int

Loading…
Cancel
Save