diff --git a/channels/rdpdbg/rdpdbg_main.c b/channels/rdpdbg/rdpdbg_main.c index d74b27548..29d010f28 100644 --- a/channels/rdpdbg/rdpdbg_main.c +++ b/channels/rdpdbg/rdpdbg_main.c @@ -24,7 +24,6 @@ #include #include #include -#include #include typedef struct rdpdbg_plugin rdpdbgPlugin; @@ -50,10 +49,10 @@ 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); } static void rdpdbg_process_terminate(rdpSvcPlugin* plugin) diff --git a/cunit/test_chanman.c b/cunit/test_chanman.c index 461a52218..5f0b568ed 100644 --- a/cunit/test_chanman.c +++ b/cunit/test_chanman.c @@ -23,6 +23,7 @@ #include #include #include +#include #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,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); + event = freerdp_event_new(FRDP_EVENT_TYPE_DEBUG, NULL, NULL); + freerdp_chanman_send_event(chan_man, "rdpdbg", event); freerdp_chanman_close(chan_man, NULL); freerdp_chanman_free(chan_man); diff --git a/include/freerdp/chanman.h b/include/freerdp/chanman.h index ea53f0465..bb54cc594 100644 --- a/include/freerdp/chanman.h +++ b/include/freerdp/chanman.h @@ -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 diff --git a/include/freerdp/constants.h b/include/freerdp/constants.h index 29bc31668..e9c8ad6a9 100644 --- a/include/freerdp/constants.h +++ b/include/freerdp/constants.h @@ -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 diff --git a/include/freerdp/utils/event.h b/include/freerdp/utils/event.h new file mode 100644 index 000000000..21b70e08a --- /dev/null +++ b/include/freerdp/utils/event.h @@ -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 +#include + +FRDP_EVENT* freerdp_event_new(uint32 event_type, FRDP_EVENT_CALLBACK callback, void* user_data); +void freerdp_event_free(FRDP_EVENT* event); + +#endif diff --git a/include/freerdp/utils/svc_plugin.h b/include/freerdp/utils/svc_plugin.h index a474d9daa..1b6e42c42 100644 --- a/include/freerdp/utils/svc_plugin.h +++ b/include/freerdp/utils/svc_plugin.h @@ -25,6 +25,7 @@ #include #include +#include typedef struct rdp_svc_plugin_private rdpSvcPluginPrivate; typedef struct rdp_svc_plugin rdpSvcPlugin; @@ -35,7 +36,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 (*event_callback)(rdpSvcPlugin* plugin, FRDP_EVENT* event); void (*terminate_callback)(rdpSvcPlugin* plugin); rdpSvcPluginPrivate* priv; diff --git a/libfreerdp-chanman/libchanman.c b/libfreerdp-chanman/libchanman.c index c7cee2885..84833cdc3 100644 --- a/libfreerdp-chanman/libchanman.c +++ b/libfreerdp-chanman/libchanman.c @@ -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; diff --git a/libfreerdp-utils/CMakeLists.txt b/libfreerdp-utils/CMakeLists.txt index fdec57ed3..dd2636caf 100644 --- a/libfreerdp-utils/CMakeLists.txt +++ b/libfreerdp-utils/CMakeLists.txt @@ -19,6 +19,7 @@ set(FREERDP_UTILS_SRCS blob.c + event.c hexdump.c load_plugin.c memory.c diff --git a/libfreerdp-utils/event.c b/libfreerdp-utils/event.c new file mode 100644 index 000000000..499e9673f --- /dev/null +++ b/libfreerdp-utils/event.c @@ -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 +#include +#include +#include + +FRDP_EVENT* freerdp_event_new(uint32 event_type, FRDP_EVENT_CALLBACK 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->event_callback = callback; + event->user_data = user_data; + } + + return event; +} + +void freerdp_event_free(FRDP_EVENT* event) +{ + if (event != NULL) + { + if (event->event_callback != NULL) + event->event_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); + } +} diff --git a/libfreerdp-utils/svc_plugin.c b/libfreerdp-utils/svc_plugin.c index 1abdbf7a1..510df6cf2 100644 --- a/libfreerdp-utils/svc_plugin.c +++ b/libfreerdp-utils/svc_plugin.c @@ -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; } }