xfreerdp: improve common client API
This commit is contained in:
parent
208c9f844a
commit
a8c268a9ff
@ -36,7 +36,6 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
xfContext* xfc;
|
||||
DWORD dwExitCode;
|
||||
freerdp* instance;
|
||||
rdpContext* context;
|
||||
rdpSettings* settings;
|
||||
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
|
||||
@ -47,15 +46,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
RdpClientEntry(&clientEntryPoints);
|
||||
|
||||
clientEntryPoints.GlobalInit();
|
||||
context = freerdp_client_context_new(&clientEntryPoints);
|
||||
|
||||
instance = freerdp_new();
|
||||
instance->ContextSize = clientEntryPoints.ContextSize;
|
||||
instance->ContextNew = clientEntryPoints.ClientNew;
|
||||
instance->ContextFree = clientEntryPoints.ClientFree;
|
||||
freerdp_context_new(instance);
|
||||
|
||||
context = instance->context;
|
||||
settings = context->settings;
|
||||
xfc = (xfContext*) context;
|
||||
|
||||
@ -70,21 +62,20 @@ int main(int argc, char* argv[])
|
||||
if (settings->ListMonitors)
|
||||
xf_list_monitors(xfc);
|
||||
|
||||
freerdp_context_free(instance);
|
||||
freerdp_free(instance);
|
||||
freerdp_client_context_free(context);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
clientEntryPoints.ClientStart(context);
|
||||
freerdp_client_start(context);
|
||||
|
||||
WaitForSingleObject(xfc->thread, INFINITE);
|
||||
|
||||
GetExitCodeThread(xfc->thread, &dwExitCode);
|
||||
|
||||
clientEntryPoints.ClientStop(context);
|
||||
freerdp_client_stop(context);
|
||||
|
||||
clientEntryPoints.GlobalUninit();
|
||||
freerdp_client_context_free(context);
|
||||
|
||||
return xf_exit_code_from_disconnect_reason(dwExitCode);
|
||||
}
|
||||
|
@ -121,16 +121,6 @@ void xf_draw_screen_scaled(xfContext* xfc)
|
||||
#endif
|
||||
}
|
||||
|
||||
void xf_context_new(freerdp* instance, rdpContext* context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void xf_context_free(freerdp* instance, rdpContext* context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void xf_sw_begin_paint(rdpContext* context)
|
||||
{
|
||||
rdpGdi* gdi = context->gdi;
|
||||
@ -1041,7 +1031,7 @@ void xf_window_free(xfContext* xfc)
|
||||
if (xfc->modifier_map)
|
||||
{
|
||||
XFreeModifiermap(xfc->modifier_map);
|
||||
xfc->modifier_map = 0;
|
||||
xfc->modifier_map = NULL;
|
||||
}
|
||||
|
||||
if (xfc->gc)
|
||||
@ -1513,19 +1503,19 @@ DWORD xf_exit_code_from_disconnect_reason(DWORD reason)
|
||||
* Client Interface
|
||||
*/
|
||||
|
||||
void freerdp_client_global_init()
|
||||
void xfreerdp_client_global_init()
|
||||
{
|
||||
setlocale(LC_ALL, "");
|
||||
freerdp_handle_signals();
|
||||
freerdp_channels_global_init();
|
||||
}
|
||||
|
||||
void freerdp_client_global_uninit()
|
||||
void xfreerdp_client_global_uninit()
|
||||
{
|
||||
freerdp_channels_global_uninit();
|
||||
}
|
||||
|
||||
int freerdp_client_start(rdpContext* context)
|
||||
int xfreerdp_client_start(rdpContext* context)
|
||||
{
|
||||
xfContext* xfc = (xfContext*) context;
|
||||
|
||||
@ -1542,7 +1532,7 @@ int freerdp_client_start(rdpContext* context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int freerdp_client_stop(rdpContext* context)
|
||||
int xfreerdp_client_stop(rdpContext* context)
|
||||
{
|
||||
xfContext* xfc = (xfContext*) context;
|
||||
|
||||
@ -1592,7 +1582,7 @@ void freerdp_client_reset_scale(rdpContext* context)
|
||||
xf_draw_screen_scaled(xfc);
|
||||
}
|
||||
|
||||
int freerdp_client_new(freerdp* instance, rdpContext* context)
|
||||
int xfreerdp_client_new(freerdp* instance, rdpContext* context)
|
||||
{
|
||||
xfContext* xfc;
|
||||
rdpSettings* settings;
|
||||
@ -1643,7 +1633,7 @@ int freerdp_client_new(freerdp* instance, rdpContext* context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void freerdp_client_free(freerdp* instance, rdpContext* context)
|
||||
void xfreerdp_client_free(freerdp* instance, rdpContext* context)
|
||||
{
|
||||
xfContext* xfc = (xfContext*) context;
|
||||
|
||||
@ -1656,9 +1646,6 @@ void freerdp_client_free(freerdp* instance, rdpContext* context)
|
||||
|
||||
if (xfc->display)
|
||||
XCloseDisplay(xfc->display);
|
||||
|
||||
freerdp_context_free(instance);
|
||||
freerdp_free(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1667,15 +1654,15 @@ int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
||||
pEntryPoints->Version = 1;
|
||||
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
||||
|
||||
pEntryPoints->GlobalInit = freerdp_client_global_init;
|
||||
pEntryPoints->GlobalUninit = freerdp_client_global_uninit;
|
||||
pEntryPoints->GlobalInit = xfreerdp_client_global_init;
|
||||
pEntryPoints->GlobalUninit = xfreerdp_client_global_uninit;
|
||||
|
||||
pEntryPoints->ContextSize = sizeof(xfContext);
|
||||
pEntryPoints->ClientNew = freerdp_client_new;
|
||||
pEntryPoints->ClientFree = freerdp_client_free;
|
||||
pEntryPoints->ClientNew = xfreerdp_client_new;
|
||||
pEntryPoints->ClientFree = xfreerdp_client_free;
|
||||
|
||||
pEntryPoints->ClientStart = freerdp_client_start;
|
||||
pEntryPoints->ClientStop = freerdp_client_stop;
|
||||
pEntryPoints->ClientStart = xfreerdp_client_start;
|
||||
pEntryPoints->ClientStop = xfreerdp_client_stop;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -81,6 +81,47 @@ int freerdp_client_set_param_string(rdpContext* context, int id, char* param)
|
||||
|
||||
/* Common API */
|
||||
|
||||
rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
||||
{
|
||||
freerdp* instance;
|
||||
rdpContext* context;
|
||||
|
||||
pEntryPoints->GlobalInit();
|
||||
|
||||
instance = freerdp_new();
|
||||
instance->ContextSize = pEntryPoints->ContextSize;
|
||||
instance->ContextNew = pEntryPoints->ClientNew;
|
||||
instance->ContextFree = pEntryPoints->ClientFree;
|
||||
freerdp_context_new(instance);
|
||||
|
||||
context = instance->context;
|
||||
|
||||
context->client->pEntryPoints = (RDP_CLIENT_ENTRY_POINTS*) malloc(pEntryPoints->Size);
|
||||
CopyMemory(context->client->pEntryPoints, pEntryPoints, pEntryPoints->Size);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
void freerdp_client_context_free(rdpContext* context)
|
||||
{
|
||||
freerdp* instance = context->instance;
|
||||
|
||||
freerdp_context_free(instance);
|
||||
freerdp_free(instance);
|
||||
}
|
||||
|
||||
int freerdp_client_start(rdpContext* context)
|
||||
{
|
||||
rdpClient* client = context->client;
|
||||
return client->pEntryPoints->ClientStart(context);
|
||||
}
|
||||
|
||||
int freerdp_client_stop(rdpContext* context)
|
||||
{
|
||||
rdpClient* client = context->client;
|
||||
return client->pEntryPoints->ClientStop(context);
|
||||
}
|
||||
|
||||
int freerdp_client_parse_command_line(rdpContext* context, int argc, char** argv)
|
||||
{
|
||||
int status;
|
||||
|
@ -29,27 +29,8 @@ typedef struct rdp_client rdpClient;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FREERDP_WINDOW_STATE_NORMAL 0
|
||||
#define FREERDP_WINDOW_STATE_MINIMIZED 1
|
||||
#define FREERDP_WINDOW_STATE_MAXIMIZED 2
|
||||
#define FREERDP_WINDOW_STATE_FULLSCREEN 3
|
||||
#define FREERDP_WINDOW_STATE_ACTIVE 4
|
||||
|
||||
typedef void (*pOnResizeWindow)(freerdp* instance, int width, int height);
|
||||
typedef void (*pOnWindowStateChange)(freerdp* instance, int state);
|
||||
typedef void (*pOnErrorInfo)(freerdp* instance, UINT32 code);
|
||||
typedef void (*pOnParamChange)(freerdp* instance, int id);
|
||||
|
||||
struct rdp_client
|
||||
{
|
||||
pOnResizeWindow OnResizeWindow;
|
||||
pOnWindowStateChange OnWindowStateChange;
|
||||
pOnErrorInfo OnErrorInfo;
|
||||
pOnParamChange OnParamChange;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic Client Interface
|
||||
* Client Entry Points
|
||||
*/
|
||||
|
||||
typedef void (*pRdpGlobalInit)(void);
|
||||
@ -84,8 +65,37 @@ typedef RDP_CLIENT_ENTRY_POINTS_V1 RDP_CLIENT_ENTRY_POINTS;
|
||||
|
||||
typedef int (*pRdpClientEntry)(RDP_CLIENT_ENTRY_POINTS* pEntryPoints);
|
||||
|
||||
/* Common Client Interface */
|
||||
|
||||
#define FREERDP_WINDOW_STATE_NORMAL 0
|
||||
#define FREERDP_WINDOW_STATE_MINIMIZED 1
|
||||
#define FREERDP_WINDOW_STATE_MAXIMIZED 2
|
||||
#define FREERDP_WINDOW_STATE_FULLSCREEN 3
|
||||
#define FREERDP_WINDOW_STATE_ACTIVE 4
|
||||
|
||||
typedef void (*pOnResizeWindow)(freerdp* instance, int width, int height);
|
||||
typedef void (*pOnWindowStateChange)(freerdp* instance, int state);
|
||||
typedef void (*pOnErrorInfo)(freerdp* instance, UINT32 code);
|
||||
typedef void (*pOnParamChange)(freerdp* instance, int id);
|
||||
|
||||
struct rdp_client
|
||||
{
|
||||
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
|
||||
|
||||
pOnResizeWindow OnResizeWindow;
|
||||
pOnWindowStateChange OnWindowStateChange;
|
||||
pOnErrorInfo OnErrorInfo;
|
||||
pOnParamChange OnParamChange;
|
||||
};
|
||||
|
||||
/* Common client functions */
|
||||
|
||||
FREERDP_API rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints);
|
||||
FREERDP_API void freerdp_client_context_free(rdpContext* context);
|
||||
|
||||
FREERDP_API int freerdp_client_start(rdpContext* context);
|
||||
FREERDP_API int freerdp_client_stop(rdpContext* context);
|
||||
|
||||
FREERDP_API int freerdp_client_parse_command_line(rdpContext* context, int argc, char** argv);
|
||||
FREERDP_API int freerdp_client_parse_connection_file(rdpContext* context, char* filename);
|
||||
FREERDP_API int freerdp_client_parse_connection_file_buffer(rdpContext* context, BYTE* buffer, size_t size);
|
||||
|
@ -319,6 +319,7 @@ void freerdp_get_version(int* major, int* minor, int* revision)
|
||||
int freerdp_context_new(freerdp* instance)
|
||||
{
|
||||
rdpRdp* rdp;
|
||||
rdpContext* context;
|
||||
|
||||
rdp = rdp_new(instance);
|
||||
|
||||
@ -328,17 +329,18 @@ int freerdp_context_new(freerdp* instance)
|
||||
|
||||
instance->context = (rdpContext*) malloc(instance->ContextSize);
|
||||
ZeroMemory(instance->context, instance->ContextSize);
|
||||
context = instance->context;
|
||||
|
||||
instance->context->graphics = graphics_new(instance->context);
|
||||
instance->context->instance = instance;
|
||||
instance->context->rdp = rdp;
|
||||
context->graphics = graphics_new(context);
|
||||
context->instance = instance;
|
||||
context->rdp = rdp;
|
||||
|
||||
instance->context->input = instance->input;
|
||||
instance->context->update = instance->update;
|
||||
instance->context->settings = instance->settings;
|
||||
context->input = instance->input;
|
||||
context->update = instance->update;
|
||||
context->settings = instance->settings;
|
||||
|
||||
instance->context->client = (rdpClient*) malloc(sizeof(rdpClient));
|
||||
ZeroMemory(instance->context->client, sizeof(rdpClient));
|
||||
context->client = (rdpClient*) malloc(sizeof(rdpClient));
|
||||
ZeroMemory(context->client, sizeof(rdpClient));
|
||||
|
||||
instance->update->context = instance->context;
|
||||
instance->update->pointer->context = instance->context;
|
||||
@ -346,7 +348,7 @@ int freerdp_context_new(freerdp* instance)
|
||||
instance->update->secondary->context = instance->context;
|
||||
instance->update->altsec->context = instance->context;
|
||||
|
||||
instance->input->context = instance->context;
|
||||
instance->input->context = context;
|
||||
|
||||
update_register_client_callbacks(rdp->update);
|
||||
|
||||
@ -373,7 +375,11 @@ void freerdp_context_free(freerdp* instance)
|
||||
rdp_free(instance->context->rdp);
|
||||
graphics_free(instance->context->graphics);
|
||||
|
||||
free(instance->context->client);
|
||||
if (instance->context->client)
|
||||
{
|
||||
free(instance->context->client->pEntryPoints);
|
||||
free(instance->context->client);
|
||||
}
|
||||
|
||||
free(instance->context);
|
||||
instance->context = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user