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