| 1 | /* | 
|---|
| 2 | * Copyright (c) 2011 Jiri Svoboda | 
|---|
| 3 | * All rights reserved. | 
|---|
| 4 | * | 
|---|
| 5 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 6 | * modification, are permitted provided that the following conditions | 
|---|
| 7 | * are met: | 
|---|
| 8 | * | 
|---|
| 9 | * - Redistributions of source code must retain the above copyright | 
|---|
| 10 | *   notice, this list of conditions and the following disclaimer. | 
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright | 
|---|
| 12 | *   notice, this list of conditions and the following disclaimer in the | 
|---|
| 13 | *   documentation and/or other materials provided with the distribution. | 
|---|
| 14 | * - The name of the author may not be used to endorse or promote products | 
|---|
| 15 | *   derived from this software without specific prior written permission. | 
|---|
| 16 | * | 
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | /** @addtogroup locinfo | 
|---|
| 30 | * @{ | 
|---|
| 31 | */ | 
|---|
| 32 | /** @file locinfo.c Print information from location service. | 
|---|
| 33 | */ | 
|---|
| 34 |  | 
|---|
| 35 | #include <errno.h> | 
|---|
| 36 | #include <loc.h> | 
|---|
| 37 | #include <stdio.h> | 
|---|
| 38 | #include <stdlib.h> | 
|---|
| 39 | #include <str.h> | 
|---|
| 40 | #include <sys/types.h> | 
|---|
| 41 | #include <sys/typefmt.h> | 
|---|
| 42 |  | 
|---|
| 43 | #define NAME "locinfo" | 
|---|
| 44 |  | 
|---|
| 45 | int main(int argc, char *argv[]) | 
|---|
| 46 | { | 
|---|
| 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; | 
|---|
| 55 | int rc; | 
|---|
| 56 |  | 
|---|
| 57 | rc = loc_get_categories(&cat_ids, &cat_cnt); | 
|---|
| 58 | if (rc != EOK) { | 
|---|
| 59 | printf(NAME ": Error getting list of categories.\n"); | 
|---|
| 60 | return 1; | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 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); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | free(cat_ids); | 
|---|
| 98 | return 0; | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 | /** @} | 
|---|
| 102 | */ | 
|---|