]> git.ipfire.org Git - thirdparty/squid.git/blame - src/base/RunnersRegistry.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / base / RunnersRegistry.h
CommitLineData
bbc27441 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
bbc27441
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
61f3a07b
AR
9#ifndef SQUID_BASE_RUNNERSREGISTRY_H
10#define SQUID_BASE_RUNNERSREGISTRY_H
11
12/**
21b7990f
AR
13 * This API allows virtually any module to register its interest in receiving
14 * notification about initial configuration availability, configuration changes
15 * and other critical events in Squid lifetime without exposing the notifier
16 * to the details of the module.
61f3a07b
AR
17 *
18 * For example, main.cc may activate registered I/O modules after parsing
21b7990f
AR
19 * squid.conf and deactivate them before exiting, all without knowing what
20 * those I/O modules really are.
61f3a07b
AR
21 *
22 * A module in this context is code providing a functionality or service to the
21b7990f
AR
23 * rest of Squid, such as src/DiskIO/Blocking, src/fs/ufs, or Cache Manager. To
24 * receive notifications, a module must declare a RegisteredRunner child class
25 * and implement the methods corresponding to the events the module is
26 * interested in.
61f3a07b 27 *
21b7990f
AR
28 * The order of events is documented in this header (where applicable), but
29 * the order in which runners are notified about a given event is undefined.
30 * If a specific notification order is required, split the event into two or
31 * more related event(s), documenting their relative order here.
61f3a07b
AR
32 *
33 */
34
21b7990f
AR
35/// a runnable registrant API
36/// kids must override [only] the methods they are interested in
37class RegisteredRunner
38{
39public:
40 /* Related methods below are declared in their calling order */
41
42 /* Configuration events */
43
44 /// Called after parsing squid.conf.
45e8762c
AR
45 /// Meant for setting configuration options that depend on other
46 /// configuration options and were not explicitly configured.
21b7990f 47 virtual void finalizeConfig() {}
45e8762c 48
21b7990f
AR
49 /// Called after finalizeConfig().
50 /// Meant for announcing memory reservations before memory is allocated.
51 virtual void claimMemoryNeeds() {}
ea2cdeb6 52
21b7990f
AR
53 /// Called after claimMemoryNeeds().
54 /// Meant for activating modules and features using a finalized
55 /// configuration with known memory requirements.
56 virtual void useConfig() {}
61f3a07b 57
21b7990f 58 /* Reconfiguration events */
61f3a07b 59
21b7990f
AR
60 /// Called after parsing squid.conf during reconfiguration.
61 /// Meant for adjusting the module state based on configuration changes.
62 virtual void syncConfig() {}
63
64 /* Shutdown events */
65
66 /// Called after receiving a shutdown request and before stopping the main
67 /// loop. At least one main loop iteration is guaranteed after this call.
68 /// Meant for cleanup and state saving that may require other modules.
69 virtual void startShutdown() {}
70
553d498c 71 /// Called after stopping the main loop and before releasing memory.
21b7990f 72 /// Meant for quick/basic cleanup that does not require any other modules.
61f3a07b 73 virtual ~RegisteredRunner() {}
21b7990f
AR
74 /// exists to simplify caller interface; override the destructor instead
75 void finishShutdown() { delete this; }
76
77 /// a pointer to one of the above notification methods
78 typedef void (RegisteredRunner::*Method)();
61f3a07b 79
61f3a07b
AR
80};
81
61f3a07b 82/// registers a given runner with the given registry and returns registry count
21b7990f
AR
83int RegisterRunner(RegisteredRunner *rr);
84
85/// Calls a given method of all runners.
86/// All runners are destroyed after the finishShutdown() call.
87void RunRegistered(const RegisteredRunner::Method &m);
61f3a07b 88
21b7990f
AR
89/// convenience macro to describe/debug the caller and the method being called
90#define RunRegisteredHere(m) \
91 debugs(1, 2, "running " # m); \
92 RunRegistered(&m)
61f3a07b 93
61f3a07b
AR
94/// convenience function to "use" an otherwise unreferenced static variable
95bool UseThisStatic(const void *);
96
97/// convenience macro: register one RegisteredRunner kid as early as possible
21b7990f
AR
98#define RunnerRegistrationEntry(Who) \
99 static const bool Who ## _Registered_ = \
100 RegisterRunner(new Who) > 0 && \
101 UseThisStatic(& Who ## _Registered_);
61f3a07b
AR
102
103#endif /* SQUID_BASE_RUNNERSREGISTRY_H */
f53969cc 104