key corresponding to the device to the context and returns true. Otherwise\r
the function returns false.\r
*/\r
-BOOL wf_check_disp_devices(wfPeerContext* context)\r
+BOOL wf_check_disp_devices(wfInfo* context)\r
{\r
BOOL result, devFound;\r
DWORD deviceNumber;\r
unsuccessful or an unexpected value is encountered, the function returns \r
false.\r
*/\r
-BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val)\r
+BOOL wf_disp_device_set_attatch(wfInfo* context, DWORD val)\r
{\r
LONG status;\r
DWORD rtype, rdata, rdata_size;\r
return false;\r
}\r
\r
- _tprintf(_T("type = %04X, data = %04X\n\nNow let's try attaching it...\n"), rtype, rdata);\r
+ _tprintf(_T("type = %04X, data = %04X\n"), rtype, rdata);\r
\r
- if (rdata == val ^ 1)\r
+ if (rdata == (val ^ 1))\r
{\r
rdata = val;\r
\r
return false;\r
}\r
\r
- _tprintf(_T("Wrote subkey \"Attach.ToDesktop\" -> %04X\n\n", rdata));\r
+ _tprintf(_T("Wrote subkey \"Attach.ToDesktop\" -> %04X\n\n"), rdata);\r
}\r
else if (rdata == val)\r
{\r
- _tprintf(_T("\"Attach.ToDesktop\" is already set to %04X!\n", rdata));\r
+ _tprintf(_T("\"Attach.ToDesktop\" is already set to %04X!\n"), rdata);\r
}\r
else\r
{\r
This function will attempt to apply the currently configured display settings \r
in the registry to the display driver. It will return true if successful \r
otherwise it returns false.\r
+\r
+If unload is nonzero then the the driver will be asked to remove it self.\r
*/\r
-BOOL wf_update_mirror_drv(wfPeerContext* context)\r
+BOOL wf_update_mirror_drv(wfInfo* context, int unload)\r
{\r
int currentScreenPixH, currentScreenPixW, currentScreenBPP;\r
HDC dc;\r
TCHAR rMsg[64];\r
BOOL rturn;\r
\r
- /*\r
- Will have to come back to this for supporting non primary displays and \r
- multimonitor setups\r
- */\r
- dc = GetDC(NULL);\r
- currentScreenPixH = GetDeviceCaps(dc, HORZRES);\r
- currentScreenPixW = GetDeviceCaps(dc, VERTRES);\r
- currentScreenBPP = GetDeviceCaps(dc, BITSPIXEL);\r
- ReleaseDC(NULL, dc);\r
- \r
- _tprintf(_T("Detected current screen settings: %dx%dx%d\n"), currentScreenPixH, currentScreenPixW, currentScreenBPP);\r
+ if(!unload)\r
+ {\r
+ /*\r
+ Will have to come back to this for supporting non primary displays and \r
+ multimonitor setups\r
+ */\r
+ dc = GetDC(NULL);\r
+ currentScreenPixH = GetDeviceCaps(dc, HORZRES);\r
+ currentScreenPixW = GetDeviceCaps(dc, VERTRES);\r
+ currentScreenBPP = GetDeviceCaps(dc, BITSPIXEL);\r
+ ReleaseDC(NULL, dc);\r
+\r
+ _tprintf(_T("Detected current screen settings: %dx%dx%d\n"), currentScreenPixH, currentScreenPixW, currentScreenBPP);\r
+ }\r
+ else\r
+ {\r
+ currentScreenPixH = 0;\r
+ currentScreenPixW = 0;\r
+ currentScreenBPP = 0;\r
+ }\r
\r
deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);\r
deviceMode->dmDriverExtra = 2 * sizeof(DWORD);\r
}\r
\r
\r
-BOOL wf_map_mirror_mem(wfPeerContext* context)\r
+BOOL wf_map_mirror_mem(wfInfo* context)\r
{\r
int status;\r
-\r
+ GETCHANGESBUF* b;\r
_tprintf(_T("\n\nCreating a device context...\n"));\r
\r
context->driverDC = CreateDC(context->deviceName, NULL, NULL, NULL);\r
}\r
\r
context->changeBuffer = malloc(sizeof(GETCHANGESBUF));\r
+ memset(context->changeBuffer, 0, sizeof(GETCHANGESBUF));\r
\r
_tprintf(_T("\n\nConnecting to driver...\n"));\r
status = ExtEscape(context->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) context->changeBuffer);\r
_tprintf(_T("Failed to map shared memory from the driver! Code %d\n"), status);\r
}\r
\r
+ b = (GETCHANGESBUF*)context->changeBuffer;\r
+ _tprintf(_T("ExtEscape() returned code %d\n"), status);\r
+\r
return true;\r
}\r
\r
/*\r
Unmap the shared memory and release the DC\r
*/\r
-BOOL wf_mirror_cleanup(wfPeerContext* context)\r
+BOOL wf_mirror_cleanup(wfInfo* context)\r
{\r
int iResult;\r
\r
}\r
\r
free(context->changeBuffer);\r
+\r
+ return true;\r
}
\ No newline at end of file
ULONG nColorBmPalEntries;\r
} Esc_dmf_pointer_shape_get_OUT;\r
\r
-BOOL wf_check_disp_devices(wfPeerContext* context);\r
-BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val);\r
-BOOL wf_update_mirror_drv(wfPeerContext* context);\r
-BOOL wf_map_mirror_mem(wfPeerContext* context);\r
-BOOL wf_mirror_cleanup(wfPeerContext* context);\r
+BOOL wf_check_disp_devices(wfInfo* context);\r
+BOOL wf_disp_device_set_attatch(wfInfo* context, DWORD val);\r
+BOOL wf_update_mirror_drv(wfInfo* context, int unload);\r
+BOOL wf_map_mirror_mem(wfInfo* context);\r
+BOOL wf_mirror_cleanup(wfInfo* context);\r
\r
#endif /* WF_MIRAGE_H */\r
\r
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)\r
{\r
- wf_check_disp_devices(context);\r
- wf_disp_device_set_attatch(context, 1);\r
- wf_update_mirror_drv(context);\r
- wf_map_mirror_mem(context);\r
+ if(!wfInfoSingleton)\r
+ {\r
+ wfInfoSingleton = (wfInfo*)malloc(sizeof(wfInfo)); //free this on shutdown\r
+ memset(wfInfoSingleton, 0, sizeof(wfInfo));\r
+ }\r
+ \r
+ if(wfInfoSingleton->subscribers == 0)\r
+ {\r
+ //only the first peer needs to call this.\r
+ context->wfInfo = wfInfoSingleton;\r
+ wf_check_disp_devices(context->wfInfo);\r
+ wf_disp_device_set_attatch(context->wfInfo, 1);\r
+ wf_update_mirror_drv(context->wfInfo, 0);\r
+ wf_map_mirror_mem(context->wfInfo);\r
+ }\r
+ ++wfInfoSingleton->subscribers;\r
}\r
\r
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)\r
{\r
- if (context)\r
+ if (context && (wfInfoSingleton->subscribers == 1))\r
{\r
- wf_mirror_cleanup(context);\r
- wf_disp_device_set_attatch(context, 0);\r
- wf_update_mirror_drv(context);\r
+ //only the last peer needs to call this\r
+ wf_mirror_cleanup(context->wfInfo);\r
+ wf_disp_device_set_attatch(context->wfInfo, 0);\r
+ wf_update_mirror_drv(context->wfInfo, 1);\r
}\r
+\r
+ --wfInfoSingleton->subscribers;\r
}\r
\r
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)\r
{\r
- wfPeerContext* context;\r
- CHANGES_BUF* buf;\r
+ wfInfo* info;\r
+ GETCHANGESBUF* buf;\r
+ //int derp;\r
\r
- context = (wfPeerContext*) lpParam;\r
- buf = (CHANGES_BUF*)context->changeBuffer;\r
+ info = wfInfoSingleton;\r
+ buf = (GETCHANGESBUF*)info->changeBuffer;\r
\r
- while(1)\r
+ //derp = 0;\r
+ while(info->subscribers > 0)\r
{\r
- _tprintf(_T("Count = %d\n"), buf->counter);\r
- freerdp_usleep(1000000);\r
+ _tprintf(_T("Count = %lu\n"), buf->buffer->counter);\r
+ freerdp_sleep(1);\r
+ //derp++;\r
}\r
+\r
+ _tprintf(_T("monitor thread terminating...\n"));\r
+ return 0;\r
}\r
\r
void wf_peer_init(freerdp_peer* client)\r
\r
_tprintf(_T("Trying to create a monitor thread...\n"));\r
\r
- if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client->context, 0, NULL) != 0)\r
+ if (CreateThread(NULL, 0, wf_peer_mirror_monitor, NULL, 0, NULL) != 0)\r
_tprintf(_T("Created!\n"));\r
+ \r
}\r
\r
boolean wf_peer_post_connect(freerdp_peer* client)\r
-/**
- * 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 */
+/**\r
+ * FreeRDP: A Remote Desktop Protocol Client\r
+ * FreeRDP Windows Server\r
+ *\r
+ * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#ifndef WFREERDP_H\r
+#define WFREERDP_H\r
+\r
+#include <freerdp/freerdp.h>\r
+\r
+struct wf_info\r
+{\r
+ HDC driverDC;\r
+ boolean activated;\r
+ void* changeBuffer;\r
+ LPTSTR deviceKey;\r
+ TCHAR deviceName[32];\r
+ int subscribers;\r
+};\r
+typedef struct wf_info wfInfo;\r
+\r
+struct wf_peer_context\r
+{\r
+ rdpContext _p;\r
+\r
+ wfInfo* wfInfo;\r
+ boolean activated;\r
+};\r
+typedef struct wf_peer_context wfPeerContext;\r
+\r
+static wfInfo * wfInfoSingleton;\r
+\r
+#endif /* WFREERDP_H */\r