AsyncJob.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 
16 template <class Cbc>
17 class CbcPointer;
18 
27 // See AsyncJobs.dox for details.
28 
31 class AsyncJob: public CbdataParent
32 {
33 public:
35 
36 public:
37  AsyncJob(const char *aTypeName);
38 
45  static void Start(const Pointer &job);
46 
47 protected:
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 
62 public:
63  bool canBeCalled(AsyncCall &call) const;
64  void callStart(AsyncCall &call);
65  virtual void callEnd();
67  virtual void callException(const std::exception &e);
69 
71  void handleStopRequest() { mustStop("externally aborted"); }
72 
74 
75 protected:
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 
bool canBeCalled(AsyncCall &call) const
whether we can be called
Definition: AsyncJob.cc:102
bool started_
Start() has finished successfully.
Definition: AsyncJob.h:83
AsyncCall::Pointer inCall
the asynchronous call being handled, if any
Definition: AsyncJob.h:81
virtual void callEnd()
called right after the called job method
Definition: AsyncJob.cc:137
virtual void swanSong()
Definition: AsyncJob.h:59
CbcPointer< AsyncJob > Pointer
Definition: AsyncJob.h:34
const char * stopReason
reason for forcing done() to be true
Definition: AsyncJob.h:79
AsyncJob(const char *aTypeName)
Definition: AsyncJob.cc:30
virtual bool doneAll() const
whether positive goal has been reached
Definition: AsyncJob.cc:97
virtual ~AsyncJob()
Definition: AsyncJob.cc:37
void mustStop(const char *aReason)
Definition: AsyncJob.cc:70
bool swanSang_
swanSong() was called
Definition: AsyncJob.h:84
const char * typeName
kid (leaf) class name, for debugging
Definition: AsyncJob.h:80
bool done() const
the job is destroyed in callEnd() when done()
Definition: AsyncJob.cc:91
virtual const char * status() const
internal cleanup; do not call directly
Definition: AsyncJob.cc:167
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
virtual void start()
called by AsyncStart; do not call directly
Definition: AsyncJob.cc:44
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: AsyncJob.cc:128
void handleStopRequest()
process external request to terminate now (i.e. during this async call)
Definition: AsyncJob.h:71
static void Start(const Pointer &job)
Definition: AsyncJob.cc:24

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors