int main(int argc, char* argv[]) { CONFIGURATION config; config_parse(argc, argv, &config); if (config.action == NULL || strcmp("help", config.action) == 0) help(); enum platform system = platform_check(config.platform); if (system == 0) { fprintf(stderr, "Platform '%s' not found\n", config.platform); exit(-1); } if (strcmp("map", config.action) == 0) { if (config.address == NULL) { perror("No filename for mapping"); exit(-1); } udev_init(!inputAdded, config.mapping); for (int i=0;i<config.inputsCount;i++) evdev_create(config.inputs[i].path, config.inputs[i].mapping); evdev_map(config.address); exit(0); } if (config.address == NULL) { config.address = malloc(MAX_ADDRESS_SIZE); if (config.address == NULL) { perror("Not enough memory"); exit(-1); } config.address[0] = 0; gs_discover_server(config.address); if (config.address[0] == 0) { fprintf(stderr, "Autodiscovery failed. Specify an IP address next time.\n"); exit(-1); } } char host_config_file[128]; sprintf(host_config_file, "hosts/%s.conf", config.address); config_file_parse(host_config_file, &config); SERVER_DATA server; server.address = config.address; int ret; if ((ret = gs_init(&server, config.key_dir)) == GS_OUT_OF_MEMORY) { fprintf(stderr, "Not enough memory\n"); exit(-1); } else if (ret == GS_INVALID) { fprintf(stderr, "Invalid data received from server: %s\n", config.address, gs_error); exit(-1); } else if (ret != GS_OK) { fprintf(stderr, "Can't connect to server %s\n", config.address); exit(-1); } if (strcmp("list", config.action) == 0) { pair_check(&server); applist(&server); } else if (strcmp("stream", config.action) == 0) { pair_check(&server); if (IS_EMBEDDED(system)) { for (int i=0;i<config.inputsCount;i++) evdev_create(config.inputs[i].path, config.inputs[i].mapping); udev_init(!inputAdded, config.mapping); evdev_init(); #ifdef HAVE_LIBCEC cec_init(); #endif /* HAVE_LIBCEC */ } #ifdef HAVE_SDL else if (system == SDL) sdl_init(config.stream.width, config.stream.height); #endif stream(&server, &config, system); } else if (strcmp("pair", config.action) == 0) { char pin[5]; sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10); printf("Please enter the following PIN on the target PC: %s\n", pin); if (gs_pair(&server, &pin[0]) != GS_OK) { fprintf(stderr, "Failed to pair to server: %s\n", gs_error); } else { printf("Succesfully paired\n"); } } else if (strcmp("quit", config.action) == 0) { pair_check(&server); gs_quit_app(&server); } else fprintf(stderr, "%s is not a valid action\n", config.action); }
int main(int argc, char* argv[]) { printf("Moonlight Embedded %d.%d.%d (%s)\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, COMPILE_OPTIONS); CONFIGURATION config; config_parse(argc, argv, &config); if (config.action == NULL || strcmp("help", config.action) == 0) help(); enum platform system = platform_check(config.platform); if (system == 0) { fprintf(stderr, "Platform '%s' not found\n", config.platform); exit(-1); } config.stream.supportsHevc = config.stream.supportsHevc || platform_supports_hevc(system); if (strcmp("map", config.action) == 0) { if (config.address == NULL) { perror("No filename for mapping"); exit(-1); } udev_init(!inputAdded, config.mapping); for (int i=0;i<config.inputsCount;i++) evdev_create(config.inputs[i].path, config.inputs[i].mapping); evdev_map(config.address); exit(0); } if (config.address == NULL) { config.address = malloc(MAX_ADDRESS_SIZE); if (config.address == NULL) { perror("Not enough memory"); exit(-1); } config.address[0] = 0; printf("Searching for server...\n"); gs_discover_server(config.address); if (config.address[0] == 0) { fprintf(stderr, "Autodiscovery failed. Specify an IP address next time.\n"); exit(-1); } } char host_config_file[128]; sprintf(host_config_file, "hosts/%s.conf", config.address); if (access(host_config_file, R_OK) != -1) config_file_parse(host_config_file, &config); SERVER_DATA server; server.address = config.address; printf("Connect to %s...\n", server.address); int ret; if ((ret = gs_init(&server, config.key_dir)) == GS_OUT_OF_MEMORY) { fprintf(stderr, "Not enough memory\n"); exit(-1); } else if (ret == GS_INVALID) { fprintf(stderr, "Invalid data received from server: %s\n", config.address, gs_error); exit(-1); } else if (ret == GS_UNSUPPORTED_VERSION) { if (!config.unsupported_version) { fprintf(stderr, "Unsupported version: %s\n", gs_error); exit(-1); } } else if (ret != GS_OK) { fprintf(stderr, "Can't connect to server %s\n", config.address); exit(-1); } printf("NVIDIA %s, GFE %s (protocol version %d)\n", server.gpuType, server.gfeVersion, server.serverMajorVersion); if (strcmp("list", config.action) == 0) { pair_check(&server); applist(&server); } else if (strcmp("stream", config.action) == 0) { pair_check(&server); if (IS_EMBEDDED(system)) { for (int i=0;i<config.inputsCount;i++) { printf("Add input %s (mapping %s)...\n", config.inputs[i].path, config.inputs[i].mapping); evdev_create(config.inputs[i].path, config.inputs[i].mapping); } udev_init(!inputAdded, config.mapping); evdev_init(); #ifdef HAVE_LIBCEC cec_init(); #endif /* HAVE_LIBCEC */ } #ifdef HAVE_SDL else if (system == SDL) sdl_init(config.stream.width, config.stream.height, config.fullscreen); #endif stream(&server, &config, system); } else if (strcmp("pair", config.action) == 0) { char pin[5]; sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10); printf("Please enter the following PIN on the target PC: %s\n", pin); if (gs_pair(&server, &pin[0]) != GS_OK) { fprintf(stderr, "Failed to pair to server: %s\n", gs_error); } else { printf("Succesfully paired\n"); } } else if (strcmp("unpair", config.action) == 0) { if (gs_unpair(&server) != GS_OK) { fprintf(stderr, "Failed to unpair to server: %s\n", gs_error); } else { printf("Succesfully unpaired\n"); } } else if (strcmp("quit", config.action) == 0) { pair_check(&server); gs_quit_app(&server); } else fprintf(stderr, "%s is not a valid action\n", config.action); }