Sen API
Sen Libraries
Loading...
Searching...
No Matches
test_kernel.h
Go to the documentation of this file.
1// === test_kernel.h ===================================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_KERNEL_TEST_KERNEL_H
9#define SEN_KERNEL_TEST_KERNEL_H
10
12#include "sen/kernel/kernel.h"
13
14// generated code
16#include "stl/sen/kernel/kernel_objects.stl.h"
17
18// std
19#include <filesystem>
20
21namespace sen::kernel
22{
23
27{
28public:
29 SEN_NOCOPY_NOMOVE(TestKernel)
30
31public: // special members
32 explicit TestKernel(KernelConfig config);
33 explicit TestKernel(Component* component);
35
36public: // factories
37 static TestKernel fromYamlFile(const std::filesystem::path& configFilePath);
38 static TestKernel fromYamlString(const std::string& configString);
39
40public:
41 void step(std::size_t count = 1);
42 [[nodiscard]] TimeStamp getTime() const;
43 [[nodiscard]] std::shared_ptr<ObjectSource> getComponentBus(std::string_view componentName,
44 const BusAddress& busAddress) const;
45 [[nodiscard]] std::optional<const ComponentContext*> getComponentContext(std::string_view componentName) const;
46 [[nodiscard]] CustomTypeRegistry& getTypes() const;
47
48private:
49 void init(KernelConfig config);
50
51private:
52 std::unique_ptr<Kernel> kernel_;
53 TimeStamp virtualTime_;
54};
55
58{
59 SEN_NOCOPY_NOMOVE(TestComponent)
60
61public:
62 using InitFunc = std::function<PassResult(InitApi&&)>;
63 using RunFunc = std::function<FuncResult(RunApi&)>;
64 using UnloadFunc = std::function<FuncResult(UnloadApi&&)>;
65
66public:
67 TestComponent() = default;
68 ~TestComponent() override = default;
69
70public:
71 void onInit(InitFunc func);
72 void onRun(RunFunc func);
73 void onUnload(UnloadFunc func);
74
75public:
76 PassResult init(InitApi&& api) override;
77 FuncResult run(RunApi& api) override;
78 FuncResult unload(UnloadApi&& api) override;
79
80private:
81 RunFunc run_;
82 InitFunc init_;
83 UnloadFunc unload_;
84};
85
86} // namespace sen::kernel
87
88#endif // SEN_KERNEL_TEST_KERNEL_H
A registry of custom types.
Definition type_registry.h:36
A point in time.
Definition timestamp.h:26
Base class for implementing sen kernel components.
Definition component.h:34
Component() noexcept=default
What can be done when initializing a component.
Definition component_api.h:213
Holds the kernel configuration information.
Definition kernel_config.h:33
What can be done while a component is running.
Definition component_api.h:224
std::function< FuncResult(UnloadApi &&)> UnloadFunc
Definition test_kernel.h:64
std::function< FuncResult(RunApi &)> RunFunc
Definition test_kernel.h:63
PassResult init(InitApi &&api) override
Initialize the component and perform kernel-related operations. This may include dependency resolutio...
~TestComponent() override=default
FuncResult unload(UnloadApi &&api) override
Unload any self-contained resources. This function is just called once.
void onUnload(UnloadFunc func)
std::function< PassResult(InitApi &&)> InitFunc
Definition test_kernel.h:62
void onInit(InitFunc func)
FuncResult run(RunApi &api) override
Runs the component in a dedicated thread. This function is called once and only when the kernel has r...
void onRun(RunFunc func)
std::optional< const ComponentContext * > getComponentContext(std::string_view componentName) const
std::shared_ptr< ObjectSource > getComponentBus(std::string_view componentName, const BusAddress &busAddress) const
static TestKernel fromYamlFile(const std::filesystem::path &configFilePath)
TestKernel(Component *component)
CustomTypeRegistry & getTypes() const
void step(std::size_t count=1)
static TestKernel fromYamlString(const std::string &configString)
TestKernel(KernelConfig config)
TimeStamp getTime() const
What can be done when unloading a component.
Definition component_api.h:291
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
Result< void, ExecError > FuncResult
The result of operations that are called once.
Definition component_api.h:50