server/shadow: Decouple shadow_subsystem and subsystem implementation detail.

Make shadow_subsystem standalone so that others can implement customized shadow server with shadow library.
This commit is contained in:
zihao.jiang 2015-04-09 01:30:57 +08:00
parent 0278f7f4ba
commit 131f030e0e
5 changed files with 51 additions and 80 deletions

View File

@ -170,6 +170,8 @@ struct rdp_shadow_subsystem
extern "C" {
#endif
FREERDP_API void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry);
FREERDP_API int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** argv);
FREERDP_API int shadow_server_command_line_status_print(rdpShadowServer* server, int argc, char** argv, int status);
@ -179,7 +181,7 @@ FREERDP_API int shadow_server_stop(rdpShadowServer* server);
FREERDP_API int shadow_server_init(rdpShadowServer* server);
FREERDP_API int shadow_server_uninit(rdpShadowServer* server);
FREERDP_API int shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors, const char* name);
FREERDP_API int shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors);
FREERDP_API rdpShadowServer* shadow_server_new();
FREERDP_API void shadow_server_free(rdpShadowServer* server);

View File

@ -37,17 +37,50 @@ static BOOL g_MessagePump = FALSE;
#include <freerdp/server/shadow.h>
#ifdef WITH_SHADOW_X11
extern int X11_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
#ifdef WITH_SHADOW_MAC
extern int Mac_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
#ifdef WITH_SHADOW_WIN
extern int Win_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
int main(int argc, char** argv)
{
MSG msg;
int status;
int status = 0;
DWORD dwExitCode;
rdpShadowServer* server;
#ifdef WITH_SHADOW_X11
shadow_subsystem_set_entry(X11_ShadowSubsystemEntry);
#endif
#ifdef WITH_SHADOW_MAC
shadow_subsystem_set_entry(Mac_ShadowSubsystemEntry);
#endif
#ifdef WITH_SHADOW_WIN
shadow_subsystem_set_entry(Win_ShadowSubsystemEntry);
#endif
server = shadow_server_new();
if (!server)
{
status = -1;
goto fail_server_new;
}
#ifdef WITH_SHADOW_X11
server->authentication = TRUE;
#else
server->authentication = FALSE;
#endif
if ((status = shadow_server_parse_command_line(server, argc, argv)) < 0)
{

View File

@ -254,7 +254,7 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
int numMonitors;
MONITOR_DEF monitors[16];
numMonitors = shadow_enum_monitors(monitors, 16, 0);
numMonitors = shadow_enum_monitors(monitors, 16);
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
{
@ -594,7 +594,7 @@ int shadow_server_init(rdpShadowServer* server)
server->listener->info = (void*) server;
server->listener->PeerAccepted = shadow_client_accepted;
server->subsystem = shadow_subsystem_new(NULL);
server->subsystem = shadow_subsystem_new();
if (!server->subsystem)
goto fail_subsystem_new;
@ -674,11 +674,7 @@ rdpShadowServer* shadow_server_new()
server->mayView = TRUE;
server->mayInteract = TRUE;
#ifdef WITH_SHADOW_X11
server->authentication = TRUE;
#else
server->authentication = FALSE;
#endif
return server;
}

View File

@ -24,92 +24,32 @@
#include "shadow_subsystem.h"
struct _RDP_SHADOW_SUBSYSTEM
static pfnShadowSubsystemEntry pSubsystemEntry = NULL;
void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry)
{
const char* name;
pfnShadowSubsystemEntry entry;
};
typedef struct _RDP_SHADOW_SUBSYSTEM RDP_SHADOW_SUBSYSTEM;
#ifdef WITH_SHADOW_X11
extern int X11_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
#ifdef WITH_SHADOW_MAC
extern int Mac_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
#ifdef WITH_SHADOW_WIN
extern int Win_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
static RDP_SHADOW_SUBSYSTEM g_Subsystems[] =
{
#ifdef WITH_SHADOW_X11
{ "X11", X11_ShadowSubsystemEntry },
#endif
#ifdef WITH_SHADOW_MAC
{ "Mac", Mac_ShadowSubsystemEntry },
#endif
#ifdef WITH_SHADOW_WIN
{ "Win", Win_ShadowSubsystemEntry },
#endif
{ "", NULL }
};
static int g_SubsystemCount = (sizeof(g_Subsystems) / sizeof(g_Subsystems[0]));
pfnShadowSubsystemEntry shadow_subsystem_load_static_entry(const char* name)
{
int index;
if (!name)
{
for (index = 0; index < g_SubsystemCount; index++)
{
if (g_Subsystems[index].name)
return g_Subsystems[index].entry;
}
}
for (index = 0; index < g_SubsystemCount; index++)
{
if (strcmp(name, g_Subsystems[index].name) == 0)
return g_Subsystems[index].entry;
}
return NULL;
pSubsystemEntry = pEntry;
}
int shadow_subsystem_load_entry_points(RDP_SHADOW_ENTRY_POINTS* pEntryPoints, const char* name)
static int shadow_subsystem_load_entry_points(RDP_SHADOW_ENTRY_POINTS* pEntryPoints)
{
pfnShadowSubsystemEntry entry;
entry = shadow_subsystem_load_static_entry(name);
ZeroMemory(pEntryPoints, sizeof(RDP_SHADOW_ENTRY_POINTS));
if (!entry)
if (!pSubsystemEntry)
return -1;
if (entry(pEntryPoints) < 0)
if (pSubsystemEntry(pEntryPoints) < 0)
return -1;
return 1;
}
rdpShadowSubsystem* shadow_subsystem_new(const char* name)
rdpShadowSubsystem* shadow_subsystem_new()
{
RDP_SHADOW_ENTRY_POINTS ep;
rdpShadowSubsystem* subsystem = NULL;
shadow_subsystem_load_entry_points(&ep, name);
shadow_subsystem_load_entry_points(&ep);
if (!ep.New)
return NULL;
@ -215,12 +155,12 @@ int shadow_subsystem_stop(rdpShadowSubsystem* subsystem)
return status;
}
int shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors, const char* name)
int shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
{
int numMonitors = 0;
RDP_SHADOW_ENTRY_POINTS ep;
if (shadow_subsystem_load_entry_points(&ep, name) < 0)
if (shadow_subsystem_load_entry_points(&ep) < 0)
return -1;
numMonitors = ep.EnumMonitors(monitors, maxMonitors);

View File

@ -67,7 +67,7 @@ typedef struct _SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE SHADOW_MSG_OUT_POINTER_ALPHA
extern "C" {
#endif
rdpShadowSubsystem* shadow_subsystem_new(const char* name);
rdpShadowSubsystem* shadow_subsystem_new();
void shadow_subsystem_free(rdpShadowSubsystem* subsystem);
int shadow_subsystem_init(rdpShadowSubsystem* subsystem, rdpShadowServer* server);