Initiate.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 93 ICAP (RFC 3507) Client */
10
11#include "squid.h"
12#include "adaptation/Answer.h"
13#include "adaptation/Initiate.h"
15#include "base/AsyncJobCalls.h"
16#include "http/Message.h"
17
18namespace Adaptation
19{
23class AnswerCall: public AsyncCallT<AnswerDialer>
24{
25public:
26 AnswerCall(const char *aName, const AnswerDialer &aDialer) :
27 AsyncCallT<AnswerDialer>(93, 5, aName, aDialer), fired(false) {}
28 void fire() override {
29 fired = true;
31 }
32 ~AnswerCall() override {
33 if (!fired && dialer.arg1.message != nullptr && dialer.arg1.message->body_pipe != nullptr)
34 dialer.arg1.message->body_pipe->expectNoConsumption();
35 }
36
37private:
38 bool fired;
39};
40}
41
42Adaptation::Initiate::Initiate(const char *aTypeName): AsyncJob(aTypeName)
43{
44}
45
47{
48 // TODO: we cannot assert(!theInitiator) because that fails if a child
49 // constructor fails. AsyncJob should have wasStarted flag so that we
50 // can assert(!(wasStarted && theInitiator)).
51}
52
53void
55{
56 Must(!theInitiator);
57 Must(i.valid());
58 theInitiator = i;
59}
60
61// internal cleanup
63{
64 debugs(93, 5, "swan sings" << status());
65
66 if (theInitiator.set()) {
67 debugs(93, 3, "fatal failure; sending abort notification");
68 tellQueryAborted(true); // final by default
69 }
70
71 debugs(93, 5, "swan sang" << status());
72}
73
75{
76 theInitiator.clear();
77}
78
80{
81 AsyncCall::Pointer call = new AnswerCall("Initiator::noteAdaptationAnswer",
82 AnswerDialer(theInitiator, &Initiator::noteAdaptationAnswer, answer));
83 ScheduleCallHere(call);
84 clearInitiator();
85}
86
88{
89 sendAnswer(Answer::Error(final));
90}
91
93{
94 return AsyncJob::status(); // for now
95}
96
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
#define Must(condition)
Definition: TextException.h:75
bool fired
whether we fired the call
Definition: Initiate.cc:38
AnswerCall(const char *aName, const AnswerDialer &aDialer)
Definition: Initiate.cc:26
~AnswerCall() override
Definition: Initiate.cc:32
void fire() override
Definition: Initiate.cc:28
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:23
static Answer Error(bool final)
create an akError answer
Definition: Answer.cc:17
Initiate(const char *aTypeName)
Definition: Initiate.cc:42
void sendAnswer(const Answer &answer)
Definition: Initiate.cc:79
~Initiate() override
Definition: Initiate.cc:46
void initiator(const CbcPointer< Initiator > &i)
sets initiator
Definition: Initiate.cc:54
void tellQueryAborted(bool final)
Definition: Initiate.cc:87
void swanSong() override
Definition: Initiate.cc:62
const char * status() const override
internal cleanup; do not call directly
Definition: Initiate.cc:92
virtual void noteAdaptationAnswer(const Answer &answer)=0
void fire() override
Definition: AsyncCall.h:148
virtual const char * status() const
internal cleanup; do not call directly
Definition: AsyncJob.cc:182
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
UnaryMemFunT< Initiator, Answer, const Answer & > AnswerDialer
Definition: Initiate.cc:20

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors