1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
5 #include "load-fragment.h"
8 static const UnitActiveState state_translation_table
[_TARGET_STATE_MAX
] = {
9 [TARGET_DEAD
] = UNIT_INACTIVE
,
10 [TARGET_ACTIVE
] = UNIT_ACTIVE
13 static const char* const state_string_table
[_TARGET_STATE_MAX
] = {
14 [TARGET_DEAD
] = "dead",
15 [TARGET_ACTIVE
] = "active"
18 static void target_dump(Unit
*u
, FILE *f
, const char *prefix
) {
19 Target
*t
= TARGET(u
);
25 "%sTarget State: %s\n",
26 prefix
, state_string_table
[t
->state
]);
29 static void target_set_state(Target
*t
, TargetState state
) {
30 TargetState old_state
;
36 log_debug("%s changing %s → %s", unit_id(UNIT(t
)), state_string_table
[old_state
], state_string_table
[state
]);
38 unit_notify(UNIT(t
), state_translation_table
[old_state
], state_translation_table
[state
]);
41 static int target_start(Unit
*u
) {
42 Target
*t
= TARGET(u
);
45 assert(t
->state
== TARGET_DEAD
);
47 target_set_state(t
, TARGET_ACTIVE
);
51 static int target_stop(Unit
*u
) {
52 Target
*t
= TARGET(u
);
55 assert(t
->state
== TARGET_ACTIVE
);
57 target_set_state(t
, TARGET_DEAD
);
61 static UnitActiveState
target_active_state(Unit
*u
) {
64 return state_translation_table
[TARGET(u
)->state
];
67 const UnitVTable target_vtable
= {
70 .init
= unit_load_fragment_and_dropin
,
74 .start
= target_start
,
77 .active_state
= target_active_state