Changeset c05642d in mainline for uspace/app/devctl/devctl.c


Ignore:
Timestamp:
2011-09-07T00:03:26Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5081276
Parents:
bb74dabe (diff), 038b289 (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 edited

Legend:

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

    rbb74dabe rc05642d  
    3737#include <stdio.h>
    3838#include <stdlib.h>
     39#include <str_error.h>
    3940#include <sys/typefmt.h>
    4041
     
    4344#define MAX_NAME_LENGTH 1024
    4445
    45 static int fun_tree_print(devman_handle_t funh, int lvl)
     46static int fun_subtree_print(devman_handle_t funh, int lvl)
    4647{
    4748        char name[MAX_NAME_LENGTH];
     
    8485
    8586        for (i = 0; i < count; i++)
    86                 fun_tree_print(cfuns[i], lvl + 1);
     87                fun_subtree_print(cfuns[i], lvl + 1);
    8788
    8889        free(cfuns);
     
    9091}
    9192
    92 int main(int argc, char *argv[])
     93static int fun_tree_print(void)
    9394{
    9495        devman_handle_t root_fun;
     
    9899        if (rc != EOK) {
    99100                printf(NAME ": Error resolving root function.\n");
     101                return EIO;
     102        }
     103
     104        rc = fun_subtree_print(root_fun, 0);
     105        if (rc != EOK)
     106                return EIO;
     107
     108        return EOK;
     109}
     110
     111static int fun_online(const char *path)
     112{
     113        devman_handle_t funh;
     114        int rc;
     115
     116        rc = devman_fun_get_handle(path, &funh, 0);
     117        if (rc != EOK) {
     118                printf(NAME ": Error resolving device function '%s' (%s)\n",
     119                    path, str_error(rc));
     120                return rc;
     121        }
     122
     123        rc = devman_fun_online(funh);
     124        if (rc != EOK) {
     125                printf(NAME ": Failed to online function '%s'.\n", path);
     126                return rc;
     127        }
     128
     129        return EOK;
     130}
     131
     132static int fun_offline(const char *path)
     133{
     134        devman_handle_t funh;
     135        int rc;
     136
     137        rc = devman_fun_get_handle(path, &funh, 0);
     138        if (rc != EOK) {
     139                printf(NAME ": Error resolving device function '%s' (%s)\n",
     140                    path, str_error(rc));
     141                return rc;
     142        }
     143
     144        rc = devman_fun_offline(funh);
     145        if (rc != EOK) {
     146                printf(NAME ": Failed to offline function '%s'.\n", path);
     147                return rc;
     148        }
     149
     150        return EOK;
     151}
     152
     153static void print_syntax(void)
     154{
     155        printf("syntax: devctl [(online|offline) <function>]\n");
     156}
     157
     158int main(int argc, char *argv[])
     159{
     160        int rc;
     161
     162        if (argc == 1) {
     163                rc = fun_tree_print();
     164                if (rc != EOK)
     165                        return 2;
     166        } else if (str_cmp(argv[1], "online") == 0) {
     167                if (argc < 3) {
     168                        printf(NAME ": Argument missing.\n");
     169                        print_syntax();
     170                        return 1;
     171                }
     172
     173                rc = fun_online(argv[2]);
     174                if (rc != EOK) {
     175                        return 2;
     176                }
     177        } else if (str_cmp(argv[1], "offline") == 0) {
     178                if (argc < 3) {
     179                        printf(NAME ": Argument missing.\n");
     180                        print_syntax();
     181                        return 1;
     182                }
     183
     184                rc = fun_offline(argv[2]);
     185                if (rc != EOK) {
     186                        return 2;
     187                }
     188        } else {
     189                printf(NAME ": Invalid argument '%s'.\n", argv[1]);
     190                print_syntax();
    100191                return 1;
    101192        }
    102 
    103         rc = fun_tree_print(root_fun, 0);
    104         if (rc != EOK)
    105                 return 1;
    106193
    107194        return 0;
Note: See TracChangeset for help on using the changeset viewer.