AsyncCall.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 #include "squid.h"
10 #include "AsyncCall.h"
11 #include "base/AsyncCall.h"
12 #include "base/AsyncCallQueue.h"
13 #include "cbdata.h"
14 #include "Debug.h"
15 #include <ostream>
16 
18 
19 /* AsyncCall */
20 
21 AsyncCall::AsyncCall(int aDebugSection, int aDebugLevel,
22  const char *aName): name(aName), debugSection(aDebugSection),
23  debugLevel(aDebugLevel), theNext(0), isCanceled(NULL)
24 {
25  debugs(debugSection, debugLevel, "The AsyncCall " << name << " constructed, this=" << this <<
26  " [" << id << ']');
27 }
28 
30 {
31  assert(!theNext); // AsyncCallQueue must clean
32 }
33 
34 void
36 {
37  debugs(debugSection, debugLevel, HERE << "make call " << name <<
38  " [" << id << ']');
39  if (canFire()) {
40  fire();
41  return;
42  }
43 
44  if (!isCanceled) // we did not cancel() when returning false from canFire()
45  isCanceled = "unknown reason";
46 
47  debugs(debugSection, debugLevel, HERE << "will not call " << name <<
48  " [" << id << ']' << " because of " << isCanceled);
49 }
50 
51 bool
52 AsyncCall::cancel(const char *reason)
53 {
54  debugs(debugSection, debugLevel, HERE << "will not call " << name <<
55  " [" << id << "] " << (isCanceled ? "also " : "") <<
56  "because " << reason);
57 
58  isCanceled = reason;
59  return false;
60 }
61 
62 bool
64 {
65  return !isCanceled;
66 }
67 
69 void
70 AsyncCall::print(std::ostream &os)
71 {
72  os << name;
73  if (const CallDialer *dialer = getDialer())
74  dialer->print(os);
75  else
76  os << "(?" << this << "?)";
77 }
78 
79 void
81 {
82  if (prev != NULL)
83  prev->setNext(Next());
84  else
85  head = Next();
86  setNext(NULL);
87 }
88 
89 bool
90 ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
91 {
92  debugs(call->debugSection, call->debugLevel, fileName << "(" << fileLine <<
93  ") will call " << *call << " [" << call->id << ']' );
95  return true;
96 }
97 
const char *const name
Definition: AsyncCall.h:76
#define assert(EX)
Definition: assert.h:17
virtual ~AsyncCall()
Definition: AsyncCall.cc:29
void make()
Definition: AsyncCall.cc:35
virtual void fire()=0
const int debugSection
Definition: AsyncCall.h:77
const int debugLevel
Definition: AsyncCall.h:78
void dequeue(AsyncCall::Pointer &head, AsyncCall::Pointer &prev)
remove us from the queue; we are head unless we are queued after prev
Definition: AsyncCall.cc:80
bool cancel(const char *reason)
Definition: AsyncCall.cc:52
void setNext(AsyncCall::Pointer aNext)
Definition: AsyncCall.h:67
bool ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
Definition: AsyncCall.cc:90
virtual CallDialer * getDialer()=0
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
const char * isCanceled
Definition: AsyncCall.h:89
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
AsyncCall::Pointer theNext
Definition: AsyncCall.h:86
void print(std::ostream &os)
Definition: AsyncCall.cc:70
AsyncCall::Pointer & Next()
Definition: AsyncCall.h:71
void schedule(AsyncCall::Pointer &call)
squidaio_request_t * head
Definition: aiops.cc:127
#define NULL
Definition: types.h:166
static AsyncCallQueue & Instance()
virtual bool canFire()
Definition: AsyncCall.cc:63
InstanceIdDefinitions(AsyncCall,"call")

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors