mirror of https://github.com/FreeRDP/FreeRDP
Integrate in/out plugin event struct and add event utils.
This commit is contained in:
parent
15f3f1521c
commit
2a217504eb
|
@ -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,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)
|
||||
|
|
|
@ -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,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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 callback, void* user_data);
|
||||
void freerdp_event_free(FRDP_EVENT* event);
|
||||
|
||||
#endif
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
set(FREERDP_UTILS_SRCS
|
||||
blob.c
|
||||
event.c
|
||||
hexdump.c
|
||||
load_plugin.c
|
||||
memory.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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue