wfreerdp-server: more progress on the back end

This commit is contained in:
C-o-r-E
2012-08-14 20:30:36 -04:00
parent 67b1d4e607
commit 7ed19d7997
4 changed files with 128 additions and 79 deletions

View File

@@ -29,7 +29,7 @@ the mirror device we want to load. If found, it will then copy the registry
key corresponding to the device to the context and returns true. Otherwise
the function returns false.
*/
BOOL wf_check_disp_devices(wfPeerContext* context)
BOOL wf_check_disp_devices(wfInfo* context)
{
BOOL result, devFound;
DWORD deviceNumber;
@@ -84,7 +84,7 @@ This function will attempt to access the the windows registry using the device
unsuccessful or an unexpected value is encountered, the function returns
false.
*/
BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val)
BOOL wf_disp_device_set_attatch(wfInfo* context, DWORD val)
{
LONG status;
DWORD rtype, rdata, rdata_size;
@@ -105,9 +105,9 @@ BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val)
return false;
}
_tprintf(_T("type = %04X, data = %04X\n\nNow let's try attaching it...\n"), rtype, rdata);
_tprintf(_T("type = %04X, data = %04X\n"), rtype, rdata);
if (rdata == val ^ 1)
if (rdata == (val ^ 1))
{
rdata = val;
@@ -121,11 +121,11 @@ BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val)
return false;
}
_tprintf(_T("Wrote subkey \"Attach.ToDesktop\" -> %04X\n\n", rdata));
_tprintf(_T("Wrote subkey \"Attach.ToDesktop\" -> %04X\n\n"), rdata);
}
else if (rdata == val)
{
_tprintf(_T("\"Attach.ToDesktop\" is already set to %04X!\n", rdata));
_tprintf(_T("\"Attach.ToDesktop\" is already set to %04X!\n"), rdata);
}
else
{
@@ -140,8 +140,10 @@ BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val)
This function will attempt to apply the currently configured display settings
in the registry to the display driver. It will return true if successful
otherwise it returns false.
If unload is nonzero then the the driver will be asked to remove it self.
*/
BOOL wf_update_mirror_drv(wfPeerContext* context)
BOOL wf_update_mirror_drv(wfInfo* context, int unload)
{
int currentScreenPixH, currentScreenPixW, currentScreenBPP;
HDC dc;
@@ -153,17 +155,26 @@ BOOL wf_update_mirror_drv(wfPeerContext* context)
TCHAR rMsg[64];
BOOL rturn;
/*
Will have to come back to this for supporting non primary displays and
multimonitor setups
*/
dc = GetDC(NULL);
currentScreenPixH = GetDeviceCaps(dc, HORZRES);
currentScreenPixW = GetDeviceCaps(dc, VERTRES);
currentScreenBPP = GetDeviceCaps(dc, BITSPIXEL);
ReleaseDC(NULL, dc);
_tprintf(_T("Detected current screen settings: %dx%dx%d\n"), currentScreenPixH, currentScreenPixW, currentScreenBPP);
if(!unload)
{
/*
Will have to come back to this for supporting non primary displays and
multimonitor setups
*/
dc = GetDC(NULL);
currentScreenPixH = GetDeviceCaps(dc, HORZRES);
currentScreenPixW = GetDeviceCaps(dc, VERTRES);
currentScreenBPP = GetDeviceCaps(dc, BITSPIXEL);
ReleaseDC(NULL, dc);
_tprintf(_T("Detected current screen settings: %dx%dx%d\n"), currentScreenPixH, currentScreenPixW, currentScreenBPP);
}
else
{
currentScreenPixH = 0;
currentScreenPixW = 0;
currentScreenBPP = 0;
}
deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);
deviceMode->dmDriverExtra = 2 * sizeof(DWORD);
@@ -233,10 +244,10 @@ BOOL wf_update_mirror_drv(wfPeerContext* context)
}
BOOL wf_map_mirror_mem(wfPeerContext* context)
BOOL wf_map_mirror_mem(wfInfo* context)
{
int status;
GETCHANGESBUF* b;
_tprintf(_T("\n\nCreating a device context...\n"));
context->driverDC = CreateDC(context->deviceName, NULL, NULL, NULL);
@@ -248,6 +259,7 @@ BOOL wf_map_mirror_mem(wfPeerContext* context)
}
context->changeBuffer = malloc(sizeof(GETCHANGESBUF));
memset(context->changeBuffer, 0, sizeof(GETCHANGESBUF));
_tprintf(_T("\n\nConnecting to driver...\n"));
status = ExtEscape(context->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) context->changeBuffer);
@@ -257,13 +269,16 @@ BOOL wf_map_mirror_mem(wfPeerContext* context)
_tprintf(_T("Failed to map shared memory from the driver! Code %d\n"), status);
}
b = (GETCHANGESBUF*)context->changeBuffer;
_tprintf(_T("ExtEscape() returned code %d\n"), status);
return true;
}
/*
Unmap the shared memory and release the DC
*/
BOOL wf_mirror_cleanup(wfPeerContext* context)
BOOL wf_mirror_cleanup(wfInfo* context)
{
int iResult;
@@ -286,4 +301,6 @@ BOOL wf_mirror_cleanup(wfPeerContext* context)
}
free(context->changeBuffer);
return true;
}

View File

@@ -200,10 +200,10 @@ typedef struct
ULONG nColorBmPalEntries;
} Esc_dmf_pointer_shape_get_OUT;
BOOL wf_check_disp_devices(wfPeerContext* context);
BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val);
BOOL wf_update_mirror_drv(wfPeerContext* context);
BOOL wf_map_mirror_mem(wfPeerContext* context);
BOOL wf_mirror_cleanup(wfPeerContext* context);
BOOL wf_check_disp_devices(wfInfo* context);
BOOL wf_disp_device_set_attatch(wfInfo* context, DWORD val);
BOOL wf_update_mirror_drv(wfInfo* context, int unload);
BOOL wf_map_mirror_mem(wfInfo* context);
BOOL wf_mirror_cleanup(wfInfo* context);
#endif /* WF_MIRAGE_H */

View File

@@ -27,35 +27,56 @@
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
wf_check_disp_devices(context);
wf_disp_device_set_attatch(context, 1);
wf_update_mirror_drv(context);
wf_map_mirror_mem(context);
if(!wfInfoSingleton)
{
wfInfoSingleton = (wfInfo*)malloc(sizeof(wfInfo)); //free this on shutdown
memset(wfInfoSingleton, 0, sizeof(wfInfo));
}
if(wfInfoSingleton->subscribers == 0)
{
//only the first peer needs to call this.
context->wfInfo = wfInfoSingleton;
wf_check_disp_devices(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 1);
wf_update_mirror_drv(context->wfInfo, 0);
wf_map_mirror_mem(context->wfInfo);
}
++wfInfoSingleton->subscribers;
}
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
{
if (context)
if (context && (wfInfoSingleton->subscribers == 1))
{
wf_mirror_cleanup(context);
wf_disp_device_set_attatch(context, 0);
wf_update_mirror_drv(context);
//only the last peer needs to call this
wf_mirror_cleanup(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 0);
wf_update_mirror_drv(context->wfInfo, 1);
}
--wfInfoSingleton->subscribers;
}
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
{
wfPeerContext* context;
CHANGES_BUF* buf;
wfInfo* info;
GETCHANGESBUF* buf;
//int derp;
context = (wfPeerContext*) lpParam;
buf = (CHANGES_BUF*)context->changeBuffer;
info = wfInfoSingleton;
buf = (GETCHANGESBUF*)info->changeBuffer;
while(1)
//derp = 0;
while(info->subscribers > 0)
{
_tprintf(_T("Count = %d\n"), buf->counter);
freerdp_usleep(1000000);
_tprintf(_T("Count = %lu\n"), buf->buffer->counter);
freerdp_sleep(1);
//derp++;
}
_tprintf(_T("monitor thread terminating...\n"));
return 0;
}
void wf_peer_init(freerdp_peer* client)
@@ -67,8 +88,9 @@ void wf_peer_init(freerdp_peer* client)
_tprintf(_T("Trying to create a monitor thread...\n"));
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client->context, 0, NULL) != 0)
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, NULL, 0, NULL) != 0)
_tprintf(_T("Created!\n"));
}
boolean wf_peer_post_connect(freerdp_peer* client)

View File

@@ -1,37 +1,47 @@
/**
* 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;
HDC driverDC;
boolean activated;
void* changeBuffer;
LPTSTR deviceKey;
TCHAR deviceName[32];
};
typedef struct wf_peer_context wfPeerContext;
#endif /* WFREERDP_H */
/**
* 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_info
{
HDC driverDC;
boolean activated;
void* changeBuffer;
LPTSTR deviceKey;
TCHAR deviceName[32];
int subscribers;
};
typedef struct wf_info wfInfo;
struct wf_peer_context
{
rdpContext _p;
wfInfo* wfInfo;
boolean activated;
};
typedef struct wf_peer_context wfPeerContext;
static wfInfo * wfInfoSingleton;
#endif /* WFREERDP_H */