Changeset b55f62a in mainline for uspace/lib/sysman/src/ctl.c
- Timestamp:
- 2019-08-07T09:29:33Z (6 years ago)
- Children:
- 918ac9b
- Parents:
- 2df7d824
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-11-02 00:50:02)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-07 09:29:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/sysman/src/ctl.c
r2df7d824 rb55f62a 29 29 #include <async.h> 30 30 #include <errno.h> 31 #include <stdlib.h> 31 32 #include <str.h> 32 33 #include <sysman/ctl.h> … … 57 58 return rc; 58 59 } 60 61 static int sysman_get_units_once(sysarg_t *buf, size_t buf_size, 62 size_t *act_size) 63 { 64 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL); 65 66 ipc_call_t answer; 67 aid_t req = async_send_0(exch, SYSMAN_CTL_GET_UNITS, &answer); 68 int rc = async_data_read_start(exch, buf, buf_size); 69 70 sysman_exchange_end(exch); 71 72 if (rc != EOK) { 73 async_forget(req); 74 return rc; 75 } 76 77 sysarg_t retval; 78 async_wait_for(req, &retval); 79 80 if (retval != EOK) { 81 return retval; 82 } 83 84 *act_size = IPC_GET_ARG1(answer); 85 return EOK; 86 } 87 88 int sysman_get_units(unit_handle_t **units_ptr, size_t *cnt_ptr) 89 { 90 *units_ptr = NULL; 91 *cnt_ptr = 0; 92 93 unit_handle_t *units = NULL; 94 size_t alloc_size = 0; 95 size_t act_size = 0; 96 97 while (true) { 98 int rc = sysman_get_units_once(units, alloc_size, &act_size); 99 if (rc != EOK) { 100 return rc; 101 } 102 103 if (act_size <= alloc_size) { 104 break; 105 } 106 107 alloc_size = act_size; 108 units = realloc(units, alloc_size); 109 if (units == NULL) { 110 return ENOMEM; 111 } 112 } 113 114 *units_ptr = units; 115 *cnt_ptr = act_size / sizeof(unit_handle_t); 116 return EOK; 117 } 118 119 int sysman_unit_get_name(unit_handle_t handle, char *buf, size_t buf_size) 120 { 121 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL); 122 123 ipc_call_t answer; 124 aid_t req = async_send_1(exch, SYSMAN_CTL_UNIT_GET_NAME, handle, &answer); 125 int rc = async_data_read_start(exch, buf, buf_size); 126 127 sysman_exchange_end(exch); 128 129 if (rc != EOK) { 130 async_forget(req); 131 return rc; 132 } 133 134 sysarg_t retval; 135 async_wait_for(req, &retval); 136 137 if (retval != EOK) { 138 return retval; 139 } 140 141 return EOK; 142 } 143 144 int sysman_unit_get_state(unit_handle_t handle, unit_state_t *state) 145 { 146 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL); 147 int rc = async_req_1_1(exch, SYSMAN_CTL_UNIT_GET_STATE, handle, state); 148 sysman_exchange_end(exch); 149 150 return rc; 151 }
Note:
See TracChangeset
for help on using the changeset viewer.