AsyncJob("Ecap::XactionRep"),
Adaptation::Initiate("Ecap::XactionRep", anInitiator, aService),
theVirgin(virginHeader), theCause(virginCause),
- theVirginRep(theVirgin), theCauseRep(theCause),
- theAnswerRep(theAnswer)
+ theVirginRep(theVirgin, NULL), theCauseRep(NULL),
+ theAnswerRep(NULL)
{
+ if (virginCause)
+ theCauseRep = new MessageRep(theCause, NULL);
}
Ecap::XactionRep::~XactionRep()
{
assert(!theMaster);
+ delete theCauseRep;
+ delete theAnswerRep;
}
void
}
libecap::Message &
-Ecap::XactionRep::virginMessage()
+Ecap::XactionRep::virgin()
{
return theVirginRep;
}
-libecap::Message &
-Ecap::XactionRep::virginCause()
+const libecap::Message *
+Ecap::XactionRep::cause()
{
return theCauseRep;
}
Ecap::XactionRep::useVirgin()
{
theMaster.reset();
- theVirgin.copyTo(theAnswer);
+ Adaptation::Message::ShortCircuit(theVirgin, theAnswer);
+ Must(!theVirgin.body_pipe == !theAnswer.body_pipe);
sendAnswer(theAnswer.header);
}
void
-Ecap::XactionRep::cloneVirgin()
+Ecap::XactionRep::adaptVirgin()
{
- theVirgin.copyTo(theAnswer);
+ // XXX: check state everywhere
+ Must(!theAnswerRep);
+ Must(!theAnswer.header);
+ Must(!theAnswer.body_pipe);
+ theAnswer.set(theVirgin.header->clone());
+ theAnswerRep = new MessageRep(theAnswer, this);
+ Must(!theAnswer.body_pipe);
}
void
-Ecap::XactionRep::makeAdaptedRequest()
+Ecap::XactionRep::adaptNewRequest()
{
theAnswer.set(new HttpRequest);
+ theAnswerRep = new MessageRep(theAnswer, this);
}
void
-Ecap::XactionRep::makeAdaptedResponse()
+Ecap::XactionRep::adaptNewResponse()
{
theAnswer.set(new HttpReply);
+ theAnswerRep = new MessageRep(theAnswer, this);
}
-libecap::Message &
-Ecap::XactionRep::adaptedMessage()
+libecap::Message *
+Ecap::XactionRep::adapted()
{
return theAnswerRep;
}
void master(const AdapterXaction &aMaster); // establish a link
// libecap::host::Xaction API
- virtual libecap::Message &virginMessage() ; // request or response
- virtual libecap::Message &virginCause() ; // request for the above response
- virtual void useVirgin() ; // final answer: no adaptation
- virtual void cloneVirgin() ; // adapted message starts as virgin
- virtual void makeAdaptedRequest() ; // make fresh adapted request
- virtual void makeAdaptedResponse() ; // make fresh adapted response
- virtual libecap::Message &adaptedMessage() ; // request or response
- virtual void useAdapted() ; // final answer: adapted msg is ready
- virtual void useNone() ; // final answer: no answer
+ virtual libecap::Message &virgin(); // request or response
+ virtual const libecap::Message *cause(); // request for the above response
+ virtual void useVirgin(); // final answer: no adaptation
+ virtual void adaptVirgin(); // adapted message starts as virgin
+ virtual void adaptNewRequest(); // make fresh adapted request
+ virtual void adaptNewResponse(); // make fresh adapted response
+ virtual libecap::Message *adapted(); // request or response
+ virtual void useAdapted(); // final answer: adapted msg is ready
+ virtual void useNone(); // final answer: no answer
// BodyProducer API
virtual void noteMoreBodySpaceAvailable(RefCount<BodyPipe> bp);
Adaptation::Message theCause;
Adaptation::Message theAnswer;
MessageRep theVirginRep;
- MessageRep theCauseRep;
- MessageRep theAnswerRep;
+ MessageRep *theCauseRep;
+ MessageRep *theAnswerRep;
CBDATA_CLASS2(XactionRep);
};