2021-06-02 09:21:01 -04:00
|
|
|
/*
|
|
|
|
sender.h
|
|
|
|
|
|
|
|
Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2021-08-25 10:57:31 -04:00
|
|
|
#include "rlp/component.h"
|
2021-06-20 09:12:14 -04:00
|
|
|
#include "universe.h"
|
2021-08-15 23:36:29 -04:00
|
|
|
|
2021-08-30 13:59:08 -04:00
|
|
|
#include <future>
|
2022-12-09 21:08:35 -05:00
|
|
|
#include <shared_mutex>
|
2021-06-20 09:12:14 -04:00
|
|
|
#include <unordered_map>
|
2021-08-30 13:59:08 -04:00
|
|
|
#include <thread>
|
|
|
|
|
2021-06-02 09:21:01 -04:00
|
|
|
|
2021-08-28 09:01:33 -04:00
|
|
|
namespace sACN {
|
2021-06-02 09:21:01 -04:00
|
|
|
|
2021-08-25 17:20:33 -04:00
|
|
|
/**
|
2021-08-28 09:01:33 -04:00
|
|
|
* @brief \cite sACN 3.5 Source: A stream of E1.31 Packets for a universe is
|
|
|
|
* said to be sent from a source.
|
|
|
|
*
|
2021-08-28 12:54:26 -04:00
|
|
|
* > A source is uniquely identified by a number in the header of the packet
|
|
|
|
* > (see field CID in Table 4-1). A source may output multiple streams of data,
|
|
|
|
* > each for a different universe. Also, multiple sources may output data for
|
|
|
|
* > a given universe.
|
2021-08-25 17:20:33 -04:00
|
|
|
*/
|
2021-06-02 09:21:01 -04:00
|
|
|
class Source
|
2021-08-25 10:57:31 -04:00
|
|
|
: public virtual ACN::RLP::Component
|
2021-06-02 09:21:01 -04:00
|
|
|
{
|
|
|
|
public:
|
2022-11-19 15:43:02 -05:00
|
|
|
Source(UUID::uuid = UUID::uuid(), std::string fctn = "OpenLCP sACN Source");
|
2021-08-30 13:59:08 -04:00
|
|
|
~Source();
|
|
|
|
|
2021-06-20 09:12:14 -04:00
|
|
|
virtual void create(const uint16_t);
|
|
|
|
virtual void terminate(const uint16_t);
|
2022-11-26 12:30:27 -05:00
|
|
|
|
2021-09-10 09:55:34 -04:00
|
|
|
std::shared_ptr<Universe> universe(const uint16_t);
|
2021-06-20 09:12:14 -04:00
|
|
|
|
2022-11-26 12:30:27 -05:00
|
|
|
// from ACN::Component
|
2022-11-24 11:35:25 -05:00
|
|
|
virtual void assignUserName(const std::string) override;
|
|
|
|
|
2021-06-20 09:35:56 -04:00
|
|
|
protected:
|
2021-08-30 13:32:20 -04:00
|
|
|
void sendExtendedFrame(const uint16_t vector,
|
2021-08-31 11:13:36 -04:00
|
|
|
std::shared_ptr<ACN::PDU::pdu_header> header,
|
|
|
|
std::shared_ptr<ACN::PDU::pdu_data> data,
|
2022-12-09 21:27:27 -05:00
|
|
|
const ACN::SDT::UDP::ipAddress&) const;
|
2021-08-30 13:32:20 -04:00
|
|
|
|
2021-06-20 09:12:14 -04:00
|
|
|
private:
|
2021-09-10 09:55:34 -04:00
|
|
|
std::unordered_map <uint16_t, std::shared_ptr<Universe>> universes_;
|
2022-12-09 21:08:35 -05:00
|
|
|
mutable std::shared_mutex mtx_universes_; //!< thread safety protection for universes_
|
2021-08-29 01:01:20 -04:00
|
|
|
|
2022-11-26 12:48:02 -05:00
|
|
|
/// > \cite sACN 12 Universe Discovery
|
|
|
|
/// >
|
|
|
|
/// > ... this specification requires any source intending to comply with
|
|
|
|
/// > E1.31 to implement Universe Discovery...
|
|
|
|
std::promise<void> discovery_exitSignal_; //!< signal the discovery worker thread to end
|
|
|
|
std::thread discovery_worker_; //!< thread responsible for sending discovery
|
2021-08-30 13:59:08 -04:00
|
|
|
void discovery_loop_();
|
2022-11-26 12:48:02 -05:00
|
|
|
void discovery_send_();
|
2021-06-02 09:21:01 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // SACN
|