mirror of https://github.com/FreeRDP/FreeRDP
Merge pull request #12 from llyzs/svc
Support sending events from UI to plugin through channel manager.
This commit is contained in:
commit
458f62f282
|
@ -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);
|
||||
|
|
|
@ -76,4 +76,20 @@ enum RDP_SVC_CHANNEL_OPTION
|
|||
CHANNEL_OPTION_INITIALIZED = 0x80000000
|
||||
};
|
||||
|
||||
/**
|
||||
* Static Virtual Channel Events
|
||||
*/
|
||||
enum RDP_SVC_CHANNEL_EVENT
|
||||
{
|
||||
CHANNEL_EVENT_INITIALIZED = 0,
|
||||
CHANNEL_EVENT_CONNECTED = 1,
|
||||
CHANNEL_EVENT_V1_CONNECTED = 2,
|
||||
CHANNEL_EVENT_DISCONNECTED = 3,
|
||||
CHANNEL_EVENT_TERMINATED = 4,
|
||||
CHANNEL_EVENT_DATA_RECEIVED = 10,
|
||||
CHANNEL_EVENT_WRITE_COMPLETE = 11,
|
||||
CHANNEL_EVENT_WRITE_CANCELLED = 12,
|
||||
CHANNEL_EVENT_USER = 1000
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,20 +45,11 @@ typedef CHANNEL_DEF** PPCHANNEL_DEF;
|
|||
typedef void (FREERDP_CC * PCHANNEL_INIT_EVENT_FN)(void* pInitHandle,
|
||||
uint32 event, void* pData, uint32 dataLength);
|
||||
|
||||
#define CHANNEL_EVENT_INITIALIZED 0
|
||||
#define CHANNEL_EVENT_CONNECTED 1
|
||||
#define CHANNEL_EVENT_V1_CONNECTED 2
|
||||
#define CHANNEL_EVENT_DISCONNECTED 3
|
||||
#define CHANNEL_EVENT_TERMINATED 4
|
||||
|
||||
typedef void (FREERDP_CC * PCHANNEL_OPEN_EVENT_FN)(uint32 openHandle,
|
||||
uint32 event, void* pData, uint32 dataLength,
|
||||
uint32 totalLength, uint32 dataFlags);
|
||||
|
||||
#define CHANNEL_EVENT_DATA_RECEIVED 10
|
||||
#define CHANNEL_EVENT_WRITE_COMPLETE 11
|
||||
#define CHANNEL_EVENT_WRITE_CANCELLED 12
|
||||
|
||||
#define CHANNEL_RC_OK 0
|
||||
#define CHANNEL_RC_ALREADY_INITIALIZED 1
|
||||
#define CHANNEL_RC_NOT_INITIALIZED 2
|
||||
|
|
|
@ -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