libwinpr-utils: rename certain PubSub functions
This commit is contained in:
parent
90ce8be9fc
commit
fbf3208b0a
@ -318,7 +318,7 @@ void freerdp_get_version(int* major, int* minor, int* revision)
|
||||
*revision = FREERDP_VERSION_REVISION;
|
||||
}
|
||||
|
||||
static wEvent FreeRDP_Events[] =
|
||||
static wEventType FreeRDP_Events[] =
|
||||
{
|
||||
DEFINE_EVENT_ENTRY(WindowStateChange)
|
||||
DEFINE_EVENT_ENTRY(ResizeWindow)
|
||||
@ -345,7 +345,7 @@ int freerdp_context_new(freerdp* instance)
|
||||
context = instance->context;
|
||||
|
||||
context->pubSub = PubSub_New(TRUE);
|
||||
PubSub_Publish(context->pubSub, FreeRDP_Events, sizeof(FreeRDP_Events) / sizeof(wEvent));
|
||||
PubSub_AddEventTypes(context->pubSub, FreeRDP_Events, sizeof(FreeRDP_Events) / sizeof(wEventType));
|
||||
|
||||
rdp = rdp_new(instance);
|
||||
instance->input = rdp->input;
|
||||
|
@ -352,14 +352,14 @@ typedef void (*pEventHandler)(void* context, wEventArgs* e);
|
||||
|
||||
#define MAX_EVENT_HANDLERS 32
|
||||
|
||||
struct _wEvent
|
||||
struct _wEventType
|
||||
{
|
||||
const char* EventName;
|
||||
wEventArgs EventArgs;
|
||||
int EventHandlerCount;
|
||||
pEventHandler EventHandlers[MAX_EVENT_HANDLERS];
|
||||
};
|
||||
typedef struct _wEvent wEvent;
|
||||
typedef struct _wEventType wEventType;
|
||||
|
||||
#define EventArgsInit(_event_args, _sender) \
|
||||
memset(_event_args, 0, sizeof(*_event_args)); \
|
||||
@ -406,17 +406,16 @@ struct _wPubSub
|
||||
|
||||
int size;
|
||||
int count;
|
||||
wEvent* events;
|
||||
wEventType* events;
|
||||
};
|
||||
typedef struct _wPubSub wPubSub;
|
||||
|
||||
WINPR_API BOOL PubSub_Lock(wPubSub* pubSub);
|
||||
WINPR_API BOOL PubSub_Unlock(wPubSub* pubSub);
|
||||
|
||||
WINPR_API wEvent* PubSub_Events(wPubSub* pubSub, int* count);
|
||||
WINPR_API wEvent* PubSub_FindEvent(wPubSub* pubSub, const char* EventName);
|
||||
|
||||
WINPR_API void PubSub_Publish(wPubSub* pubSub, wEvent* events, int count);
|
||||
WINPR_API wEventType* PubSub_GetEventTypes(wPubSub* pubSub, int* count);
|
||||
WINPR_API void PubSub_AddEventTypes(wPubSub* pubSub, wEventType* events, int count);
|
||||
WINPR_API wEventType* PubSub_FindEventType(wPubSub* pubSub, const char* EventName);
|
||||
|
||||
WINPR_API int PubSub_Subscribe(wPubSub* pubSub, const char* EventName, pEventHandler EventHandler);
|
||||
WINPR_API int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, pEventHandler EventHandler);
|
||||
|
@ -34,7 +34,7 @@
|
||||
* Properties
|
||||
*/
|
||||
|
||||
wEvent* PubSub_Events(wPubSub* pubSub, int* count)
|
||||
wEventType* PubSub_GetEventTypes(wPubSub* pubSub, int* count)
|
||||
{
|
||||
if (count)
|
||||
*count = pubSub->count;
|
||||
@ -56,10 +56,10 @@ BOOL PubSub_Unlock(wPubSub* pubSub)
|
||||
return ReleaseMutex(pubSub->mutex);
|
||||
}
|
||||
|
||||
wEvent* PubSub_FindEvent(wPubSub* pubSub, const char* EventName)
|
||||
wEventType* PubSub_FindEventType(wPubSub* pubSub, const char* EventName)
|
||||
{
|
||||
int index;
|
||||
wEvent* event = NULL;
|
||||
wEventType* event = NULL;
|
||||
|
||||
for (index = 0; pubSub->count; index++)
|
||||
{
|
||||
@ -73,7 +73,7 @@ wEvent* PubSub_FindEvent(wPubSub* pubSub, const char* EventName)
|
||||
return event;
|
||||
}
|
||||
|
||||
void PubSub_Publish(wPubSub* pubSub, wEvent* events, int count)
|
||||
void PubSub_AddEventTypes(wPubSub* pubSub, wEventType* events, int count)
|
||||
{
|
||||
if (pubSub->synchronized)
|
||||
PubSub_Lock(pubSub);
|
||||
@ -81,10 +81,10 @@ void PubSub_Publish(wPubSub* pubSub, wEvent* events, int count)
|
||||
while (pubSub->count + count >= pubSub->size)
|
||||
{
|
||||
pubSub->size *= 2;
|
||||
pubSub->events = (wEvent*) realloc(pubSub->events, pubSub->size);
|
||||
pubSub->events = (wEventType*) realloc(pubSub->events, pubSub->size);
|
||||
}
|
||||
|
||||
CopyMemory(&pubSub->events[pubSub->count], events, count * sizeof(wEvent));
|
||||
CopyMemory(&pubSub->events[pubSub->count], events, count * sizeof(wEventType));
|
||||
pubSub->count += count;
|
||||
|
||||
if (pubSub->synchronized)
|
||||
@ -93,13 +93,13 @@ void PubSub_Publish(wPubSub* pubSub, wEvent* events, int count)
|
||||
|
||||
int PubSub_Subscribe(wPubSub* pubSub, const char* EventName, pEventHandler EventHandler)
|
||||
{
|
||||
wEvent* event;
|
||||
wEventType* event;
|
||||
int status = -1;
|
||||
|
||||
if (pubSub->synchronized)
|
||||
PubSub_Lock(pubSub);
|
||||
|
||||
event = PubSub_FindEvent(pubSub, EventName);
|
||||
event = PubSub_FindEventType(pubSub, EventName);
|
||||
|
||||
if (event)
|
||||
{
|
||||
@ -125,13 +125,13 @@ int PubSub_Subscribe(wPubSub* pubSub, const char* EventName, pEventHandler Event
|
||||
int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, pEventHandler EventHandler)
|
||||
{
|
||||
int index;
|
||||
wEvent* event;
|
||||
wEventType* event;
|
||||
int status = -1;
|
||||
|
||||
if (pubSub->synchronized)
|
||||
PubSub_Lock(pubSub);
|
||||
|
||||
event = PubSub_FindEvent(pubSub, EventName);
|
||||
event = PubSub_FindEventType(pubSub, EventName);
|
||||
|
||||
if (event)
|
||||
{
|
||||
@ -144,7 +144,7 @@ int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, pEventHandler Eve
|
||||
event->EventHandlers[index] = NULL;
|
||||
event->EventHandlerCount--;
|
||||
MoveMemory(&event->EventHandlers[index], &event->EventHandlers[index + 1],
|
||||
(MAX_EVENT_HANDLERS - index - 1) * sizeof(wEvent));
|
||||
(MAX_EVENT_HANDLERS - index - 1) * sizeof(wEventType));
|
||||
status = 1;
|
||||
}
|
||||
}
|
||||
@ -159,13 +159,13 @@ int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, pEventHandler Eve
|
||||
int PubSub_OnEvent(wPubSub* pubSub, const char* EventName, void* context, wEventArgs* e)
|
||||
{
|
||||
int index;
|
||||
wEvent* event;
|
||||
wEventType* event;
|
||||
int status = -1;
|
||||
|
||||
if (pubSub->synchronized)
|
||||
PubSub_Lock(pubSub);
|
||||
|
||||
event = PubSub_FindEvent(pubSub, EventName);
|
||||
event = PubSub_FindEventType(pubSub, EventName);
|
||||
|
||||
if (event)
|
||||
{
|
||||
@ -207,8 +207,8 @@ wPubSub* PubSub_New(BOOL synchronized)
|
||||
pubSub->count = 0;
|
||||
pubSub->size = 64;
|
||||
|
||||
pubSub->events = (wEvent*) malloc(sizeof(wEvent) * pubSub->size);
|
||||
ZeroMemory(pubSub->events, sizeof(wEvent) * pubSub->size);
|
||||
pubSub->events = (wEventType*) malloc(sizeof(wEventType) * pubSub->size);
|
||||
ZeroMemory(pubSub->events, sizeof(wEventType) * pubSub->size);
|
||||
}
|
||||
|
||||
return pubSub;
|
||||
|
@ -25,25 +25,13 @@ void MouseButtonEventHandler(void* context, MouseButtonEventArgs* e)
|
||||
printf("MouseButtonEvent: x: %d y: %d flags: %d button: %d\n", e->x, e->y, e->flags, e->button);
|
||||
}
|
||||
|
||||
static wEvent Node_Events[] =
|
||||
static wEventType Node_Events[] =
|
||||
{
|
||||
DEFINE_EVENT_ENTRY(MouseMotion)
|
||||
DEFINE_EVENT_ENTRY(MouseButton)
|
||||
};
|
||||
|
||||
#define NODE_EVENT_COUNT (sizeof(Node_Events) / sizeof(wEvent))
|
||||
|
||||
/* strongly-typed wrappers could be automatically defined using a macro */
|
||||
|
||||
static INLINE int PubSub_SubscribeMouseMotion(wPubSub* pubSub, pMouseMotionEventHandler MouseMotionEventHandler)
|
||||
{
|
||||
return PubSub_Subscribe(pubSub, "MouseMotion", (pEventHandler) MouseMotionEventHandler);
|
||||
}
|
||||
|
||||
static INLINE int PubSub_OnMouseMotion(wPubSub* pubSub, void* context, MouseMotionEventArgs* e)
|
||||
{
|
||||
return PubSub_OnEvent(pubSub, "MouseMotion", context, (wEventArgs*) e);
|
||||
}
|
||||
#define NODE_EVENT_COUNT (sizeof(Node_Events) / sizeof(wEventType))
|
||||
|
||||
int TestPubSub(int argc, char* argv[])
|
||||
{
|
||||
@ -51,12 +39,10 @@ int TestPubSub(int argc, char* argv[])
|
||||
|
||||
node = PubSub_New(TRUE);
|
||||
|
||||
PubSub_Publish(node, Node_Events, NODE_EVENT_COUNT);
|
||||
|
||||
/* Register Event Handler */
|
||||
PubSub_AddEventTypes(node, Node_Events, NODE_EVENT_COUNT);
|
||||
|
||||
PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler);
|
||||
PubSub_Subscribe(node, "MouseButton", (pEventHandler) MouseButtonEventHandler);
|
||||
PubSub_SubscribeMouseButton(node, MouseButtonEventHandler);
|
||||
|
||||
/* Call Event Handler */
|
||||
{
|
||||
@ -76,7 +62,7 @@ int TestPubSub(int argc, char* argv[])
|
||||
e.flags = 7;
|
||||
e.button = 1;
|
||||
|
||||
PubSub_OnEvent(node, "MouseButton", NULL, (wEventArgs*) &e);
|
||||
PubSub_OnMouseButton(node, NULL, &e);
|
||||
}
|
||||
|
||||
PubSub_Free(node);
|
||||
|
Loading…
Reference in New Issue
Block a user