FreeRDP
server/Windows/cli/wfreerdp.c
1 
20 #include <freerdp/config.h>
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <errno.h>
26 
27 #include <winpr/tchar.h>
28 #include <winpr/windows.h>
29 
30 #include "wf_interface.h"
31 
32 #include "wfreerdp.h"
33 
34 #include <freerdp/server/server-common.h>
35 #include <freerdp/log.h>
36 #define TAG SERVER_TAG("windows")
37 
38 int IDcount = 0;
39 
40 BOOL CALLBACK moncb(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
41 {
42  WLog_DBG(TAG, "%d\t(%ld, %ld), (%ld, %ld)", IDcount, lprcMonitor->left, lprcMonitor->top,
43  lprcMonitor->right, lprcMonitor->bottom);
44  IDcount++;
45  return TRUE;
46 }
47 
48 int main(int argc, char* argv[])
49 {
50  freerdp_server_warn_unmaintained(argc, argv);
51 
52  BOOL screen_selected = FALSE;
53  int index = 1;
54  wfServer* server;
55  server = wfreerdp_server_new();
56  set_screen_id(0);
57  // handle args
58  errno = 0;
59 
60  while (index < argc)
61  {
62  // first the args that will cause the program to terminate
63  if (strcmp("--list-screens", argv[index]) == 0)
64  {
65  int width;
66  int height;
67  int bpp;
68  WLog_INFO(TAG, "Detecting screens...");
69  WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
70 
71  for (int i = 0;; i++)
72  {
73  _TCHAR name[128] = { 0 };
74  if (get_screen_info(i, name, ARRAYSIZE(name), &width, &height, &bpp) != 0)
75  {
76  if ((width * height * bpp) == 0)
77  continue;
78 
79  WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
80  WLog_INFO(TAG, "%s", name);
81  }
82  else
83  {
84  break;
85  }
86  }
87 
88  {
89  int vscreen_w;
90  int vscreen_h;
91  vscreen_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
92  vscreen_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
93  WLog_INFO(TAG, "");
94  EnumDisplayMonitors(NULL, NULL, moncb, 0);
95  IDcount = 0;
96  WLog_INFO(TAG, "Virtual Screen = %dx%d", vscreen_w, vscreen_h);
97  }
98 
99  return 0;
100  }
101 
102  if (strcmp("--screen", argv[index]) == 0)
103  {
104  UINT32 val;
105  screen_selected = TRUE;
106  index++;
107 
108  if (index == argc)
109  {
110  WLog_INFO(TAG, "missing screen id parameter");
111  return 0;
112  }
113 
114  val = strtoul(argv[index], NULL, 0);
115 
116  if ((errno != 0) || (val > UINT32_MAX))
117  return -1;
118 
119  set_screen_id(val);
120  index++;
121  }
122 
123  if (index == argc - 1)
124  {
125  UINT32 val = strtoul(argv[index], NULL, 0);
126 
127  if ((errno != 0) || (val > UINT32_MAX))
128  return -1;
129 
130  server->port = val;
131  break;
132  }
133  }
134 
135  if (screen_selected == FALSE)
136  {
137  int width;
138  int height;
139  int bpp;
140  WLog_INFO(TAG, "screen id not provided. attempting to detect...");
141  WLog_INFO(TAG, "Detecting screens...");
142  WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
143 
144  for (int i = 0;; i++)
145  {
146  _TCHAR name[128] = { 0 };
147  if (get_screen_info(i, name, ARRAYSIZE(name), &width, &height, &bpp) != 0)
148  {
149  if ((width * height * bpp) == 0)
150  continue;
151 
152  WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
153  WLog_INFO(TAG, "%s", name);
154  set_screen_id(i);
155  break;
156  }
157  else
158  {
159  break;
160  }
161  }
162  }
163 
164  WLog_INFO(TAG, "Starting server");
165  wfreerdp_server_start(server);
166  (void)WaitForSingleObject(server->thread, INFINITE);
167  WLog_INFO(TAG, "Stopping server");
168  wfreerdp_server_stop(server);
169  wfreerdp_server_free(server);
170  return 0;
171 }