]> git.ipfire.org Git - thirdparty/squid.git/blob - src/base/RunnersRegistry.h
Added RunnersRegistry, an API to register and, later, run a group of actions.
[thirdparty/squid.git] / src / base / RunnersRegistry.h
1 #ifndef SQUID_BASE_RUNNERSREGISTRY_H
2 #define SQUID_BASE_RUNNERSREGISTRY_H
3
4 /**
5 * This API allows different modules to register with a well-known registry,
6 * be activated by some central processor at some registry-specific time, and
7 * be deactiveated by some central processor at some registry-specific time.
8 *
9 * For example, main.cc may activate registered I/O modules after parsing
10 * squid.conf and deactivate them before exiting.
11 *
12 */
13
14 /// well-known registries (currently, deactivation is not performed for these)
15 typedef enum {
16 rrAfterConfig, ///< activated by main.cc after parsing squid.conf
17 rrEnd ///< not a real registry, just a label to mark the end of enum
18 } RunnerRegistry;
19
20 /// a runnable registrant API
21 class RegisteredRunner {
22 public:
23 // called when this runner's registry is deactivated
24 virtual ~RegisteredRunner() {}
25
26 // called when this runner's registry is activated
27 virtual void run(const RunnerRegistry &r) = 0;
28 };
29
30
31 /// registers a given runner with the given registry and returns registry count
32 int RegisterRunner(const RunnerRegistry &registry, RegisteredRunner *rr);
33
34 /// calls run() methods of all runners in the given registry
35 int ActivateRegistered(const RunnerRegistry &registry);
36 /// deletes all runners in the given registry
37 void DeactivateRegistered(const RunnerRegistry &registry);
38
39
40 /// convenience function to "use" an otherwise unreferenced static variable
41 bool UseThisStatic(const void *);
42
43 /// convenience macro: register one RegisteredRunner kid as early as possible
44 #define RunnerRegistrationEntry(Registry, Who) \
45 static const bool Who ## _RegisteredWith_ ## Registry = \
46 RegisterRunner(Registry, new Who) > 0 && \
47 UseThisStatic(& Who ## _RegisteredWith_ ## Registry);
48
49 #endif /* SQUID_BASE_RUNNERSREGISTRY_H */