source: mainline/uspace/app/devctl/devctl.c@ dc6b148

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dc6b148 was 7beb220, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Skeleton of devctl utility. Currently prints device tree.

  • Property mode set to 100644
File size: 2.9 KB
Line 
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 devctl
30 * @{
31 */
32/** @file Control device framework (devman server).
33 */
34
35#include <devman.h>
36#include <errno.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <sys/typefmt.h>
40
41#define NAME "devctl"
42
43#define MAX_NAME_LENGTH 1024
44
45static int fun_tree_print(devman_handle_t funh, int lvl)
46{
47 char name[MAX_NAME_LENGTH];
48 devman_handle_t devh;
49 devman_handle_t *cfuns;
50 size_t count, i;
51 int rc;
52 int j;
53
54 for (j = 0; j < lvl; j++)
55 printf(" ");
56
57 rc = devman_fun_get_name(funh, name, MAX_NAME_LENGTH);
58 if (rc != EOK) {
59 str_cpy(name, MAX_NAME_LENGTH, "unknown");
60 return ENOMEM;
61 }
62
63 if (name[0] == '\0')
64 str_cpy(name, MAX_NAME_LENGTH, "/");
65
66 printf("%s (%" PRIun ")\n", name, funh);
67
68 rc = devman_fun_get_child(funh, &devh);
69 if (rc == ENOENT)
70 return EOK;
71
72 if (rc != EOK) {
73 printf(NAME ": Failed getting child device for function "
74 "%s.\n", "xxx");
75 return rc;
76 }
77
78 rc = devman_dev_get_functions(devh, &cfuns, &count);
79 if (rc != EOK) {
80 printf(NAME ": Failed getting list of functions for "
81 "device %s.\n", "xxx");
82 return rc;
83 }
84
85 for (i = 0; i < count; i++)
86 fun_tree_print(cfuns[i], lvl + 1);
87
88 free(cfuns);
89 return EOK;
90}
91
92int main(int argc, char *argv[])
93{
94 devman_handle_t root_fun;
95 int rc;
96
97 rc = devman_fun_get_handle("/", &root_fun, 0);
98 if (rc != EOK) {
99 printf(NAME ": Error resolving root function.\n");
100 return 1;
101 }
102
103 rc = fun_tree_print(root_fun, 0);
104 if (rc != EOK)
105 return 1;
106
107 return 0;
108}
109
110/** @}
111 */
Note: See TracBrowser for help on using the repository browser.