Dante Application Library API
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 
9 namespace Audinate { namespace DAL {
10 
14 enum 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 
33 std::string toString(InstanceState state);
34 
39 {
40 public:
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 
74 private:
75  Type mType;
76  Component mComponent;
77 };
78 
82 std::string toString(InstanceEvent::Type type);
83 
84 //----------------------------------------------------------
85 // Instance Monitoring - regular rate callback providing current
86 // system runtime state
87 //----------------------------------------------------------
88 
89 typedef std::function<void(const InstanceEvent &)> InstanceEventFn;
90 
92 {
93 public:
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 
138 private:
139  Timestamp mTimestamp;
140  std::vector<bool> mTypes;
141  Uint32 mMaxControlThreadIntervalUs;
142  Uint32 mMaxAudioThreadIntervalUs;
143  Uint32 mLatePacketCount;
144  Uint32 mNonSequentialPacketCount;
145 
146 };
147 
148 typedef std::function<void(const MonitoringEvent &)> MonitoringEventFn;
149 
154 {
155 public:
156  DomainInfo() : mIsEnrolled(false), mDomainName("") {};
157  bool mIsEnrolled;
158  std::string mDomainName;
159 };
160 
164 class Instance
165 {
166 protected:
167  Instance() {}
168  virtual ~Instance() {}
169 
170 public:
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 
255 std::shared_ptr<Instance> createInstance(std::shared_ptr<DAL> dal, const InstanceConfig & config);
256 
257 }; };
Audinate::DAL::DomainInfo
A class encapsulating the information about DAL Instance's domain enrolment.
Definition: Instance.hpp:153
Audinate::DAL::DomainInfo::mIsEnrolled
bool mIsEnrolled
Is the DAL device currently enrolled in a managed Dante Domain.
Definition: Instance.hpp:156
Audinate::DAL::InstanceEvent
A class encapsulating events that are propagated by a DAL Instance.
Definition: Instance.hpp:38
Audinate::DAL::Instance::getDomainInfo
virtual DomainInfo getDomainInfo() const =0
Get the domain info.
Audinate::DAL::SocketDescriptor
Definition: Common.hpp:71
Audinate::DAL::MonitoringEvent
Definition: Instance.hpp:91
Audinate::DAL::InstanceConfig
Configuration for an DAL instance.
Definition: InstanceConfig.hpp:16
Audinate::DAL::MonitoringEvent::Timestamp
Definition: Instance.hpp:94
Audinate::DAL::Instance::start
virtual void start()=0
Start the instance.
Audinate::DAL::Instance::clearDomainCredentials
virtual void clearDomainCredentials()=0
Delete the domain information.
Audinate::DAL::Instance::getInstanceState
virtual InstanceState getInstanceState() const =0
Get the current instance state.
Audinate::DAL::Instance::setMonitoringFn
virtual void setMonitoringFn(MonitoringEventFn fn)=0
Set monitoring events callback function.
Audinate::DAL::Instance::setEventFn
virtual void setEventFn(InstanceEventFn fn)=0
Set the instance event function for this instance object.
Audinate::DAL::Instance
A class encapsulating the DAL Instance.
Definition: Instance.hpp:164
Audinate::DAL::Instance::getComponentStatus
virtual ComponentStatus getComponentStatus(Component component)=0
Get the current status for the given component.
Audinate::DAL::Instance::clearConfiguration
virtual void clearConfiguration()=0
Delete the configuration files of the child processes.
Audinate::DAL::Instance::getProtocolSocketDescriptor
virtual SocketDescriptor getProtocolSocketDescriptor(Protocol protocol)=0
Get the socket descriptor number for a protocol server socket.
Audinate::DAL::Instance::isDeviceActivated
virtual bool isDeviceActivated() const =0
Get the device activation status.
Audinate::DAL::DomainInfo::mDomainName
std::string mDomainName
Name of the managed Dante Domain.
Definition: Instance.hpp:158
Audinate::DAL::InstanceEvent::getType
Type getType() const
Get the event type for this event.
Definition: Instance.hpp:60
Audinate::DAL::Instance::getAudio
virtual std::shared_ptr< Audio > getAudio()=0
Get the audio component object associated with this instance object.
Audinate::DAL::InstanceEvent::getComponent
Component getComponent() const
Get the component (if any) associated with this event.
Definition: Instance.hpp:66
Audinate::DAL::InstanceEvent::Type
Type
An enumeration of the different kinds of events that can occur.
Definition: Instance.hpp:44
Audinate::DAL::Instance::stop
virtual void stop()=0
Stop the instance.