return rturn;\r
}\r
\r
-int wf_mirage_step4(wfPeerContext* context)\r
+\r
+BOOL wf_map_mirror_mem(wfPeerContext* context)\r
{\r
int status;\r
\r
- printf("\n\nCreating a device context...\n");\r
+ _tprintf(_T("\n\nCreating a device context...\n"));\r
\r
context->driverDC = CreateDC(context->deviceName, NULL, NULL, NULL);\r
\r
if (context->driverDC == NULL)\r
{\r
- printf("Could not create device driver context!\n");\r
- return -1;\r
+ _tprintf(_T("Could not create device driver context!\n"));\r
+ return false;\r
}\r
\r
context->changeBuffer = malloc(sizeof(GETCHANGESBUF));\r
\r
- printf("\n\nConnecting to driver...\n");\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
\r
if (status <= 0)\r
{\r
- printf("Failed to map shared memory from the driver! Code %d\n", status);\r
+ _tprintf(_T("Failed to map shared memory from the driver! Code %d\n"), status);\r
}\r
\r
- return 0;\r
+ return true;\r
}\r
+\r
+/*\r
+Unmap the shared memory and release the DC\r
+*/\r
+BOOL wf_mirror_cleanup(wfPeerContext* context)\r
+{\r
+ int iResult;\r
+\r
+ _tprintf(_T("\n\nCleaning up...\nDisconnecting driver...\n"));\r
+ iResult = ExtEscape(context->driverDC, dmf_esc_usm_pipe_unmap, sizeof(context->changeBuffer), (LPSTR) context->changeBuffer, 0, 0);\r
+\r
+ if(iResult <= 0)\r
+ {\r
+ _tprintf(_T("Failed to unmap shared memory from the driver! Code %d\n"), iResult);\r
+ }\r
+\r
+ _tprintf(_T("Releasing DC\n"));\r
+ if(context->driverDC != NULL)\r
+ {\r
+ iResult = DeleteDC(context->driverDC);\r
+ if(iResult == 0)\r
+ {\r
+ _tprintf(_T("Failed to release DC!\n"));\r
+ }\r
+ }\r
+\r
+ free(context->changeBuffer);\r
+}
\ No newline at end of file
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
-int wf_mirage_step4(wfPeerContext* context);\r
+BOOL wf_map_mirror_mem(wfPeerContext* context);\r
+BOOL wf_mirror_cleanup(wfPeerContext* context);\r
\r
#endif /* WF_MIRAGE_H */\r
* See the License for the specific language governing permissions and\r
* limitations under the License.\r
*/\r
-\r
+#include <winpr/tchar.h>\r
+#include <winpr/windows.h>\r
#include <freerdp/listener.h>\r
+#include <freerdp/utils/sleep.h>\r
\r
#include "wf_mirage.h"\r
\r
wf_check_disp_devices(context);\r
wf_disp_device_set_attatch(context, 1);\r
wf_update_mirror_drv(context);\r
- wf_mirage_step4(context);\r
+ wf_map_mirror_mem(context);\r
}\r
\r
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)\r
{\r
if (context)\r
{\r
+ wf_mirror_cleanup(context);\r
+ wf_disp_device_set_attatch(context, 0);\r
+ wf_update_mirror_drv(context);\r
+ }\r
+}\r
+\r
+static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)\r
+{\r
+ wfPeerContext* context;\r
+ CHANGES_BUF* buf;\r
\r
+ context = (wfPeerContext*) lpParam;\r
+ buf = (CHANGES_BUF*)context->changeBuffer;\r
+\r
+ while(1)\r
+ {\r
+ _tprintf(_T("Count = %d\n"), buf->counter);\r
+ freerdp_usleep(1000000);\r
}\r
}\r
\r
client->ContextNew = (psPeerContextNew) wf_peer_context_new;\r
client->ContextFree = (psPeerContextFree) wf_peer_context_free;\r
freerdp_peer_context_new(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
+ _tprintf(_T("Created!\n"));\r
}\r
\r
boolean wf_peer_post_connect(freerdp_peer* client)\r