diff --git a/client/Android/android_freerdp.c b/client/Android/android_freerdp.c index 5015d8718..7fb9be4ef 100644 --- a/client/Android/android_freerdp.c +++ b/client/Android/android_freerdp.c @@ -57,7 +57,8 @@ /* Defines the JNI version supported by this library. */ #define FREERDP_JNI_VERSION "3.0.0-dev" -static void android_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e) +static void android_OnChannelConnectedEventHandler(void* context, + const ChannelConnectedEventArgs* e) { rdpSettings* settings; androidContext* afc; @@ -90,7 +91,7 @@ static void android_OnChannelConnectedEventHandler(void* context, ChannelConnect } static void android_OnChannelDisconnectedEventHandler(void* context, - ChannelDisconnectedEventArgs* e) + const ChannelDisconnectedEventArgs* e) { rdpSettings* settings; androidContext* afc; diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index bb3aaeb9d..35cebf31c 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -813,7 +813,7 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) mfc->client_width = width; } -void mac_OnChannelConnectedEventHandler(void *context, ChannelConnectedEventArgs *e) +static void mac_OnChannelConnectedEventHandler(void *context, const ChannelConnectedEventArgs *e) { mfContext *mfc = (mfContext *)context; rdpSettings *settings = mfc->context.settings; @@ -835,7 +835,8 @@ void mac_OnChannelConnectedEventHandler(void *context, ChannelConnectedEventArgs } } -void mac_OnChannelDisconnectedEventHandler(void *context, ChannelDisconnectedEventArgs *e) +static void mac_OnChannelDisconnectedEventHandler(void *context, + const ChannelDisconnectedEventArgs *e) { mfContext *mfc = (mfContext *)context; rdpSettings *settings = mfc->context.settings; diff --git a/client/Mac/cli/AppDelegate.m b/client/Mac/cli/AppDelegate.m index e6e625bd0..a4904542f 100644 --- a/client/Mac/cli/AppDelegate.m +++ b/client/Mac/cli/AppDelegate.m @@ -13,10 +13,10 @@ #import static AppDelegate *_singleDelegate = nil; -void AppDelegate_ConnectionResultEventHandler(void *context, ConnectionResultEventArgs *e); -void AppDelegate_ErrorInfoEventHandler(void *ctx, ErrorInfoEventArgs *e); -void AppDelegate_EmbedWindowEventHandler(void *context, EmbedWindowEventArgs *e); -void AppDelegate_ResizeWindowEventHandler(void *context, ResizeWindowEventArgs *e); +void AppDelegate_ConnectionResultEventHandler(void *context, const ConnectionResultEventArgs *e); +void AppDelegate_ErrorInfoEventHandler(void *ctx, const ErrorInfoEventArgs *e); +void AppDelegate_EmbedWindowEventHandler(void *context, const EmbedWindowEventArgs *e); +void AppDelegate_ResizeWindowEventHandler(void *context, const ResizeWindowEventArgs *e); void mac_set_view_size(rdpContext *context, MRDPView *view); @implementation AppDelegate @@ -197,7 +197,7 @@ void mac_set_view_size(rdpContext *context, MRDPView *view); * On connection error, display message and quit application ***********************************************************************/ -void AppDelegate_ConnectionResultEventHandler(void *ctx, ConnectionResultEventArgs *e) +void AppDelegate_ConnectionResultEventHandler(void *ctx, const ConnectionResultEventArgs *e) { rdpContext *context = (rdpContext *)ctx; NSLog(@"ConnectionResult event result:%d\n", e->result); @@ -226,7 +226,7 @@ void AppDelegate_ConnectionResultEventHandler(void *ctx, ConnectionResultEventAr } } -void AppDelegate_ErrorInfoEventHandler(void *ctx, ErrorInfoEventArgs *e) +void AppDelegate_ErrorInfoEventHandler(void *ctx, const ErrorInfoEventArgs *e) { NSLog(@"ErrorInfo event code:%d\n", e->code); @@ -249,7 +249,7 @@ void AppDelegate_ErrorInfoEventHandler(void *ctx, ErrorInfoEventArgs *e) } } -void AppDelegate_EmbedWindowEventHandler(void *ctx, EmbedWindowEventArgs *e) +void AppDelegate_EmbedWindowEventHandler(void *ctx, const EmbedWindowEventArgs *e) { rdpContext *context = (rdpContext *)ctx; @@ -269,7 +269,7 @@ void AppDelegate_EmbedWindowEventHandler(void *ctx, EmbedWindowEventArgs *e) } } -void AppDelegate_ResizeWindowEventHandler(void *ctx, ResizeWindowEventArgs *e) +void AppDelegate_ResizeWindowEventHandler(void *ctx, const ResizeWindowEventArgs *e) { rdpContext *context = (rdpContext *)ctx; fprintf(stderr, "ResizeWindowEventHandler: %d %d\n", e->width, e->height); diff --git a/client/Sample/tf_channels.c b/client/Sample/tf_channels.c index 71f706624..53a145273 100644 --- a/client/Sample/tf_channels.c +++ b/client/Sample/tf_channels.c @@ -73,7 +73,7 @@ static UINT tf_update_surfaces(RdpgfxClientContext* context) return CHANNEL_RC_OK; } -void tf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e) +void tf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e) { tfContext* tf = (tfContext*)context; @@ -103,7 +103,7 @@ void tf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* } } -void tf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e) +void tf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e) { tfContext* tf = (tfContext*)context; diff --git a/client/Sample/tf_channels.h b/client/Sample/tf_channels.h index b1c0b8655..d00a5c2f0 100644 --- a/client/Sample/tf_channels.h +++ b/client/Sample/tf_channels.h @@ -27,7 +27,7 @@ int tf_on_channel_connected(freerdp* instance, const char* name, void* pInterface); int tf_on_channel_disconnected(freerdp* instance, const char* name, void* pInterface); -void tf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e); -void tf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e); +void tf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e); +void tf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e); #endif /* FREERDP_CLIENT_SAMPLE_CHANNELS_H */ diff --git a/client/Wayland/wlf_channels.c b/client/Wayland/wlf_channels.c index 6df91c0bb..a0b86565e 100644 --- a/client/Wayland/wlf_channels.c +++ b/client/Wayland/wlf_channels.c @@ -99,7 +99,7 @@ static void wlf_encomsp_uninit(wlfContext* wlf, EncomspClientContext* encomsp) wlf->encomsp = NULL; } -void wlf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e) +void wlf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e) { wlfContext* wlf = (wlfContext*)context; @@ -140,7 +140,7 @@ void wlf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs } } -void wlf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e) +void wlf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e) { wlfContext* wlf = (wlfContext*)context; diff --git a/client/Wayland/wlf_channels.h b/client/Wayland/wlf_channels.h index c56be6a9e..e8760316b 100644 --- a/client/Wayland/wlf_channels.h +++ b/client/Wayland/wlf_channels.h @@ -31,7 +31,7 @@ int wlf_on_channel_connected(freerdp* instance, const char* name, void* pInterface); int wlf_on_channel_disconnected(freerdp* instance, const char* name, void* pInterface); -void wlf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e); -void wlf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e); +void wlf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e); +void wlf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e); #endif /* FREERDP_CLIENT_WAYLAND_CHANNELS_H */ diff --git a/client/Wayland/wlf_disp.c b/client/Wayland/wlf_disp.c index 51a5f9e31..f06d0040a 100644 --- a/client/Wayland/wlf_disp.c +++ b/client/Wayland/wlf_disp.c @@ -165,7 +165,7 @@ static BOOL wlf_disp_check_context(void* context, wlfContext** ppwlc, wlfDispCon return TRUE; } -static void wlf_disp_OnActivated(void* context, ActivatedEventArgs* e) +static void wlf_disp_OnActivated(void* context, const ActivatedEventArgs* e) { wlfContext* wlc; wlfDispContext* wlfDisp; @@ -187,7 +187,7 @@ static void wlf_disp_OnActivated(void* context, ActivatedEventArgs* e) } } -static void wlf_disp_OnGraphicsReset(void* context, GraphicsResetEventArgs* e) +static void wlf_disp_OnGraphicsReset(void* context, const GraphicsResetEventArgs* e) { wlfContext* wlc; wlfDispContext* wlfDisp; diff --git a/client/Windows/wf_channels.c b/client/Windows/wf_channels.c index f6d29240b..b83d92a90 100644 --- a/client/Windows/wf_channels.c +++ b/client/Windows/wf_channels.c @@ -31,7 +31,7 @@ #include #define TAG CLIENT_TAG("windows") -void wf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e) +void wf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e) { wfContext* wfc = (wfContext*)context; rdpSettings* settings = wfc->context.settings; @@ -76,7 +76,7 @@ void wf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* } } -void wf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e) +void wf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e) { wfContext* wfc = (wfContext*)context; rdpSettings* settings = wfc->context.settings; diff --git a/client/Windows/wf_channels.h b/client/Windows/wf_channels.h index 64a408ac6..867631062 100644 --- a/client/Windows/wf_channels.h +++ b/client/Windows/wf_channels.h @@ -20,6 +20,7 @@ #define FREERDP_CLIENT_WIN_CHANNELS_H #include +#include #include #include #include @@ -29,7 +30,7 @@ #include "wf_client.h" -void wf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e); -void wf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e); +void wf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e); +void wf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e); #endif /* FREERDP_CLIENT_WIN_CHANNELS_H */ diff --git a/client/X11/xf_channels.c b/client/X11/xf_channels.c index 6253aca6e..b17266636 100644 --- a/client/X11/xf_channels.c +++ b/client/X11/xf_channels.c @@ -36,7 +36,7 @@ #include "xf_disp.h" #include "xf_video.h" -void xf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e) +void xf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e) { xfContext* xfc = (xfContext*)context; rdpSettings* settings; @@ -95,7 +95,7 @@ void xf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* } } -void xf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e) +void xf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e) { xfContext* xfc = (xfContext*)context; rdpSettings* settings; diff --git a/client/X11/xf_channels.h b/client/X11/xf_channels.h index c12d823dd..86b00b953 100644 --- a/client/X11/xf_channels.h +++ b/client/X11/xf_channels.h @@ -31,7 +31,7 @@ #include #include -void xf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e); -void xf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e); +void xf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e); +void xf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e); #endif /* FREERDP_CLIENT_X11_CHANNELS_H */ diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 9100ed463..00792002b 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1766,7 +1766,7 @@ DWORD xf_exit_code_from_disconnect_reason(DWORD reason) return reason; } -static void xf_TerminateEventHandler(void* context, TerminateEventArgs* e) +static void xf_TerminateEventHandler(void* context, const TerminateEventArgs* e) { rdpContext* ctx = (rdpContext*)context; WINPR_UNUSED(e); @@ -1774,7 +1774,7 @@ static void xf_TerminateEventHandler(void* context, TerminateEventArgs* e) } #ifdef WITH_XRENDER -static void xf_ZoomingChangeEventHandler(void* context, ZoomingChangeEventArgs* e) +static void xf_ZoomingChangeEventHandler(void* context, const ZoomingChangeEventArgs* e) { xfContext* xfc = (xfContext*)context; rdpSettings* settings = xfc->context.settings; @@ -1798,7 +1798,7 @@ static void xf_ZoomingChangeEventHandler(void* context, ZoomingChangeEventArgs* xf_draw_screen(xfc, 0, 0, settings->DesktopWidth, settings->DesktopHeight); } -static void xf_PanningChangeEventHandler(void* context, PanningChangeEventArgs* e) +static void xf_PanningChangeEventHandler(void* context, const PanningChangeEventArgs* e) { xfContext* xfc = (xfContext*)context; rdpSettings* settings = xfc->context.settings; diff --git a/client/X11/xf_disp.c b/client/X11/xf_disp.c index 1577b24e2..25fca8777 100644 --- a/client/X11/xf_disp.c +++ b/client/X11/xf_disp.c @@ -213,7 +213,7 @@ static void xf_disp_OnActivated(void* context, ActivatedEventArgs* e) } } -static void xf_disp_OnGraphicsReset(void* context, GraphicsResetEventArgs* e) +static void xf_disp_OnGraphicsReset(void* context, const GraphicsResetEventArgs* e) { xfContext* xfc; xfDispContext* xfDisp; @@ -231,7 +231,7 @@ static void xf_disp_OnGraphicsReset(void* context, GraphicsResetEventArgs* e) } } -static void xf_disp_OnTimer(void* context, TimerEventArgs* e) +static void xf_disp_OnTimer(void* context, const TimerEventArgs* e) { xfContext* xfc; xfDispContext* xfDisp; diff --git a/client/iOS/FreeRDP/ios_freerdp.m b/client/iOS/FreeRDP/ios_freerdp.m index 295d769a8..711880b75 100644 --- a/client/iOS/FreeRDP/ios_freerdp.m +++ b/client/iOS/FreeRDP/ios_freerdp.m @@ -28,7 +28,7 @@ #pragma mark Connection helpers -static void ios_OnChannelConnectedEventHandler(void *context, ChannelConnectedEventArgs *e) +static void ios_OnChannelConnectedEventHandler(void *context, const ChannelConnectedEventArgs *e) { rdpSettings *settings; mfContext *afc; @@ -56,7 +56,8 @@ static void ios_OnChannelConnectedEventHandler(void *context, ChannelConnectedEv } } -static void ios_OnChannelDisconnectedEventHandler(void *context, ChannelDisconnectedEventArgs *e) +static void ios_OnChannelDisconnectedEventHandler(void *context, + const ChannelDisconnectedEventArgs *e) { rdpSettings *settings; mfContext *afc; diff --git a/include/freerdp/event.h b/include/freerdp/event.h index 15623625f..826609e61 100644 --- a/include/freerdp/event.h +++ b/include/freerdp/event.h @@ -23,6 +23,8 @@ #include #include +#include + #ifdef __cplusplus extern "C" { diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 1f44dba7d..04c7e049a 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -601,14 +601,14 @@ const char* freerdp_get_build_revision(void) } static wEventType FreeRDP_Events[] = { - DEFINE_EVENT_ENTRY(WindowStateChange) DEFINE_EVENT_ENTRY(ResizeWindow) - DEFINE_EVENT_ENTRY(LocalResizeWindow) DEFINE_EVENT_ENTRY(EmbedWindow) - DEFINE_EVENT_ENTRY(PanningChange) DEFINE_EVENT_ENTRY(ZoomingChange) - DEFINE_EVENT_ENTRY(ErrorInfo) DEFINE_EVENT_ENTRY(Terminate) - DEFINE_EVENT_ENTRY(ConnectionResult) DEFINE_EVENT_ENTRY(ChannelConnected) - DEFINE_EVENT_ENTRY(ChannelDisconnected) DEFINE_EVENT_ENTRY(MouseEvent) - DEFINE_EVENT_ENTRY(Activated) DEFINE_EVENT_ENTRY(Timer) - DEFINE_EVENT_ENTRY(GraphicsReset) + DEFINE_EVENT_ENTRY(WindowStateChange), DEFINE_EVENT_ENTRY(ResizeWindow), + DEFINE_EVENT_ENTRY(LocalResizeWindow), DEFINE_EVENT_ENTRY(EmbedWindow), + DEFINE_EVENT_ENTRY(PanningChange), DEFINE_EVENT_ENTRY(ZoomingChange), + DEFINE_EVENT_ENTRY(ErrorInfo), DEFINE_EVENT_ENTRY(Terminate), + DEFINE_EVENT_ENTRY(ConnectionResult), DEFINE_EVENT_ENTRY(ChannelConnected), + DEFINE_EVENT_ENTRY(ChannelDisconnected), DEFINE_EVENT_ENTRY(MouseEvent), + DEFINE_EVENT_ENTRY(Activated), DEFINE_EVENT_ENTRY(Timer), + DEFINE_EVENT_ENTRY(GraphicsReset) }; /** Allocator function for a rdp context. diff --git a/libfreerdp/gdi/video.c b/libfreerdp/gdi/video.c index ac62d5a94..3384622e5 100644 --- a/libfreerdp/gdi/video.c +++ b/libfreerdp/gdi/video.c @@ -147,7 +147,7 @@ void gdi_video_control_uninit(rdpGdi* gdi, VideoClientContext* video) gdi->video = NULL; } -static void gdi_video_timer(void* context, TimerEventArgs* timer) +static void gdi_video_timer(void* context, const TimerEventArgs* timer) { rdpContext* ctx = (rdpContext*)context; rdpGdi* gdi; diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index 642929a8c..841c98014 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -69,7 +69,7 @@ static BOOL proxy_server_reactivate(rdpContext* ps, const rdpContext* pc) return TRUE; } -static void pf_client_on_error_info(void* ctx, ErrorInfoEventArgs* e) +static void pf_client_on_error_info(void* ctx, const ErrorInfoEventArgs* e) { pClientContext* pc = (pClientContext*)ctx; pServerContext* ps; @@ -91,7 +91,7 @@ static void pf_client_on_error_info(void* ctx, ErrorInfoEventArgs* e) freerdp_send_error_info(ps->context.rdp); } -static void pf_client_on_activated(void* ctx, ActivatedEventArgs* e) +static void pf_client_on_activated(void* ctx, const ActivatedEventArgs* e) { pClientContext* pc = (pClientContext*)ctx; pServerContext* ps; diff --git a/server/shadow/Win/win_rdp.c b/server/shadow/Win/win_rdp.c index cf9acddd1..21c37eb6c 100644 --- a/server/shadow/Win/win_rdp.c +++ b/server/shadow/Win/win_rdp.c @@ -21,6 +21,7 @@ #endif #include +#include #include #include @@ -28,22 +29,29 @@ #define TAG SERVER_TAG("shadow.win") -static void shw_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e) +static void shw_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e) { shwContext* shw = (shwContext*)context; + WINPR_ASSERT(e); WLog_INFO(TAG, "OnChannelConnected: %s", e->name); } -static void shw_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e) +static void shw_OnChannelDisconnectedEventHandler(void* context, + const ChannelDisconnectedEventArgs* e) { shwContext* shw = (shwContext*)context; + WINPR_ASSERT(e); WLog_INFO(TAG, "OnChannelDisconnected: %s", e->name); } static BOOL shw_begin_paint(rdpContext* context) { shwContext* shw; - rdpGdi* gdi = context->gdi; + rdpGdi* gdi; + + WINPR_ASSERT(context); + gdi = context->gdi; + WINPR_ASSERT(gdi); shw = (shwContext*)context; gdi->primary->hdc->hwnd->invalid->null = TRUE; gdi->primary->hdc->hwnd->ninvalid = 0; @@ -104,9 +112,10 @@ static int shw_verify_x509_certificate(freerdp* instance, const BYTE* data, size return 1; } -static void shw_OnConnectionResultEventHandler(void* context, ConnectionResultEventArgs* e) +static void shw_OnConnectionResultEventHandler(void* context, const ConnectionResultEventArgs* e) { shwContext* shw = (shwContext*)context; + WINPR_ASSERT(e); WLog_INFO(TAG, "OnConnectionResult: %d", e->result); } diff --git a/winpr/include/winpr/collections.h b/winpr/include/winpr/collections.h index df14f03a6..c1e76b463 100644 --- a/winpr/include/winpr/collections.h +++ b/winpr/include/winpr/collections.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -492,7 +493,7 @@ extern "C" }; typedef struct _wEventArgs wEventArgs; - typedef void (*pEventHandler)(void* context, wEventArgs* e); + typedef void (*pEventHandler)(void* context, const wEventArgs* e); #define MAX_EVENT_HANDLERS 32 @@ -505,48 +506,54 @@ extern "C" }; typedef struct _wEventType wEventType; -#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 EventArgsInit(_event_args, _sender) \ + memset(_event_args, 0, sizeof(*_event_args)); \ + (_event_args)->e.Size = sizeof(*_event_args); \ + (_event_args)->e.Sender = _sender -#define DEFINE_EVENT_HANDLER(_name) \ - typedef void (*p##_name##EventHandler)(void* context, _name##EventArgs* e) +#define DEFINE_EVENT_HANDLER(name) \ + typedef void (*p##name##EventHandler)(void* context, const 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_RAISE(name) \ + static INLINE int PubSub_On##name(wPubSub* pubSub, void* context, const name##EventArgs* e) \ + { \ + WINPR_ASSERT(e); \ + return PubSub_OnEvent(pubSub, #name, context, &e->e); \ } -#define DEFINE_EVENT_SUBSCRIBE(_name) \ - static INLINE int PubSub_Subscribe##_name(wPubSub* pubSub, \ - p##_name##EventHandler EventHandler) \ +#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_Subscribe(pubSub, #_name, (pEventHandler)EventHandler); \ + return PubSub_Unsubscribe(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 \ - { \ +#define DEFINE_EVENT_BEGIN(name) \ + typedef struct _##name##EventArgs \ + { \ wEventArgs e; -#define DEFINE_EVENT_END(_name) \ - } \ - _name##EventArgs; \ - DEFINE_EVENT_HANDLER(_name); \ - DEFINE_EVENT_RAISE(_name) \ - DEFINE_EVENT_SUBSCRIBE(_name) \ - DEFINE_EVENT_UNSUBSCRIBE(_name) +#define DEFINE_EVENT_END(name) \ + } \ + name##EventArgs; \ + 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), NULL }, 0, { NULL } }, +#define DEFINE_EVENT_ENTRY(name) \ + { \ +#name, { sizeof(name##EventArgs), NULL }, 0, \ + { \ + NULL \ + } \ + } typedef struct _wPubSub wPubSub; @@ -563,7 +570,7 @@ extern "C" pEventHandler EventHandler); WINPR_API int PubSub_OnEvent(wPubSub* pubSub, const char* EventName, void* context, - wEventArgs* e); + const wEventArgs* e); WINPR_API wPubSub* PubSub_New(BOOL synchronized); WINPR_API void PubSub_Free(wPubSub* pubSub); diff --git a/winpr/libwinpr/utils/collections/PubSub.c b/winpr/libwinpr/utils/collections/PubSub.c index ba16cf0af..306be1bd7 100644 --- a/winpr/libwinpr/utils/collections/PubSub.c +++ b/winpr/libwinpr/utils/collections/PubSub.c @@ -46,6 +46,7 @@ struct _wPubSub wEventType* PubSub_GetEventTypes(wPubSub* pubSub, size_t* count) { + WINPR_ASSERT(pubSub); if (count) *count = pubSub->count; @@ -58,12 +59,14 @@ wEventType* PubSub_GetEventTypes(wPubSub* pubSub, size_t* count) void PubSub_Lock(wPubSub* pubSub) { + WINPR_ASSERT(pubSub); if (pubSub->synchronized) EnterCriticalSection(&pubSub->lock); } void PubSub_Unlock(wPubSub* pubSub) { + WINPR_ASSERT(pubSub); if (pubSub->synchronized) LeaveCriticalSection(&pubSub->lock); } @@ -73,6 +76,8 @@ wEventType* PubSub_FindEventType(wPubSub* pubSub, const char* EventName) size_t index; wEventType* event = NULL; + WINPR_ASSERT(pubSub); + WINPR_ASSERT(EventName); for (index = 0; index < pubSub->count; index++) { if (strcmp(pubSub->events[index].EventName, EventName) == 0) @@ -87,6 +92,8 @@ wEventType* PubSub_FindEventType(wPubSub* pubSub, const char* EventName) void PubSub_AddEventTypes(wPubSub* pubSub, wEventType* events, size_t count) { + WINPR_ASSERT(pubSub); + WINPR_ASSERT(events || (count == 0)); if (pubSub->synchronized) PubSub_Lock(pubSub); @@ -114,6 +121,8 @@ int PubSub_Subscribe(wPubSub* pubSub, const char* EventName, pEventHandler Event { wEventType* event; int status = -1; + WINPR_ASSERT(pubSub); + WINPR_ASSERT(EventHandler); if (pubSub->synchronized) PubSub_Lock(pubSub); @@ -141,6 +150,9 @@ int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, pEventHandler Eve size_t index; wEventType* event; int status = -1; + WINPR_ASSERT(pubSub); + WINPR_ASSERT(EventName); + WINPR_ASSERT(EventHandler); if (pubSub->synchronized) PubSub_Lock(pubSub); @@ -170,11 +182,13 @@ int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, pEventHandler Eve return status; } -int PubSub_OnEvent(wPubSub* pubSub, const char* EventName, void* context, wEventArgs* e) +int PubSub_OnEvent(wPubSub* pubSub, const char* EventName, void* context, const wEventArgs* e) { size_t index; wEventType* event; int status = -1; + WINPR_ASSERT(pubSub); + WINPR_ASSERT(e); if (pubSub->synchronized) PubSub_Lock(pubSub); diff --git a/winpr/libwinpr/utils/test/TestPubSub.c b/winpr/libwinpr/utils/test/TestPubSub.c index 1ec08340a..18157d931 100644 --- a/winpr/libwinpr/utils/test/TestPubSub.c +++ b/winpr/libwinpr/utils/test/TestPubSub.c @@ -15,18 +15,18 @@ int flags; int button; DEFINE_EVENT_END(MouseButton) -static void MouseMotionEventHandler(void* context, MouseMotionEventArgs* e) +static void MouseMotionEventHandler(void* context, const MouseMotionEventArgs* e) { printf("MouseMotionEvent: x: %d y: %d\n", e->x, e->y); } -static void MouseButtonEventHandler(void* context, MouseButtonEventArgs* e) +static void MouseButtonEventHandler(void* context, const MouseButtonEventArgs* e) { printf("MouseButtonEvent: x: %d y: %d flags: %d button: %d\n", e->x, e->y, e->flags, e->button); } -static wEventType Node_Events[] = { DEFINE_EVENT_ENTRY(MouseMotion) - DEFINE_EVENT_ENTRY(MouseButton) }; +static wEventType Node_Events[] = { DEFINE_EVENT_ENTRY(MouseMotion), + DEFINE_EVENT_ENTRY(MouseButton) }; #define NODE_EVENT_COUNT (sizeof(Node_Events) / sizeof(wEventType))