source: mainline/uspace/srv/sysman/unit.h@ aa0faeca

Last change on this file since aa0faeca was aa0faeca, checked in by Matthieu Riolo <matthieu.riolo@…>, 5 years ago

Adding "ConditionArchitecture" to sysman's unit

the services s3c24xx_uart and s3c24xx_ts are specific for
arm32. This newly flag allows sysman to ignore those units
when they are asked to be loaded

  • Property mode set to 100644
File size: 5.3 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
50/* Represents presence of unit in repo during modifications */
51typedef enum {
52 REPO_EMBRYO,
53 REPO_LIVING,
54 REPO_ZOMBIE
55} repo_state_t;
56
57typedef enum {
58 UNIT_CONDITION_NONE = 0,
59 UNIT_CONDITION_ARCHITECTURE = 1
60} unit_condition_t;
61
62typedef struct {
63 /** Link to name-to-unit hash table */
64 ht_link_t units_by_name;
65
66 /** Link to handle-to-unit hash table */
67 ht_link_t units_by_handle;
68
69 /** Link to list of all units */
70 link_t units;
71
72 /** Link to queue, when BFS traversing units */
73 link_t bfs_link;
74
75 /** Mark during BFS traversal unit is already queued */
76 bool bfs_tag;
77
78 /** Auxiliary data for BFS traverse users .*/
79 void *bfs_data;
80
81 /** Job assigned to unit in transitional state */
82 job_t *job;
83
84 /** Handle for IPC (immutable) */
85 unit_handle_t handle;
86
87 /** Unit type (immutable) */
88 unit_type_t type;
89
90 /** Unit name (immutable) */
91 char *name;
92
93 unit_state_t state;
94
95 repo_state_t repo_state;
96
97 list_t edges_in;
98 list_t edges_out;
99
100 /**
101 * flag for conditions which were not meet
102 * determines if the unit should be started
103 */
104 unit_condition_t conditions;
105} unit_t;
106
107#include "unit_cfg.h"
108#include "unit_mnt.h"
109#include "unit_tgt.h"
110#include "unit_svc.h"
111
112#define DEFINE_CAST(NAME, TYPE, ENUM_TYPE) \
113 static inline TYPE *CAST_##NAME(unit_t *u) \
114 { \
115 if (u->type == ENUM_TYPE) \
116 return (TYPE *)u; \
117 else \
118 return NULL; \
119 }
120
121DEFINE_CAST(CFG, unit_cfg_t, UNIT_CONFIGURATION);
122DEFINE_CAST(MNT, unit_mnt_t, UNIT_MOUNT);
123DEFINE_CAST(TGT, unit_tgt_t, UNIT_TARGET);
124DEFINE_CAST(SVC, unit_svc_t, UNIT_SERVICE);
125
126struct unit_vmt {
127 size_t size;
128
129 void (*init)(unit_t *);
130
131 void (*destroy)(unit_t *);
132
133 errno_t (*load)(unit_t *, ini_configuration_t *, text_parse_t *);
134
135 errno_t (*start)(unit_t *);
136
137 errno_t (*stop)(unit_t *);
138
139 void (*exposee_created)(unit_t *);
140
141 void (*fail)(unit_t *);
142};
143
144extern unit_vmt_t *unit_type_vmts[];
145
146#define DEFINE_UNIT_VMT(PREFIX) \
147 unit_vmt_t PREFIX##_vmt = { \
148 .size = sizeof(PREFIX##_t), \
149 .init = &PREFIX##_init, \
150 .load = &PREFIX##_load, \
151 .destroy = &PREFIX##_destroy, \
152 .start = &PREFIX##_start, \
153 .stop = &PREFIX##_stop, \
154 .exposee_created = &PREFIX##_exposee_created, \
155 .fail = &PREFIX##_fail \
156 };
157
158#define UNIT_VMT(UNIT) unit_type_vmts[(UNIT)->type]
159
160extern unit_t *unit_create(unit_type_t);
161extern void unit_destroy(unit_t **);
162
163extern errno_t unit_load(unit_t *, ini_configuration_t *, text_parse_t *);
164extern errno_t unit_start(unit_t *);
165extern errno_t unit_stop(unit_t *);
166extern void unit_exposee_created(unit_t *);
167extern void unit_fail(unit_t *);
168
169extern void unit_notify_state(unit_t *);
170
171extern unit_type_t unit_type_name_to_type(const char *);
172
173extern const char *unit_name(const unit_t *);
174extern void unit_log_condition(unit_t *unit);
175
176extern bool unit_parse_unit_list(const char *, void *, text_parse_t *, size_t);
177extern bool unit_parse_condition_architecture(const char *, void *, text_parse_t *, size_t);
178
179#endif
Note: See TracBrowser for help on using the repository browser.