1
0
Fork 0

documenaton churn

This commit is contained in:
Kevin Matz 2021-07-26 22:47:25 -04:00
parent 0cb3c72226
commit 42022baecf
3 changed files with 113 additions and 68 deletions

View File

@ -32,6 +32,10 @@
namespace ACN {
/**
* @brief Appliance::Appliance
* @param cid
*/
Appliance::Appliance(UUID::uuid cid)
: Component(cid)
{
@ -45,9 +49,13 @@ Appliance::Appliance(UUID::uuid cid)
/**
EPI 17
*/
void Appliance::UdpStreamHandler(PDU::Stream stream) {
* @brief Appliance::UdpStreamHandler
* @param stream
*
* EPI 17
*/
void Appliance::UdpStreamHandler(PDU::Stream stream)
{
// verify the UDP preamble
RLP::UDP::preamble_t preamble(stream);
@ -60,9 +68,9 @@ void Appliance::UdpStreamHandler(PDU::Stream stream) {
// octets in the preamble or postamble.
for(int i = RLP::UDP::PREAMBLE_MINIMUM_SIZE; i < preamble.length; i++)
stream->readType<uint8_t>();
if (!stream->good())
return;
auto block = PDU::readBlock<RLP::Pdu>(stream);
if (stream->fail())
return;
@ -74,9 +82,13 @@ void Appliance::UdpStreamHandler(PDU::Stream stream) {
/**
EPI 33
*/
void Appliance::TcpStreamHandler(PDU::Stream stream) {
* @brief Appliance::TcpStreamHandler
* @param stream
*
* EPI 33
*/
void Appliance::TcpStreamHandler(PDU::Stream stream)
{
// verify the TCP preamble
RLP::TCP::preamble_t preamble(stream);
@ -84,69 +96,87 @@ void Appliance::TcpStreamHandler(PDU::Stream stream) {
// Identifier is not correct the receiver shall close the connection.
if (!preamble)
stream->setstate(std::ios_base::failbit);
if (!stream->good())
return;
auto block = PDU::readBlock<RLP::Pdu>(stream);
if (stream->fail())
return;
for(auto const &root : *block) {
for(auto const &root : *block)
RlpReceiver(root);
}
}
/**
Dispatch a recieved RLP PDU to the appropriate vector handlers.
*/
void Appliance::RlpReceiver(std::shared_ptr<RLP::Pdu> root) {
* @brief Appliance::RlpReceiver
* @param root
*
* Dispatch a recieved RLP PDU to the appropriate vector handlers.
*/
void Appliance::RlpReceiver(std::shared_ptr<RLP::Pdu> root)
{
if (!rlp_vectors_.count(root->vector()))
return;
for(auto const &handler : rlp_vectors_[root->vector()]) {
for(auto const &handler : rlp_vectors_[root->vector()])
handler(root);
}
}
/**
Add callback handler for a given RLP vector.
*/
* @brief Appliance::registerRlpVectorHandler
* @param vect
* @param handle
*
* Add callback handler for a given RLP vector.
*/
void Appliance::registerRlpVectorHandler(uint32_t vect,
PDU::Handler<RLP::Pdu> handle) {
PDU::Handler<RLP::Pdu> handle)
{
rlp_vectors_[vect].push_back(handle);
}
/**
Deregister RLP protocol handlers for the given vector.
*/
void Appliance::deregisterRlpVector(uint32_t vect) {
* @brief Appliance::deregisterRlpVector
* @param vect
*
* Deregister RLP protocol handlers for the given vector.
*/
void Appliance::deregisterRlpVector(uint32_t vect)
{
rlp_vectors_.erase(vect);
}
/**
Deregister _ALL_ RLP protocol handlers.
*/
void Appliance::deregisterRlpVector() {
* @brief Appliance::deregisterRlpVector
*
* Deregister _ALL_ RLP protocol handlers.
*/
void Appliance::deregisterRlpVector()
{
rlp_vectors_.clear();
}
/**
*/
void Appliance::rootSdtHandler(std::shared_ptr<RLP::Pdu> rlp) {
* @brief Appliance::rootSdtHandler
* @param rlp
*/
void Appliance::rootSdtHandler(std::shared_ptr<RLP::Pdu> rlp)
{
/// TODO: handle SDT
}
/**
*/
void Appliance::rootDmpHandler(std::shared_ptr<RLP::Pdu> rlp) {
* @brief Appliance::rootDmpHandler
* @param rlp
*/
void Appliance::rootDmpHandler(std::shared_ptr<RLP::Pdu> rlp)
{
/// TODO: DMP in root
}
}; // ACN

View File

@ -22,17 +22,16 @@
SOFTWARE.
*/
#pragma once
#include <memory>
#include <iostream>
namespace ACN {
namespace PDU {
/**
Input/Output stream of nested PDU
*/
* @brief Input/Output stream of nested PDU
*/
class pdu_stream
: private std::basic_streambuf<uint8_t>
, public std::basic_iostream<uint8_t>
@ -45,8 +44,10 @@ public:
setg(p, p, p + l);
setp(p, p + l);
}
uint32_t available() { return in_avail(); }
uint8_t * data() { return gptr(); };
pdu_stream& operator>> (uint8_t& val);
pdu_stream& operator>> (uint16_t& val);
pdu_stream& operator>> (uint32_t& val);
@ -55,6 +56,7 @@ public:
pdu_stream& operator<< (const uint16_t& val);
pdu_stream& operator<< (const uint32_t& val);
pdu_stream& operator<< (const uint64_t& val);
template<typename T> T readType()
{
if (in_avail() < sizeof(T)) {
@ -69,6 +71,7 @@ public:
setstate(std::ios_base::eofbit);
return ret;
}
template<typename T> void writeType (const T& val)
{
auto data = reinterpret_cast<const uint8_t*>(&val);
@ -76,6 +79,7 @@ public:
put(data[i]);
}
};
using Stream = std::shared_ptr<pdu_stream>;

View File

@ -23,7 +23,6 @@
*/
#pragma once
#include <cstdint>
#include <functional>
#include <memory>
#include <vector>
@ -32,15 +31,14 @@
namespace ACN {
namespace PDU {
using std::uint8_t;
using std::uint16_t;
using std::uint32_t;
using std::vector;
using std::shared_ptr;
// 2.4.1. Flags
// Flags is a 4-bit field containing flags L, V, H and D which declare how the PDU is packed.
struct pdu_flags {
/**
* @brief 2.4.1. Flags
*
* Flags is a 4-bit field containing flags L, V, H and D which declare how
* the PDU is packed.
*/
struct pdu_flags
{
bool hasLength : 1;
bool hasVector : 1;
bool hasHeader : 1;
@ -48,24 +46,36 @@ struct pdu_flags {
pdu_flags(uint8_t);
};
// MAYBE: remove virtuals?
// Arduino doen't enable RTTI for run-time polymorphism.
struct pdu_header { virtual ~pdu_header() {} };
struct pdu_data { virtual ~pdu_data() {} };
/**
* @brief The pdu_header struct
*/
struct pdu_header
{
virtual ~pdu_header() {}
};
/**
Base class PDU
* @brief The pdu_data struct
*/
struct pdu_data
{
virtual ~pdu_data() {}
};
All PDU share common structure of:
flags, length, vector,
and protocol specific header/data.
Flag values indicate if lenght, vector, header or data
are present in the PDU, or if they should be inherited from the
preceding PDU.
*/
/**
* @brief The Pdu class
*
* All PDU share common structure of:
* flags, length, vector,
* and protocol specific header/data.
*
* Flag values indicate if lenght, vector, header or data
* are present in the PDU, or if they should be inherited from the
* preceding PDU.
*/
class Pdu {
public:
Pdu(Stream, size_t vector_size);
@ -77,19 +87,19 @@ public:
const uint32_t vector(); // may inherit
pdu_header * header(); // may inherit
pdu_data * data(); // may inherit
shared_ptr<Pdu> parent() {return parent_;}
std::shared_ptr<Pdu> parent() {return parent_;}
Stream stream() {return stream_;}
// setters
void setParent (shared_ptr<Pdu> pdu) {parent_ = pdu;}
void setInherit(shared_ptr<Pdu> pdu) {inherit_ = pdu;}
void setParent (std::shared_ptr<Pdu> pdu) {parent_ = pdu;}
void setInherit(std::shared_ptr<Pdu> pdu) {inherit_ = pdu;}
protected:
pdu_flags flags_;
uint32_t length_;
uint32_t vector_;
shared_ptr<Pdu> parent_;
shared_ptr<Pdu> inherit_;
std::shared_ptr<Pdu> parent_;
std::shared_ptr<Pdu> inherit_;
Stream stream_;
// private setters
@ -104,23 +114,24 @@ private:
void readVector(uint8_t);
};
template <typename T>
using Handler = std::function<void(std::shared_ptr<T>)>;
template <typename T>
using Block = std::shared_ptr<std::vector<std::shared_ptr<T>>>;
/**
Template creator of a PDU Block.
/**
@brief Template creator of a PDU Block.
@param std::shared_ptr<PDU::pdu_stream> The stream to read from.
@return std::shared_ptr<std::vector<std::shared_ptr<T>>> A block of PDU
*/
template<typename T>
Block<T> readBlock(Stream buffer, shared_ptr<PDU::Pdu> parent = nullptr) {
auto block = Block<T>(new vector<shared_ptr<T>>);
Block<T> readBlock(Stream buffer, std::shared_ptr<PDU::Pdu> parent = nullptr) {
auto block = Block<T>(new std::vector<std::shared_ptr<T>>);
while(buffer->good()) {
shared_ptr<T> pdu(new T(buffer));
std::shared_ptr<T> pdu(new T(buffer));
if (buffer->fail()) // stream failed during pdu constructor
break;
if (pdu->stream()->fail()) // pdu buffer errors