2021-08-18 16:55:57 -04:00
|
|
|
/*
|
2021-08-24 18:10:20 -04:00
|
|
|
provenance.cpp
|
2021-08-18 16:55:57 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-08-24 18:10:20 -04:00
|
|
|
#include "provenance.h"
|
|
|
|
#include "rlp/rlp.h"
|
|
|
|
|
2021-08-27 12:09:19 -04:00
|
|
|
namespace sACN {
|
2021-08-18 16:55:57 -04:00
|
|
|
|
|
|
|
/**
|
2021-08-28 09:01:33 -04:00
|
|
|
* @brief default constructor
|
2021-08-18 16:55:57 -04:00
|
|
|
*/
|
2021-08-24 18:10:20 -04:00
|
|
|
Provenance::Provenance()
|
2021-08-27 12:09:19 -04:00
|
|
|
: cid(UUID::uuid())
|
|
|
|
, source_name(std::string())
|
|
|
|
, priority(100)
|
|
|
|
, sync_address(0)
|
|
|
|
, sequence_number(0)
|
|
|
|
, universe(0)
|
2021-08-24 18:10:20 -04:00
|
|
|
{}
|
2021-08-18 16:55:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-08-28 09:01:33 -04:00
|
|
|
* @brief Compile metadata from an sACN::DATA PDU
|
2021-08-24 18:10:20 -04:00
|
|
|
* @param pdu
|
2021-08-18 16:55:57 -04:00
|
|
|
*/
|
2021-08-27 12:09:19 -04:00
|
|
|
Provenance::Provenance(ACN::PDU::Message<DATA::Pdu> pdu)
|
2021-08-24 18:10:20 -04:00
|
|
|
{
|
|
|
|
auto root_header = static_cast<ACN::RLP::rlp_header*>(pdu->parent()->header());
|
|
|
|
auto frame_header = static_cast<DATA::data_header*>(pdu->header());
|
2021-08-18 16:55:57 -04:00
|
|
|
|
2021-08-27 12:09:19 -04:00
|
|
|
cid = root_header->cid;
|
|
|
|
source_name = frame_header->source_name;
|
|
|
|
universe = frame_header->universe;
|
|
|
|
priority = frame_header->priority;
|
|
|
|
sync_address = frame_header->sync_address;
|
|
|
|
sequence_number = frame_header->sequence_number;
|
|
|
|
options = frame_header->options;
|
2021-08-24 18:10:20 -04:00
|
|
|
};
|
2021-08-18 16:55:57 -04:00
|
|
|
|
|
|
|
|
2021-08-25 17:20:33 -04:00
|
|
|
/**
|
2021-08-27 12:09:19 -04:00
|
|
|
* @brief Metadata is equivalent if the CID, Priority, and Universe match.
|
2021-08-24 18:10:20 -04:00
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @return
|
2021-08-18 16:55:57 -04:00
|
|
|
*/
|
2021-08-24 18:10:20 -04:00
|
|
|
bool operator== (const Provenance& a, const Provenance& b)
|
|
|
|
{
|
2021-08-27 12:09:19 -04:00
|
|
|
return (a.cid == b.cid &&
|
|
|
|
a.priority == b.priority &&
|
|
|
|
a.universe == b.universe);
|
2021-08-18 16:55:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-25 17:20:33 -04:00
|
|
|
/**
|
2021-08-27 12:09:19 -04:00
|
|
|
* @brief For matching universe numbers, lower priorities are lesser.
|
2021-08-25 17:20:33 -04:00
|
|
|
* @param a
|
2021-08-27 12:09:19 -04:00
|
|
|
* @param b
|
|
|
|
* @return
|
2021-08-25 17:20:33 -04:00
|
|
|
*/
|
2021-08-27 12:09:19 -04:00
|
|
|
bool operator< (const Provenance& a, const Provenance& b)
|
2021-08-25 17:20:33 -04:00
|
|
|
{
|
2021-08-27 12:09:19 -04:00
|
|
|
return (a.universe == b.universe &&
|
|
|
|
a.priority < b.priority);
|
2021-08-25 17:20:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-08-27 12:09:19 -04:00
|
|
|
* @brief For matching universe numbers, higher priorities are greater.
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @return
|
2021-08-25 17:20:33 -04:00
|
|
|
*/
|
2021-08-27 12:09:19 -04:00
|
|
|
bool operator> (const Provenance& a, const Provenance& b)
|
2021-08-25 17:20:33 -04:00
|
|
|
{
|
2021-08-27 12:09:19 -04:00
|
|
|
return (a.universe == b.universe &&
|
|
|
|
a.priority > b.priority);
|
2021-08-25 17:20:33 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 16:55:57 -04:00
|
|
|
|
2021-08-24 18:10:20 -04:00
|
|
|
} // namespace SACN
|