libfreerdp-chanman: add API for sending events from UI to plugin.
This commit is contained in:
parent
3046424760
commit
15f3f1521c
@ -22,7 +22,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#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;
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user