]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/RunnersRegistry.h
1 #ifndef SQUID_BASE_RUNNERSREGISTRY_H
2 #define SQUID_BASE_RUNNERSREGISTRY_H
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.
9 * For example, main.cc may activate registered I/O modules after parsing
10 * squid.conf and deactivate them before exiting.
14 /// well-known registries (currently, deactivation is not performed for these)
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
20 /// a runnable registrant API
21 class RegisteredRunner
{
23 // called when this runner's registry is deactivated
24 virtual ~RegisteredRunner() {}
26 // called when this runner's registry is activated
27 virtual void run(const RunnerRegistry
&r
) = 0;
31 /// registers a given runner with the given registry and returns registry count
32 int RegisterRunner(const RunnerRegistry
®istry
, RegisteredRunner
*rr
);
34 /// calls run() methods of all runners in the given registry
35 int ActivateRegistered(const RunnerRegistry
®istry
);
36 /// deletes all runners in the given registry
37 void DeactivateRegistered(const RunnerRegistry
®istry
);
40 /// convenience function to "use" an otherwise unreferenced static variable
41 bool UseThisStatic(const void *);
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);
49 #endif /* SQUID_BASE_RUNNERSREGISTRY_H */