source: mainline/uspace/srv/sysman/unit.h@ 25a9fec

Last change on this file since 25a9fec was 9532981, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

sysman: Rename dependency to edge (more generic)

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2015 Michal Koutny
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * Unit terminology and OOP based on systemd.
31 */
32#ifndef SYSMAN_UNIT_H
33#define SYSMAN_UNIT_H
34
35#include <adt/hash_table.h>
36#include <adt/list.h>
37#include <conf/configuration.h>
38#include <conf/ini.h>
39#include <conf/text_parse.h>
40#include <fibril_synch.h>
41#include <ipc/sysman.h>
42
43/* Forward declarations */
44typedef struct unit_vmt unit_vmt_t;
45struct unit_vmt;
46
47typedef struct job job_t;
48struct job;
49
50typedef struct {
51 /** Link to name-to-unit hash table */
52 ht_link_t units_by_name;
53
54 /** Link to handle-to-unit hash table */
55 ht_link_t units_by_handle;
56
57 /** Link to list of all units */
58 link_t units;
59
60 /** Link to queue, when BFS traversing units */
61 link_t bfs_link;
62
63 /** Auxiliary job created during BFS traverse, its presence serves also
64 * as BFS tag */
65 job_t *bfs_job;
66
67 /** Job assigned to unit in transitional state */
68 job_t *job;
69
70 unit_handle_t handle;
71 unit_type_t type;
72 char *name;
73
74 unit_state_t state;
75
76 list_t edges_in;
77 list_t edges_out;
78} unit_t;
79
80#include "unit_cfg.h"
81#include "unit_mnt.h"
82#include "unit_tgt.h"
83#include "unit_svc.h"
84
85#define DEFINE_CAST(NAME, TYPE, ENUM_TYPE) \
86 static inline TYPE *CAST_##NAME(unit_t *u) \
87 { \
88 if (u->type == ENUM_TYPE) \
89 return (TYPE *)u; \
90 else \
91 return NULL; \
92 } \
93
94DEFINE_CAST(CFG, unit_cfg_t, UNIT_CONFIGURATION)
95DEFINE_CAST(MNT, unit_mnt_t, UNIT_MOUNT)
96DEFINE_CAST(TGT, unit_tgt_t, UNIT_TARGET)
97DEFINE_CAST(SVC, unit_svc_t, UNIT_SERVICE)
98
99struct unit_vmt {
100 size_t size;
101
102 void (*init)(unit_t *);
103
104 void (*destroy)(unit_t *);
105
106 int (*load)(unit_t *, ini_configuration_t *, text_parse_t *);
107
108 int (*start)(unit_t *);
109
110 void (*exposee_created)(unit_t *);
111
112 void (*fail)(unit_t *);
113};
114
115extern unit_vmt_t *unit_type_vmts[];
116
117#define DEFINE_UNIT_VMT(PREFIX) \
118 unit_vmt_t PREFIX##_vmt = { \
119 .size = sizeof(PREFIX##_t), \
120 .init = &PREFIX##_init, \
121 .load = &PREFIX##_load, \
122 .destroy = &PREFIX##_destroy, \
123 .start = &PREFIX##_start, \
124 .exposee_created = &PREFIX##_exposee_created, \
125 .fail = &PREFIX##_fail \
126 };
127
128#define UNIT_VMT(UNIT) unit_type_vmts[(UNIT)->type]
129
130extern unit_t *unit_create(unit_type_t);
131extern void unit_destroy(unit_t **);
132
133extern int unit_load(unit_t *, ini_configuration_t *, text_parse_t *);
134extern int unit_start(unit_t *);
135extern void unit_exposee_created(unit_t *);
136extern void unit_fail(unit_t *);
137
138extern void unit_notify_state(unit_t *);
139
140extern unit_type_t unit_type_name_to_type(const char *);
141
142extern const char *unit_name(const unit_t *);
143
144extern bool unit_parse_unit_list(const char *, void *, text_parse_t *, size_t);
145
146#endif
Note: See TracBrowser for help on using the repository browser.