JobWait.h
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 #ifndef SQUID_SRC_BASE_JOBWAIT_H
10 #define SQUID_SRC_BASE_JOBWAIT_H
11 
12 #include "base/AsyncJob.h"
13 #include "base/CbcPointer.h"
14 
15 #include <iosfwd>
16 
20 {
21 public:
22  JobWaitBase();
23  ~JobWaitBase();
24 
26  JobWaitBase(JobWaitBase &&) = delete;
27 
28  explicit operator bool() const { return waiting(); }
29 
32  bool waiting() const { return bool(callback_); }
33 
36  void finish();
37 
40  void cancel(const char *reason);
41 
43  void print(std::ostream &) const;
44 
45 protected:
48 
49 private:
51  void clear() { job_.clear(); callback_ = nullptr; }
52 
55 
58 };
59 
62 template <class Job>
63 class JobWait: public JobWaitBase
64 {
65 public:
67 
69  void start(const JobPointer &aJob, const AsyncCall::Pointer &aCallback) {
70  start_(aJob, aCallback);
71  typedJob_ = aJob;
72  }
73 
76  JobPointer job() const { return waiting() ? typedJob_ : nullptr; }
77 
78 private:
81 };
82 
83 inline
84 std::ostream &operator <<(std::ostream &os, const JobWaitBase &wait)
85 {
86  wait.print(os);
87  return os;
88 }
89 
90 #endif /* SQUID_SRC_BASE_JOBWAIT_H */
91 
JobPointer typedJob_
nearly duplicates JobWaitBase::job_ but exposes the actual job type
Definition: JobWait.h:80
JobPointer job() const
Definition: JobWait.h:76
AsyncJob::Pointer job_
the job that we are waiting to call us back (or nil)
Definition: JobWait.h:54
std::ostream & operator<<(std::ostream &os, const JobWaitBase &wait)
Definition: JobWait.h:84
void print(std::ostream &) const
summarizes what we are waiting for (for debugging)
Definition: JobWait.cc:71
bool waiting() const
Definition: JobWait.h:32
void start_(AsyncJob::Pointer, AsyncCall::Pointer)
starts waiting for the given job to call the given callback
Definition: JobWait.cc:24
void clear()
make pointer not set; does not invalidate cbdata
Definition: CbcPointer.h:144
void finish()
Definition: JobWait.cc:44
void cancel(const char *reason)
Definition: JobWait.cc:54
void start(const JobPointer &aJob, const AsyncCall::Pointer &aCallback)
starts waiting for the given job to call the given callback
Definition: JobWait.h:69
CbcPointer< Job > JobPointer
Definition: JobWait.h:66
void clear()
the common part of finish() and cancel()
Definition: JobWait.h:51
AsyncCall::Pointer callback_
the call we are waiting for the job_ to make (or nil)
Definition: JobWait.h:57
~JobWaitBase()
Definition: JobWait.cc:18

 

Introduction

Documentation

Support

Miscellaneous