AsyncJob.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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_ASYNC_JOB_H
10#define SQUID_ASYNC_JOB_H
11
12#include "base/AsyncCall.h"
13#include "base/InstanceId.h"
14#include "cbdata.h"
15
16template <class Cbc>
17class CbcPointer;
18
27// See AsyncJobs.dox for details.
28
32{
33public:
35
36public:
37 AsyncJob(const char *aTypeName);
38
45 static void Start(const Pointer &job);
46
47protected:
48 // XXX: temporary method to replace "delete this" in jobs-in-transition.
49 // Will be replaced with calls to mustStop() when transition is complete.
50 void deleteThis(const char *aReason);
51
52 // force done() for a reason but continue with the current method
53 void mustStop(const char *aReason);
54
55 bool done() const;
56
57 virtual void start();
58 virtual bool doneAll() const;
59 virtual void swanSong() {};
60 virtual const char *status() const;
61
62public:
63 bool canBeCalled(AsyncCall &call) const;
64 void callStart(AsyncCall &call);
66 virtual void callEnd();
68 virtual void callException(const std::exception &e);
69
71 void handleStopRequest() { mustStop("externally aborted"); }
72
74
75protected:
76 // external destruction prohibited to ensure swanSong() is called
77 virtual ~AsyncJob();
78
79 const char *stopReason;
80 const char *typeName;
82
83 bool started_ = false;
84 bool swanSang_ = false;
85};
86
87#endif /* SQUID_ASYNC_JOB_H */
88
static void Start(const Pointer &job)
Definition: AsyncJob.cc:24
virtual bool doneAll() const
whether positive goal has been reached
Definition: AsyncJob.cc:97
void handleStopRequest()
process external request to terminate now (i.e. during this async call)
Definition: AsyncJob.h:71
virtual void start()
called by AsyncStart; do not call directly
Definition: AsyncJob.cc:44
AsyncJob(const char *aTypeName)
Definition: AsyncJob.cc:30
bool swanSang_
swanSong() was called
Definition: AsyncJob.h:84
virtual void callEnd()
called right after the called job method
Definition: AsyncJob.cc:137
void mustStop(const char *aReason)
Definition: AsyncJob.cc:70
const char * typeName
kid (leaf) class name, for debugging
Definition: AsyncJob.h:80
bool started_
Start() has finished successfully.
Definition: AsyncJob.h:83
void deleteThis(const char *aReason)
Definition: AsyncJob.cc:50
void callStart(AsyncCall &call)
Definition: AsyncJob.cc:115
const InstanceId< AsyncJob > id
job identifier
Definition: AsyncJob.h:73
bool done() const
the job is destroyed in callEnd() when done()
Definition: AsyncJob.cc:91
virtual void swanSong()
Definition: AsyncJob.h:59
AsyncCall::Pointer inCall
the asynchronous call being handled, if any
Definition: AsyncJob.h:81
virtual const char * status() const
internal cleanup; do not call directly
Definition: AsyncJob.cc:167
CbcPointer< AsyncJob > Pointer
Definition: AsyncJob.h:34
virtual ~AsyncJob()
Definition: AsyncJob.cc:37
bool canBeCalled(AsyncCall &call) const
whether we can be called
Definition: AsyncJob.cc:102
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: AsyncJob.cc:128
const char * stopReason
reason for forcing done() to be true
Definition: AsyncJob.h:79

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors