diff --git a/server/Windows/wf_mirage.c b/server/Windows/wf_mirage.c index d87cba9f0..9c20610a7 100644 --- a/server/Windows/wf_mirage.c +++ b/server/Windows/wf_mirage.c @@ -232,29 +232,58 @@ BOOL wf_update_mirror_drv(wfPeerContext* context) return rturn; } -int wf_mirage_step4(wfPeerContext* context) + +BOOL wf_map_mirror_mem(wfPeerContext* context) { int status; - printf("\n\nCreating a device context...\n"); + _tprintf(_T("\n\nCreating a device context...\n")); context->driverDC = CreateDC(context->deviceName, NULL, NULL, NULL); if (context->driverDC == NULL) { - printf("Could not create device driver context!\n"); - return -1; + _tprintf(_T("Could not create device driver context!\n")); + return false; } context->changeBuffer = malloc(sizeof(GETCHANGESBUF)); - printf("\n\nConnecting to driver...\n"); + _tprintf(_T("\n\nConnecting to driver...\n")); status = ExtEscape(context->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) context->changeBuffer); if (status <= 0) { - printf("Failed to map shared memory from the driver! Code %d\n", status); + _tprintf(_T("Failed to map shared memory from the driver! Code %d\n"), status); } - return 0; + return true; } + +/* +Unmap the shared memory and release the DC +*/ +BOOL wf_mirror_cleanup(wfPeerContext* context) +{ + int iResult; + + _tprintf(_T("\n\nCleaning up...\nDisconnecting driver...\n")); + iResult = ExtEscape(context->driverDC, dmf_esc_usm_pipe_unmap, sizeof(context->changeBuffer), (LPSTR) context->changeBuffer, 0, 0); + + if(iResult <= 0) + { + _tprintf(_T("Failed to unmap shared memory from the driver! Code %d\n"), iResult); + } + + _tprintf(_T("Releasing DC\n")); + if(context->driverDC != NULL) + { + iResult = DeleteDC(context->driverDC); + if(iResult == 0) + { + _tprintf(_T("Failed to release DC!\n")); + } + } + + free(context->changeBuffer); +} \ No newline at end of file diff --git a/server/Windows/wf_mirage.h b/server/Windows/wf_mirage.h index 4a26d9b4a..9d63beaf3 100644 --- a/server/Windows/wf_mirage.h +++ b/server/Windows/wf_mirage.h @@ -203,6 +203,7 @@ typedef struct BOOL wf_check_disp_devices(wfPeerContext* context); BOOL wf_disp_device_set_attatch(wfPeerContext* context, DWORD val); BOOL wf_update_mirror_drv(wfPeerContext* context); -int wf_mirage_step4(wfPeerContext* context); +BOOL wf_map_mirror_mem(wfPeerContext* context); +BOOL wf_mirror_cleanup(wfPeerContext* context); #endif /* WF_MIRAGE_H */ diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 4ef397897..2d271f7c4 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -16,8 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include +#include #include +#include #include "wf_mirage.h" @@ -28,14 +30,31 @@ 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_mirage_step4(context); + wf_map_mirror_mem(context); } void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context) { if (context) { + wf_mirror_cleanup(context); + wf_disp_device_set_attatch(context, 0); + wf_update_mirror_drv(context); + } +} +static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam) +{ + wfPeerContext* context; + CHANGES_BUF* buf; + + context = (wfPeerContext*) lpParam; + buf = (CHANGES_BUF*)context->changeBuffer; + + while(1) + { + _tprintf(_T("Count = %d\n"), buf->counter); + freerdp_usleep(1000000); } } @@ -45,6 +64,11 @@ void wf_peer_init(freerdp_peer* client) client->ContextNew = (psPeerContextNew) wf_peer_context_new; client->ContextFree = (psPeerContextFree) wf_peer_context_free; freerdp_peer_context_new(client); + + _tprintf(_T("Trying to create a monitor thread...\n")); + + if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client->context, 0, NULL) != 0) + _tprintf(_T("Created!\n")); } boolean wf_peer_post_connect(freerdp_peer* client)