FreeRDP/server/shadow/shadow_subsystem.c

210 lines
4.2 KiB
C
Raw Normal View History

2014-09-17 22:58:57 -04:00
/**
* FreeRDP: A Remote Desktop Protocol Implementation
*
* Copyright 2014 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "shadow.h"
#include "shadow_subsystem.h"
2014-09-18 15:43:11 -04:00
struct _RDP_SHADOW_SUBSYSTEM
{
const char* name;
pfnShadowSubsystemEntry entry;
};
typedef struct _RDP_SHADOW_SUBSYSTEM RDP_SHADOW_SUBSYSTEM;
#ifdef WITH_SHADOW_X11
2014-09-18 15:43:11 -04:00
extern int X11_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
#ifdef WITH_SHADOW_MAC
2014-09-18 15:43:11 -04:00
extern int Mac_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
#ifdef WITH_SHADOW_WIN
2014-09-18 15:43:11 -04:00
extern int Win_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
#endif
2014-09-18 15:43:11 -04:00
static RDP_SHADOW_SUBSYSTEM g_Subsystems[] =
2014-09-17 22:58:57 -04:00
{
#ifdef WITH_SHADOW_X11
2014-09-18 15:43:11 -04:00
{ "X11", X11_ShadowSubsystemEntry },
#endif
#ifdef WITH_SHADOW_MAC
2014-09-18 15:43:11 -04:00
{ "Mac", Mac_ShadowSubsystemEntry },
#endif
#ifdef WITH_SHADOW_WIN
2014-09-18 15:43:11 -04:00
{ "Win", Win_ShadowSubsystemEntry },
#endif
2014-09-18 15:43:11 -04:00
{ "", 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;
}
int shadow_subsystem_load_entry_points(RDP_SHADOW_ENTRY_POINTS* pEntryPoints, const char* name)
{
pfnShadowSubsystemEntry entry;
entry = shadow_subsystem_load_static_entry(name);
2014-12-07 00:23:46 +01:00
ZeroMemory(pEntryPoints, sizeof(RDP_SHADOW_ENTRY_POINTS));
2014-09-18 15:43:11 -04:00
if (!entry)
return -1;
if (entry(pEntryPoints) < 0)
return -1;
return 1;
}
rdpShadowSubsystem* shadow_subsystem_new(const char* name)
{
RDP_SHADOW_ENTRY_POINTS ep;
rdpShadowSubsystem* subsystem = NULL;
shadow_subsystem_load_entry_points(&ep, name);
if (!ep.New)
return NULL;
subsystem = ep.New();
if (!subsystem)
return NULL;
CopyMemory(&(subsystem->ep), &ep, sizeof(RDP_SHADOW_ENTRY_POINTS));
2014-09-17 22:58:57 -04:00
return subsystem;
}
void shadow_subsystem_free(rdpShadowSubsystem* subsystem)
{
2014-09-18 15:43:11 -04:00
if (subsystem->ep.Free)
subsystem->ep.Free(subsystem);
}
int shadow_subsystem_init(rdpShadowSubsystem* subsystem, rdpShadowServer* server)
{
int status;
subsystem->server = server;
subsystem->selectedMonitor = server->selectedMonitor;
subsystem->MsgPipe = MessagePipe_New();
subsystem->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
2014-09-17 22:58:57 -04:00
region16_init(&(subsystem->invalidRegion));
2014-09-18 15:43:11 -04:00
if (!subsystem->ep.Init)
return -1;
2014-09-19 19:58:49 -04:00
status = subsystem->ep.Init(subsystem);
return status;
2014-09-17 22:58:57 -04:00
}
void shadow_subsystem_uninit(rdpShadowSubsystem* subsystem)
2014-09-17 22:58:57 -04:00
{
2014-09-18 15:43:11 -04:00
if (subsystem->ep.Uninit)
subsystem->ep.Uninit(subsystem);
if (subsystem->MsgPipe)
{
MessagePipe_Free(subsystem->MsgPipe);
subsystem->MsgPipe = NULL;
}
2014-09-17 22:58:57 -04:00
if (subsystem->updateEvent)
{
CloseHandle(subsystem->updateEvent);
subsystem->updateEvent = NULL;
}
if (subsystem->invalidRegion.data)
region16_uninit(&(subsystem->invalidRegion));
2014-09-17 22:58:57 -04:00
}
2014-09-18 15:43:11 -04:00
int shadow_subsystem_start(rdpShadowSubsystem* subsystem)
{
int status;
if (!subsystem->ep.Start)
return -1;
status = subsystem->ep.Start(subsystem);
return status;
}
int shadow_subsystem_stop(rdpShadowSubsystem* subsystem)
{
int status;
if (!subsystem->ep.Stop)
return -1;
status = subsystem->ep.Stop(subsystem);
return status;
}
int shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors, const char* name)
{
int numMonitors = 0;
RDP_SHADOW_ENTRY_POINTS ep;
if (shadow_subsystem_load_entry_points(&ep, name) < 0)
return -1;
numMonitors = ep.EnumMonitors(monitors, maxMonitors);
return numMonitors;
}