Debian Codegraph @

src/broker/broker.h

raw
1 #pragma once
2
3 /*
4 * Broker
5 */
6
7 #include <c-stdaux.h>
8 #include <stdlib.h>
9 #include "broker/controller.h"
10 #include "bus/bus.h"
11 #include "util/dispatch.h"
12 #include "util/log.h"
13
14 enum {
15 _BROKER_E_SUCCESS,
16
17 BROKER_E_FORWARD_FAILED,
18 };
19
20 typedef struct Broker Broker;
21 typedef struct User User;
22
23 struct Broker {
24 Log *log;
25 Bus bus;
26 DispatchContext dispatcher;
27
28 int signals_fd;
29 DispatchFile signals_file;
30
31 Controller controller;
32 };
33
34 /* broker */
35
36 int broker_new(Broker **brokerp, Log *log, const char *machine_id, int controller_fd, uint64_t max_bytes, uint64_t max_fds, uint64_t max_matches, uint64_t max_objects);
37 Broker *broker_free(Broker *broker);
38
39 int broker_run(Broker *broker);
40 int broker_update_environment(Broker *broker, const char * const *env, size_t n_env);
41 int broker_reload_config(Broker *broker, User *sender_user, uint64_t sender_id, uint32_t sender_serial);
42
43 C_DEFINE_CLEANUP(Broker *, broker_free);
44
45 /* inline helpers */
46
47 static inline Broker *BROKER(Bus *bus) {
48 /*
49 * This function up-casts a Bus to its parent class Broker. In our code
50 * base we pretend a Bus is an abstract class with several virtual
51 * methods. However, we only do this to clearly separate our code
52 * bases. We never intended this to be modular. Hence, instead of
53 * providing real vtables with userdata pointers, we instead allow
54 * explicit up-casts to the parent type.
55 *
56 * This function performs the up-cast, relying on the fact that all our
57 * Bus objects are always owned by a Broker object.
58 */
59 return c_container_of(bus, Broker, bus);
60 }