Initiate.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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 virtual void fire() {
29 fired = true;
31 }
32 virtual ~AnswerCall() {
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:164
#define false
Definition: GnuRegex.c:240
#define Must(condition)
Definition: TextException.h:71
bool fired
whether we fired the call
Definition: Initiate.cc:38
AnswerCall(const char *aName, const AnswerDialer &aDialer)
Definition: Initiate.cc:26
virtual void fire()
Definition: Initiate.cc:28
virtual ~AnswerCall()
Definition: Initiate.cc:32
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
virtual ~Initiate()
Definition: Initiate.cc:46
Initiate(const char *aTypeName)
Definition: Initiate.cc:42
void sendAnswer(const Answer &answer)
Definition: Initiate.cc:79
virtual const char * status() const
internal cleanup; do not call directly
Definition: Initiate.cc:92
void initiator(const CbcPointer< Initiator > &i)
sets initiator
Definition: Initiate.cc:54
void tellQueryAborted(bool final)
Definition: Initiate.cc:87
virtual void swanSong()
Definition: Initiate.cc:62
virtual void noteAdaptationAnswer(const Answer &answer)=0
virtual void fire()
Definition: AsyncCall.h:143
virtual const char * status() const
internal cleanup; do not call directly
Definition: AsyncJob.cc:167
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
UnaryMemFunT< Initiator, Answer, const Answer & > AnswerDialer
Definition: Initiate.cc:20

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors