AsyncCall.h
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 #ifndef SQUID_ASYNCCALL_H
10 #define SQUID_ASYNCCALL_H
11 
12 #include "base/InstanceId.h"
13 #include "event.h"
14 #include "RefCount.h"
15 
36 class CallDialer;
37 class AsyncCallQueue;
38 
44 class AsyncCall: public RefCountable
45 {
46 public:
48  friend class AsyncCallQueue;
49 
50  AsyncCall(int aDebugSection, int aDebugLevel, const char *aName);
51  virtual ~AsyncCall();
52 
53  void make(); // fire if we can; handles general call debugging
54 
55  // can be called from canFire() for debugging; always returns false
56  bool cancel(const char *reason);
57 
58  bool canceled() { return isCanceled != NULL; }
59 
60  virtual CallDialer *getDialer() = 0;
61 
62  void print(std::ostream &os);
63 
66 
68  theNext = aNext;
69  }
70 
72  return theNext;
73  }
74 
75 public:
76  const char *const name;
77  const int debugSection;
78  const int debugLevel;
80 
81 protected:
82  virtual bool canFire();
83 
84  virtual void fire() = 0;
85 
86  AsyncCall::Pointer theNext; // used exclusively by AsyncCallQueue
87 
88 private:
89  const char *isCanceled; // set to the cancelation reason by cancel()
90 
91  // not implemented to prevent nil calls from being passed around and unknowingly scheduled, for now.
92  AsyncCall();
93  AsyncCall(const AsyncCall &);
94 };
95 
96 inline
97 std::ostream &operator <<(std::ostream &os, AsyncCall &call)
98 {
99  call.print(os);
100  return os;
101 }
102 
108 {
109 public:
111  virtual ~CallDialer() {}
112 
113  // TODO: Add these for clarity when CommCbFunPtrCallT is gone
114  //virtual bool canDial(AsyncCall &call) = 0;
115  //virtual void dial(AsyncCall &call) = 0;
116 
117  virtual void print(std::ostream &os) const = 0;
118 };
119 
124 template <class Dialer>
125 class AsyncCallT: public AsyncCall
126 {
127 public:
128  AsyncCallT(int aDebugSection, int aDebugLevel, const char *aName,
129  const Dialer &aDialer): AsyncCall(aDebugSection, aDebugLevel, aName),
130  dialer(aDialer) {}
131 
134  dialer(o.dialer) {}
135 
137 
138  CallDialer *getDialer() { return &dialer; }
139 
140 protected:
141  virtual bool canFire() {
142  return AsyncCall::canFire() &&
143  dialer.canDial(*this);
144  }
145  virtual void fire() { dialer.dial(*this); }
146 
147  Dialer dialer;
148 
149 private:
150  AsyncCallT & operator=(const AsyncCallT &); // not defined. call assignments not permitted.
151 };
152 
153 template <class Dialer>
154 inline
155 AsyncCall *
156 asyncCall(int aDebugSection, int aDebugLevel, const char *aName,
157  const Dialer &aDialer)
158 {
159  return new AsyncCallT<Dialer>(aDebugSection, aDebugLevel, aName, aDialer);
160 }
161 
163 bool ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call);
164 
166 #define ScheduleCallHere(call) ScheduleCall(__FILE__, __LINE__, (call))
167 
168 #endif /* SQUID_ASYNCCALL_H */
169 
const char *const name
Definition: AsyncCall.h:76
virtual ~AsyncCall()
Definition: AsyncCall.cc:29
std::ostream & operator<<(std::ostream &os, AsyncCall &call)
Definition: AsyncCall.h:97
void make()
Definition: AsyncCall.cc:35
virtual void fire()=0
const int debugSection
Definition: AsyncCall.h:77
virtual bool canFire()
Definition: AsyncCall.h:141
const int debugLevel
Definition: AsyncCall.h:78
const InstanceId< AsyncCall > id
Definition: AsyncCall.h:79
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
AsyncCall * asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:156
void setNext(AsyncCall::Pointer aNext)
Definition: AsyncCall.h:67
virtual CallDialer * getDialer()=0
Dialer dialer
Definition: AsyncCall.h:147
const char * isCanceled
Definition: AsyncCall.h:89
virtual void fire()
Definition: AsyncCall.h:145
AsyncCallT(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:128
RefCount< AsyncCall > Pointer
Definition: AsyncCall.h:47
virtual void print(std::ostream &os) const =0
AsyncCall::Pointer theNext
Definition: AsyncCall.h:86
AsyncCallT(const AsyncCallT< Dialer > &o)
Definition: AsyncCall.h:132
void print(std::ostream &os)
Definition: AsyncCall.cc:70
virtual ~CallDialer()
Definition: AsyncCall.h:111
AsyncCallT & operator=(const AsyncCallT &)
AsyncCall::Pointer & Next()
Definition: AsyncCall.h:71
bool canceled()
Definition: AsyncCall.h:58
bool ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
Definition: AsyncCall.cc:90
CallDialer * getDialer()
Definition: AsyncCall.h:138
squidaio_request_t * head
Definition: aiops.cc:127
#define NULL
Definition: types.h:166
virtual bool canFire()
Definition: AsyncCall.cc:63

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors