Changeset 07b39338 in mainline for uspace/app/devctl/devctl.c
- Timestamp:
- 2011-08-20T18:21:49Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ab014d
- Parents:
- 0cf27ee (diff), f00af83 (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. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/devctl/devctl.c
r0cf27ee r07b39338 1 1 /* 2 * Copyright (c) 2011 Vojtech Horky2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup tester 30 * @brief Test devman service. 29 /** @addtogroup devctl 31 30 * @{ 32 31 */ 33 /** 34 * @file 32 /** @file Control device framework (devman server). 35 33 */ 36 34 37 #include < inttypes.h>35 #include <devman.h> 38 36 #include <errno.h> 39 #include <str_error.h> 40 #include <sys/types.h> 41 #include <async.h> 42 #include <devman.h> 43 #include <str.h> 44 #include <async.h> 45 #include <vfs/vfs.h> 46 #include <vfs/vfs_sess.h> 47 #include <sys/stat.h> 48 #include <fcntl.h> 49 #include "../tester.h" 37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <sys/typefmt.h> 50 40 51 #define DEVICE_CLASS "test3"41 #define NAME "devctl" 52 42 53 const char *test_devman2(void) 43 #define MAX_NAME_LENGTH 1024 44 45 static int fun_tree_print(devman_handle_t funh, int lvl) 54 46 { 55 size_t idx = 1; 56 int rc = EOK; 57 const char *err_msg = NULL; 58 char *path = NULL; 59 while (rc == EOK) { 60 rc = asprintf(&path, "/loc/class/%s\\%zu", DEVICE_CLASS, idx); 61 if (rc < 0) { 62 continue; 63 } 64 int fd = open(path, O_RDONLY); 65 if (fd < 0) { 66 TPRINTF("Failed opening `%s': %s.\n", 67 path, str_error(fd)); 68 rc = fd; 69 err_msg = "Failed opening file"; 70 continue; 71 } 72 async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd); 73 close(fd); 74 if (sess == NULL) { 75 TPRINTF("Failed opening phone: %s.\n", str_error(errno)); 76 rc = errno; 77 err_msg = "Failed opening file descriptor phone"; 78 continue; 79 } 80 async_hangup(sess); 81 TPRINTF("Path `%s' okay.\n", path); 82 free(path); 83 idx++; 84 rc = EOK; 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; 85 61 } 86 87 if (path != NULL) 88 free(path); 89 90 return err_msg; 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 92 int 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; 91 108 } 92 109
Note:
See TracChangeset
for help on using the changeset viewer.