summaryrefslogtreecommitdiff
path: root/main.h
blob: a3b5512d3a298db225e960f0bdabfe76252590ac (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
#ifndef foomainhfoo
#define foomainhfoo

#include <sys/socket.h>
#include <netinet/ip.h>
#include "utils.h"

extern bool exiting;

extern int debuglvl;

void debug(unsigned lvl, const char *fmt, ...);

#define info(...) fprintf(stderr, __VA_ARGS__)
#define error(...) fprintf(stderr, __VA_ARGS__)

void die(const char *fmt, ...);

#define perrordie(msg) die("%s: %m\n", msg)

struct cfg;

struct uring_task;

/* To save typing in all the function definitions below */
typedef void (*callback_t)(struct cfg *, struct uring_task *, int res);
typedef int (*rcallback_t)(struct cfg *, struct uring_task *, int res);

struct uring_task_buf {
	char buf[4096];
	size_t len;
	size_t done;
};

struct uring_task {
	const char *name;
        unsigned refcount;
	int fd;
        void *parent;
        void (*free)(struct uring_task *);
	bool dead;
	struct uring_task_buf *tbuf;
        callback_t callback;
        rcallback_t complete_callback; /* to check if tbuf processing is done */
        callback_t final_callback; /* once tbuf processing is done */
};

struct cfg {
	const char *homedir;
	struct uring_ev *uev;
	struct inotify_ev *iev;
	struct signalfd_ev *sev;
	struct announce *aev;
	struct sd_bus *sd_bus;
	bool sd_bus_failed;
	struct uring_task task;
	struct list_head servers;
};

#endif