Dante Application Library API
Loading...
Searching...
No Matches
Instance.hpp
1#pragma once
2
3#include "audinate/dal/DAL.hpp"
4#include "audinate/dal/Audio.hpp"
5#include "audinate/dal/InstanceConfig.hpp"
6
7#include <iostream>
8
9namespace Audinate { namespace DAL {
10
14enum class InstanceState
15{
16 // The DAL instance has been created but has not been started.
17 Stopped,
18
19 // The DAL instance is starting up
20 Starting,
21
22 // The DAL instance is running.
23 Running,
24
25 // The DAL instance is stopping
26 Stopping
27};
28
33std::string toString(InstanceState state);
34
39{
40public:
44 enum class Type
45 {
46 // An event indicating that the instance's state has changed
47 InstanceStateChanged,
48 // An event indicating that the status of one of the instance's child components has changed
49 ComponentStatusChanged,
50 // An event indicating that the domain enrolment info of the instance has changed
51 DomainInfoChanged,
52 // An event indicating that the device activation status has changed
53 DeviceActivationStatusChanged
54 };
55
60 Type getType() const { return mType; }
61
66 Component getComponent() const { return mComponent; }
67
68 // Set event information. For internal use only
69 void set(Type type, Component component) { mType = type; mComponent = component; }
70
71 // Set event information. For internal use only
72 void set(Type type) { mType = type; }
73
74private:
75 Type mType;
76 Component mComponent;
77};
78
82std::string toString(InstanceEvent::Type type);
83
84//----------------------------------------------------------
85// Instance Monitoring - regular rate callback providing current
86// system runtime state
87//----------------------------------------------------------
88
89typedef std::function<void(const InstanceEvent &)> InstanceEventFn;
90
91class MonitoringEvent
92{
93public:
94 class Timestamp
95 {
96 public:
97 Uint32 mSeconds;
98 Uint32 mNanoseconds;
99
100 Timestamp(Uint32 seconds, Uint32 nanoseconds) : mSeconds(seconds), mNanoseconds(nanoseconds) {}
101
102 bool operator==(const Timestamp & t) const { return mSeconds == t.mSeconds && mNanoseconds == t.mNanoseconds; }
103 bool operator!=(const Timestamp & t) const { return ! operator==(t); }
104 };
105
106 enum class Type
107 {
108 MaxControlThreadInterval,
109 MaxAudioThreadInterval,
110 LatePacketCount, // The number of late packets seen since the last monitoring event. Only valid in PTP mode
111 NonSequentialPacketCount, // The number of packets received that were not sequential w.r.t to the previous packet received for that packet's audio flows. Usually caused by missing / dropped packets
112
113 NumTypes // must be last...
114 };
115
116 MonitoringEvent(Timestamp timestamp) : mTimestamp(timestamp), mTypes(), mMaxControlThreadIntervalUs(), mMaxAudioThreadIntervalUs(), mLatePacketCount(), mNonSequentialPacketCount() { mTypes.resize(static_cast<size_t>(Type::NumTypes)); }
117 ~MonitoringEvent() {}
118
119 Timestamp getTimestamp() const { return mTimestamp; }
120
121 bool hasType(Type type) const { size_t index = static_cast<size_t>(type); return mTypes[index]; }
122 void setType(Type type) { size_t index = static_cast<size_t>(type); mTypes[index] = true; }
123
124
125 Uint32 getMaxControlThreadIntervalUs() const { return mMaxControlThreadIntervalUs; }
126 void setMaxControlThreadIntervalUs(Uint32 interval) { setType(Type::MaxControlThreadInterval); mMaxControlThreadIntervalUs = interval; }
127
128 Uint32 getMaxAudioThreadIntervalUs() const { return mMaxAudioThreadIntervalUs; }
129 void setMaxAudioThreadIntervalUs(Uint32 interval) { setType(Type::MaxAudioThreadInterval); mMaxAudioThreadIntervalUs = interval; }
130
131 Uint32 getLatePacketCount() const { return mLatePacketCount; }
132 void setLatePacketCount(Uint32 count) { setType(Type::LatePacketCount); mLatePacketCount = count; }
133
134 Uint32 getNonSequentialPacketCount() const { return mNonSequentialPacketCount; }
135 void setNonSequentialPacketCount(Uint32 count) { setType(Type::NonSequentialPacketCount); mNonSequentialPacketCount = count; }
136
137
138private:
139 Timestamp mTimestamp;
140 std::vector<bool> mTypes;
141 Uint32 mMaxControlThreadIntervalUs;
142 Uint32 mMaxAudioThreadIntervalUs;
143 Uint32 mLatePacketCount;
144 Uint32 mNonSequentialPacketCount;
145
146};
147
148typedef std::function<void(const MonitoringEvent &)> MonitoringEventFn;
149
153class DomainInfo
154{
155public:
156 DomainInfo() : mIsEnrolled(false), mDomainName("") {};
158 std::string mDomainName;
159};
160
164class Instance
165{
166protected:
167 Instance() {}
168 virtual ~Instance() {}
169
170public:
171
172 //------------------------------------------------------
173 // Instance Management
174 //------------------------------------------------------
175
180 virtual void setEventFn(InstanceEventFn fn) = 0;
181
186 virtual void start() = 0;
187
191 virtual void stop() = 0;
192
197 virtual InstanceState getInstanceState() const = 0;
198
205 virtual SocketDescriptor getProtocolSocketDescriptor(Protocol protocol) = 0;
206
211 virtual ComponentStatus getComponentStatus(Component component) = 0;
212
216 virtual void clearConfiguration() = 0;
217
221 virtual void clearDomainCredentials() = 0;
222
227 virtual std::shared_ptr<Audio> getAudio() = 0;
228
233 virtual void setMonitoringFn(MonitoringEventFn fn) = 0;
234
239 virtual DomainInfo getDomainInfo() const = 0;
240
245 virtual bool isDeviceActivated() const = 0;
246};
247
255std::shared_ptr<Instance> createInstance(std::shared_ptr<DAL> dal, const InstanceConfig & config);
256
257}; };
A class encapsulating the information about DAL Instance's domain enrolment.
Definition Instance.hpp:154
std::string mDomainName
Name of the managed Dante Domain.
Definition Instance.hpp:158
bool mIsEnrolled
Is the DAL device currently enrolled in a managed Dante Domain.
Definition Instance.hpp:157
Configuration for a DAL instance.
Definition InstanceConfig.hpp:17
A class encapsulating events that are propagated by a DAL Instance.
Definition Instance.hpp:39
Component getComponent() const
Get the component (if any) associated with this event.
Definition Instance.hpp:66
Type
An enumeration of the different kinds of events that can occur.
Definition Instance.hpp:45
Type getType() const
Get the event type for this event.
Definition Instance.hpp:60
virtual void setMonitoringFn(MonitoringEventFn fn)=0
Set monitoring events callback function.
virtual ComponentStatus getComponentStatus(Component component)=0
Get the current status for the given component.
virtual void clearConfiguration()=0
Delete the configuration files of the child processes.
virtual bool isDeviceActivated() const =0
Get the device activation status.
virtual InstanceState getInstanceState() const =0
Get the current instance state.
virtual void start()=0
Start the instance.
virtual SocketDescriptor getProtocolSocketDescriptor(Protocol protocol)=0
Get the socket descriptor number for a protocol server socket.
virtual void clearDomainCredentials()=0
Delete the domain information.
virtual std::shared_ptr< Audio > getAudio()=0
Get the audio component object associated with this instance object.
virtual void stop()=0
Stop the instance.
virtual void setEventFn(InstanceEventFn fn)=0
Set the instance event function for this instance object.
virtual DomainInfo getDomainInfo() const =0
Get the domain info.
Definition Instance.hpp:92
Definition Common.hpp:72