Changeset ad2a8b1 in mainline


Ignore:
Timestamp:
2017-12-21T09:24:17Z (6 years ago)
Author:
Petr Mánek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d37dd3b9
Parents:
e9d600c2
Message:

tmon: refactoring, moved device resolving functions into a separate file

Location:
uspace/app/tmon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tmon/Makefile

    re9d600c2 rad2a8b1  
    3535        main.c\
    3636        list.c\
    37         test.c
     37        test.c\
     38        resolve.c
    3839
    3940include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tmon/test.c

    re9d600c2 rad2a8b1  
    3737#include <stdio.h>
    3838#include <devman.h>
    39 #include <loc.h>
    40 #include <errno.h>
    4139#include <str_error.h>
    4240#include <usbdiag_iface.h>
    4341#include "commands.h"
     42#include "resolve.h"
    4443
    4544#define NAME "tmon"
     
    4948#define DEFAULT_SIZE    65432
    5049
    51 static int resolve_default_fun(devman_handle_t *fun)
    52 {
    53         category_id_t diag_cat;
    54         service_id_t *svcs;
    55         size_t count;
    56         int rc;
    57 
    58         if ((rc = loc_category_get_id(USBDIAG_CATEGORY, &diag_cat, 0))) {
    59                 printf(NAME ": Error resolving category '%s'", USBDIAG_CATEGORY);
    60                 return rc;
    61         }
    62 
    63         if ((rc = loc_category_get_svcs(diag_cat, &svcs, &count))) {
    64                 printf(NAME ": Error getting list of diagnostic devices.\n");
    65                 return rc;
    66         }
    67 
    68         // There must be exactly one diagnostic device for this to work.
    69         if (count != 1) {
    70                 if (count) {
    71                         printf(NAME ": Found %ld devices. Please specify which to use.\n", count);
    72                 } else {
    73                         printf(NAME ": No diagnostic devices found.\n");
    74                 }
    75                 return ENOENT;
    76         }
    77 
    78         if ((rc = devman_fun_sid_to_handle(svcs[0], fun))) {
    79                 printf(NAME ": Error resolving handle of device with SID %ld.\n", svcs[0]);
    80                 return rc;
    81         }
    82 
    83         return EOK;
    84 }
    85 
    86 static int resolve_named_fun(const char *dev_path, devman_handle_t *fun)
    87 {
    88         int rc;
    89         service_id_t svc;
    90         if ((rc = loc_service_get_id(dev_path, &svc, IPC_FLAG_BLOCKING))) {
    91                 printf(NAME ": Error resolving device. %s\n", str_error(rc));
    92                 return rc;
    93         }
    94 
    95         if ((rc = devman_fun_sid_to_handle(svc, fun))) {
    96                 printf(NAME ": Error resolving handle of device with SID %ld.\n", svc);
    97                 return rc;
    98         }
    99 
    100         return EOK;
    101 }
    102 
    10350static int resolve_and_test(int argc, char *argv[], int (*test)(devman_handle_t, int, size_t)) {
    10451        devman_handle_t fun = -1;
    10552
    10653        if (argc == 0) {
    107                 if (resolve_default_fun(&fun))
     54                if (tmon_resolve_default(&fun))
    10855                        return 1;
    10956        } else if (argc == 1) {
    110                 if (resolve_named_fun(argv[0], &fun))
     57                if (tmon_resolve_named(argv[0], &fun))
    11158                        return 1;
    11259        } else {
Note: See TracChangeset for help on using the changeset viewer.