libfreerdp-core: message queue refactoring

This commit is contained in:
Marc-André Moreau 2013-02-04 11:05:24 -05:00
parent e18a0b807f
commit ea7a35ee9b
10 changed files with 475 additions and 527 deletions

View File

@ -58,7 +58,7 @@ typedef struct rdp_input rdpInput;
#define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH 4 #define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH 4
/* defined inside libfreerdp-core */ /* defined inside libfreerdp-core */
typedef struct rdp_event rdpEvent; typedef struct rdp_input_proxy rdpInputProxy;
/* Input Interface */ /* Input Interface */
@ -84,7 +84,7 @@ struct rdp_input
/* Internal */ /* Internal */
BOOL asynchronous; BOOL asynchronous;
rdpEvent* event; rdpInputProxy* proxy;
wMessageQueue* queue; wMessageQueue* queue;
}; };

View File

@ -135,7 +135,7 @@ enum SURFCMD_FRAMEACTION
}; };
/* defined inside libfreerdp-core */ /* defined inside libfreerdp-core */
typedef struct rdp_message rdpMessage; typedef struct rdp_update_proxy rdpUpdateProxy;
/* Update Interface */ /* Update Interface */
@ -204,7 +204,7 @@ struct rdp_update
SURFACE_FRAME_MARKER surface_frame_marker; SURFACE_FRAME_MARKER surface_frame_marker;
BOOL asynchronous; BOOL asynchronous;
rdpMessage* message; rdpUpdateProxy* proxy;
wMessageQueue* queue; wMessageQueue* queue;
}; };

View File

@ -64,8 +64,6 @@ set(${MODULE_PREFIX}_SRCS
info.h info.h
input.c input.c
input.h input.h
event.c
event.h
license.c license.c
license.h license.h
errinfo.c errinfo.c

View File

@ -1,212 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Asynchronous Event Queue
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "event.h"
#include <winpr/crt.h>
#include <winpr/collections.h>
/* Input */
static void event_SynchronizeEvent(rdpInput* input, UINT32 flags)
{
MessageQueue_Post(input->queue, (void*) input,
MakeMessageId(Input, SynchronizeEvent), (void*) (size_t) flags, NULL);
}
static void event_KeyboardEvent(rdpInput* input, UINT16 flags, UINT16 code)
{
MessageQueue_Post(input->queue, (void*) input,
MakeMessageId(Input, KeyboardEvent), (void*) (size_t) flags, (void*) (size_t) code);
}
static void event_UnicodeKeyboardEvent(rdpInput* input, UINT16 flags, UINT16 code)
{
MessageQueue_Post(input->queue, (void*) input,
MakeMessageId(Input, UnicodeKeyboardEvent), (void*) (size_t) flags, (void*) (size_t) code);
}
static void event_MouseEvent(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
UINT32 pos = (x << 16) | y;
MessageQueue_Post(input->queue, (void*) input,
MakeMessageId(Input, MouseEvent), (void*) (size_t) flags, (void*) (size_t) pos);
}
static void event_ExtendedMouseEvent(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
UINT32 pos = (x << 16) | y;
MessageQueue_Post(input->queue, (void*) input,
MakeMessageId(Input, ExtendedMouseEvent), (void*) (size_t) flags, (void*) (size_t) pos);
}
/* Event Queue */
int event_process_input_class(rdpEvent* event, wMessage* msg, int type)
{
int status = 0;
switch (type)
{
case Input_SynchronizeEvent:
IFCALL(event->SynchronizeEvent, msg->context, (UINT32) (size_t) msg->wParam);
break;
case Input_KeyboardEvent:
IFCALL(event->KeyboardEvent, msg->context, (UINT16) (size_t) msg->wParam, (UINT16) (size_t) msg->lParam);
break;
case Input_UnicodeKeyboardEvent:
IFCALL(event->UnicodeKeyboardEvent, msg->context, (UINT16) (size_t) msg->wParam, (UINT16) (size_t) msg->lParam);
break;
case Input_MouseEvent:
{
UINT32 pos;
UINT16 x, y;
pos = (UINT32) (size_t) msg->lParam;
x = ((pos & 0xFFFF0000) >> 16);
y = (pos & 0x0000FFFF);
IFCALL(event->MouseEvent, msg->context, (UINT16) (size_t) msg->wParam, x, y);
}
break;
case Input_ExtendedMouseEvent:
{
UINT32 pos;
UINT16 x, y;
pos = (UINT32) (size_t) msg->lParam;
x = ((pos & 0xFFFF0000) >> 16);
y = (pos & 0x0000FFFF);
IFCALL(event->ExtendedMouseEvent, msg->context, (UINT16) (size_t) msg->wParam, x, y);
}
break;
default:
status = -1;
break;
}
return status;
}
int event_process_class(rdpEvent* event, wMessage* msg, int msgClass, int msgType)
{
int status = 0;
switch (msgClass)
{
case Input_Class:
status = event_process_input_class(event, msg, msgType);
break;
default:
status = -1;
break;
}
if (status < 0)
printf("Unknown event: class: %d type: %d\n", msgClass, msgType);
return status;
}
int event_process_pending_input(rdpInput* input)
{
int status;
int msgClass;
int msgType;
wMessage message;
wMessageQueue* queue;
queue = input->queue;
while (1)
{
status = MessageQueue_Peek(queue, &message, TRUE);
if (!status)
break;
if (message.type == WMQ_QUIT)
break;
msgClass = GetMessageClass(message.type);
msgType = GetMessageType(message.type);
status = event_process_class(input->event, &message, msgClass, msgType);
}
return 0;
}
void event_register_input(rdpEvent* event, rdpInput* input)
{
/* Input */
event->SynchronizeEvent = input->SynchronizeEvent;
event->KeyboardEvent = input->KeyboardEvent;
event->UnicodeKeyboardEvent = input->UnicodeKeyboardEvent;
event->MouseEvent = input->MouseEvent;
event->ExtendedMouseEvent = input->ExtendedMouseEvent;
input->SynchronizeEvent = event_SynchronizeEvent;
input->KeyboardEvent = event_KeyboardEvent;
input->UnicodeKeyboardEvent = event_UnicodeKeyboardEvent;
input->MouseEvent = event_MouseEvent;
input->ExtendedMouseEvent = event_ExtendedMouseEvent;
}
rdpEvent* event_new(rdpInput* input)
{
rdpEvent* event;
event = (rdpEvent*) malloc(sizeof(rdpEvent));
if (event)
{
ZeroMemory(event, sizeof(rdpEvent));
event->input = input;
input->queue = MessageQueue_New();
event_register_input(event, input);
}
return event;
}
void event_free(rdpEvent* event)
{
if (event)
{
MessageQueue_Free(event->input->queue);
free(event);
}
}

View File

@ -1,60 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Asynchronous Event Queue
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FREERDP_CORE_EVENT_PRIVATE_H
#define FREERDP_CORE_EVENT_PRIVATE_H
#include "message.h"
#include <freerdp/freerdp.h>
/* Input */
#define Input_Class 1
#define Input_SynchronizeEvent 1
#define Input_KeyboardEvent 2
#define Input_UnicodeKeyboardEvent 3
#define Input_MouseEvent 4
#define Input_ExtendedMouseEvent 5
/* Event Queue */
struct rdp_event
{
/* Input */
pSynchronizeEvent SynchronizeEvent;
pKeyboardEvent KeyboardEvent;
pUnicodeKeyboardEvent UnicodeKeyboardEvent;
pMouseEvent MouseEvent;
pExtendedMouseEvent ExtendedMouseEvent;
/* Internal */
rdpInput* input;
};
int event_process_pending_input(rdpInput* input);
rdpEvent* event_new(rdpInput* input);
void event_free(rdpEvent* event);
#endif /* FREERDP_CORE_EVENT_PRIVATE_H */

View File

@ -25,8 +25,9 @@
#include <freerdp/input.h> #include <freerdp/input.h>
#include "message.h"
#include "input.h" #include "input.h"
#include "event.h"
void rdp_write_client_input_pdu_header(STREAM* s, UINT16 number) void rdp_write_client_input_pdu_header(STREAM* s, UINT16 number)
{ {
@ -392,7 +393,7 @@ void input_register_client_callbacks(rdpInput* input)
if (input->asynchronous) if (input->asynchronous)
{ {
input->event = event_new(input); input->proxy = input_message_proxy_new(input);
} }
} }
@ -431,7 +432,7 @@ void freerdp_input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT
int input_process_events(rdpInput* input) int input_process_events(rdpInput* input)
{ {
return event_process_pending_input(input); return input_message_process_pending_input(input);
} }
rdpInput* input_new(rdpRdp* rdp) rdpInput* input_new(rdpRdp* rdp)
@ -453,7 +454,7 @@ void input_free(rdpInput* input)
if (input != NULL) if (input != NULL)
{ {
if (input->asynchronous) if (input->asynchronous)
event_free(input->event); input_message_proxy_free(input->proxy);
free(input); free(input);
} }

View File

@ -22,7 +22,7 @@
#include "rdp.h" #include "rdp.h"
#include "fastpath.h" #include "fastpath.h"
#include "event.h" #include "message.h"
#include <freerdp/input.h> #include <freerdp/input.h>
#include <freerdp/freerdp.h> #include <freerdp/freerdp.h>

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,10 @@
#define MakeMessageId(_class, _type) \ #define MakeMessageId(_class, _type) \
(((_class ##_Class) << 16) | (_class ## _ ## _type)) (((_class ##_Class) << 16) | (_class ## _ ## _type))
/**
* Update Message Queue
*/
/* Update */ /* Update */
#define Update_Class 1 #define Update_Class 1
@ -128,10 +132,12 @@
#define PointerUpdate_PointerNew 4 #define PointerUpdate_PointerNew 4
#define PointerUpdate_PointerCached 5 #define PointerUpdate_PointerCached 5
/* Message Queue */ /* Update Proxy Interface */
struct rdp_message struct rdp_update_proxy
{ {
rdpUpdate* update;
/* Update */ /* Update */
pBeginPaint BeginPaint; pBeginPaint BeginPaint;
@ -219,15 +225,45 @@ struct rdp_message
pPointerColor PointerColor; pPointerColor PointerColor;
pPointerNew PointerNew; pPointerNew PointerNew;
pPointerCached PointerCached; pPointerCached PointerCached;
/* Internal */
rdpUpdate* update;
}; };
int message_process_pending_updates(rdpUpdate* update); int update_message_process_pending_updates(rdpUpdate* update);
rdpMessage* message_new(rdpUpdate* update); rdpUpdateProxy* update_message_proxy_new(rdpUpdate* update);
void message_free(rdpMessage* message); void update_message_proxy_free(rdpUpdateProxy* message);
/**
* Input Message Queue
*/
/* Input */
#define Input_Class 1
#define Input_SynchronizeEvent 1
#define Input_KeyboardEvent 2
#define Input_UnicodeKeyboardEvent 3
#define Input_MouseEvent 4
#define Input_ExtendedMouseEvent 5
/* Input Proxy Interface */
struct rdp_input_proxy
{
rdpInput* input;
/* Input */
pSynchronizeEvent SynchronizeEvent;
pKeyboardEvent KeyboardEvent;
pUnicodeKeyboardEvent UnicodeKeyboardEvent;
pMouseEvent MouseEvent;
pExtendedMouseEvent ExtendedMouseEvent;
};
int input_message_process_pending_input(rdpInput* input);
rdpInputProxy* input_message_proxy_new(rdpInput* input);
void input_message_proxy_free(rdpInputProxy* proxy);
#endif /* FREERDP_CORE_MESSAGE_PRIVATE_H */ #endif /* FREERDP_CORE_MESSAGE_PRIVATE_H */

View File

@ -429,7 +429,7 @@ void update_post_connect(rdpUpdate* update)
update->asynchronous = update->context->settings->AsyncUpdate; update->asynchronous = update->context->settings->AsyncUpdate;
if (update->asynchronous) if (update->asynchronous)
update->message = message_new(update); update->proxy = update_message_proxy_new(update);
update->altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE; update->altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
IFCALL(update->altsec->SwitchSurface, update->context, &(update->altsec->switch_surface)); IFCALL(update->altsec->SwitchSurface, update->context, &(update->altsec->switch_surface));
@ -735,7 +735,7 @@ void update_register_client_callbacks(rdpUpdate* update)
int update_process_messages(rdpUpdate* update) int update_process_messages(rdpUpdate* update)
{ {
return message_process_pending_updates(update); return update_message_process_pending_updates(update);
} }
rdpUpdate* update_new(rdpRdp* rdp) rdpUpdate* update_new(rdpRdp* rdp)
@ -808,7 +808,7 @@ void update_free(rdpUpdate* update)
free(update->window); free(update->window);
if (update->asynchronous) if (update->asynchronous)
message_free(update->message); update_message_proxy_free(update->proxy);
free(update); free(update);
} }