]> git.ipfire.org Git - thirdparty/squid.git/blame - src/eCAP/XactionRep.cc
Merge from trunk
[thirdparty/squid.git] / src / eCAP / XactionRep.cc
CommitLineData
fdc96a39
AR
1#include "squid.h"
2#include <libecap/adapter/xaction.h>
3#include "TextException.h"
4#include "assert.h"
5#include "HttpRequest.h"
6#include "HttpReply.h"
7#include "eCAP/XactionRep.h"
8
9// CBDATA_CLASS_INIT(Ecap::XactionRep);
10// TODO: add CBDATA_NAMESPACED_CLASS_INIT(namespace, classname)
11cbdata_type Ecap::XactionRep::CBDATA_XactionRep = CBDATA_UNKNOWN;
12
13
14Ecap::XactionRep::XactionRep(Adaptation::Initiator *anInitiator,
15 HttpMsg *virginHeader, HttpRequest *virginCause,
16 const Adaptation::ServicePointer &aService):
17 AsyncJob("Ecap::XactionRep"),
18 Adaptation::Initiate("Ecap::XactionRep", anInitiator, aService),
19 theVirgin(virginHeader), theCause(virginCause),
20 theVirginTranslator(theVirgin), theCauseTranslator(theCause),
21 theAnswerTranslator(theAnswer)
22{
23}
24
25Ecap::XactionRep::~XactionRep()
26{
27 assert(!theMaster);
28}
29
30void
31Ecap::XactionRep::master(const AdapterXaction &x)
32{
33 Must(!theMaster);
34 Must(x != NULL);
35 theMaster = x;
36}
37
38void
39Ecap::XactionRep::start()
40{
41 Must(theMaster);
42 theMaster->start();
43}
44
45void
46Ecap::XactionRep::swangSong()
47{
48 terminateMaster();
49 Adaptation::Initiate::swanSong();
50}
51
52void
53Ecap::XactionRep::terminateMaster()
54{
55 if (theMaster) {
56 AdapterXaction x = theMaster;
57 theMaster.reset();
58 x->stop();
59 }
60}
61
62libecap::Message &
63Ecap::XactionRep::virginMessage()
64{
65 return theVirginTranslator;
66}
67
68libecap::Message &
69Ecap::XactionRep::virginCause()
70{
71 return theCauseTranslator;
72}
73
74void
75Ecap::XactionRep::useVirgin()
76{
77 theMaster.reset();
78 theVirgin.copyTo(theAnswer);
79 sendAnswer(theAnswer.header);
80}
81
82void
83Ecap::XactionRep::cloneVirgin()
84{
85 theVirgin.copyTo(theAnswer);
86}
87
88void
89Ecap::XactionRep::makeAdaptedRequest()
90{
91 theAnswer.set(new HttpRequest);
92}
93
94void
95Ecap::XactionRep::makeAdaptedResponse()
96{
97 theAnswer.set(new HttpReply);
98}
99
100libecap::Message &
101Ecap::XactionRep::adaptedMessage()
102{
103 return theAnswerTranslator;
104}
105
106void
107Ecap::XactionRep::useAdapted()
108{
109 theMaster.reset();
110 sendAnswer(theAnswer.header);
111}
112
113void
114Ecap::XactionRep::useNone()
115{
116 theMaster.reset();
117 tellQueryAborted(true); // should eCAP support retries?
118}
119
120void
121Ecap::XactionRep::noteMoreBodySpaceAvailable(RefCount<BodyPipe> bp)
122{
123 Must(theMaster);
124 theMaster->noteAdaptedSpaceAvailable();
125}
126
127void
128Ecap::XactionRep::noteBodyConsumerAborted(RefCount<BodyPipe> bp)
129{
130 Must(theMaster);
131 theMaster->noteAdaptedAborted();
132}
133
134void
135Ecap::XactionRep::noteMoreBodyDataAvailable(RefCount<BodyPipe> bp)
136{
137 Must(theMaster);
138 theMaster->noteVirginDataAvailable();
139}
140
141void
142Ecap::XactionRep::noteBodyProductionEnded(RefCount<BodyPipe> bp)
143{
144 Must(theMaster);
145 theMaster->noteVirginDataEnded();
146}
147
148void
149Ecap::XactionRep::noteBodyProducerAborted(RefCount<BodyPipe> bp)
150{
151 Must(theMaster);
152 theMaster->noteVirginAborted();
153}
154
155void
156Ecap::XactionRep::noteInitiatorAborted()
157{
158 mustStop("initiator aborted");
159}
160
161const char *Ecap::XactionRep::status() const
162{
163 return Adaptation::Initiate::status();
164}