Beispiel #1
0
int main(int argc, char **argv) {
    try {
        main_impl(argc, argv);
        return 0;
    } catch (std::exception const & e) {
        std::cerr << "Unhandled exception reached the top of main: " << e.what();
    }
    return 1;
}
Beispiel #2
0
int main(int argc, char **argv)
{
	const char* progname = "z-connector";

    struct arg_file *device = arg_file1("dD", "device", NULL, "path to the serial port of Z-Wave dongle");
    struct arg_str *server = arg_str1("sS", "server", NULL, "IP address or host name to connect to");
    struct arg_int *port = arg_int0("pP", "port", NULL, "port number (defaults to 9087)");
	struct arg_file *cert = arg_file0(NULL, "cert", NULL, "personal certificate");
	struct arg_file *key = arg_file0(NULL, "key", NULL, "personal certificate key");
	struct arg_file *cacert = arg_file0(NULL, "cacert", NULL, "CA certificate");
	struct arg_file *log = arg_file0("lL", "log", NULL, "file to write log to (defaults to stdout)");
	struct arg_lit *debug = arg_lit0(NULL, "debug", "log debugging information");
    struct arg_lit *help = arg_lit0("h", "help", "print this help and exit");
    struct arg_end *end = arg_end(20);

	void* argTable[] = {device, server, port, cert, key, cacert, log, debug, help, end};

#ifdef WIN32
	WSADATA wsa;
	WORD wsaVersion = MAKEWORD(2, 2);
	int wsaError;
	DWORD win32err;
#endif

	int retCode, nErrors;

	if (arg_nullcheck(argTable) != 0)
	{
        printf("%s: insufficient memory\n", progname);

		CLEAN_RETURN(1);
    }

	nErrors = arg_parse(argc, argv, argTable);

    if (IS_ARG_SET(help))
    {
        printf("Usage: %s", progname);
        arg_print_syntax(stdout, argTable, "\n");
        //printf("Print certain system information.  With no options, same as -s.\n\n");
        arg_print_glossary(stdout, argTable,"  %-25s %s\n");
        printf("\nReport bugs to <*****@*****.**>.\n");

        CLEAN_RETURN(0);
    }

	LogLevel = (IS_ARG_SET(debug)) ? 3 : 2;

    if (nErrors > 0)
	{
        arg_print_errors(stdout, end, progname);
        printf("Try '%s --help' for more information.\n", progname);

        CLEAN_RETURN(2);
    }

#ifdef WIN32
	hStoppingEvent = CreateEvent(NULL, TRUE, FALSE, "Local\\Z-Agent-Stop");
	if (hStoppingEvent == NULL)
	{
		win32err = GetLastError();
		if (win32err == ERROR_INVALID_HANDLE)
		{
			printf("Another instance is already running\n");

			CLEAN_RETURN(0);
		}
		else
		{
			printf("Failed to create synchronization event: %d\n", win32err);

			CLEAN_RETURN(3);
		}
	}

	wsaError = WSAStartup(wsaVersion, &wsa);
	if (wsaError != 0)
	{
		printf("WSA Startup failed with code %d\n", wsaError);

		CloseHandle(hStoppingEvent);
		CLEAN_RETURN(3);
	}

	if (wsa.wVersion != wsaVersion)
	{
		printf("Required WSA version not found\n");

		CloseHandle(hStoppingEvent);
		CLEAN_RETURN(3);
	}
#endif

	retCode = main_impl(device->filename[0], 
						server->sval[0], SAFE_INT(port, 9087),
						SAFE_FILE(cert, ""), SAFE_FILE(key, ""), SAFE_FILE(cacert, ""), 
						SAFE_FILE(log, "-"));

#ifdef WIN32
	WSACleanup();

	CloseHandle(hStoppingEvent);
#endif

	CLEAN_RETURN(retCode);
}
Beispiel #3
0
int platform::main( /* ... */ ) { return main_impl( /* ... */ ) ; }