]>
Commit | Line | Data |
---|---|---|
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) | |
11 | cbdata_type Ecap::XactionRep::CBDATA_XactionRep = CBDATA_UNKNOWN; | |
12 | ||
13 | ||
14 | Ecap::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), | |
027320b4 AR |
20 | theVirginRep(theVirgin, NULL), theCauseRep(NULL), |
21 | theAnswerRep(NULL) | |
fdc96a39 | 22 | { |
027320b4 AR |
23 | if (virginCause) |
24 | theCauseRep = new MessageRep(theCause, NULL); | |
fdc96a39 AR |
25 | } |
26 | ||
27 | Ecap::XactionRep::~XactionRep() | |
28 | { | |
29 | assert(!theMaster); | |
027320b4 AR |
30 | delete theCauseRep; |
31 | delete theAnswerRep; | |
fdc96a39 AR |
32 | } |
33 | ||
34 | void | |
35 | Ecap::XactionRep::master(const AdapterXaction &x) | |
36 | { | |
37 | Must(!theMaster); | |
38 | Must(x != NULL); | |
39 | theMaster = x; | |
40 | } | |
41 | ||
42 | void | |
43 | Ecap::XactionRep::start() | |
44 | { | |
45 | Must(theMaster); | |
46 | theMaster->start(); | |
47 | } | |
48 | ||
49 | void | |
50 | Ecap::XactionRep::swangSong() | |
51 | { | |
52 | terminateMaster(); | |
53 | Adaptation::Initiate::swanSong(); | |
54 | } | |
55 | ||
56 | void | |
57 | Ecap::XactionRep::terminateMaster() | |
58 | { | |
59 | if (theMaster) { | |
60 | AdapterXaction x = theMaster; | |
61 | theMaster.reset(); | |
62 | x->stop(); | |
63 | } | |
64 | } | |
65 | ||
66 | libecap::Message & | |
027320b4 | 67 | Ecap::XactionRep::virgin() |
fdc96a39 | 68 | { |
7b67e5b6 | 69 | return theVirginRep; |
fdc96a39 AR |
70 | } |
71 | ||
027320b4 AR |
72 | const libecap::Message * |
73 | Ecap::XactionRep::cause() | |
fdc96a39 | 74 | { |
7b67e5b6 | 75 | return theCauseRep; |
fdc96a39 AR |
76 | } |
77 | ||
78 | void | |
79 | Ecap::XactionRep::useVirgin() | |
80 | { | |
81 | theMaster.reset(); | |
027320b4 AR |
82 | Adaptation::Message::ShortCircuit(theVirgin, theAnswer); |
83 | Must(!theVirgin.body_pipe == !theAnswer.body_pipe); | |
fdc96a39 AR |
84 | sendAnswer(theAnswer.header); |
85 | } | |
86 | ||
87 | void | |
027320b4 | 88 | Ecap::XactionRep::adaptVirgin() |
fdc96a39 | 89 | { |
027320b4 AR |
90 | // XXX: check state everywhere |
91 | Must(!theAnswerRep); | |
92 | Must(!theAnswer.header); | |
93 | Must(!theAnswer.body_pipe); | |
94 | theAnswer.set(theVirgin.header->clone()); | |
95 | theAnswerRep = new MessageRep(theAnswer, this); | |
96 | Must(!theAnswer.body_pipe); | |
fdc96a39 AR |
97 | } |
98 | ||
99 | void | |
027320b4 | 100 | Ecap::XactionRep::adaptNewRequest() |
fdc96a39 AR |
101 | { |
102 | theAnswer.set(new HttpRequest); | |
027320b4 | 103 | theAnswerRep = new MessageRep(theAnswer, this); |
fdc96a39 AR |
104 | } |
105 | ||
106 | void | |
027320b4 | 107 | Ecap::XactionRep::adaptNewResponse() |
fdc96a39 AR |
108 | { |
109 | theAnswer.set(new HttpReply); | |
027320b4 | 110 | theAnswerRep = new MessageRep(theAnswer, this); |
fdc96a39 AR |
111 | } |
112 | ||
027320b4 AR |
113 | libecap::Message * |
114 | Ecap::XactionRep::adapted() | |
fdc96a39 | 115 | { |
7b67e5b6 | 116 | return theAnswerRep; |
fdc96a39 AR |
117 | } |
118 | ||
119 | void | |
120 | Ecap::XactionRep::useAdapted() | |
121 | { | |
122 | theMaster.reset(); | |
123 | sendAnswer(theAnswer.header); | |
124 | } | |
125 | ||
126 | void | |
127 | Ecap::XactionRep::useNone() | |
128 | { | |
129 | theMaster.reset(); | |
130 | tellQueryAborted(true); // should eCAP support retries? | |
131 | } | |
132 | ||
133 | void | |
134 | Ecap::XactionRep::noteMoreBodySpaceAvailable(RefCount<BodyPipe> bp) | |
135 | { | |
136 | Must(theMaster); | |
137 | theMaster->noteAdaptedSpaceAvailable(); | |
138 | } | |
139 | ||
140 | void | |
141 | Ecap::XactionRep::noteBodyConsumerAborted(RefCount<BodyPipe> bp) | |
142 | { | |
143 | Must(theMaster); | |
144 | theMaster->noteAdaptedAborted(); | |
145 | } | |
146 | ||
147 | void | |
148 | Ecap::XactionRep::noteMoreBodyDataAvailable(RefCount<BodyPipe> bp) | |
149 | { | |
150 | Must(theMaster); | |
151 | theMaster->noteVirginDataAvailable(); | |
152 | } | |
153 | ||
154 | void | |
155 | Ecap::XactionRep::noteBodyProductionEnded(RefCount<BodyPipe> bp) | |
156 | { | |
157 | Must(theMaster); | |
158 | theMaster->noteVirginDataEnded(); | |
159 | } | |
160 | ||
161 | void | |
162 | Ecap::XactionRep::noteBodyProducerAborted(RefCount<BodyPipe> bp) | |
163 | { | |
164 | Must(theMaster); | |
165 | theMaster->noteVirginAborted(); | |
166 | } | |
167 | ||
168 | void | |
169 | Ecap::XactionRep::noteInitiatorAborted() | |
170 | { | |
171 | mustStop("initiator aborted"); | |
172 | } | |
173 | ||
174 | const char *Ecap::XactionRep::status() const | |
175 | { | |
176 | return Adaptation::Initiate::status(); | |
177 | } |