Sen API
Sen Libraries
Loading...
Searching...
No Matches
source_info.h
Go to the documentation of this file.
1// === source_info.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_SOURCE_INFO_H
9#define SEN_KERNEL_SOURCE_INFO_H
10
13
14namespace sen::kernel
15{
16
17// forward declarations
18class KernelApi;
19
20namespace impl
21{
22class Session;
23class KernelImpl;
24} // namespace impl
25
26// Forward declarations
28
31{
32public:
33 SEN_NOCOPY_NOMOVE(SourceInfo)
34
35public:
36 virtual ~SourceInfo() = default;
37
38public:
40 [[nodiscard]] const std::string& getName() const noexcept;
41
43 [[nodiscard]] std::vector<std::string> getDetectedSources() const;
44
48 void onSourceDetected(const std::function<void(const std::string&)>& callback);
49
52 void onSourceUndetected(const std::function<void(const std::string&)>& callback);
53
54protected: // interface towards the owner
55 friend class SessionsDiscoverer;
56 friend class impl::Runner;
57
58 explicit SourceInfo(std::string name);
59 void addSource(const std::string& name);
60 void removeSource(const std::string& name);
61 virtual void drainInputs();
62 void lock();
63 void unlock();
64
65private:
66 void remove(const std::string& elem, std::vector<std::string>& vec) const;
67
68private:
69 using Mutex = std::recursive_mutex;
70 using Lock = std::scoped_lock<Mutex>;
71
72private:
73 std::string name_;
74 std::function<void(const std::string&)> detectedCallback_ = nullptr;
75 std::function<void(const std::string&)> undetectedCallback_ = nullptr;
76
77 mutable Mutex sourcesMutex_;
78 std::vector<std::string> pendingAdditions_;
79 std::vector<std::string> pendingRemovals_;
80 std::vector<std::string> currentSources_;
81};
82
84class SessionInfoProvider: public SourceInfo, public std::enable_shared_from_this<SessionInfoProvider>
85{
86public:
87 SEN_NOCOPY_NOMOVE(SessionInfoProvider)
88
89public:
90 SessionInfoProvider(std::string name, std::shared_ptr<impl::Session> session);
92
93private:
94 friend class impl::Session;
95 std::shared_ptr<impl::Session> session_;
96};
97
98class SessionsDiscoverer: public SourceInfo, public std::enable_shared_from_this<SessionsDiscoverer>
99{
100public:
101 SEN_NOCOPY_NOMOVE(SessionsDiscoverer)
102
103public:
104 ~SessionsDiscoverer() override = default;
105
106public:
107 [[nodiscard]] std::shared_ptr<SessionInfoProvider> makeSessionInfoProvider(const std::string& sessionName);
108
109protected:
110 void drainInputs() override;
111
112private:
113 friend class KernelApi;
114 friend class impl::KernelImpl;
115 friend class impl::Runner;
116
117 explicit SessionsDiscoverer(impl::Runner* owner);
118 void sessionAvailable(const std::string& name);
119 void sessionUnavailable(const std::string& name);
120
121private:
122 impl::Runner* owner_;
123 std::vector<std::weak_ptr<SessionInfoProvider>> children_;
124 std::vector<std::weak_ptr<SessionInfoProvider>> validChildren_;
125};
126
127} // namespace sen::kernel
128
129#endif // SEN_KERNEL_SOURCE_INFO_H
User-facing kernel functions.
Definition component_api.h:103
SessionInfoProvider(std::string name, std::shared_ptr< impl::Session > session)
Definition source_info.h:99
friend class KernelApi
Definition source_info.h:113
~SessionsDiscoverer() override=default
std::shared_ptr< SessionInfoProvider > makeSessionInfoProvider(const std::string &sessionName)
void onSourceUndetected(const std::function< void(const std::string &)> &callback)
Sets a callback that will be invoked when sources are undetected. Replaces any previously-set callbac...
friend class SessionsDiscoverer
Definition source_info.h:55
std::vector< std::string > getDetectedSources() const
Name of the buses discovered so far.
virtual void drainInputs()
const std::string & getName() const noexcept
The name of the session.
virtual ~SourceInfo()=default
friend class impl::Runner
Definition source_info.h:56
SourceInfo(std::string name)
void removeSource(const std::string &name)
void onSourceDetected(const std::function< void(const std::string &)> &callback)
Sets a callback that will be invoked when sources are detected. The first time it will be called for ...
void addSource(const std::string &name)
Strong type for the unique identifier for a transport timer.
Definition native_object_impl.h:39
STL namespace.