Public Member Functions | Protected Member Functions | Private Attributes | List of all members
RunnableService Class Referenceabstract

#include <service.h>

Inheritance diagram for RunnableService:
Inheritance graph
[legend]

Public Member Functions

std::string getStatusString () override
 
virtual bool isRunning ()
 
void join ()
 
 RunnableService ()
 
bool shutdown () override
 
bool start () override
 
void waitForShutdown ()
 
void waitForShutdown (std::chrono::milliseconds millis)
 
 ~RunnableService () override=default
 
- Public Member Functions inherited from Service
ServiceState getState ()
 
 Service ()
 
virtual ~Service ()=default
 

Protected Member Functions

virtual void run ()
 
virtual bool startWorkerThread ()
 
virtual bool stopWorkerThread ()
 
virtual void work ()=0
 
- Protected Member Functions inherited from Service
void setState (ServiceState new_state)
 

Private Attributes

std::condition_variable cv_
 
std::mutex mtx_
 
std::thread runnable_thread_
 
std::atomic< bool > should_run_ {}
 

Detailed Description

Interface that implements basic Service methods and provides a mechanism to start a thread. Any interesting work in the implemented class should be implemented in the "work" method. Note: start and shutdown methods should be override if the implementing class requires extra steps in either scenarios.

Definition at line 128 of file service.h.

Constructor & Destructor Documentation

RunnableService::RunnableService ( )
inline

Definition at line 131 of file service.h.

RunnableService::~RunnableService ( )
overridedefault

Member Function Documentation

std::string RunnableService::getStatusString ( )
inlineoverridevirtual

Return a descriptive string describing the service and it's state.

Returns

Reimplemented from Service.

Definition at line 198 of file service.h.

virtual bool RunnableService::isRunning ( )
inlinevirtual

Return if the RunnableService work thread is active

Returns
true if the work thread is active / running, false otherwise

Definition at line 160 of file service.h.

void RunnableService::join ( )
inline

Join the running thread if available.

Definition at line 188 of file service.h.

virtual void RunnableService::run ( )
inlineprotectedvirtual

Calls the abstract work method and notifies when shutdown was called.

Definition at line 233 of file service.h.

bool RunnableService::shutdown ( )
inlineoverridevirtual

Stops the worker thread. Should be overridden if other actions are necessary to stop.

Returns

Reimplemented from Service.

Reimplemented in HardWorker.

Definition at line 150 of file service.h.

bool RunnableService::start ( )
inlineoverridevirtual

Starts the worker thread. Should be overridden if other actions are necessary to start.

Returns

Reimplemented from Service.

Definition at line 140 of file service.h.

virtual bool RunnableService::startWorkerThread ( )
inlineprotectedvirtual

Start the worker thread if not already running.

Returns
true if the worker thread was started, false if already running

Definition at line 209 of file service.h.

virtual bool RunnableService::stopWorkerThread ( )
inlineprotectedvirtual

Set the should_run_ flag to false for the worker thread to exit

Returns

Definition at line 222 of file service.h.

void RunnableService::waitForShutdown ( )
inline

Wait for the work thread shutdown

Definition at line 167 of file service.h.

void RunnableService::waitForShutdown ( std::chrono::milliseconds  millis)
inline

Wait for the work thread shutdown

Parameters
millistime to wait

Definition at line 178 of file service.h.

virtual void RunnableService::work ( )
protectedpure virtual

Implement this method to do work. Note: this method is assumed to NOT block, otherwise shutdown does nothing.

Implemented in Aws::CloudWatch::CloudWatchService< D, T >, and HardWorker.

Member Data Documentation

std::condition_variable RunnableService::cv_
private

Definition at line 250 of file service.h.

std::mutex RunnableService::mtx_
mutableprivate

Definition at line 251 of file service.h.

std::thread RunnableService::runnable_thread_
private

Definition at line 248 of file service.h.

std::atomic<bool> RunnableService::should_run_ {}
private

Definition at line 249 of file service.h.


The documentation for this class was generated from the following file:


dataflow_lite
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:22