wfreerdp-server: code structure cleanup

This commit is contained in:
Marc-André Moreau 2012-07-30 21:32:44 -04:00
parent 263f76b555
commit a1c5768dc8
8 changed files with 374 additions and 234 deletions

View File

@ -43,24 +43,32 @@ set(FREERDP_CODEC_SRCS
nsc_encode.h nsc_encode.h
nsc_types.h nsc_types.h
mppc_dec.c mppc_dec.c
mppc_enc.c mppc_enc.c)
)
if(WITH_SSE2) set(FREERDP_CODEC_SSE2_SRCS
set(FREERDP_CODEC_SRCS ${FREERDP_CODEC_SRCS}
rfx_sse2.c rfx_sse2.c
rfx_sse2.h rfx_sse2.h
nsc_sse2.c nsc_sse2.c
nsc_sse2.h nsc_sse2.h)
)
set_property(SOURCE rfx_sse2.c nsc_sse2.c PROPERTY COMPILE_FLAGS "-msse2") set(FREERDP_CODEC_NEON_SRCS
rfx_neon.c
rfx_neon.h)
if(WITH_SSE2)
set(FREERDP_CODEC_SRCS ${FREERDP_CODEC_SRCS} ${FREERDP_CODEC_SSE2_SRCS})
if(CMAKE_COMPILER_IS_GNUCC)
set_property(SOURCE rfx_sse2.c nsc_sse2.c PROPERTY COMPILE_FLAGS "-msse2")
endif()
if(MSVC)
set_property(SOURCE rfx_sse2.c nsc_sse2.c PROPERTY COMPILE_FLAGS "/arch:SSE2")
endif()
endif() endif()
if(WITH_NEON) if(WITH_NEON)
set(FREERDP_CODEC_SRCS ${FREERDP_CODEC_SRCS} set(FREERDP_CODEC_SRCS ${FREERDP_CODEC_SRCS} ${FREERDP_CODEC_NEON_SRCS})
rfx_neon.c
rfx_neon.h
)
set_property(SOURCE rfx_neon.c PROPERTY COMPILE_FLAGS "-mfpu=neon -mfloat-abi=softfp") set_property(SOURCE rfx_neon.c PROPERTY COMPILE_FLAGS "-mfpu=neon -mfloat-abi=softfp")
endif() endif()

View File

@ -18,7 +18,12 @@
# limitations under the License. # limitations under the License.
add_executable(wfreerdp-server add_executable(wfreerdp-server
wfreerdp.c) wf_input.c
wf_input.h
wf_peer.c
wf_peer.h
wfreerdp.c
wfreerdp.h)
target_link_libraries(wfreerdp-server freerdp-core) target_link_libraries(wfreerdp-server freerdp-core)
target_link_libraries(wfreerdp-server freerdp-utils) target_link_libraries(wfreerdp-server freerdp-utils)

157
server/Windows/wf_input.c Normal file
View File

@ -0,0 +1,157 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server
*
* Copyright 2012 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.
*/
#include <winpr/windows.h>
#include "wf_input.h"
void wf_peer_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
{
INPUT keyboard_event;
keyboard_event.type = INPUT_KEYBOARD;
keyboard_event.ki.wVk = 0;
keyboard_event.ki.wScan = code;
keyboard_event.ki.dwFlags = KEYEVENTF_SCANCODE;
keyboard_event.ki.dwExtraInfo = 0;
keyboard_event.ki.time = 0;
if (flags & KBD_FLAGS_RELEASE)
keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
if (flags & KBD_FLAGS_EXTENDED)
keyboard_event.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
SendInput(1, &keyboard_event, sizeof(INPUT));
}
void wf_peer_unicode_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
{
INPUT keyboard_event;
keyboard_event.type = INPUT_KEYBOARD;
keyboard_event.ki.wVk = 0;
keyboard_event.ki.wScan = code;
keyboard_event.ki.dwFlags = KEYEVENTF_UNICODE;
keyboard_event.ki.dwExtraInfo = 0;
keyboard_event.ki.time = 0;
if (flags & KBD_FLAGS_RELEASE)
keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
SendInput(1, &keyboard_event, sizeof(INPUT));
}
void wf_peer_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
INPUT mouse_event;
ZeroMemory(&mouse_event, sizeof(INPUT));
mouse_event.type = INPUT_MOUSE;
if (flags & PTR_FLAGS_WHEEL)
{
mouse_event.mi.dwFlags = MOUSEEVENTF_WHEEL;
mouse_event.mi.mouseData = flags & WheelRotationMask;
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
mouse_event.mi.mouseData *= -1;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else
{
if (flags & PTR_FLAGS_MOVE)
{
mouse_event.mi.dx = x * (0xFFFF / GetSystemMetrics(SM_CXSCREEN));
mouse_event.mi.dy = y * (0xFFFF / GetSystemMetrics(SM_CYSCREEN));
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
SendInput(1, &mouse_event, sizeof(INPUT));
}
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
if (flags & PTR_FLAGS_BUTTON1)
{
if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else if (flags & PTR_FLAGS_BUTTON2)
{
if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else if (flags & PTR_FLAGS_BUTTON3)
{
if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
SendInput(1, &mouse_event, sizeof(INPUT));
}
}
}
void wf_peer_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
{
INPUT mouse_event;
ZeroMemory(&mouse_event, sizeof(INPUT));
mouse_event.type = INPUT_MOUSE;
if (flags & PTR_FLAGS_MOVE)
{
mouse_event.mi.dx = x * (0xFFFF / GetSystemMetrics(SM_CXSCREEN));
mouse_event.mi.dy = y * (0xFFFF / GetSystemMetrics(SM_CYSCREEN));
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
SendInput(1, &mouse_event, sizeof(INPUT));
}
mouse_event.mi.dx = mouse_event.mi.dy = mouse_event.mi.dwFlags = 0;
if (flags & PTR_XFLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_XDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_XUP;
if (flags & PTR_XFLAGS_BUTTON1)
mouse_event.mi.mouseData = XBUTTON1;
else if (flags & PTR_XFLAGS_BUTTON2)
mouse_event.mi.mouseData = XBUTTON2;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else
{
wf_peer_mouse_event(input, flags, x, y);
}
}

30
server/Windows/wf_input.h Normal file
View File

@ -0,0 +1,30 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server
*
* Copyright 2012 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 WF_INPUT_H
#define WF_INPUT_H
#include "wfreerdp.h"
void wf_peer_keyboard_event(rdpInput* input, uint16 flags, uint16 code);
void wf_peer_unicode_keyboard_event(rdpInput* input, uint16 flags, uint16 code);
void wf_peer_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
void wf_peer_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
#endif /* WF_INPUT_H */

87
server/Windows/wf_peer.c Normal file
View File

@ -0,0 +1,87 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server
*
* Copyright 2012 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.
*/
#include <freerdp/listener.h>
#include "wf_peer.h"
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
}
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
{
if (context)
{
}
}
void wf_peer_init(freerdp_peer* client)
{
client->context_size = sizeof(wfPeerContext);
client->ContextNew = (psPeerContextNew) wf_peer_context_new;
client->ContextFree = (psPeerContextFree) wf_peer_context_free;
freerdp_peer_context_new(client);
}
boolean wf_peer_post_connect(freerdp_peer* client)
{
wfPeerContext* context = (wfPeerContext*) client->context;
/**
* This callback is called when the entire connection sequence is done, i.e. we've received the
* Font List PDU from the client and sent out the Font Map PDU.
* The server may start sending graphics output and receiving keyboard/mouse input after this
* callback returns.
*/
printf("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname,
client->settings->os_major_type, client->settings->os_minor_type);
if (client->settings->autologon)
{
printf(" and wants to login automatically as %s\\%s",
client->settings->domain ? client->settings->domain : "",
client->settings->username);
/* A real server may perform OS login here if NLA is not executed previously. */
}
printf("\n");
printf("Client requested desktop: %dx%dx%d\n",
client->settings->width, client->settings->height, client->settings->color_depth);
return true;
}
boolean wf_peer_activate(freerdp_peer* client)
{
wfPeerContext* context = (wfPeerContext*) client->context;
context->activated = true;
return true;
}
void wf_peer_synchronize_event(rdpInput* input, uint32 flags)
{
}

35
server/Windows/wf_peer.h Normal file
View File

@ -0,0 +1,35 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server
*
* Copyright 2012 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 WF_PEER_H
#define WF_PEER_H
#include "wfreerdp.h"
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context);
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context);
void wf_peer_init(freerdp_peer* client);
boolean wf_peer_post_connect(freerdp_peer* client);
boolean wf_peer_activate(freerdp_peer* client);
void wf_peer_synchronize_event(rdpInput* input, uint32 flags);
#endif /* WF_PEER_H */

View File

@ -22,238 +22,24 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <winpr/tchar.h> #include <winpr/tchar.h>
#include <winpr/windows.h> #include <winpr/windows.h>
#include <freerdp/constants.h>
#include <freerdp/listener.h>
#include <freerdp/utils/sleep.h> #include <freerdp/utils/sleep.h>
#include <freerdp/utils/memory.h> #include <freerdp/utils/memory.h>
#include <freerdp/utils/thread.h> #include <freerdp/utils/thread.h>
#include <freerdp/locale/keyboard.h> #include <freerdp/locale/keyboard.h>
#include <freerdp/codec/rfx.h>
#include <freerdp/codec/nsc.h> #include "wf_input.h"
#include <freerdp/listener.h> #include "wf_peer.h"
#include "wfreerdp.h"
HANDLE g_done_event; HANDLE g_done_event;
int g_thread_count = 0; int g_thread_count = 0;
struct wf_peer_context
{
rdpContext _p;
boolean activated;
};
typedef struct wf_peer_context wfPeerContext;
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
}
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
{
if (context)
{
}
}
static void wf_peer_init(freerdp_peer* client)
{
client->context_size = sizeof(wfPeerContext);
client->ContextNew = (psPeerContextNew) wf_peer_context_new;
client->ContextFree = (psPeerContextFree) wf_peer_context_free;
freerdp_peer_context_new(client);
}
boolean wf_peer_post_connect(freerdp_peer* client)
{
wfPeerContext* context = (wfPeerContext*) client->context;
/**
* This callback is called when the entire connection sequence is done, i.e. we've received the
* Font List PDU from the client and sent out the Font Map PDU.
* The server may start sending graphics output and receiving keyboard/mouse input after this
* callback returns.
*/
printf("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname,
client->settings->os_major_type, client->settings->os_minor_type);
if (client->settings->autologon)
{
printf(" and wants to login automatically as %s\\%s",
client->settings->domain ? client->settings->domain : "",
client->settings->username);
/* A real server may perform OS login here if NLA is not executed previously. */
}
printf("\n");
printf("Client requested desktop: %dx%dx%d\n",
client->settings->width, client->settings->height, client->settings->color_depth);
/* A real server should tag the peer as activated here and start sending updates in main loop. */
/* Return false here would stop the execution of the peer mainloop. */
return true;
}
boolean wf_peer_activate(freerdp_peer* client)
{
wfPeerContext* context = (wfPeerContext*) client->context;
context->activated = true;
return true;
}
void wf_peer_synchronize_event(rdpInput* input, uint32 flags)
{
//printf("Client sent a synchronize event (flags:0x%X)\n", flags);
}
void wf_peer_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
{
INPUT keyboard_event;
//printf("Client sent a keyboard event (flags:0x%X code:0x%X)\n", flags, code);
keyboard_event.type = INPUT_KEYBOARD;
keyboard_event.ki.wVk = 0;
keyboard_event.ki.wScan = code;
keyboard_event.ki.dwFlags = KEYEVENTF_SCANCODE;
keyboard_event.ki.dwExtraInfo = 0;
keyboard_event.ki.time = 0;
if (flags & KBD_FLAGS_RELEASE)
keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
if (flags & KBD_FLAGS_EXTENDED)
keyboard_event.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
SendInput(1, &keyboard_event, sizeof(INPUT));
}
void wf_peer_unicode_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
{
INPUT keyboard_event;
//printf("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code);
keyboard_event.type = INPUT_KEYBOARD;
keyboard_event.ki.wVk = 0;
keyboard_event.ki.wScan = code;
keyboard_event.ki.dwFlags = KEYEVENTF_UNICODE;
keyboard_event.ki.dwExtraInfo = 0;
keyboard_event.ki.time = 0;
if (flags & KBD_FLAGS_RELEASE)
keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
SendInput(1, &keyboard_event, sizeof(INPUT));
}
void wf_peer_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
INPUT mouse_event;
//printf("Client sent a mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y);
ZeroMemory(&mouse_event, sizeof(INPUT));
mouse_event.type = INPUT_MOUSE;
if (flags & PTR_FLAGS_WHEEL)
{
mouse_event.mi.dwFlags = MOUSEEVENTF_WHEEL;
mouse_event.mi.mouseData = flags & WheelRotationMask;
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
mouse_event.mi.mouseData *= -1;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else
{
if (flags & PTR_FLAGS_MOVE)
{
mouse_event.mi.dx = x * (0xFFFF / GetSystemMetrics(SM_CXSCREEN));
mouse_event.mi.dy = y * (0xFFFF / GetSystemMetrics(SM_CYSCREEN));
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
SendInput(1, &mouse_event, sizeof(INPUT));
}
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
if (flags & PTR_FLAGS_BUTTON1)
{
if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else if (flags & PTR_FLAGS_BUTTON2)
{
if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else if (flags & PTR_FLAGS_BUTTON3)
{
if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
SendInput(1, &mouse_event, sizeof(INPUT));
}
}
}
void wf_peer_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
//printf("Client sent an extended mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y);
if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
{
INPUT mouse_event;
ZeroMemory(&mouse_event, sizeof(INPUT));
mouse_event.type = INPUT_MOUSE;
if (flags & PTR_FLAGS_MOVE)
{
mouse_event.mi.dx = x * (0xFFFF / GetSystemMetrics(SM_CXSCREEN));
mouse_event.mi.dy = y * (0xFFFF / GetSystemMetrics(SM_CYSCREEN));
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
SendInput(1, &mouse_event, sizeof(INPUT));
}
mouse_event.mi.dx = mouse_event.mi.dy = mouse_event.mi.dwFlags = 0;
if (flags & PTR_XFLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_XDOWN;
else
mouse_event.mi.dwFlags |= MOUSEEVENTF_XUP;
if (flags & PTR_XFLAGS_BUTTON1)
mouse_event.mi.mouseData = XBUTTON1;
else if (flags & PTR_XFLAGS_BUTTON2)
mouse_event.mi.mouseData = XBUTTON2;
SendInput(1, &mouse_event, sizeof(INPUT));
}
else
{
wf_peer_mouse_event(input, flags, x, y);
}
}
static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam) static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
{ {
int rcount; int rcount;

32
server/Windows/wfreerdp.h Normal file
View File

@ -0,0 +1,32 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server
*
* Copyright 2012 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 WFREERDP_H
#define WFREERDP_H
#include <freerdp/freerdp.h>
struct wf_peer_context
{
rdpContext _p;
boolean activated;
};
typedef struct wf_peer_context wfPeerContext;
#endif /* WFREERDP_H */