Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
|
Service runner, a reusable dedicated thread performing custom user services. More...
#include <service_runner.hpp>
Public Types | |
typedef function< void(service_runner_ref)> | Callback |
typedef service_runner & | service_runner_ref |
Public Member Functions | |
service_runner (std::string name, fraction_i64 service_shutdown_timeout, Callback service_work, Callback service_init_locked=Callback(), Callback service_end_locked=Callback()) noexcept | |
Service runner constructor. More... | |
~service_runner () noexcept | |
Service runner destructor. More... | |
std::condition_variable & | cv_shall_stop () noexcept |
mtx_shall_stop() and cv_shall_stop() allows caller to be notified when shall_stop() changes, i.e. More... | |
bool | is_running () const noexcept |
Returns true if service is running. More... | |
bool | join () noexcept |
Blocks the current thread until service is stopped or returns immediately if not running or called from the service thread. More... | |
std::mutex & | mtx_shall_stop () noexcept |
mtx_shall_stop() and cv_shall_stop() allows caller to be notified when shall_stop() changes, i.e. More... | |
const std::string & | name () const noexcept |
Return the given name of this service. More... | |
fraction_i64 | service_shutdown_timeout () const noexcept |
Returns maximum duration in fractions of seconds to wait for service to stop at stop() and join(), where fractions_i64::zero waits infinitely. More... | |
void | set_shall_stop () noexcept |
Marks the service thread to stop in due process by flagging shall stop to true . More... | |
bool | shall_stop () const noexcept |
Returns true if service shall stop. More... | |
bool | shall_stop2 (int dummy) noexcept |
Helper function to easy FunctionDef usage w/o creating a lambda alike capture with same semantics as shall_stop(). More... | |
void | start () noexcept |
Starts this service, if not running already. More... | |
bool | stop () noexcept |
Stops this service, if running. More... | |
pthread_t | thread_id () const noexcept |
Return the thread-id of this service service thread, zero if not running. More... | |
std::string | toString () const noexcept |
Returns a string representation of this service. More... | |
Static Public Member Functions | |
static bool | remove_sighandler () noexcept |
Remove the sighandler. More... | |
static bool | singleton_sighandler () noexcept |
Install the singleton SIGALRM sighandler instance. More... | |
Static Public Attributes | |
static const ::pid_t | pid_self = ::getpid() |
Service runner, a reusable dedicated thread performing custom user services.
Definition at line 59 of file service_runner.hpp.
Definition at line 61 of file service_runner.hpp.
typedef function<void(service_runner_ref)> jau::service_runner::Callback |
Definition at line 62 of file service_runner.hpp.
|
noexcept |
Service runner constructor.
start() shall be issued to kick off this service.
name | service name |
service_shutdown_timeout | maximum duration in fractions of seconds to wait for service to stop at stop() and join(), where fractions_i64::zero waits infinitely |
service_work | service working function |
service_init_locked | optional service init function, lifecycle mutex is locked |
service_end_locked | optional service end function, lifecycle mutex is locked |
Definition at line 118 of file service_runner.cpp.
|
noexcept |
|
staticnoexcept |
Remove the sighandler.
Definition at line 104 of file service_runner.cpp.
|
inlinestaticnoexcept |
Install the singleton SIGALRM sighandler instance.
Definition at line 102 of file service_runner.hpp.
|
inlinenoexcept |
Return the given name of this service.
Definition at line 144 of file service_runner.hpp.
|
inlinenoexcept |
Returns maximum duration in fractions of seconds to wait for service to stop at stop() and join(), where fractions_i64::zero waits infinitely.
Definition at line 151 of file service_runner.hpp.
|
inlinenoexcept |
Return the thread-id of this service service thread, zero if not running.
Definition at line 156 of file service_runner.hpp.
|
inlinenoexcept |
Returns true if service is running.
Definition at line 165 of file service_runner.hpp.
|
inlinenoexcept |
Returns true if service shall stop.
This flag can be used by the service_work Callback to determine whether to skip lengthly tasks, or even to skip stopping this service (again).
Definition at line 181 of file service_runner.hpp.
|
inlinenoexcept |
Helper function to easy FunctionDef usage w/o creating a lambda alike capture with same semantics as shall_stop().
The const qualifier has also been lifted, since free function pointer declarations can't match it.
dummy | a dummy argument to help FunctionDef template parameter pack, not used |
Definition at line 192 of file service_runner.hpp.
|
noexcept |
Marks the service thread to stop in due process by flagging shall stop
to true
.
Definition at line 140 of file service_runner.cpp.
|
inlinenoexcept |
mtx_shall_stop() and cv_shall_stop() allows caller to be notified when shall_stop() changes, i.e.
start(), set_shall_stop() or stop() is called.
Definition at line 207 of file service_runner.hpp.
|
inlinenoexcept |
mtx_shall_stop() and cv_shall_stop() allows caller to be notified when shall_stop() changes, i.e.
start(), set_shall_stop() or stop() is called.
Definition at line 210 of file service_runner.hpp.
|
noexcept |
Starts this service, if not running already.
Methods blocks the current thread until service is started.
Definition at line 148 of file service_runner.cpp.
|
noexcept |
Stops this service, if running.
If called from the service thread, method just issues set_shall_stop() without blocking, otherwise methods blocks the current thread until service is stopped.
Maximum blocked wait period is optionally limited by service_shutdown_timeout().
Method attempts to stop the service thread
shall stop
via set_shall_stop()SIGALRM
to the service threadImplementation requires a SIGALRM
handler to be install, e.g. using singleton_sighandler().
Definition at line 177 of file service_runner.cpp.
|
noexcept |
Blocks the current thread until service is stopped or returns immediately if not running or called from the service thread.
Maximum blocked wait period is optionally limited by service_shutdown_timeout().
Definition at line 221 of file service_runner.cpp.
|
noexcept |
Returns a string representation of this service.
Definition at line 256 of file service_runner.cpp.
|
static |
Definition at line 64 of file service_runner.hpp.