Blame server/Windows/cli/wfreerdp.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 * FreeRDP Windows Server
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit 1fb8d4
 *
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1fb8d4
 * you may not use this file except in compliance with the License.
Packit 1fb8d4
 * You may obtain a copy of the License at
Packit 1fb8d4
 *
Packit 1fb8d4
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1fb8d4
 *
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1fb8d4
 * See the License for the specific language governing permissions and
Packit 1fb8d4
 * limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef HAVE_CONFIG_H
Packit 1fb8d4
#include "config.h"
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#include <stdio.h>
Packit 1fb8d4
#include <stdlib.h>
Packit 1fb8d4
#include <string.h>
Packit 1fb8d4
#include <errno.h>
Packit 1fb8d4
Packit 1fb8d4
#include <winpr/tchar.h>
Packit 1fb8d4
#include <winpr/windows.h>
Packit 1fb8d4
Packit 1fb8d4
#include "wf_interface.h"
Packit 1fb8d4
Packit 1fb8d4
#include "wfreerdp.h"
Packit 1fb8d4
Packit 1fb8d4
#include <freerdp/log.h>
Packit 1fb8d4
#define TAG SERVER_TAG("windows")
Packit 1fb8d4
Packit 1fb8d4
int IDcount = 0;
Packit 1fb8d4
Packit 1fb8d4
BOOL CALLBACK moncb(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
Packit 1fb8d4
{
Packit Service 5a9772
	WLog_DBG(TAG, "%d\t(%ld, %ld), (%ld, %ld)", IDcount, lprcMonitor->left, lprcMonitor->top,
Packit 1fb8d4
	         lprcMonitor->right, lprcMonitor->bottom);
Packit 1fb8d4
	IDcount++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int main(int argc, char* argv[])
Packit 1fb8d4
{
Packit 1fb8d4
	BOOL screen_selected = FALSE;
Packit 1fb8d4
	int index;
Packit 1fb8d4
	wfServer* server;
Packit 1fb8d4
	server = wfreerdp_server_new();
Packit 1fb8d4
	set_screen_id(0);
Packit Service 5a9772
	// handle args
Packit 1fb8d4
	index = 1;
Packit 1fb8d4
	errno = 0;
Packit 1fb8d4
Packit 1fb8d4
	while (index < argc)
Packit 1fb8d4
	{
Packit Service 5a9772
		// first the args that will cause the program to terminate
Packit 1fb8d4
		if (strcmp("--list-screens", argv[index]) == 0)
Packit 1fb8d4
		{
Packit 1fb8d4
			_TCHAR name[128];
Packit 1fb8d4
			int width;
Packit 1fb8d4
			int height;
Packit 1fb8d4
			int bpp;
Packit 1fb8d4
			int i;
Packit 1fb8d4
			WLog_INFO(TAG, "Detecting screens...");
Packit 1fb8d4
			WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
Packit 1fb8d4
Packit Service 5a9772
			for (i = 0;; i++)
Packit 1fb8d4
			{
Packit 1fb8d4
				if (get_screen_info(i, name, &width, &height, &bpp) != 0)
Packit 1fb8d4
				{
Packit 1fb8d4
					if ((width * height * bpp) == 0)
Packit 1fb8d4
						continue;
Packit 1fb8d4
Packit 1fb8d4
					WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
Packit 1fb8d4
					WLog_INFO(TAG, "%s", name);
Packit 1fb8d4
				}
Packit 1fb8d4
				else
Packit 1fb8d4
				{
Packit 1fb8d4
					break;
Packit 1fb8d4
				}
Packit 1fb8d4
			}
Packit 1fb8d4
Packit 1fb8d4
			{
Packit 1fb8d4
				int vscreen_w;
Packit 1fb8d4
				int vscreen_h;
Packit 1fb8d4
				vscreen_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
Packit 1fb8d4
				vscreen_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
Packit 1fb8d4
				WLog_INFO(TAG, "");
Packit 1fb8d4
				EnumDisplayMonitors(NULL, NULL, moncb, 0);
Packit 1fb8d4
				IDcount = 0;
Packit 1fb8d4
				WLog_INFO(TAG, "Virtual Screen = %dx%d", vscreen_w, vscreen_h);
Packit 1fb8d4
			}
Packit 1fb8d4
Packit 1fb8d4
			return 0;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (strcmp("--screen", argv[index]) == 0)
Packit 1fb8d4
		{
Packit 1fb8d4
			UINT32 val;
Packit 1fb8d4
			screen_selected = TRUE;
Packit 1fb8d4
			index++;
Packit 1fb8d4
Packit 1fb8d4
			if (index == argc)
Packit 1fb8d4
			{
Packit 1fb8d4
				WLog_INFO(TAG, "missing screen id parameter");
Packit 1fb8d4
				return 0;
Packit 1fb8d4
			}
Packit 1fb8d4
Packit 1fb8d4
			val = strtoul(argv[index], NULL, 0);
Packit 1fb8d4
Packit 1fb8d4
			if ((errno != 0) || (val > UINT32_MAX))
Packit 1fb8d4
				return -1;
Packit 1fb8d4
Packit 1fb8d4
			set_screen_id(val);
Packit 1fb8d4
			index++;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (index == argc - 1)
Packit 1fb8d4
		{
Packit 1fb8d4
			UINT32 val = strtoul(argv[index], NULL, 0);
Packit 1fb8d4
Packit 1fb8d4
			if ((errno != 0) || (val > UINT32_MAX))
Packit 1fb8d4
				return -1;
Packit 1fb8d4
Packit 1fb8d4
			server->port = val;
Packit 1fb8d4
			break;
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (screen_selected == FALSE)
Packit 1fb8d4
	{
Packit 1fb8d4
		_TCHAR name[128];
Packit 1fb8d4
		int width;
Packit 1fb8d4
		int height;
Packit 1fb8d4
		int bpp;
Packit 1fb8d4
		int i;
Packit 1fb8d4
		WLog_INFO(TAG, "screen id not provided. attempting to detect...");
Packit 1fb8d4
		WLog_INFO(TAG, "Detecting screens...");
Packit 1fb8d4
		WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
Packit 1fb8d4
Packit Service 5a9772
		for (i = 0;; i++)
Packit 1fb8d4
		{
Packit 1fb8d4
			if (get_screen_info(i, name, &width, &height, &bpp) != 0)
Packit 1fb8d4
			{
Packit 1fb8d4
				if ((width * height * bpp) == 0)
Packit 1fb8d4
					continue;
Packit 1fb8d4
Packit 1fb8d4
				WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
Packit 1fb8d4
				WLog_INFO(TAG, "%s", name);
Packit 1fb8d4
				set_screen_id(i);
Packit 1fb8d4
				break;
Packit 1fb8d4
			}
Packit 1fb8d4
			else
Packit 1fb8d4
			{
Packit 1fb8d4
				break;
Packit 1fb8d4
			}
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	WLog_INFO(TAG, "Starting server");
Packit 1fb8d4
	wfreerdp_server_start(server);
Packit 1fb8d4
	WaitForSingleObject(server->thread, INFINITE);
Packit 1fb8d4
	WLog_INFO(TAG, "Stopping server");
Packit 1fb8d4
	wfreerdp_server_stop(server);
Packit 1fb8d4
	wfreerdp_server_free(server);
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}