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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors