ewmscp  ..
Public Types | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
stopRequest Class Reference

#include <ewmscp.h>

Collaboration diagram for stopRequest:
[legend]

Public Types

enum  handlerIdType { handlerIdType::unhandled, handlerIdType::undefined, handlerIdType::requestProvider, handlerIdType::processLoop }
 

Static Public Member Functions

static void instantiate (handlerIdType id)
 
static bool Requested ()
 
static bool Requested (handlerIdType id)
 
static void RequestStop (const std::string &aReason)
 
static void ThrowUpReasonably ()
 

Static Private Member Functions

static void sigHandler (int)
 

Static Private Attributes

static handlerIdType handlerId
 
static std::string reason
 
static volatile std::atomic< bool > stopRequested
 

Detailed Description

Definition at line 117 of file ewmscp.h.

Member Enumeration Documentation

◆ handlerIdType

Enumerator
unhandled 
undefined 
requestProvider 
processLoop 

Definition at line 119 of file ewmscp.h.

119  {
120  unhandled,
121  undefined,
123  processLoop
124  };

Member Function Documentation

◆ instantiate()

void stopRequest::instantiate ( stopRequest::handlerIdType  id)
static

Definition at line 143 of file ewmscp.cpp.

143  {
145  throw std::logic_error("stop request handler cannot be instatiated twice");
146  }
148  throw std::logic_error("illegal handler id value");
149  }
150  std::signal(SIGTERM, sigHandler);
151  handlerId = id;
152 }

References handlerId, sigHandler(), undefined, and unhandled.

Here is the call graph for this function:

◆ Requested() [1/2]

bool stopRequest::Requested ( )
static

Definition at line 153 of file ewmscp.cpp.

153  {
155  return stopRequested;
156  }
157  return false;
158 }

References handlerId, stopRequested, and unhandled.

Referenced by followInotifyWatchRequestProvider::followStream(), followJsonRequestProvider::followStream(), copyRequest::base::processQueue(), and followKafkaRequestProvider::processSources().

Here is the caller graph for this function:

◆ Requested() [2/2]

bool stopRequest::Requested ( handlerIdType  id)
static

Definition at line 159 of file ewmscp.cpp.

159  {
160  return handlerId == id && stopRequested;
161 }

References handlerId, and stopRequested.

◆ RequestStop()

void stopRequest::RequestStop ( const std::string &  aReason)
static

Definition at line 162 of file ewmscp.cpp.

162  {
164  static std::mutex instanceProtector;
165  std::unique_lock<decltype(instanceProtector)> lock(instanceProtector);
166  stopRequested = true;
167  reason = aReason;
168  } else {
170  "stopRequest", "requestStop", "no stop request instance");
171  }
172 }

References errMsg::crit, errMsg::emit(), handlerId, reason, stopRequested, and unhandled.

Referenced by printErrors(), printResults(), and copyRequest::base::processQueue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigHandler()

void stopRequest::sigHandler ( int  )
staticprivate

Definition at line 139 of file ewmscp.cpp.

139  {
140  stopRequested = true;
141  // static_assert(std::atomic_is_lock_free(&stopRequested), "atomic bool is not always lock free"); // assert that stopRequested is always lock-free
142 }

References stopRequested.

Referenced by instantiate().

Here is the caller graph for this function:

◆ ThrowUpReasonably()

void stopRequest::ThrowUpReasonably ( )
static

Definition at line 173 of file ewmscp.cpp.

173  {
175  if (stopRequested) {
176  if (! reason.empty()) {
177  throw std::runtime_error(reason);
178  } else {
179  throw std::runtime_error("SIGTERM received");
180  }
181  }
182  }
183 }

References handlerId, reason, stopRequested, and unhandled.

Member Data Documentation

◆ handlerId

handlerIdType stopRequest::handlerId
staticprivate

Definition at line 126 of file ewmscp.h.

Referenced by instantiate(), Requested(), RequestStop(), and ThrowUpReasonably().

◆ reason

std::string stopRequest::reason
staticprivate

Definition at line 127 of file ewmscp.h.

Referenced by RequestStop(), and ThrowUpReasonably().

◆ stopRequested

volatile std::atomic<bool> stopRequest::stopRequested
staticprivate

Definition at line 129 of file ewmscp.h.

Referenced by Requested(), RequestStop(), sigHandler(), and ThrowUpReasonably().


The documentation for this class was generated from the following files:
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
errMsg::level::crit
@ crit
requestProvider
generic provider of copy requests
Definition: requestProvider.h:13
stopRequest::stopRequested
static volatile std::atomic< bool > stopRequested
Definition: ewmscp.h:129
stopRequest::handlerId
static handlerIdType handlerId
Definition: ewmscp.h:126
stopRequest::sigHandler
static void sigHandler(int)
Definition: ewmscp.cpp:139
stopRequest::handlerIdType::unhandled
@ unhandled
stopRequest::handlerIdType::undefined
@ undefined
errMsg::emit
void emit(level aLogLevel, const location &loc, const std::string &aObject, const std::string &aAction, const Args &... args)
function to create and enqueue a message, this is the only way that messages should be created!
Definition: errMsgQueue.h:148
stopRequest::reason
static std::string reason
Definition: ewmscp.h:127