Merge pull request #13 from llyzs/svc

Enhance plugin event system to be consistant in both direction.
This commit is contained in:
Marc-André Moreau 2011-07-11 08:41:14 -07:00
commit 5d86daf7ea
11 changed files with 173 additions and 47 deletions

View File

@ -24,7 +24,6 @@
#include <freerdp/constants.h>
#include <freerdp/types.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/hexdump.h>
#include <freerdp/utils/svc_plugin.h>
typedef struct rdpdbg_plugin rdpdbgPlugin;
@ -50,10 +49,13 @@ static void rdpdbg_process_receive(rdpSvcPlugin* plugin, STREAM* data_in)
svc_plugin_send(plugin, data_out);
}
static void rdpdbg_process_event(rdpSvcPlugin* plugin, void* data, int size)
static void rdpdbg_process_event(rdpSvcPlugin* plugin, FRDP_EVENT* event)
{
printf("rdpdbg_process_event: size %d\n", size);
freerdp_hexdump(data, size);
printf("rdpdbg_process_event: event_type %d\n", event->event_type);
freerdp_event_free(event);
event = freerdp_event_new(FRDP_EVENT_TYPE_DEBUG, NULL, NULL);
svc_plugin_send_event(plugin, event);
}
static void rdpdbg_process_terminate(rdpSvcPlugin* plugin)
@ -69,7 +71,6 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
rdpdbg = (rdpdbgPlugin*)xmalloc(sizeof(rdpdbgPlugin));
memset(rdpdbg, 0, sizeof(rdpdbgPlugin));
rdpdbg->plugin.channel_entry_points = *pEntryPoints;
rdpdbg->plugin.channel_def.options = CHANNEL_OPTION_INITIALIZED |
CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP |
CHANNEL_OPTION_SHOW_PROTOCOL;
@ -80,7 +81,7 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
rdpdbg->plugin.event_callback = rdpdbg_process_event;
rdpdbg->plugin.terminate_callback = rdpdbg_process_terminate;
svc_plugin_init((rdpSvcPlugin*)rdpdbg);
svc_plugin_init((rdpSvcPlugin*)rdpdbg, pEntryPoints);
return 1;
}

View File

@ -23,6 +23,7 @@
#include <freerdp/freerdp.h>
#include <freerdp/constants.h>
#include <freerdp/chanman.h>
#include <freerdp/utils/event.h>
#include "test_chanman.h"
@ -57,6 +58,7 @@ void test_chanman(void)
rdpChanMan* chan_man;
rdpSettings settings = { 0 };
rdpInst inst = { 0 };
FRDP_EVENT* event;
settings.hostname = "testhost";
inst.settings = &settings;
@ -72,7 +74,12 @@ void test_chanman(void)
freerdp_chanman_check_fds(chan_man, &inst);
freerdp_chanman_send_event(chan_man, "rdpdbg", CHANNEL_EVENT_USER + 1, "testevent", 9);
event = freerdp_event_new(FRDP_EVENT_TYPE_DEBUG, NULL, NULL);
freerdp_chanman_send_event(chan_man, "rdpdbg", event);
event = freerdp_chanman_pop_event(chan_man);
printf("responded event_type %d\n", event->event_type);
freerdp_event_free(event);
freerdp_chanman_close(chan_man, NULL);
freerdp_chanman_free(chan_man);

View File

@ -40,13 +40,11 @@ FREERDP_API int freerdp_chanman_pre_connect(rdpChanMan* chan_man, rdpInst* inst)
FREERDP_API int freerdp_chanman_post_connect(rdpChanMan* chan_man, rdpInst* inst);
FREERDP_API int freerdp_chanman_data(rdpInst* inst, int chan_id, char* data, int data_size,
int flags, int total_size);
FREERDP_API int freerdp_chanman_send_event(rdpChanMan* chan_man, const char* name, uint32 event,
void* data, int data_size);
FREERDP_API int freerdp_chanman_send_event(rdpChanMan* chan_man, const char* name, FRDP_EVENT* event);
FREERDP_API int freerdp_chanman_get_fds(rdpChanMan* chan_man, rdpInst* inst, void** read_fds,
int* read_count, void** write_fds, int* write_count);
FREERDP_API int freerdp_chanman_check_fds(rdpChanMan* chan_man, rdpInst* inst);
FREERDP_API FRDP_EVENT* freerdp_chanman_pop_event(rdpChanMan* chan_man);
FREERDP_API void freerdp_chanman_free_event(rdpChanMan* chan_man, FRDP_EVENT* event);
FREERDP_API void freerdp_chanman_close(rdpChanMan* chan_man, rdpInst* inst);
#ifdef __cplusplus

View File

@ -92,4 +92,14 @@ enum RDP_SVC_CHANNEL_EVENT
CHANNEL_EVENT_USER = 1000
};
/**
* FreeRDP Event Types
*/
enum FRDP_EVENT_TYPE
{
FRDP_EVENT_TYPE_DEBUG = 0,
FRDP_EVENT_TYPE_VIDEO_FRAME = 1,
FRDP_EVENT_TYPE_REDRAW = 2
};
#endif

View File

@ -113,7 +113,7 @@ FRDP_BRUSH;
typedef struct _FRDP_PLUGIN_DATA
{
uint16 size;
void * data[4];
void* data[4];
}
FRDP_PLUGIN_DATA;
@ -128,19 +128,19 @@ FRDP_RECT;
typedef struct _FRDP_EVENT FRDP_EVENT;
typedef void (*FRDP_EVENT_CALLBACK) (FRDP_EVENT * event);
typedef void (*FRDP_EVENT_CALLBACK) (FRDP_EVENT* event);
struct _FRDP_EVENT
{
uint16 event_type;
FRDP_EVENT_CALLBACK event_callback;
void * user_data;
FRDP_EVENT_CALLBACK on_event_free_callback;
void* user_data;
};
struct _FRDP_VIDEO_FRAME_EVENT
{
FRDP_EVENT event;
uint8 * frame_data;
uint8* frame_data;
uint32 frame_size;
uint32 frame_pixfmt;
sint16 frame_width;
@ -150,7 +150,7 @@ struct _FRDP_VIDEO_FRAME_EVENT
sint16 width;
sint16 height;
uint16 num_visible_rects;
FRDP_RECT * visible_rects;
FRDP_RECT* visible_rects;
};
typedef struct _FRDP_VIDEO_FRAME_EVENT FRDP_VIDEO_FRAME_EVENT;

View File

@ -0,0 +1,29 @@
/**
* FreeRDP: A Remote Desktop Protocol client.
* Events
*
* Copyright 2011 Vic Lee
*
* 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 __EVENT_UTILS_H
#define __EVENT_UTILS_H
#include <freerdp/types.h>
#include <freerdp/constants.h>
FRDP_EVENT* freerdp_event_new(uint32 event_type, FRDP_EVENT_CALLBACK on_event_free_callback, void* user_data);
void freerdp_event_free(FRDP_EVENT* event);
#endif

View File

@ -25,23 +25,25 @@
#include <freerdp/svc.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/event.h>
typedef struct rdp_svc_plugin_private rdpSvcPluginPrivate;
typedef struct rdp_svc_plugin rdpSvcPlugin;
struct rdp_svc_plugin
{
CHANNEL_ENTRY_POINTS channel_entry_points;
CHANNEL_ENTRY_POINTS_EX channel_entry_points;
CHANNEL_DEF channel_def;
void (*connect_callback)(rdpSvcPlugin* plugin);
void (*receive_callback)(rdpSvcPlugin* plugin, STREAM* data_in);
void (*event_callback)(rdpSvcPlugin* plugin, void* data, int size);
void (*event_callback)(rdpSvcPlugin* plugin, FRDP_EVENT* event);
void (*terminate_callback)(rdpSvcPlugin* plugin);
rdpSvcPluginPrivate* priv;
};
void svc_plugin_init(rdpSvcPlugin* plugin);
void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints);
int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out);
int svc_plugin_send_event(rdpSvcPlugin* plugin, FRDP_EVENT* event);
#endif /* __SVC_PLUGIN_UTILS_H */

View File

@ -770,12 +770,9 @@ int freerdp_chanman_data(rdpInst* inst, int chan_id, char* data, int data_size,
* called only from main thread
* @param chan_man the channel manager instance
* @param name the static virtual channel name, such as 'cliprdr'
* @param event plugin-defined event id, defined as CHANNEL_EVENT_USER + n
* @param data arbitrary buffer or struct to be passed to the plugin
* @param data_size the size of the data argument
* @param event an event object created by freerdp_event_new()
*/
FREERDP_API int freerdp_chanman_send_event(rdpChanMan* chan_man, const char* name, uint32 event,
void* data, int data_size)
FREERDP_API int freerdp_chanman_send_event(rdpChanMan* chan_man, const char* name, FRDP_EVENT* event)
{
struct chan_data* lchan_data;
int index;
@ -789,8 +786,8 @@ FREERDP_API int freerdp_chanman_send_event(rdpChanMan* chan_man, const char* nam
if (lchan_data->open_event_proc != NULL)
{
lchan_data->open_event_proc(lchan_data->open_handle,
event,
data, data_size, data_size, 0);
CHANNEL_EVENT_USER,
event, sizeof(FRDP_EVENT), sizeof(FRDP_EVENT), 0);
}
return 0;
}
@ -869,11 +866,6 @@ FRDP_EVENT* freerdp_chanman_pop_event(rdpChanMan* chan_man)
return event;
}
void freerdp_chanman_free_event(rdpChanMan* chan_man, FRDP_EVENT * event)
{
event->event_callback(event);
}
void freerdp_chanman_close(rdpChanMan* chan_man, rdpInst* inst)
{
int index;

View File

@ -19,6 +19,7 @@
set(FREERDP_UTILS_SRCS
blob.c
event.c
hexdump.c
load_plugin.c
memory.c

74
libfreerdp-utils/event.c Normal file
View File

@ -0,0 +1,74 @@
/**
* FreeRDP: A Remote Desktop Protocol client.
* Events
*
* Copyright 2011 Vic Lee
*
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <freerdp/utils/event.h>
FRDP_EVENT* freerdp_event_new(uint32 event_type, FRDP_EVENT_CALLBACK on_event_free_callback, void* user_data)
{
FRDP_EVENT* event = NULL;
switch (event_type)
{
case FRDP_EVENT_TYPE_DEBUG:
event = (FRDP_EVENT*)xmalloc(sizeof(FRDP_EVENT));
memset(event, 0, sizeof(FRDP_EVENT));
break;
case FRDP_EVENT_TYPE_VIDEO_FRAME:
event = (FRDP_EVENT*)xmalloc(sizeof(FRDP_VIDEO_FRAME_EVENT));
memset(event, 0, sizeof(FRDP_VIDEO_FRAME_EVENT));
break;
case FRDP_EVENT_TYPE_REDRAW:
event = (FRDP_EVENT*)xmalloc(sizeof(FRDP_REDRAW_EVENT));
memset(event, 0, sizeof(FRDP_REDRAW_EVENT));
break;
}
if (event != NULL)
{
event->event_type = event_type;
event->on_event_free_callback = on_event_free_callback;
event->user_data = user_data;
}
return event;
}
void freerdp_event_free(FRDP_EVENT* event)
{
if (event != NULL)
{
if (event->on_event_free_callback != NULL)
event->on_event_free_callback(event);
switch (event->event_type)
{
case FRDP_EVENT_TYPE_VIDEO_FRAME:
{
FRDP_VIDEO_FRAME_EVENT* vevent = (FRDP_VIDEO_FRAME_EVENT*)event;
xfree(vevent->frame_data);
xfree(vevent->visible_rects);
}
break;
}
xfree(event);
}
}

View File

@ -159,21 +159,17 @@ static void svc_plugin_open_event(uint32 openHandle, uint32 event, void* pData,
printf("svc_plugin_open_event: error no match\n");
return;
}
if (event >= CHANNEL_EVENT_USER)
switch (event)
{
plugin->event_callback(plugin, pData, dataLength);
}
else
{
switch (event)
{
case CHANNEL_EVENT_DATA_RECEIVED:
svc_plugin_process_received(plugin, pData, dataLength, totalLength, dataFlags);
break;
case CHANNEL_EVENT_WRITE_COMPLETE:
stream_free((STREAM*)pData);
break;
}
case CHANNEL_EVENT_DATA_RECEIVED:
svc_plugin_process_received(plugin, pData, dataLength, totalLength, dataFlags);
break;
case CHANNEL_EVENT_WRITE_COMPLETE:
stream_free((STREAM*)pData);
break;
case CHANNEL_EVENT_USER:
plugin->event_callback(plugin, (FRDP_EVENT*)pData);
break;
}
}
@ -233,7 +229,7 @@ static void svc_plugin_init_event(void* pInitHandle, uint32 event, void* pData,
}
}
void svc_plugin_init(rdpSvcPlugin* plugin)
void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints)
{
rdpSvcPluginList* list;
@ -244,6 +240,8 @@ void svc_plugin_init(rdpSvcPlugin* plugin)
if (g_mutex == NULL)
g_mutex = freerdp_mutex_new();
memcpy(&plugin->channel_entry_points, pEntryPoints, pEntryPoints->cbSize);
plugin->priv = (rdpSvcPluginPrivate*)xmalloc(sizeof(rdpSvcPluginPrivate));
memset(plugin->priv, 0, sizeof(rdpSvcPluginPrivate));
@ -269,7 +267,21 @@ int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out)
error = plugin->channel_entry_points.pVirtualChannelWrite(plugin->priv->open_handle,
stream_get_data(data_out), stream_get_length(data_out), data_out);
if (error != CHANNEL_RC_OK)
printf("svc_plugin_send: VirtualChannelWrite failed %d", error);
printf("svc_plugin_send: VirtualChannelWrite failed %d\n", error);
return error;
}
int svc_plugin_send_event(rdpSvcPlugin* plugin, FRDP_EVENT* event)
{
uint32 error = 0;
DEBUG_SVC("event_type %d", event->event_type);
error = plugin->channel_entry_points.pVirtualChannelEventPush(plugin->priv->open_handle,
event);
if (error != CHANNEL_RC_OK)
printf("svc_plugin_send_event: VirtualChannelEventPush failed %d\n", error);
return error;
}