Cleaned up PubSub

* Callback arguments now const
* Fixed missing includes
This commit is contained in:
akallabeth 2022-01-19 09:08:02 +01:00 committed by akallabeth
parent 1326134cdf
commit e6e6ed5dbd
23 changed files with 127 additions and 91 deletions

View File

@ -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;

View File

@ -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;

View File

@ -13,10 +13,10 @@
#import <freerdp/client/cmdline.h>
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);

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -31,7 +31,7 @@
#include <freerdp/log.h>
#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;

View File

@ -20,6 +20,7 @@
#define FREERDP_CLIENT_WIN_CHANNELS_H
#include <freerdp/freerdp.h>
#include <freerdp/client.h>
#include <freerdp/client/channels.h>
#include <freerdp/client/rdpei.h>
#include <freerdp/client/rdpgfx.h>
@ -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 */

View File

@ -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;

View File

@ -31,7 +31,7 @@
#include <freerdp/client/geometry.h>
#include <freerdp/client/video.h>
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 */

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -23,6 +23,8 @@
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#include <winpr/collections.h>
#ifdef __cplusplus
extern "C"
{

View File

@ -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.

View File

@ -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;

View File

@ -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;

View File

@ -21,6 +21,7 @@
#endif
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/print.h>
#include <freerdp/log.h>
@ -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);
}

View File

@ -27,6 +27,7 @@
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#include <winpr/assert.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
@ -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);

View File

@ -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);

View File

@ -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))