Initiate.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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"
14 #include "adaptation/Initiator.h"
15 #include "base/AsyncJobCalls.h"
16 #include "http/Message.h"
17 
18 namespace Adaptation
19 {
23 class AnswerCall: public AsyncCallT<AnswerDialer>
24 {
25 public:
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 != NULL && dialer.arg1.message->body_pipe != NULL)
34  dialer.arg1.message->body_pipe->expectNoConsumption();
35  }
36 
37 private:
38  bool fired;
39 };
40 }
41 
42 Adaptation::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 
53 void
55 {
56  Must(!theInitiator);
57  Must(i.valid());
58  theInitiator = i;
59 }
60 
61 // internal cleanup
63 {
64  debugs(93, 5, HERE << "swan sings" << status());
65 
66  if (theInitiator.set()) {
67  debugs(93, 3, HERE << "fatal failure; sending abort notification");
68  tellQueryAborted(true); // final by default
69  }
70 
71  debugs(93, 5, HERE << "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 
92 const char *Adaptation::Initiate::status() const
93 {
94  return AsyncJob::status(); // for now
95 }
96 
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:22
void tellQueryAborted(bool final)
Definition: Initiate.cc:87
virtual ~Initiate()
Definition: Initiate.cc:46
static Answer Error(bool final)
create an akError answer
Definition: Answer.cc:17
int i
Definition: membanger.c:49
bool fired
whether we fired the call
Definition: Initiate.cc:38
Initiate(const char *aTypeName)
Definition: Initiate.cc:42
virtual const char * status() const
internal cleanup; do not call directly
Definition: AsyncJob.cc:159
virtual ~AnswerCall()
Definition: Initiate.cc:32
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
virtual void fire()
Definition: AsyncCall.h:145
virtual const char * status() const
internal cleanup; do not call directly
Definition: Initiate.cc:92
AnswerCall(const char *aName, const AnswerDialer &aDialer)
Definition: Initiate.cc:26
virtual void fire()
Definition: Initiate.cc:28
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
#define Must(cond)
Definition: TextException.h:89
void sendAnswer(const Answer &answer)
Definition: Initiate.cc:79
void initiator(const CbcPointer< Initiator > &i)
sets initiator
Definition: Initiate.cc:54
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
UnaryMemFunT< Initiator, Answer, const Answer & > AnswerDialer
Definition: Initiate.cc:20
virtual void noteAdaptationAnswer(const Answer &answer)=0
#define NULL
Definition: types.h:166
virtual void swanSong()
Definition: Initiate.cc:62
#define false
Definition: GnuRegex.c:233

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors