freerdp: remove temporary rdpClient* interface and replace with pubSub hooks

This commit is contained in:
Marc-André Moreau 2013-06-15 17:39:45 -04:00
parent 6c9a3b8e64
commit 59b7c53c5f
10 changed files with 114 additions and 88 deletions

View File

@ -498,7 +498,7 @@ void xf_toggle_fullscreen(xfContext* xfc)
e.state = xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0;
PubSub_OnEvent(xfc->pubSub, "WindowStateChange", xfc, (wEventArgs*) &e);
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "WindowStateChange", xfc, (wEventArgs*) &e);
}
void xf_lock_x11(xfContext* xfc, BOOL display)
@ -897,7 +897,7 @@ BOOL xf_post_connect(freerdp* instance)
e.width = settings->DesktopWidth;
e.height = settings->DesktopHeight;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
return TRUE;
}
@ -1553,11 +1553,6 @@ int xfreerdp_client_stop(rdpContext* context)
return 0;
}
rdpClient* freerdp_client_get_interface(rdpContext* context)
{
return context->client;
}
double freerdp_client_get_scale(rdpContext* context)
{
xfContext* xfc = (xfContext*) context;
@ -1574,7 +1569,7 @@ void freerdp_client_reset_scale(rdpContext* context)
e.width = (int) xfc->originalWidth * xfc->scale;
e.height = (int) xfc->originalHeight * xfc->scale;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
xf_draw_screen_scaled(xfc);
}
@ -1596,7 +1591,6 @@ int xfreerdp_client_new(freerdp* instance, rdpContext* context)
context->channels = freerdp_channels_new();
settings = instance->settings;
xfc->client = instance->context->client;
xfc->settings = instance->context->settings;
settings->OsMajorType = OSMAJORTYPE_UNIX;

View File

@ -199,7 +199,7 @@ void xf_input_detect_pinch(xfContext* xfc)
e.width = (int) xfc->originalWidth * xfc->scale;
e.height = (int) xfc->originalHeight * xfc->scale;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
z_vector = 0;
}
@ -215,7 +215,7 @@ void xf_input_detect_pinch(xfContext* xfc)
e.width = (int) xfc->originalWidth * xfc->scale;
e.height = (int) xfc->originalHeight * xfc->scale;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
PubSub_OnEvent(((rdpContext*) xfc)->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
z_vector = 0;
}

View File

@ -62,7 +62,6 @@ struct xf_context
DEFINE_RDP_CLIENT_COMMON();
freerdp* instance;
rdpClient* client;
rdpSettings* settings;
GC gc;

View File

@ -26,36 +26,15 @@
#include <freerdp/client/file.h>
#include <freerdp/client/cmdline.h>
static wEvent Client_Events[] =
{
DEFINE_EVENT_ENTRY(WindowStateChange)
DEFINE_EVENT_ENTRY(ResizeWindow)
};
int freerdp_client_common_new(freerdp* instance, rdpContext* context)
{
rdpClientContext* clientContext;
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
clientContext = (rdpClientContext*) context;
pEntryPoints = instance->pClientEntryPoints;
clientContext->pubSub = PubSub_New(TRUE);
PubSub_Publish(clientContext->pubSub, Client_Events, sizeof(Client_Events) / sizeof(wEvent));
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints;
return pEntryPoints->ClientNew(instance, context);
}
void freerdp_client_common_free(freerdp* instance, rdpContext* context)
{
rdpClientContext* clientContext;
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
clientContext = (rdpClientContext*) context;
pEntryPoints = instance->pClientEntryPoints;
PubSub_Free(clientContext->pubSub);
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = instance->pClientEntryPoints;
pEntryPoints->ClientFree(instance, context);
}
@ -78,9 +57,6 @@ rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
context = instance->context;
context->client->pEntryPoints = (RDP_CLIENT_ENTRY_POINTS*) malloc(pEntryPoints->Size);
CopyMemory(context->client->pEntryPoints, pEntryPoints, pEntryPoints->Size);
return context;
}
@ -94,14 +70,14 @@ void freerdp_client_context_free(rdpContext* context)
int freerdp_client_start(rdpContext* context)
{
rdpClient* client = context->client;
return client->pEntryPoints->ClientStart(context);
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
return pEntryPoints->ClientStart(context);
}
int freerdp_client_stop(rdpContext* context)
{
rdpClient* client = context->client;
return client->pEntryPoints->ClientStop(context);
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
return pEntryPoints->ClientStop(context);
}
freerdp* freerdp_client_get_instance(rdpContext* context)

View File

@ -63,35 +63,8 @@ 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 (*pOnErrorInfo)(freerdp* instance, UINT32 code);
typedef void (*pOnParamChange)(freerdp* instance, int id);
DEFINE_EVENT_BEGIN(ResizeWindow)
int width;
int height;
DEFINE_EVENT_END(ResizeWindow)
DEFINE_EVENT_BEGIN(WindowStateChange)
int state;
DEFINE_EVENT_END(WindowStateChange)
struct rdp_client
{
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
pOnErrorInfo OnErrorInfo;
pOnParamChange OnParamChange;
};
#define DEFINE_RDP_CLIENT_COMMON() \
HANDLE thread; \
wPubSub* pubSub
HANDLE thread
struct rdp_client_context
{

57
include/freerdp/event.h Normal file
View File

@ -0,0 +1,57 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Event Definitions
*
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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 FREERDP_EVENT_H
#define FREERDP_EVENT_H
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#ifdef __cplusplus
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
DEFINE_EVENT_BEGIN(WindowStateChange)
int state;
DEFINE_EVENT_END(WindowStateChange)
DEFINE_EVENT_BEGIN(ResizeWindow)
int width;
int height;
DEFINE_EVENT_END(ResizeWindow)
DEFINE_EVENT_BEGIN(ErrorInfo)
UINT32 code;
DEFINE_EVENT_END(ErrorInfo)
DEFINE_EVENT_BEGIN(ParamChange)
int id;
DEFINE_EVENT_END(ParamChange)
#ifdef __cplusplus
}
#endif
#endif /* FREERDP_EVENT_H */

View File

@ -26,7 +26,6 @@ typedef struct rdp_rail rdpRail;
typedef struct rdp_cache rdpCache;
typedef struct rdp_channels rdpChannels;
typedef struct rdp_graphics rdpGraphics;
typedef struct rdp_client rdpClient;
typedef struct rdp_freerdp freerdp;
typedef struct rdp_context rdpContext;
@ -39,6 +38,7 @@ typedef RDP_CLIENT_ENTRY_POINTS_V1 RDP_CLIENT_ENTRY_POINTS;
#include <freerdp/api.h>
#include <freerdp/types.h>
#include <freerdp/error.h>
#include <freerdp/event.h>
#include <freerdp/settings.h>
#include <freerdp/extension.h>
@ -95,7 +95,9 @@ struct rdp_context
Used to keep this data available and used later on, typically just before connection initialization.
@see freerdp_parse_args() */
UINT64 paddingB[32 - 18]; /* 18 */
ALIGN64 wPubSub* pubSub; /* (offset 18) */
UINT64 paddingB[32 - 19]; /* 19 */
ALIGN64 rdpRdp* rdp; /**< (offset 32)
Pointer to a rdp_rdp structure used to keep the connection's parameters.
@ -112,8 +114,7 @@ struct rdp_context
ALIGN64 rdpInput* input; /* 38 */
ALIGN64 rdpUpdate* update; /* 39 */
ALIGN64 rdpSettings* settings; /* 40 */
ALIGN64 rdpClient* client; /* 41 */
UINT64 paddingC[64 - 42]; /* 42 */
UINT64 paddingC[64 - 41]; /* 41 */
UINT64 paddingD[96 - 64]; /* 64 */
UINT64 paddingE[128 - 96]; /* 96 */
@ -138,7 +139,7 @@ struct rdp_freerdp
Can be allocated by a call to freerdp_context_new().
Must be deallocated by a call to freerdp_context_free() before deallocating the current instance. */
RDP_CLIENT_ENTRY_POINTS* pClientEntryPoints;
ALIGN64 RDP_CLIENT_ENTRY_POINTS* pClientEntryPoints;
UINT64 paddingA[16 - 2]; /* 2 */

View File

@ -744,6 +744,9 @@ BOOL freerdp_get_param_bool(rdpSettings* settings, int id)
int freerdp_set_param_bool(rdpSettings* settings, int id, BOOL param)
{
ParamChangeEventArgs e;
rdpContext* context = ((freerdp*) settings->instance)->context;
switch (id)
{
case FreeRDP_ServerMode:
@ -1185,7 +1188,9 @@ int freerdp_set_param_bool(rdpSettings* settings, int id, BOOL param)
// Mark field as modified
settings->settings_modified[id] = 1;
IFCALL(((freerdp*) settings->instance)->context->client->OnParamChange, ((freerdp*) settings->instance), id);
e.id = id;
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
return -1;
}
@ -1508,6 +1513,9 @@ UINT32 freerdp_get_param_uint32(rdpSettings* settings, int id)
int freerdp_set_param_uint32(rdpSettings* settings, int id, UINT32 param)
{
ParamChangeEventArgs e;
rdpContext* context = ((freerdp*) settings->instance)->context;
switch (id)
{
case FreeRDP_ShareId:
@ -1821,7 +1829,9 @@ int freerdp_set_param_uint32(rdpSettings* settings, int id, UINT32 param)
// Mark field as modified
settings->settings_modified[id] = 1;
IFCALL(((freerdp*) settings->instance)->context->client->OnParamChange, ((freerdp*) settings->instance), id);
e.id = id;
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
return 0;
}
@ -1844,6 +1854,9 @@ UINT64 freerdp_get_param_uint64(rdpSettings* settings, int id)
int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param)
{
ParamChangeEventArgs e;
rdpContext* context = ((freerdp*) settings->instance)->context;
switch (id)
{
case FreeRDP_ParentWindowId:
@ -1857,7 +1870,9 @@ int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param)
// Mark field as modified
settings->settings_modified[id] = 1;
IFCALL(((freerdp*) settings->instance)->context->client->OnParamChange, ((freerdp*) settings->instance), id);
e.id = id;
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
return 0;
}
@ -2028,6 +2043,9 @@ char* freerdp_get_param_string(rdpSettings* settings, int id)
int freerdp_set_param_string(rdpSettings* settings, int id, char* param)
{
ParamChangeEventArgs e;
rdpContext* context = ((freerdp*) settings->instance)->context;
switch (id)
{
case FreeRDP_ServerHostname:
@ -2189,7 +2207,9 @@ int freerdp_set_param_string(rdpSettings* settings, int id, char* param)
// Mark field as modified
settings->settings_modified[id] = 1;
IFCALL(((freerdp*) settings->instance)->context->client->OnParamChange, ((freerdp*) settings->instance), id);
e.id = id;
PubSub_OnEvent(context->pubSub, "ParamChange", context->instance, (wEventArgs*) &e);
return 0;
}

View File

@ -308,6 +308,14 @@ void freerdp_get_version(int* major, int* minor, int* revision)
*revision = FREERDP_VERSION_REVISION;
}
static wEvent FreeRDP_Events[] =
{
DEFINE_EVENT_ENTRY(WindowStateChange)
DEFINE_EVENT_ENTRY(ResizeWindow)
DEFINE_EVENT_ENTRY(ErrorInfo)
DEFINE_EVENT_ENTRY(ParamChange)
};
/** Allocator function for a rdp context.
* The function will allocate a rdpRdp structure using rdp_new(), then copy
* its contents to the appropriate fields in the rdp_freerdp structure given in parameters.
@ -339,8 +347,8 @@ int freerdp_context_new(freerdp* instance)
context->update = instance->update;
context->settings = instance->settings;
context->client = (rdpClient*) malloc(sizeof(rdpClient));
ZeroMemory(context->client, sizeof(rdpClient));
context->pubSub = PubSub_New(TRUE);
PubSub_Publish(context->pubSub, FreeRDP_Events, sizeof(FreeRDP_Events) / sizeof(wEvent));
instance->update->context = instance->context;
instance->update->pointer->context = instance->context;
@ -375,11 +383,7 @@ void freerdp_context_free(freerdp* instance)
rdp_free(instance->context->rdp);
graphics_free(instance->context->graphics);
if (instance->context->client)
{
free(instance->context->client->pEntryPoints);
free(instance->context->client);
}
PubSub_Free(instance->context->pubSub);
free(instance->context);
instance->context = NULL;

View File

@ -502,11 +502,13 @@ BOOL rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, wStream* s)
if (rdp->errorInfo != ERRINFO_SUCCESS)
{
rdpClient* client = rdp->instance->context->client;
ErrorInfoEventArgs e;
rdpContext* context = rdp->instance->context;
rdp_print_errinfo(rdp->errorInfo);
IFCALL(client->OnErrorInfo, rdp->instance, rdp->errorInfo);
e.code = rdp->errorInfo;
PubSub_OnEvent(context->pubSub, "ErrorInfo", context, (wEventArgs*) &e);
}
return TRUE;