From 15f3f1521cdb7627983981fe0719c5775c06f608 Mon Sep 17 00:00:00 2001 From: Vic Lee Date: Sun, 10 Jul 2011 23:56:52 +0800 Subject: [PATCH] libfreerdp-chanman: add API for sending events from UI to plugin. --- channels/rdpdbg/rdpdbg_main.c | 9 +++++++++ cunit/test_chanman.c | 2 ++ include/freerdp/chanman.h | 2 ++ include/freerdp/utils/svc_plugin.h | 1 + libfreerdp-chanman/libchanman.c | 30 ++++++++++++++++++++++++++++++ libfreerdp-utils/svc_plugin.c | 21 ++++++++++++++------- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/channels/rdpdbg/rdpdbg_main.c b/channels/rdpdbg/rdpdbg_main.c index 0a0a7235a..d74b27548 100644 --- a/channels/rdpdbg/rdpdbg_main.c +++ b/channels/rdpdbg/rdpdbg_main.c @@ -22,7 +22,9 @@ #include #include #include +#include #include +#include #include typedef struct rdpdbg_plugin rdpdbgPlugin; @@ -48,6 +50,12 @@ 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) +{ + printf("rdpdbg_process_event: size %d\n", size); + freerdp_hexdump(data, size); +} + static void rdpdbg_process_terminate(rdpSvcPlugin* plugin) { printf("rdpdbg_process_terminate\n"); @@ -69,6 +77,7 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) rdpdbg->plugin.connect_callback = rdpdbg_process_connect; rdpdbg->plugin.receive_callback = rdpdbg_process_receive; + rdpdbg->plugin.event_callback = rdpdbg_process_event; rdpdbg->plugin.terminate_callback = rdpdbg_process_terminate; svc_plugin_init((rdpSvcPlugin*)rdpdbg); diff --git a/cunit/test_chanman.c b/cunit/test_chanman.c index 882368f82..461a52218 100644 --- a/cunit/test_chanman.c +++ b/cunit/test_chanman.c @@ -72,6 +72,8 @@ void test_chanman(void) freerdp_chanman_check_fds(chan_man, &inst); + freerdp_chanman_send_event(chan_man, "rdpdbg", CHANNEL_EVENT_USER + 1, "testevent", 9); + freerdp_chanman_close(chan_man, NULL); freerdp_chanman_free(chan_man); } diff --git a/include/freerdp/chanman.h b/include/freerdp/chanman.h index a0124dd26..ea53f0465 100644 --- a/include/freerdp/chanman.h +++ b/include/freerdp/chanman.h @@ -40,6 +40,8 @@ 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_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); diff --git a/include/freerdp/utils/svc_plugin.h b/include/freerdp/utils/svc_plugin.h index 48cbdf61e..a474d9daa 100644 --- a/include/freerdp/utils/svc_plugin.h +++ b/include/freerdp/utils/svc_plugin.h @@ -35,6 +35,7 @@ struct rdp_svc_plugin void (*connect_callback)(rdpSvcPlugin* plugin); void (*receive_callback)(rdpSvcPlugin* plugin, STREAM* data_in); + void (*event_callback)(rdpSvcPlugin* plugin, void* data, int size); void (*terminate_callback)(rdpSvcPlugin* plugin); rdpSvcPluginPrivate* priv; diff --git a/libfreerdp-chanman/libchanman.c b/libfreerdp-chanman/libchanman.c index 5d6e2a554..c7cee2885 100644 --- a/libfreerdp-chanman/libchanman.c +++ b/libfreerdp-chanman/libchanman.c @@ -765,6 +765,36 @@ int freerdp_chanman_data(rdpInst* inst, int chan_id, char* data, int data_size, return 0; } +/** + * Send a plugin-defined event to the plugin. + * 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 + */ +FREERDP_API int freerdp_chanman_send_event(rdpChanMan* chan_man, const char* name, uint32 event, + void* data, int data_size) +{ + struct chan_data* lchan_data; + int index; + + lchan_data = freerdp_chanman_find_chan_data_by_name(chan_man, name, &index); + if (lchan_data == NULL) + { + DEBUG_CHANMAN("could not find channel name %s", name); + return 1; + } + if (lchan_data->open_event_proc != NULL) + { + lchan_data->open_event_proc(lchan_data->open_handle, + event, + data, data_size, data_size, 0); + } + return 0; +} + /** * called only from main thread */ diff --git a/libfreerdp-utils/svc_plugin.c b/libfreerdp-utils/svc_plugin.c index 809bd906c..1abdbf7a1 100644 --- a/libfreerdp-utils/svc_plugin.c +++ b/libfreerdp-utils/svc_plugin.c @@ -159,14 +159,21 @@ static void svc_plugin_open_event(uint32 openHandle, uint32 event, void* pData, printf("svc_plugin_open_event: error no match\n"); return; } - switch (event) + if (event >= CHANNEL_EVENT_USER) { - 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; + 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; + } } }