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