Changeset bb154c6 in mainline for uspace/srv/sysman/unit.h


Ignore:
Timestamp:
2019-08-03T08:15:25Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
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)
Message:

Add skeleton for configuration files loading

  • Create content of /cfg directory,
  • create sample configuration file,
  • refactored polymorphism.

Conflicts:

boot/Makefile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/unit.h

    r6006f35 rbb154c6  
     1/*
     2 * Unit terminology and OOP based on systemd.
     3 */
    14#ifndef SYSMAN_UNIT_H
    25#define SYSMAN_UNIT_H
    36
     7#include <adt/hash_table.h>
    48#include <adt/list.h>
     9#include <conf/configuration.h>
     10#include <conf/ini.h>
     11#include <conf/text_parse.h>
    512#include <fibril_synch.h>
    613
    7 #include "unit_mnt.h"
    8 #include "unit_cfg.h"
    9 #include "unit_tgt.h"
    10 #include "unit_types.h"
     14typedef enum {
     15        UNIT_TYPE_INVALID = -1,
     16        UNIT_TARGET = 0,
     17        UNIT_MOUNT,
     18        UNIT_CONFIGURATION,
     19} unit_type_t;
    1120
    12 struct unit {
    13         link_t units;
     21typedef enum {
     22        STATE_EMBRYO = 0,
     23        STATE_STARTING,
     24        STATE_STARTED,
     25        STATE_STOPPED,
     26        STATE_FAILED
     27} unit_state_t;
     28
     29typedef struct {
     30        ht_link_t units;
    1431
    1532        unit_type_t type;
     33        char *name;
    1634
    1735        unit_state_t state;
     
    2139        list_t dependencies;
    2240        list_t dependants;
     41} unit_t;
    2342
    24         union {
    25                 unit_mnt_t mnt;
    26                 unit_cfg_t cfg;
    27         } data;
     43typedef struct unit_vmt unit_vmt_t;
     44struct 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
     59DEFINE_CAST(CFG, unit_cfg_t, UNIT_CONFIGURATION)
     60DEFINE_CAST(MNT, unit_mnt_t, UNIT_MOUNT)
     61DEFINE_CAST(TGT, unit_tgt_t, UNIT_TARGET)
     62
     63struct 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 *);
    2873};
    2974
     75extern 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]
    3087
    3188extern unit_t *unit_create(unit_type_t);
     
    3592extern void unit_set_state(unit_t *, unit_state_t);
    3693
     94extern int unit_load(unit_t *, ini_configuration_t *, text_parse_t *);
    3795extern int unit_start(unit_t *);
    3896
     97extern unit_type_t unit_type_name_to_type(const char *);
     98
     99extern const char *unit_name(const unit_t *);
     100
     101extern bool unit_parse_unit_list(const char *, void *, text_parse_t *, size_t);
     102
    39103#endif
Note: See TracChangeset for help on using the changeset viewer.