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