]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Iterator.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / adaptation / Iterator.h
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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
9 #ifndef SQUID_ADAPTATION__ITERATOR_H
10 #define SQUID_ADAPTATION__ITERATOR_H
11
12 #include "AccessLogEntry.h"
13 #include "adaptation/Initiate.h"
14 #include "adaptation/Initiator.h"
15 #include "adaptation/ServiceGroups.h"
16 #include "http/forward.h"
17
18 namespace Adaptation
19 {
20
21 /* Iterator is started by client or server Initiators. It iterates services
22 in a given group, starting transaction launcher for each service, according
23 to the service plan. Service plans support adaptation sets and chains.
24
25 Note: Initiate must be the first parent for cbdata to work. We use
26 a temporary InitiatorHolder/toCbdata hacks and do not call cbdata
27 operations on the initiator directly.
28 */
29
30 /// iterates services in ServiceGroup, starting adaptation launchers
31 class Iterator: public Initiate, public Initiator
32 {
33 CBDATA_CLASS(Iterator);
34
35 public:
36 Iterator(Http::Message *virginHeader, HttpRequest *virginCause,
37 AccessLogEntry::Pointer &alp,
38 const Adaptation::ServiceGroupPointer &aGroup);
39 virtual ~Iterator();
40
41 // Adaptation::Initiate: asynchronous communication with the initiator
42 void noteInitiatorAborted();
43
44 // Adaptation::Initiator: asynchronous communication with the current launcher
45 virtual void noteAdaptationAnswer(const Answer &answer);
46
47 protected:
48 // Adaptation::Initiate API implementation
49 virtual void start();
50 virtual bool doneAll() const;
51 virtual void swanSong();
52
53 /// launches adaptation for the service selected by the plan
54 void step();
55
56 /// replace the current group and plan with service-proposed ones if needed
57 bool updatePlan(bool adopt); // returns true iff the plan was replaced
58
59 /// creates service filter for the current step
60 ServiceFilter filter() const;
61
62 void handleAdaptedHeader(Http::Message *msg);
63 void handleAdaptationBlock(const Answer &answer);
64 void handleAdaptationError(bool final);
65
66 ServiceGroupPointer theGroup; ///< the service group we are iterating
67 ServicePlan thePlan; ///< which services to use and in what order
68 Http::Message *theMsg; ///< the message being adapted (virgin for each step)
69 HttpRequest *theCause; ///< the cause of the original virgin message
70 AccessLogEntry::Pointer al; ///< info for the future access.log entry
71 CbcPointer<Adaptation::Initiate> theLauncher; ///< current transaction launcher
72 int iterations; ///< number of steps initiated
73 bool adapted; ///< whether the virgin message has been replaced
74 };
75
76 } // namespace Adaptation
77
78 #endif /* SQUID_ADAPTATION__ITERATOR_H */
79