]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/XactionRep.h
SourceFormat: enforcement
[thirdparty/squid.git] / src / adaptation / ecap / XactionRep.h
1
2 /*
3 * $Id$
4 */
5
6 #ifndef SQUID_ECAP_XACTION_REP_H
7 #define SQUID_ECAP_XACTION_REP_H
8
9 #include "BodyPipe.h"
10 #include "adaptation/Initiate.h"
11 #include "adaptation/Message.h"
12 #include "adaptation/ecap/MessageRep.h"
13 #include "adaptation/ecap/ServiceRep.h"
14 #include <libecap/common/forward.h>
15 #include <libecap/common/memory.h>
16 #include <libecap/host/xaction.h>
17 #include <libecap/adapter/xaction.h>
18
19 namespace Adaptation
20 {
21 namespace Ecap
22 {
23
24 /* The eCAP xaction representative maintains information about a single eCAP
25 xaction that Squid communicates with. One eCAP module may register many
26 eCAP xactions. */
27 class XactionRep : public Adaptation::Initiate, public libecap::host::Xaction,
28 public BodyConsumer, public BodyProducer
29 {
30 public:
31 XactionRep(Adaptation::Initiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, const Adaptation::ServicePointer &service);
32 virtual ~XactionRep();
33
34 typedef libecap::shared_ptr<libecap::adapter::Xaction> AdapterXaction;
35 void master(const AdapterXaction &aMaster); // establish a link
36
37 // libecap::host::Xaction API
38 virtual libecap::Message &virgin();
39 virtual const libecap::Message &cause();
40 virtual libecap::Message &adapted();
41 virtual void useVirgin();
42 virtual void useAdapted(const libecap::shared_ptr<libecap::Message> &msg);
43 virtual void adaptationDelayed(const libecap::Delay &);
44 virtual void adaptationAborted();
45 virtual void vbDiscard();
46 virtual void vbMake();
47 virtual void vbStopMaking();
48 virtual void vbMakeMore();
49 virtual libecap::Area vbContent(libecap::size_type offset, libecap::size_type size);
50 virtual void vbContentShift(libecap::size_type size);
51 virtual void noteAbContentDone(bool atEnd);
52 virtual void noteAbContentAvailable();
53
54 // libecap::Callable API, via libecap::host::Xaction
55 virtual bool callable() const;
56
57 // BodyProducer API
58 virtual void noteMoreBodySpaceAvailable(RefCount<BodyPipe> bp);
59 virtual void noteBodyConsumerAborted(RefCount<BodyPipe> bp);
60
61 // BodyConsumer API
62 virtual void noteMoreBodyDataAvailable(RefCount<BodyPipe> bp);
63 virtual void noteBodyProductionEnded(RefCount<BodyPipe> bp);
64 virtual void noteBodyProducerAborted(RefCount<BodyPipe> bp);
65
66 // Initiate API
67 virtual void noteInitiatorAborted();
68
69 // AsyncJob API (via Initiate)
70 virtual void start();
71 virtual bool doneAll() const;
72 virtual void swanSong();
73 virtual const char *status() const;
74
75 protected:
76 Service &service();
77
78 Adaptation::Message &answer();
79
80 void dropVirgin(const char *reason);
81 void moveAbContent();
82
83 void terminateMaster();
84 void scheduleStop(const char *reason);
85
86 private:
87 AdapterXaction theMaster; // the actual adaptation xaction we represent
88 Adaptation::ServicePointer theService; ///< xaction's adaptation service
89
90 MessageRep theVirginRep;
91 MessageRep *theCauseRep;
92
93 typedef libecap::shared_ptr<libecap::Message> MessagePtr;
94 MessagePtr theAnswerRep;
95
96 typedef enum { opUndecided, opOn, opComplete, opNever } OperationState;
97 OperationState proxyingVb; // delivering virgin body from core to adapter
98 OperationState proxyingAb; // delivering adapted body from adapter to core
99 int adaptHistoryId; ///< adaptation history slot reservation
100 bool canAccessVb; // virgin BodyPipe content is accessible
101 bool abProductionFinished; // whether adapter has finished producing ab
102 bool abProductionAtEnd; // whether adapter produced a complete ab
103
104 CBDATA_CLASS2(XactionRep);
105 };
106
107 } // namespace Ecap
108 } // namespace Adaptation
109
110 #endif /* SQUID_ECAP_XACTION_REP_H */