From 176ad52bd59e0fe568e9d23eab292e0f7f5ff6c3 Mon Sep 17 00:00:00 2001 From: "zihao.jiang" Date: Sat, 27 Feb 2016 01:07:30 +0800 Subject: [PATCH] server/shadow: Export API to set built-in subsystem modules for freerdp-shadow-subsystem --- include/freerdp/server/shadow.h | 2 + server/shadow/CMakeLists.txt | 9 ++- server/shadow/shadow.c | 24 +----- server/shadow/shadow_subsystem_builtin.c | 96 ++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 26 deletions(-) create mode 100644 server/shadow/shadow_subsystem_builtin.c diff --git a/include/freerdp/server/shadow.h b/include/freerdp/server/shadow.h index 5e8c71bf6..49bd0564a 100644 --- a/include/freerdp/server/shadow.h +++ b/include/freerdp/server/shadow.h @@ -277,7 +277,9 @@ typedef struct _SHADOW_MSG_OUT_AUDIO_OUT_VOLUME SHADOW_MSG_OUT_AUDIO_OUT_VOLUME; extern "C" { #endif +FREERDP_API void shadow_subsystem_set_entry_builtin(const char* name); FREERDP_API void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry); + FREERDP_API int shadow_subsystem_pointer_convert_alpha_pointer_data(BYTE* pixels, BOOL premultiplied, UINT32 width, UINT32 height, SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* pointerColor); diff --git a/server/shadow/CMakeLists.txt b/server/shadow/CMakeLists.txt index 67c3aa2a5..13c0f480d 100644 --- a/server/shadow/CMakeLists.txt +++ b/server/shadow/CMakeLists.txt @@ -97,6 +97,9 @@ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/shadow") set(MODULE_NAME "freerdp-shadow-subsystem") set(MODULE_PREFIX "FREERDP_SERVER_SHADOW_SUBSYSTEM") +set(${MODULE_PREFIX}_SRCS + shadow_subsystem_builtin.c) + if(WIN32) set(WITH_SHADOW_WIN 1) elseif(X11_FOUND AND NOT APPLE) @@ -245,15 +248,15 @@ set(${MODULE_PREFIX}_MAC_SRCS if(WITH_SHADOW_WIN) add_definitions(-DWITH_SHADOW_WIN) - set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_WIN_SRCS}) + list(APPEND ${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_WIN_SRCS}) list(APPEND ${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_WIN_LIBS}) elseif(WITH_SHADOW_X11) add_definitions(-DWITH_SHADOW_X11) - set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_X11_SRCS}) + list(APPEND ${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_X11_SRCS}) list(APPEND ${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_X11_LIBS}) elseif(WITH_SHADOW_MAC) add_definitions(-DWITH_SHADOW_MAC) - set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_MAC_SRCS}) + list(APPEND ${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_MAC_SRCS}) list(APPEND ${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_MAC_LIBS}) endif() diff --git a/server/shadow/shadow.c b/server/shadow/shadow.c index 83a834bc0..bc985192e 100644 --- a/server/shadow/shadow.c +++ b/server/shadow/shadow.c @@ -37,18 +37,6 @@ static BOOL g_MessagePump = FALSE; #include -#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; @@ -56,17 +44,7 @@ int main(int argc, char** argv) 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 + shadow_subsystem_set_entry_builtin(NULL); server = shadow_server_new(); diff --git a/server/shadow/shadow_subsystem_builtin.c b/server/shadow/shadow_subsystem_builtin.c new file mode 100644 index 000000000..be143d731 --- /dev/null +++ b/server/shadow/shadow_subsystem_builtin.c @@ -0,0 +1,96 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2016 Jiang Zihao + * + * 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 + +struct _RDP_SHADOW_SUBSYSTEM +{ + 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])); + +static 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; +} + +void shadow_subsystem_set_entry_builtin(const char* name) +{ + pfnShadowSubsystemEntry entry; + + entry = shadow_subsystem_load_static_entry(name); + + if (entry) + shadow_subsystem_set_entry(entry); + + return; +}