Changeset 5559712 in mainline for uspace/srv/sysman/unit.c
- Timestamp:
- 2019-08-03T09:28:50Z (5 years ago)
- Children:
- c0e4fc50
- Parents:
- 2dda1d4
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-05-07 11:49:47)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:28:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/unit.c
r2dda1d4 r5559712 37 37 #include <stdlib.h> 38 38 #include <str.h> 39 #include <sysman/unit.h> 39 40 40 41 #include "dep.h" 41 42 #include "log.h" 43 #include "sysman.h" 42 44 #include "unit.h" 43 45 44 46 /** Virtual method table for each unit type */ 45 47 unit_vmt_t *unit_type_vmts[] = { 46 [UNIT_TARGET] = &unit_tgt_ops, 47 [UNIT_MOUNT] = &unit_mnt_ops, 48 [UNIT_CONFIGURATION] = &unit_cfg_ops 48 [UNIT_CONFIGURATION] = &unit_cfg_vmt, 49 [UNIT_MOUNT] = &unit_mnt_vmt, 50 [UNIT_TARGET] = &unit_tgt_vmt, 51 [UNIT_SERVICE] = &unit_svc_vmt 49 52 }; 50 53 … … 61 64 assert(unit); 62 65 63 // TODO is this necessary?64 memset(unit, 0, size of(unit_t));66 size_t size = unit_type_vmts[type]->size; 67 memset(unit, 0, size); 65 68 66 69 unit->type = type; 67 unit->name = NULL;68 69 70 unit->state = STATE_EMBRYO; 70 71 … … 103 104 } 104 105 105 106 /** Issue request to restarter to start a unit107 *108 * Ideally this function is non-blocking synchronous, however, some units109 * cannot be started synchronously and thus return from this function generally110 * means that start was requested.111 *112 * Check state of the unit for actual result, start method can end in states:113 * - STATE_STARTED, (succesful synchronous start)114 * - STATE_STARTING, (succesful asynchronous start request)115 * - STATE_FAILED. (error occured)116 */117 int unit_start(unit_t *unit)118 {119 sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit));120 return UNIT_VMT(unit)->start(unit);121 }122 123 106 int unit_load(unit_t *unit, ini_configuration_t *ini_conf, 124 107 text_parse_t *text_parse) … … 140 123 } 141 124 125 /** Issue request to restarter to start a unit 126 * 127 * Ideally this function is non-blocking synchronous, however, some units 128 * cannot be started synchronously and thus return from this function generally 129 * means that start was requested. 130 * 131 * Check state of the unit for actual result, start method can end in states: 132 * - STATE_STARTED, (succesful synchronous start) 133 * - STATE_STARTING, (succesful asynchronous start request) 134 * - STATE_FAILED. (unit state changed and error occured) 135 */ 136 int unit_start(unit_t *unit) 137 { 138 sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit)); 139 return UNIT_VMT(unit)->start(unit); 140 } 141 142 void unit_exposee_created(unit_t *unit) 143 { 144 sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit)); 145 return UNIT_VMT(unit)->exposee_created(unit); 146 } 147 148 void unit_fail(unit_t *unit) 149 { 150 sysman_log(LVL_DEBUG, "%s('%s')", __func__, unit_name(unit)); 151 return UNIT_VMT(unit)->fail(unit); 152 } 153 154 void unit_notify_state(unit_t *unit) 155 { 156 sysman_raise_event(&sysman_event_unit_state_changed, unit); 157 } 158 142 159 unit_type_t unit_type_name_to_type(const char *type_name) 143 160 { 144 if (str_cmp(type_name, "cfg") == 0)161 if (str_cmp(type_name, UNIT_CFG_TYPE_NAME) == 0) 145 162 return UNIT_CONFIGURATION; 146 163 147 else if (str_cmp(type_name, "mnt") == 0)164 else if (str_cmp(type_name, UNIT_MNT_TYPE_NAME) == 0) 148 165 return UNIT_MOUNT; 149 166 150 else if (str_cmp(type_name, "tgt") == 0)167 else if (str_cmp(type_name, UNIT_TGT_TYPE_NAME) == 0) 151 168 return UNIT_TARGET; 169 170 else if (str_cmp(type_name, UNIT_SVC_TYPE_NAME) == 0) 171 return UNIT_SERVICE; 152 172 153 173 else … … 160 180 return unit->name ? unit->name : ""; 161 181 } 162 163 164 165 182 166 183 bool unit_parse_unit_list(const char *value, void *dst, text_parse_t *parse,
Note:
See TracChangeset
for help on using the changeset viewer.