summaryrefslogtreecommitdiff
path: root/src/server/state.h
blob: a6b82f66ecdfe8759e482c8e920fc6970044da36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ISC license. */

#ifndef S6RCD_STATE_H
#define S6RCD_STATE_H

#include <stdint.h>

#include <skalibs/genalloc.h>

#include "db.h"

 /* Service states, instances, machine state */

#define SSTATE_TRANSITIONING 0x01u
#define SSTATE_FAILED 0x02u
#define SSTATE_CURRENT 0x04u
#define SSTATE_WANTED 0x08u
#define SSTATE_EXPLICIT 0x10u
#define SSTATE_INVALID 0x80u

typedef struct sstate_s sstate_t, *sstate_t_ref ;
struct sstate_s
{
  uint8_t bits ;  /* the real state, saved to the fs */
  uint8_t tmp ;  /* bits used for computations e.g. recursive dep walks */
}
#define SSTATE_ZERO { .bits = 0, .tmp = 0 }

typedef struct instance_s instance_t, *instance_t_ref ;
struct instance_s
{
  char const *param ;  /* refcounted pointer to dynstorage */
  sstate_t sstate ;
} ;

typedef struct mstate_s mstate_t, *mstate_t_ref ;
struct mstate_s
{
  sstate_t *sta[S6RC_STYPE_N] ;
  genalloc *dyn[S6RC_STYPE_N] ;  /* every genalloc is a list of instance_t */
} ;

typedef int sstate_func (sstate_t *, void *) ;
typedef sstate_func *sstate_func_ref ;
typedef int instancelen_func (uint32_t, void *) ;
typedef instancelen_func *instancelen_func_ref ;
typedef instance_func (instance_t *, void *) ;
typedef instance_func *instance_func_ref ;

extern instancelen_func_ref const instancelen_nop ;

extern sstate_t *instance_create (mstate_t *, uint32_t, char const *) ;
extern void instance_remove (mstate_t *, uint32_t, char const *) ;

extern void mstate_free (mstate_t *, uint32_t const *) ;
extern int mstate_init (mstate_t *, uint32_t const *) ;

extern int mstate_write (char const *, mstate_t const *, uint32_t const *) ;
extern int mstate_read (char const *, mstate_t *, uint32_t const *) ; /* also inits */

extern int mstate_iterate (mstate_t *, uint32_t const *, sstate_func_ref, instancelen_func_ref, instance_func_ref, void *) ;
extern void mstate_zerotmp (mstate_t *, uint32_t const *) ;

extern sstate_t *sstate_tn (mstate_t *, uint8_t, uint32_t, char const *) ;
extern sstate_t *sstate (uint32_t const *, mstate_t *, uint32_t, char const *) ;

#endif