| 1 | /*
|
|---|
| 2 | * Copyright (c) 2012 Maurizio Lombardi
|
|---|
| 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 |
|
|---|
| 30 | #include <stdio.h>
|
|---|
| 31 | #include <devman.h>
|
|---|
| 32 | #include <device/clock_dev.h>
|
|---|
| 33 | #include <errno.h>
|
|---|
| 34 | #include <loc.h>
|
|---|
| 35 |
|
|---|
| 36 | #define NAME "date"
|
|---|
| 37 |
|
|---|
| 38 | int
|
|---|
| 39 | main(int argc, char **argv)
|
|---|
| 40 | {
|
|---|
| 41 | int rc;
|
|---|
| 42 | category_id_t cat_id;
|
|---|
| 43 | size_t svc_cnt;
|
|---|
| 44 | service_id_t *svc_ids = NULL;
|
|---|
| 45 | char *svc_name = NULL;
|
|---|
| 46 | char *devpath;
|
|---|
| 47 |
|
|---|
| 48 | /* Get the id of the clock category */
|
|---|
| 49 | rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING);
|
|---|
| 50 | if (rc != EOK) {
|
|---|
| 51 | printf(NAME ": Cannot get clock category id\n");
|
|---|
| 52 | goto exit;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | /* Get the list of available services in the clock category */
|
|---|
| 56 | rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt);
|
|---|
| 57 | if (rc != EOK) {
|
|---|
| 58 | printf(NAME ": Cannot get the list of services in category \
|
|---|
| 59 | clock\n");
|
|---|
| 60 | goto exit;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | /* Check if the are available services in the clock category */
|
|---|
| 64 | if (svc_cnt == 0) {
|
|---|
| 65 | printf(NAME ": No available service found in \
|
|---|
| 66 | the clock category\n");
|
|---|
| 67 | goto exit;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /* Get the name of the clock service */
|
|---|
| 71 | rc = loc_service_get_name(svc_ids[0], &svc_name);
|
|---|
| 72 | if (rc != EOK) {
|
|---|
| 73 | printf(NAME ": Cannot get the name of the service\n");
|
|---|
| 74 | goto exit;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | const char delim[] = {"/\0"};
|
|---|
| 78 | strtok(svc_name, delim);
|
|---|
| 79 | devpath = strtok(svc_name, delim);
|
|---|
| 80 |
|
|---|
| 81 | printf("Found device %s\n", devpath);
|
|---|
| 82 |
|
|---|
| 83 | exit:
|
|---|
| 84 | free(svc_name);
|
|---|
| 85 | free(svc_ids);
|
|---|
| 86 | return rc;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|