/* sdt.cpp 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. */ #include "sdt.h" namespace ACN { namespace SDT { params_t::params_t(PDU::Stream stream) { Expiry = stream->readType(); auto packed = stream->readType(); NAK_Outbound = packed >> 7; reserved = packed & 0xef; NAKholdoff = stream->readType(); NAKmodulus = stream->readType(); NAKmaxwait = stream->readType(); } join_data_t::join_data_t(PDU::Stream stream) { mid = stream->readType(); number = stream->readType(); reciprocal = stream->readType(); sequence = stream->readType(); reliable = stream->readType(); destination = UDP::address_t(stream); parameters = params_t(stream); expiry = stream->readType(); } join_accept_data_t::join_accept_data_t(PDU::Stream stream) { uint8_t buf[16]; stream->read(buf, sizeof(buf)); leader = UUID::uuid(buf); number = stream->readType(); mid = stream->readType(); reliable = stream->readType(); reciprocal = stream->readType(); } join_refuse_data_t::join_refuse_data_t(PDU::Stream stream) { uint8_t buf[16]; stream->read(buf, sizeof(buf)); leader = UUID::uuid(buf); number = stream->readType(); mid = stream->readType(); reliable = stream->readType(); code = stream->readType(); } nak_data_t::nak_data_t(PDU::Stream stream) { uint8_t buf[16]; stream->read(buf, sizeof(buf)); leader = UUID::uuid(buf); number = stream->readType(); mid = stream->readType(); reliable = stream->readType(); missed_first = stream->readType(); missed_last = stream->readType(); } wrapper_data_t::wrapper_data_t(PDU::Stream stream) { number = stream->readType(); } /** compare to another sessionID */ bool SessionId::operator== (const SessionId & other) const { return ((other.cid == cid) & (other.number == number) & (other.protocol == protocol)); } /** Constuct a sequenced channel with an owner and a direction. @param owner the owner of the channel @param direction the direction of channel communication */ Channel::Channel(std::shared_ptr owner, Direction direction) { owner_ = owner; direction_ = direction; } /** deconstructor that closes the channel cleanly. */ Channel::~Channel() { // TODO: close the channel. } /** Construct a new session. */ Session::Session() { } /** deconstructor that leaves the session gracefully. */ Session::~Session() { // TODO: Disconnect the session. } /** get the ID of the session */ SessionId Session::id() { SessionId ret; ret.cid = leader->cid(); ret.number = number_; ret.protocol = protocol_; return ret; } Pdu::Pdu(PDU::Stream stream) : PDU::Pdu(stream, 1) // vectors are 1 octet { // if (stream->fail()) return; // if (!buffer_->good()) return; } client_pdu_header_t::client_pdu_header_t(PDU::Stream stream) { protocol = stream->readType(); association = stream->readType(); } ClientPdu::ClientPdu(PDU::Stream stream) : PDU::Pdu(stream, 2) // vectors are 2 octets (MID) { if (stream->fail()) return; if (!stream_->good()) return; if (flags_.hasHeader) setHeader(new client_pdu_header_t(stream_)); } }; // SDT }; // ACN