ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
triggered.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_threads of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2019 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_AWORX_ALIB_THREADS_MODEL_TRIGGERED
9#define HPP_AWORX_ALIB_THREADS_MODEL_TRIGGERED
10
11#if !defined(ALIB_DOX) // todo remove
12
13#if !defined(HPP_ALIB_LANG_INTEGERS)
14# include "alib/lang/integers.hpp"
15#endif
16
17
18namespace alib { namespace threads::model {
19
20// forward declaration
21class ThreadManager;
22
23
24/** ************************************************************************************************
25 * This class is declares a simple interface for objects that allow to be triggerd periodically.
26 * The use of this class is recommended to avoid to either creating a dedicated thread for
27 * simple, periodic tasks, or to add invoctions to perform such tasks to other threadds of the
28 * application.
29 *
30 * Instead, class \alib{threads::model;ThreadManager} will be the only responsible entity to
31 * trigger such actions within its own execution thread.
32 **************************************************************************************************/
33class Triggered
34{
35 protected:
36 /** Class ThreadManager is the only one that will trigger us and hence has access to
37 * our protected functions. */
38 friend class ThreadManager;
39
40 /** The name of the triggered object. This is mainly used for log output and some
41 * convenience methods. */
42 const String Name;
43
44 /**
45 * Constructor. Stores the name in constant member #Name. Usually these names are
46 * hard-coded C++ character arrays. If progarmmatically created, it has to be assured that
47 * the life-cycle of the string supersedes the lifecycle of the instnace of this class.
48 * @param pName The name of this object.
49 */
50 Triggered(const String& pName) : Name( pName ) {}
51
52 /** Virtual empty destructor. Needed with any virtual class. */
53 virtual ~Triggered() {}
54
55 /** Implementations need to implement this function to return the trigger period.
56 * The period is allowed to change with each request. A request is made
57 * when the type is added to the thread manager for triggering and after each
58 * call to #trigger(), when the next trigger time is scheduled.
59 *
60 * @return The desired sleep time between two trigger events in milliseconds.
61 */
62 virtual integer triggerPeriodInMilliseconds() = 0;
63
64 /**
65 * Implementations need to implement this function and perform their trigger actions
66 * here.
67 */
68 virtual void trigger() = 0;
69
70}; // interface class Triggered
71
72} // namespace alib[::threads::model]
73
74/// Type alias in namespace #alib.
75using Triggered = alib::threads::model::Triggered;
76
77} // namespace [alib]
78
79#endif // #if !defined(ALIB_DOX) // todo remove
80
81#endif // HPP_AWORX_ALIB_THREADS_MODEL_TRIGGERED
platform_specific integer
Definition integers.hpp:50
Definition alib.cpp:57
strings::TString< character > String
Type alias in namespace alib.