1#ifndef DETERMINISTIC_CLIENT_H
2#define DETERMINISTIC_CLIENT_H
8#include <condition_variable>
9#include "../core/result.h"
10#include "./worker_runnable.h"
11#include "./helper/atomic_optional.h"
32 using TimeStamp = std::chrono::time_point<std::chrono::steady_clock>;
38 static std::atomic_uint8_t mCounter;
39 static std::future<void> mFuture;
41 static std::mutex mCycleMutex;
42 static std::condition_variable mCycleConditionVariable;
43 static std::default_random_engine mGenerator;
44 static std::uniform_int_distribution<uint64_t> mDistribution;
46 static uint64_t mRandomNumber;
50 static void activateCycle();
67 template <
typename ValueType,
typename Container>
70 Container &container)
noexcept
73 std::is_same<ValueType, typename Container::value_type>::value,
74 "Container value type mismatch!");
76 for (
auto element : container)
78 runnableObj.Run(element, mWorkerThread);
A wrapper around the callee's return value and its possible error.
Definition: result.h:16
Class that utilizes a client to have deterministic behaviour.
Definition: deterministic_client.h:29
static const uint64_t cCycleDelayMs
Theoretical cyclic delay in millisecond.
Definition: deterministic_client.h:35
void SetRandomSeed(uint64_t seed) noexcept
Set a seed number to the deterministic random number generator.
Definition: deterministic_client.cpp:70
uint64_t GetRandom() noexcept
Get a deterministic random number.
Definition: deterministic_client.cpp:65
std::chrono::time_point< std::chrono::steady_clock > TimeStamp
Steady clock time point for deterministic cycles.
Definition: deterministic_client.h:32
core::Result< TimeStamp > GetActivationTime() noexcept
Get the last activation time.
Definition: deterministic_client.cpp:75
ara::core::Result< void > RunWorkerPool(WorkerRunnable< ValueType > &runnableObj, Container &container) noexcept
Run a deterministic worker pool to process a container via a runnable object.
Definition: deterministic_client.h:68
core::Result< TimeStamp > GetNextActivationTime()
Get the next comming activation time.
Definition: deterministic_client.cpp:81
core::Result< ActivationReturnType > WaitForActivation()
Blocks the caller till reaching the next activation time.
Definition: deterministic_client.cpp:56
DeterministicClient worker runnable abstract class.
Definition: worker_runnable.h:14
DeterministicClient random number generator.
Definition: worker_thread.h:14
A wrapper around a possible atomic value.
Definition: atomic_optional.h:20
ActivationReturnType
Application deterministic behaviour lifecycle action.
Definition: deterministic_client.h:19
@ kTerminate
Application shall terminate itself.
@ kServiceDiscovery
Application shall discover its service server.
@ kRegisterService
Application shall register its service server.
@ kInit
Application shall intialize itself.
@ kRun
Application shall perform its normal operation.