1
0
Fork 0
OpenLCP/protocol/acn/component.h

105 lines
3.4 KiB
C++

/*
component.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
#include "uuid.h"
#include <string>
/**
* @brief @cite ACN Architecture for Control Networks
*/
namespace ACN {
/**
* @brief The process, program or application corresponding to a single ACN endpoint.
*
* All messages in ACN are sent and received by a component.
* See @cite ACN [Arch] for a more complete definition.
*
* @cite epi19 **EPI 19: ACN Discovery on IP Networks**
*
* (3) Component Name Strings
* Each component shall maintain two text identifier strings intended to
* indicate the function of the component in human readable terms for
* browsing purposes.
*/
class Component {
public:
/**
* @brief Component
* @param cid
* @param fctn
*/
Component(UUID::uuid cid = UUID::uuid(), std::string fctn = "OpenLCP ACN Component")
: cid_(cid)
, fctn_(fctn)
, uacn_(std::string())
{};
/**
* @brief Component Identifier
* @return the CID
*
* @cite ACN 1.2.3: In ACN each distinct endpoint transmitting and receiving ACN data is called a
* Component and all ACN communications take place between components. Each ACN component has a
* component identifier or CID which is unique not just within the system but across the whole
* world and does not change with time.
*/
const UUID::uuid cid() const { return cid_; }
/**
* @brief @cite epi19 3.1 Fixed Component Type Name (FCTN)
* @return the FCTN
*
* Shall be a UTF-8 string that is assigned during manufacture.
*/
const std::string fixedName() const { return fctn_; }
/**
* @brief @cite epi19 3.2 User Assigned Component Name (UACN)
* @return the UACN
*
* Shall be a UTF-8 string that may be assigned by the user.
*/
const std::string userName() const { return uacn_; }
/**
* @brief Component Name, either User Asigned or Fixed.
* @return a name
*/
const std::string name() const { return uacn_.empty() ? fctn_ : uacn_; }
/**
* @brief Set the User Asigned Component Name (UACN).
* @param s UACN Name string
*
* If not an empty string, will be prefered over the FCTN.
*/
virtual void assignUserName(const std::string s) { uacn_ = s; }
private:
const UUID::uuid cid_;
const std::string fctn_; //!< Fixed Component Type Name (FCTN)
std::string uacn_; //!< User Assigned Component Name (UACN)
};
}; // ACN