libwinpr-utils: improve PubSub with automatic strongly-typed helpers
This commit is contained in:
parent
b55725487f
commit
508bae674b
@ -496,9 +496,9 @@ void xf_toggle_fullscreen(xfContext* xfc)
|
||||
|
||||
xf_unlock_x11(xfc, TRUE);
|
||||
|
||||
EventArgsInit(&e, "xfreerdp");
|
||||
e.state = xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0;
|
||||
|
||||
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "WindowStateChange", xfc, (wEventArgs*) &e);
|
||||
PubSub_OnWindowStateChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
||||
}
|
||||
|
||||
void xf_lock_x11(xfContext* xfc, BOOL display)
|
||||
@ -894,10 +894,10 @@ BOOL xf_post_connect(freerdp* instance)
|
||||
|
||||
xf_cliprdr_init(xfc, channels);
|
||||
|
||||
EventArgsInit(&e, "xfreerdp");
|
||||
e.width = settings->DesktopWidth;
|
||||
e.height = settings->DesktopHeight;
|
||||
|
||||
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
|
||||
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -1567,9 +1567,10 @@ void freerdp_client_reset_scale(rdpContext* context)
|
||||
xfc->scale = 1.0;
|
||||
XResizeWindow(xfc->display, xfc->window->handle, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
|
||||
|
||||
EventArgsInit(&e, "xfreerdp");
|
||||
e.width = (int) xfc->originalWidth * xfc->scale;
|
||||
e.height = (int) xfc->originalHeight * xfc->scale;
|
||||
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
|
||||
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
||||
|
||||
xf_draw_screen_scaled(xfc);
|
||||
}
|
||||
|
@ -197,9 +197,10 @@ void xf_input_detect_pinch(xfContext* xfc)
|
||||
|
||||
XResizeWindow(xfc->display, xfc->window->handle, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
|
||||
|
||||
EventArgsInit(&e, "xfreerdp");
|
||||
e.width = (int) xfc->originalWidth * xfc->scale;
|
||||
e.height = (int) xfc->originalHeight * xfc->scale;
|
||||
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
|
||||
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
||||
|
||||
z_vector = 0;
|
||||
}
|
||||
@ -213,9 +214,10 @@ void xf_input_detect_pinch(xfContext* xfc)
|
||||
|
||||
XResizeWindow(xfc->display, xfc->window->handle, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
|
||||
|
||||
EventArgsInit(&e, "xfreerdp");
|
||||
e.width = (int) xfc->originalWidth * xfc->scale;
|
||||
e.height = (int) xfc->originalHeight * xfc->scale;
|
||||
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
|
||||
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
||||
|
||||
z_vector = 0;
|
||||
}
|
||||
|
@ -1189,8 +1189,9 @@ int freerdp_set_param_bool(rdpSettings* settings, int id, BOOL param)
|
||||
// Mark field as modified
|
||||
settings->settings_modified[id] = 1;
|
||||
|
||||
EventArgsInit(&e, "freerdp");
|
||||
e.id = id;
|
||||
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
|
||||
PubSub_OnParamChange(context->pubSub, context->instance, &e);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -1830,8 +1831,9 @@ int freerdp_set_param_uint32(rdpSettings* settings, int id, UINT32 param)
|
||||
// Mark field as modified
|
||||
settings->settings_modified[id] = 1;
|
||||
|
||||
EventArgsInit(&e, "freerdp");
|
||||
e.id = id;
|
||||
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
|
||||
PubSub_OnParamChange(context->pubSub, context->instance, &e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1871,8 +1873,9 @@ int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param)
|
||||
// Mark field as modified
|
||||
settings->settings_modified[id] = 1;
|
||||
|
||||
EventArgsInit(&e, "freerdp");
|
||||
e.id = id;
|
||||
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
|
||||
PubSub_OnParamChange(context->pubSub, context->instance, &e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2208,8 +2211,9 @@ int freerdp_set_param_string(rdpSettings* settings, int id, char* param)
|
||||
// Mark field as modified
|
||||
settings->settings_modified[id] = 1;
|
||||
|
||||
EventArgsInit(&e, "freerdp");
|
||||
e.id = id;
|
||||
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
|
||||
PubSub_OnParamChange(context->pubSub, context->instance, &e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -507,8 +507,9 @@ BOOL rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, wStream* s)
|
||||
|
||||
rdp_print_errinfo(rdp->errorInfo);
|
||||
|
||||
EventArgsInit(&e, "freerdp");
|
||||
e.code = rdp->errorInfo;
|
||||
PubSub_OnEvent(context->pubSub, "ErrorInfo", context, (wEventArgs*) &e);
|
||||
PubSub_OnErrorInfo(context->pubSub, context, &e);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -343,7 +343,8 @@ WINPR_API void MessagePipe_Free(wMessagePipe* pipe);
|
||||
|
||||
struct _wEventArgs
|
||||
{
|
||||
DWORD size;
|
||||
DWORD Size;
|
||||
const char* Sender;
|
||||
};
|
||||
typedef struct _wEventArgs wEventArgs;
|
||||
|
||||
@ -360,16 +361,36 @@ struct _wEvent
|
||||
};
|
||||
typedef struct _wEvent wEvent;
|
||||
|
||||
#define EventArgsInit(_event_args, _sender) \
|
||||
memset(_event_args, 0, sizeof(*_event_args)); \
|
||||
((wEventArgs*) _event_args)->Size = sizeof(*_event_args); \
|
||||
((wEventArgs*) _event_args)->Sender = _sender
|
||||
|
||||
#define DEFINE_EVENT_HANDLER(_name) \
|
||||
typedef void (*p ## _name ## EventHandler)(void* context, _name ## EventArgs* e)
|
||||
|
||||
#define DEFINE_EVENT_RAISE(_name) \
|
||||
static INLINE int PubSub_On ## _name (wPubSub* pubSub, void* context, _name ## EventArgs* e) { \
|
||||
return PubSub_OnEvent(pubSub, #_name, context, (wEventArgs*) e); }
|
||||
|
||||
#define DEFINE_EVENT_SUBSCRIBE(_name) \
|
||||
static INLINE int PubSub_Subscribe ## _name (wPubSub* pubSub, p ## _name ## EventHandler EventHandler) { \
|
||||
return PubSub_Subscribe(pubSub, #_name, (pEventHandler) EventHandler); }
|
||||
|
||||
#define DEFINE_EVENT_UNSUBSCRIBE(_name) \
|
||||
static INLINE int PubSub_Unsubscribe ## _name (wPubSub* pubSub, p ## _name ## EventHandler EventHandler) { \
|
||||
return PubSub_Unsubscribe(pubSub, #_name, (pEventHandler) EventHandler); }
|
||||
|
||||
#define DEFINE_EVENT_BEGIN(_name) \
|
||||
typedef struct _ ## _name ## EventArgs { \
|
||||
wEventArgs e;
|
||||
|
||||
#define DEFINE_EVENT_END(_name) \
|
||||
} _name ## EventArgs; \
|
||||
DEFINE_EVENT_HANDLER(_name);
|
||||
DEFINE_EVENT_HANDLER(_name); \
|
||||
DEFINE_EVENT_RAISE(_name); \
|
||||
DEFINE_EVENT_SUBSCRIBE(_name); \
|
||||
DEFINE_EVENT_UNSUBSCRIBE(_name);
|
||||
|
||||
#define DEFINE_EVENT_ENTRY(_name) \
|
||||
{ #_name, { sizeof( _name ## EventArgs) }, 0, { \
|
||||
|
@ -25,6 +25,11 @@
|
||||
|
||||
#include <winpr/collections.h>
|
||||
|
||||
/**
|
||||
* Events (C# Programming Guide)
|
||||
* http://msdn.microsoft.com/en-us/library/awbftdfh.aspx
|
||||
*/
|
||||
|
||||
/**
|
||||
* Properties
|
||||
*/
|
||||
@ -171,7 +176,7 @@ int PubSub_OnEvent(wPubSub* pubSub, const char* EventName, void* context, wEvent
|
||||
if (event->EventHandlers[index])
|
||||
{
|
||||
event->EventHandlers[index](context, e);
|
||||
status = 1;
|
||||
status++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user