Changeset bb154c6 in mainline for uspace/srv/sysman/unit.h
- Timestamp:
- 2019-08-03T08:15:25Z (5 years ago)
- Children:
- 09a8006
- Parents:
- 6006f35
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-04-15 15:14:58)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 08:15:25)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/unit.h
r6006f35 rbb154c6 1 /* 2 * Unit terminology and OOP based on systemd. 3 */ 1 4 #ifndef SYSMAN_UNIT_H 2 5 #define SYSMAN_UNIT_H 3 6 7 #include <adt/hash_table.h> 4 8 #include <adt/list.h> 9 #include <conf/configuration.h> 10 #include <conf/ini.h> 11 #include <conf/text_parse.h> 5 12 #include <fibril_synch.h> 6 13 7 #include "unit_mnt.h" 8 #include "unit_cfg.h" 9 #include "unit_tgt.h" 10 #include "unit_types.h" 14 typedef enum { 15 UNIT_TYPE_INVALID = -1, 16 UNIT_TARGET = 0, 17 UNIT_MOUNT, 18 UNIT_CONFIGURATION, 19 } unit_type_t; 11 20 12 struct unit { 13 link_t units; 21 typedef enum { 22 STATE_EMBRYO = 0, 23 STATE_STARTING, 24 STATE_STARTED, 25 STATE_STOPPED, 26 STATE_FAILED 27 } unit_state_t; 28 29 typedef struct { 30 ht_link_t units; 14 31 15 32 unit_type_t type; 33 char *name; 16 34 17 35 unit_state_t state; … … 21 39 list_t dependencies; 22 40 list_t dependants; 41 } unit_t; 23 42 24 union { 25 unit_mnt_t mnt; 26 unit_cfg_t cfg; 27 } data; 43 typedef struct unit_vmt unit_vmt_t; 44 struct unit_vmt; 45 46 #include "unit_cfg.h" 47 #include "unit_mnt.h" 48 #include "unit_tgt.h" 49 50 #define DEFINE_CAST(NAME, TYPE, ENUM_TYPE) \ 51 static inline TYPE *CAST_##NAME(unit_t *u) \ 52 { \ 53 if (u->type == ENUM_TYPE) \ 54 return (TYPE *)u; \ 55 else \ 56 return NULL; \ 57 } \ 58 59 DEFINE_CAST(CFG, unit_cfg_t, UNIT_CONFIGURATION) 60 DEFINE_CAST(MNT, unit_mnt_t, UNIT_MOUNT) 61 DEFINE_CAST(TGT, unit_tgt_t, UNIT_TARGET) 62 63 struct unit_vmt { 64 size_t size; 65 66 void (*init)(unit_t *); 67 68 void (*destroy)(unit_t *); 69 70 int (*load)(unit_t *, ini_configuration_t *, text_parse_t *); 71 72 int (*start)(unit_t *); 28 73 }; 29 74 75 extern unit_vmt_t *unit_type_vmts[]; 76 77 #define DEFINE_UNIT_VMT(PREFIX) \ 78 unit_vmt_t PREFIX##_ops = { \ 79 .size = sizeof(PREFIX##_t), \ 80 .init = &PREFIX##_init, \ 81 .load = &PREFIX##_load, \ 82 .destroy = &PREFIX##_destroy, \ 83 .start = &PREFIX##_start \ 84 }; 85 86 #define UNIT_VMT(UNIT) unit_type_vmts[(UNIT)->type] 30 87 31 88 extern unit_t *unit_create(unit_type_t); … … 35 92 extern void unit_set_state(unit_t *, unit_state_t); 36 93 94 extern int unit_load(unit_t *, ini_configuration_t *, text_parse_t *); 37 95 extern int unit_start(unit_t *); 38 96 97 extern unit_type_t unit_type_name_to_type(const char *); 98 99 extern const char *unit_name(const unit_t *); 100 101 extern bool unit_parse_unit_list(const char *, void *, text_parse_t *, size_t); 102 39 103 #endif
Note:
See TracChangeset
for help on using the changeset viewer.