Changeset 73b0773 in mainline
- Timestamp:
- 2017-12-15T23:12:44Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2bd04b2
- Parents:
- 64d138b
- git-author:
- Petr Mánek <petr.manek@…> (2017-12-15 23:11:44)
- git-committer:
- Petr Mánek <petr.manek@…> (2017-12-15 23:12:44)
- Location:
- uspace/app/tmon
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tmon/Makefile
r64d138b r73b0773 33 33 34 34 SOURCES = \ 35 main.c 35 main.c\ 36 list.c 36 37 37 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/tmon/main.c
r64d138b r73b0773 36 36 37 37 #include <stdio.h> 38 #include <loc.h> 39 #include <usb/diag/diag.h> 40 #include <usb/diag/iface.h> 41 #include <devman.h> 42 #include <errno.h> 38 #include "commands.h" 43 39 44 40 #define NAME "tmon" … … 49 45 } 50 46 51 static void print_list_item(service_id_t svc) 52 { 53 int rc;54 devman_handle_t diag_handle = 0;47 typedef struct { 48 const char *name; 49 int (*action)(int, char **); 50 } usb_diag_cmd_t; 55 51 56 if ((rc = devman_fun_sid_to_handle(svc, &diag_handle))) { 57 printf(NAME ": Error resolving handle of device with SID %ld, skipping.\n", svc); 58 return; 52 static usb_diag_cmd_t commands[] = { 53 { 54 .name = "list", 55 .action = tmon_list, 56 }, 57 { 58 .name = NULL 59 59 } 60 } 61 62 static int print_list() 63 { 64 category_id_t diag_cat; 65 service_id_t *svcs; 66 size_t count; 67 int rc; 68 69 if ((rc = loc_category_get_id(USB_DIAG_CATEGORY, &diag_cat, 0))) { 70 printf(NAME ": Error resolving category '%s'", USB_DIAG_CATEGORY); 71 return 1; 72 } 73 74 if ((rc = loc_category_get_svcs(diag_cat, &svcs, &count))) { 75 printf(NAME ": Error getting list of host controllers.\n"); 76 return 1; 77 } 78 79 for (unsigned i = 0; i < count; ++i) { 80 print_list_item(svcs[i]); 81 } 82 83 free(svcs); 84 return 0; 85 } 60 }; 86 61 87 62 int main(int argc, char *argv[]) 88 63 { 89 if (argc <= 1) { 64 // Find a command to execute. 65 usb_diag_cmd_t *cmd = NULL; 66 for (int i = 0; argc > 1 && commands[i].name; ++i) { 67 if (str_cmp(argv[1], commands[i].name) == 0) { 68 cmd = commands + i; 69 break; 70 } 71 } 72 73 if (!cmd) { 90 74 print_usage(argv[0]); 91 75 return -1; 92 76 } 93 77 94 return print_list();78 return cmd->action(argc - 2, argv + 2); 95 79 } 96 80
Note:
See TracChangeset
for help on using the changeset viewer.