FreeRDP
Loading...
Searching...
No Matches
server/drdynvc_main.c
1
22#include <freerdp/config.h>
23
24#include <winpr/crt.h>
25#include <winpr/print.h>
26#include <winpr/stream.h>
27#include <freerdp/channels/log.h>
28#include <freerdp/channels/drdynvc.h>
29
30#include "drdynvc_main.h"
31
32#define TAG CHANNELS_TAG("drdynvc.server")
33
39static UINT drdynvc_server_start(DrdynvcServerContext* context)
40{
41 context->priv->ChannelHandle =
42 WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, DRDYNVC_SVC_CHANNEL_NAME);
43
44 if (!context->priv->ChannelHandle)
45 {
46 WLog_ERR(TAG, "WTSVirtualChannelOpen failed!");
47 return CHANNEL_RC_NO_MEMORY;
48 }
49
50 if (!(context->priv->StopEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr)))
51 {
52 WLog_ERR(TAG, "CreateEvent failed!");
53 return ERROR_INTERNAL_ERROR;
54 }
55
56 return ERROR_INTERNAL_ERROR;
57}
58
64static UINT drdynvc_server_stop(DrdynvcServerContext* context)
65{
66 UINT error = 0;
67 (void)SetEvent(context->priv->StopEvent);
68
69 if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
70 {
71 error = GetLastError();
72 WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error);
73 return error;
74 }
75
76 (void)CloseHandle(context->priv->Thread);
77 return CHANNEL_RC_OK;
78}
79
80DrdynvcServerContext* drdynvc_server_context_new(HANDLE vcm)
81{
82 DrdynvcServerContext* context = nullptr;
83 context = (DrdynvcServerContext*)calloc(1, sizeof(DrdynvcServerContext));
84
85 if (context)
86 {
87 context->vcm = vcm;
88 context->Start = drdynvc_server_start;
89 context->Stop = drdynvc_server_stop;
90 context->priv = (DrdynvcServerPrivate*)calloc(1, sizeof(DrdynvcServerPrivate));
91
92 if (!context->priv)
93 {
94 WLog_ERR(TAG, "calloc failed!");
95 free(context);
96 return nullptr;
97 }
98 }
99 else
100 {
101 WLog_ERR(TAG, "calloc failed!");
102 }
103
104 return context;
105}
106
107void drdynvc_server_context_free(DrdynvcServerContext* context)
108{
109 if (context)
110 {
111 free(context->priv);
112 free(context);
113 }
114}