8#ifndef SEN_KERNEL_COMPONENT_API_H
9#define SEN_KERNEL_COMPONENT_API_H
32#include "stl/sen/kernel/basic_types.stl.h"
65[[nodiscard]]
FuncResult execLoop(Runner* runner,
Duration cycleTime, std::function<
void()>&& workFunction);
69void remoteProcessDetected(
RunApi& api,
const ProcessInfo& processInfo);
71void remoteProcessLost(
RunApi& api,
const ProcessInfo& processInfo);
73[[nodiscard]] std::shared_ptr<ObjectSource> getSource(Runner* runner,
const BusAddress& address);
77[[nodiscard]]
const ProcessInfo* fetchOwnerInfo(
const Object*
object);
79[[nodiscard]] ::sen::impl::WorkQueue* getWorkQueue(Runner* runner);
135 template <typename T, typename B>
143 template <
typename T>
144 [[nodiscard]] std::string buildQuery(
const BusAddress& address)
const;
146 template <
typename T>
147 [[nodiscard]] std::string buildQuery(std::string_view bus)
const;
151 impl::Runner* runner_;
230 impl::KernelImpl& kernelImpl,
231 impl::Runner* runner,
259 std::function<
void()>&& func =
nullptr,
260 bool logOverruns = true);
283 impl::KernelImpl& kernelImpl_;
284 impl::Runner* runner_;
285 std::atomic_bool& stopRequested_;
303template <typename T, typename B>
306 auto sub = std::make_shared<Subscription<T>>();
313inline std::string KernelApi::buildQuery(
const BusAddress& address)
const
315 const ClassType* meta =
nullptr;
316 if constexpr (!std::is_same_v<T, Object>)
321 std::string query =
"SELECT ";
322 query.append(meta ? meta->getQualifiedName() :
"*");
323 query.append(
" FROM ");
324 query.append(address.sessionName);
326 query.append(address.busName);
332inline std::string KernelApi::buildQuery(std::string_view bus)
const
334 const ClassType* meta =
nullptr;
335 if constexpr (!std::is_same_v<T, Object>)
337 meta = T::meta()->asClassType();
340 std::string query =
"SELECT ";
341 query.append(meta ? meta->getQualifiedName() :
"*");
342 query.append(
" FROM ");
A registry of custom types.
Definition type_registry.h:36
A time duration.
Definition duration.h:25
static std::shared_ptr< Interest > make(std::string_view query, const CustomTypeRegistry &typeRegistry)
Make an interest from a query. Throws std::exception if not well formed.
A sen object.
Definition object.h:76
Allows adding and receiving objects.
Definition object_source.h:35
Result<T, E> is a template type that can be used to return and propagate errors. The intent is to rep...
Definition result.h:135
A point in time.
Definition timestamp.h:26
ConfigGetter(const VarMap &config) noexcept
const VarMap & getConfig() const noexcept
Gets the configuration associated with this component.
~InitApi() noexcept=default
InitApi(Kernel &kernel, impl::Runner *runner, const VarMap &config) noexcept
User-facing kernel functions.
Definition component_api.h:103
::sen::impl::WorkQueue * getWorkQueue() const noexcept
The work queue of this runner.
KernelApi(Kernel &kernel, impl::Runner *runner) noexcept
std::shared_ptr< ObjectSource > getSource(const BusAddress &address)
Gets an object source, where objects can be found and published.
std::shared_ptr< Subscription< T > > selectAllFrom(const B &bus)
Definition component_api.h:304
std::filesystem::path getConfigFilePath() const noexcept
Gets the path to the configuration file used to construct the kernel. It might be empty if the kernel...
Definition component_api.h:140
CustomTypeRegistry & getTypes() noexcept
The types registered into the kernel.
SessionsDiscoverer & getSessionsDiscoverer() noexcept
Object that allows discovering sessions and buses.
const ProcessInfo * fetchOwnerInfo(const Object *object) const noexcept
Gets information about the process where an object is. Returns nullptr if the object resides in the c...
const std::string & getAppName() const noexcept
Gets the (optional) application name passed to the kernel as a configuration parameter.
void requestKernelStop(int exitCode=0)
Issues an asynchronous request to stop the kernel. The request is ignored if a previous stop request ...
Main entry point of a sen microkernel.
Definition kernel.h:40
~LoadApi() noexcept=default
LoadApi(Kernel &kernel, impl::Runner *runner, const VarMap &config) noexcept
PreloadApi(Kernel &kernel, impl::Runner *runner, const VarMap &config) noexcept
~PreloadApi() noexcept=default
void installTracerFactory(TracerFactory &&factory) const
Installs a tracer factory.
void installTransportFactory(TransportFactory &&factory, uint32_t transportVersion) const
Installs a transport factory for the kernel to use for sessions.
RegistrationApi(Kernel &kernel, impl::Runner *runner, const VarMap &config) noexcept
~RegistrationApi() noexcept=default
What can be done while a component is running.
Definition component_api.h:224
TimeStamp getStartTime() const noexcept
The initial simulation time for the objects in the component.
void commit()
Send changes, so that they become visible to other participants. This includes object additions and r...
Tracer & getTracer() const noexcept
Create a scoped zone used for tracing runtime performance.
void drainInputs()
Perform any request coming from the outside and drainInputs all the local data structures with their ...
~RunApi() noexcept=default
std::optional< Duration > getTargetCycleTime() const noexcept
If present, it returns the configured cycle time for iterations.
FuncResult execLoop(Duration cycleTime, std::function< void()> &&func=nullptr, bool logOverruns=true)
A basic execution loop. Func is an optional callback that will be invoked on each cycle.
RunApi(Kernel &kernel, impl::KernelImpl &kernelImpl, impl::Runner *runner, std::atomic_bool &stopRequested, const VarMap &config, Guarded< TimeStamp > &timePoint) noexcept
KernelMonitoringInfo fetchMonitoringInfo() const
Monitoring information.
friend void impl::remoteProcessLost(RunApi &api, const ProcessInfo &processInfo)
const std::atomic_bool & stopRequested() const noexcept
True if stop has been requested by the runtime.
void update()
This calls update() on all the objects registered by the component.
friend void impl::remoteProcessDetected(RunApi &api, const ProcessInfo &processInfo)
TimeStamp getTime() const noexcept
The (potentially virtualized) time.
Definition source_info.h:99
Interface implemented by tracers. You can use it to trace the behavior of your code....
Definition tracer.h:28
UnloadApi(Kernel &kernel, const VarMap &config, impl::Runner *runner) noexcept
~UnloadApi() noexcept=default
std::function< std::unique_ptr< Transport >(const std::string &, std::unique_ptr< Tracer > tracer)> TransportFactory
A function that creates a transport given a session name.
Definition include/sen/kernel/transport.h:203
Global transport statistics.
Definition include/sen/kernel/transport.h:146
std::map< std::string, Var, std::less<> > VarMap
A map of vars to represent structures.
Definition var.h:107
Strong type for the unique identifier for a transport timer.
Definition native_object_impl.h:39
Result< OpState, ExecError > PassResult
The result of operations that may be called multiple times.
Definition component_api.h:53
std::function< std::unique_ptr< Tracer >(std::string_view)> TracerFactory
A factory function for tracers.
Definition tracer.h:119
Result< void, ExecError > FuncResult
The result of operations that are called once.
Definition component_api.h:50
ComponentConfig config
Definition component_api.h:87
std::optional< Duration > cycleTime
Definition component_api.h:89
std::vector< ComponentMonitoringInfo > components
Definition component_api.h:98
std::size_t objectCount
Definition component_api.h:90
RunMode runMode
Definition component_api.h:96
bool requiresRealTime
Definition component_api.h:88
TransportStats transportStats
Definition component_api.h:97
ComponentInfo info
Definition component_api.h:86
Monitoring information about components.
Definition component_api.h:85
Kernel monitoring information.
Definition component_api.h:95
Guarded is a lightweight wrapper class that can be used to protect an objet of type T from concurrent...
Definition mutex_utils.h:49
A list of objects and a reference to its source (to keep it alive).
Definition subscription.h:24