Changeset 903bac0a in mainline for uspace/app/locinfo/locinfo.c


Ignore:
Timestamp:
2011-08-19T09:00:38Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2ab36f1
Parents:
d894fbd (diff), 42a619b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/locinfo/locinfo.c

    rd894fbd r903bac0a  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup tester
    30  * @brief Test devman service.
     29/** @addtogroup locinfo
    3130 * @{
    3231 */
    33 /**
    34  * @file
     32/** @file locinfo.c Print information from location service.
    3533 */
    3634
    37 #include <inttypes.h>
    3835#include <errno.h>
    39 #include <str_error.h>
     36#include <loc.h>
     37#include <stdio.h>
     38#include <stdlib.h>
     39#include <str.h>
    4040#include <sys/types.h>
    41 #include <async.h>
    42 #include <devman.h>
    43 #include <str.h>
    44 #include <vfs/vfs.h>
    45 #include <sys/stat.h>
    46 #include <fcntl.h>
    47 #include "../tester.h"
     41#include <sys/typefmt.h>
    4842
    49 #define DEVICE_PATH_NORMAL "/virt/null/a"
    50 #define DEVICE_CLASS "virt-null"
    51 #define DEVICE_CLASS_NAME "1"
    52 #define DEVICE_PATH_CLASSES DEVICE_CLASS "/" DEVICE_CLASS_NAME
     43#define NAME "locinfo"
    5344
    54 const char *test_devman1(void)
     45int main(int argc, char *argv[])
    5546{
    56         devman_handle_t handle_primary;
    57         devman_handle_t handle_class;
    58        
     47        category_id_t *cat_ids;
     48        size_t cat_cnt;
     49        service_id_t *svc_ids;
     50        size_t svc_cnt;
     51
     52        size_t i, j;
     53        char *cat_name;
     54        char *svc_name;
    5955        int rc;
    60        
    61         TPRINTF("Asking for handle of `%s'...\n", DEVICE_PATH_NORMAL);
    62         rc = devman_device_get_handle(DEVICE_PATH_NORMAL, &handle_primary, 0);
     56
     57        rc = loc_get_categories(&cat_ids, &cat_cnt);
    6358        if (rc != EOK) {
    64                 TPRINTF(" ...failed: %s.\n", str_error(rc));
    65                 if (rc == ENOENT) {
    66                         TPRINTF("Have you compiled the test drivers?\n");
    67                 }
    68                 return "Failed getting device handle";
     59                printf(NAME ": Error getting list of categories.\n");
     60                return 1;
    6961        }
    7062
    71         TPRINTF("Asking for handle of `%s' by class..\n", DEVICE_PATH_CLASSES);
    72         rc = devman_device_get_handle_by_class(DEVICE_CLASS, DEVICE_CLASS_NAME,
    73             &handle_class, 0);
    74         if (rc != EOK) {
    75                 TPRINTF(" ...failed: %s.\n", str_error(rc));
    76                 return "Failed getting device class handle";
     63        for (i = 0; i < cat_cnt; i++) {
     64                rc = loc_category_get_name(cat_ids[i], &cat_name);
     65                if (rc != EOK)
     66                        cat_name = str_dup("<unknown>");
     67
     68                if (cat_name == NULL) {
     69                        printf(NAME ": Error allocating memory.\n");
     70                        return 1;
     71                }
     72
     73                printf("%s (%" PRIun "):\n", cat_name, cat_ids[i]);
     74
     75                rc = loc_category_get_svcs(cat_ids[i], &svc_ids, &svc_cnt);
     76                if (rc != EOK) {
     77                        printf(NAME ": Failed getting list of services in "
     78                            "category %s, skipping.\n", cat_name);
     79                        free(cat_name);
     80                        continue;
     81                }
     82
     83                for (j = 0; j < svc_cnt; j++) {
     84                        rc = loc_service_get_name(svc_ids[j], &svc_name);
     85                        if (rc != EOK) {
     86                                printf(NAME ": Unknown service name (SID %"
     87                                    PRIun ").\n", svc_ids[j]);
     88                                continue;
     89                        }
     90                        printf("\t%s (%" PRIun ")\n", svc_name, svc_ids[j]);
     91                }
     92
     93                free(svc_ids);
     94                free(cat_name);
    7795        }
    7896
    79         TPRINTF("Received handles %" PRIun " and %" PRIun ".\n",
    80             handle_primary, handle_class);
    81         if (handle_primary != handle_class) {
    82                 return "Retrieved different handles for the same device";
    83         }
    84 
    85         return NULL;
     97        free(cat_ids);
     98        return 0;
    8699}
    87100
Note: See TracChangeset for help on using the changeset viewer.