Sen API
Sen Libraries
Toggle main menu visibility
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
11
#include "
sen/core/obj/object_provider.h
"
12
#include "
sen/core/obj/object_source.h
"
13
14
namespace
sen::kernel
15
{
16
17
// forward declarations
18
class
KernelApi
;
19
20
namespace
impl
21
{
22
class
Session;
23
class
KernelImpl;
24
}
// namespace impl
25
26
// Forward declarations
27
class
SessionsDiscoverer
;
28
30
class
SourceInfo
31
{
32
public
:
33
SEN_NOCOPY_NOMOVE(
SourceInfo
)
34
35
public
:
36
virtual
~SourceInfo
() =
default
;
37
38
public
:
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
54
protected:
// 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
65
private:
66
void
remove(const
std
::
string
& elem,
std
::vector<
std
::
string
>& vec) const;
67
68
private:
69
using Mutex =
std
::recursive_mutex;
70
using Lock =
std
::scoped_lock<Mutex>;
71
72
private:
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
84
class
SessionInfoProvider
: public
SourceInfo
, public
std
::enable_shared_from_this<
SessionInfoProvider
>
85
{
86
public
:
87
SEN_NOCOPY_NOMOVE(
SessionInfoProvider
)
88
89
public
:
90
SessionInfoProvider
(std::string name, std::shared_ptr<impl::Session> session);
91
~SessionInfoProvider
()
override
;
92
93
private
:
94
friend
class
impl::Session;
95
std::shared_ptr<impl::Session> session_;
96
};
97
98
class
SessionsDiscoverer:
public
SourceInfo
,
public
std::enable_shared_from_this<SessionsDiscoverer>
99
{
100
public
:
101
SEN_NOCOPY_NOMOVE(SessionsDiscoverer)
102
103
public
:
104
~SessionsDiscoverer
()
override
=
default
;
105
106
public
:
107
[[nodiscard]] std::shared_ptr<SessionInfoProvider>
makeSessionInfoProvider
(
const
std::string& sessionName);
108
109
protected
:
110
void
drainInputs
()
override
;
111
112
private
:
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
121
private
:
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
sen::kernel::KernelApi
User-facing kernel functions.
Definition
component_api.h:114
sen::kernel::SessionInfoProvider::SessionInfoProvider
SessionInfoProvider(std::string name, std::shared_ptr< impl::Session > session)
sen::kernel::SessionInfoProvider::~SessionInfoProvider
~SessionInfoProvider() override
sen::kernel::SessionsDiscoverer
Definition
source_info.h:99
sen::kernel::SessionsDiscoverer::KernelApi
friend class KernelApi
Definition
source_info.h:113
sen::kernel::SessionsDiscoverer::~SessionsDiscoverer
~SessionsDiscoverer() override=default
sen::kernel::SessionsDiscoverer::drainInputs
void drainInputs() override
sen::kernel::SessionsDiscoverer::makeSessionInfoProvider
std::shared_ptr< SessionInfoProvider > makeSessionInfoProvider(const std::string &sessionName)
sen::kernel::SourceInfo::onSourceUndetected
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...
sen::kernel::SourceInfo::SessionsDiscoverer
friend class SessionsDiscoverer
Definition
source_info.h:55
sen::kernel::SourceInfo::getDetectedSources
std::vector< std::string > getDetectedSources() const
Name of the buses discovered so far.
sen::kernel::SourceInfo::drainInputs
virtual void drainInputs()
sen::kernel::SourceInfo::getName
const std::string & getName() const noexcept
The name of the session.
sen::kernel::SourceInfo::~SourceInfo
virtual ~SourceInfo()=default
sen::kernel::SourceInfo::Runner
friend class impl::Runner
Definition
source_info.h:56
sen::kernel::SourceInfo::unlock
void unlock()
sen::kernel::SourceInfo::SourceInfo
SourceInfo(std::string name)
sen::kernel::SourceInfo::removeSource
void removeSource(const std::string &name)
sen::kernel::SourceInfo::onSourceDetected
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 ...
sen::kernel::SourceInfo::addSource
void addSource(const std::string &name)
sen::kernel::SourceInfo::lock
void lock()
sen::kernel
Strong type for the unique identifier for a transport timer.
Definition
native_object_impl.h:39
std
STL namespace.
object_provider.h
object_source.h
libs
kernel
include
sen
kernel
source_info.h
Generated by
1.17.0