Changeset cf00f2e4 in mainline


Ignore:
Timestamp:
2012-04-03T12:48:41Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fd37139d
Parents:
cca5c8d
Message:

date: get the list of available clock devices from the loc service

File:
1 edited

Legend:

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

    rcca5c8d rcf00f2e4  
    2929
    3030#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"
    3137
    3238int
    3339main(int argc, char **argv)
    3440{
    35         return 0;
     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
     83exit:
     84        free(svc_name);
     85        free(svc_ids);
     86        return rc;
    3687}
    3788
Note: See TracChangeset for help on using the changeset viewer.