static void find_receiver(void) { _cleanup_free_ struct dirent **hidraw_list = NULL; int n, i; char path[PATH_MAX] = {0}; bool found = false; n = scandir("/dev/", &hidraw_list, filter_hidraw, alphasort); if (n < 0) return; for (i = 0; i < n; i++) { struct lur_receiver *receiver; sprintf_safe(path, "/dev/%s", hidraw_list[i]->d_name); receiver = open_receiver(path); if (receiver) { found = true; printf("%s\n", path); lur_receiver_unref(receiver); } free(hidraw_list[i]); } if (!found) fprintf(stderr, "No receivers found.\n"); }
int main(int argc, char **argv) { struct lur_receiver *receiver; const char *path; const char *command; while (1) { int c; int option_index = 0; static struct option opts[] = { { "help", 0, 0, OPT_HELP }, }; c = getopt_long(argc, argv, "+h", opts, &option_index); if (c == -1) break; switch(c) { case 'h': case OPT_HELP: usage(); return EXIT_SUCCESS; default: usage(); return EXIT_FAILURE; } } if (argc < 2) { usage(); return EXIT_FAILURE; } command = argv[1]; if (streq(command, "find")) { find_receiver(); return EXIT_SUCCESS; } if (argc < 3) { usage(); return EXIT_FAILURE; } path = argv[argc - 1]; receiver = open_receiver(path); if (!receiver) { fprintf(stderr, "Failed to open receiver at %s\n", path); return EXIT_FAILURE; } if (streq(command, "list")) { list_connected_devices(receiver); } else if (streq(command, "open")) { lur_receiver_open(receiver, 0); } else if (streq(command, "close")) { lur_receiver_close(receiver); } else if (streq(command, "disconnect")) { int index; if (argc < 4) { usage(); return EXIT_FAILURE; } index = atoi(argv[2]); disconnect_device(receiver, index); } else { usage(); return EXIT_FAILURE; } lur_receiver_unref(receiver); return EXIT_SUCCESS; }
returned<receiver> standard_container::open_receiver(const std::string &url, const proton::connection_options &co) { return open_receiver(url, receiver_options(), co); }
receiver connection::open_receiver(const std::string &addr) { return open_receiver(addr, receiver_options()); }
returned<receiver> container::open_receiver(const std::string &url, const proton::receiver_options &lo) { return open_receiver(url, lo, connection_options()); }