mirror of
https://github.com/Telecominfraproject/oopt-tai-implementations.git
synced 2025-10-29 17:22:39 +00:00
mux: add mux custom attributes
Signed-off-by: Wataru Ishida <ishida@nel-america.com>
This commit is contained in:
committed by
Wataru Ishida
parent
31658b2d44
commit
2f2590ee66
@@ -34,13 +34,17 @@ HEADERS := $(wildcard *.hpp $(TAI_LIB_DIR)/*.hpp $(TAI_FRAMEWORK_DIR)/*.hpp)
|
||||
OBJECTS := $(addprefix $(BUILDDIR)/,$(SOURCES:%.cpp=%.o))
|
||||
DEPS := $(addprefix $(BUILDDIR)/,$(SOURCES:%.cpp=%.d))
|
||||
|
||||
.PHONY = all meta test cmd docker docker-image bash clean clean-all
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
$(PROG): $(TAI_META_LIBRARY) $(OBJECTS) $(HEADERS)
|
||||
$(CXX) $(CFLAGS) $(INCLUDES) -shared $(OBJECTS) -o $@ -ldl -lpthread -L $(dir $(TAI_META_LIBRARY)) -lmetatai
|
||||
|
||||
$(TAI_META_LIBRARY):
|
||||
$(MAKE) -C $(@D)
|
||||
$(TAI_META_LIBRARY): $(wildcard custom_attrs/*)
|
||||
TAI_META_CUSTOM_FILES="$(abspath $(wildcard custom_attrs/*))" $(MAKE) -C $(@D)
|
||||
|
||||
meta: $(TAI_META_LIBRARY)
|
||||
|
||||
$(BUILDDIR)/%.o: %.cpp Makefile
|
||||
mkdir -p $(@D)
|
||||
|
||||
18
tai_mux/custom_attrs/mux_hostif.h
Normal file
18
tai_mux/custom_attrs/mux_hostif.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __TAI_MUX_HOSTIF__
|
||||
#define __TAI_MUX_HOSTIF__
|
||||
|
||||
#include <tai.h>
|
||||
|
||||
typedef enum _mux_host_interface_attr_t
|
||||
{
|
||||
/**
|
||||
* @brief The real OID
|
||||
*
|
||||
* @type #tai_object_id_t
|
||||
* @flags READ_ONLY
|
||||
*/
|
||||
TAI_HOST_INTERFACE_ATTR_MUX_REAL_OID = TAI_HOST_INTERFACE_ATTR_CUSTOM_MUX_START,
|
||||
|
||||
} mux_host_interface_attr_t;
|
||||
|
||||
#endif
|
||||
41
tai_mux/custom_attrs/mux_module.h
Normal file
41
tai_mux/custom_attrs/mux_module.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef __TAI_MUX_MODULE__
|
||||
#define __TAI_MUX_MODULE__
|
||||
|
||||
#include <tai.h>
|
||||
|
||||
typedef enum _tai_mux_platform_adapter_type_t
|
||||
{
|
||||
TAI_MUX_PLATFORM_ADAPTER_TYPE_UNKNOWN,
|
||||
TAI_MUX_PLATFORM_ADAPTER_TYPE_STATIC,
|
||||
TAI_MUX_PLATFORM_ADAPTER_TYPE_MAX,
|
||||
} tai_mux_platform_adapter_type_t;
|
||||
|
||||
typedef enum _mux_module_attr_t
|
||||
{
|
||||
/**
|
||||
* @brief The platform adapter type
|
||||
*
|
||||
* @type #tai_mux_platform_adapter_type_t
|
||||
* @flags READ_ONLY
|
||||
*/
|
||||
TAI_MODULE_ATTR_MUX_PLATFORM_ADAPTER_TYPE = TAI_MODULE_ATTR_CUSTOM_MUX_START,
|
||||
|
||||
/**
|
||||
* @brief The loaded TAI library
|
||||
*
|
||||
* @type #tai_char_list_t
|
||||
* @flags READ_ONLY
|
||||
*/
|
||||
TAI_MODULE_ATTR_MUX_CURRENT_LOADED_TAI_LIBRARY,
|
||||
|
||||
/**
|
||||
* @brief The real OID
|
||||
*
|
||||
* @type #tai_object_id_t
|
||||
* @flags READ_ONLY
|
||||
*/
|
||||
TAI_MODULE_ATTR_MUX_REAL_OID,
|
||||
|
||||
} mux_module_attr_t;
|
||||
|
||||
#endif
|
||||
18
tai_mux/custom_attrs/mux_netif.h
Normal file
18
tai_mux/custom_attrs/mux_netif.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __TAI_MUX_NETWORKIF__
|
||||
#define __TAI_MUX_NETWORKIF__
|
||||
|
||||
#include <tai.h>
|
||||
|
||||
typedef enum _mux_network_interface_attr_t
|
||||
{
|
||||
/**
|
||||
* @brief The real OID
|
||||
*
|
||||
* @type #tai_object_id_t
|
||||
* @flags READ_ONLY
|
||||
*/
|
||||
TAI_NETWORK_INTERFACE_ATTR_MUX_REAL_OID = TAI_NETWORK_INTERFACE_ATTR_CUSTOM_MUX_START,
|
||||
|
||||
} mux_network_interface_attr_t;
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,10 @@ namespace tai::mux {
|
||||
~ModuleAdapter();
|
||||
static uint64_t dl_address(const std::string& name);
|
||||
|
||||
std::string name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
tai_status_t tai_api_initialize(uint64_t flags, const tai_service_method_table_t* services) {
|
||||
return m_tai_api_initialize(flags, services);
|
||||
}
|
||||
@@ -192,7 +196,7 @@ namespace tai::mux {
|
||||
|
||||
private:
|
||||
void* m_dl;
|
||||
const std::string& m_name;
|
||||
const std::string m_name;
|
||||
tai_api_initialize_fn m_tai_api_initialize;
|
||||
tai_api_uninitialize_fn m_tai_api_uninitialize;
|
||||
tai_api_query_fn m_tai_api_query;
|
||||
|
||||
@@ -32,12 +32,12 @@ namespace tai::mux {
|
||||
} else {
|
||||
pa_name = std::string(pa);
|
||||
}
|
||||
platform_adapter_t pa_kind;
|
||||
tai_mux_platform_adapter_type_t pa_type;
|
||||
if ( pa_name == "static" ) {
|
||||
pa_kind = PLATFORM_ADAPTER_STATIC;
|
||||
pa_type = TAI_MUX_PLATFORM_ADAPTER_TYPE_STATIC;
|
||||
}
|
||||
switch ( pa_kind ) {
|
||||
case PLATFORM_ADAPTER_STATIC:
|
||||
switch ( pa_type ) {
|
||||
case TAI_MUX_PLATFORM_ADAPTER_TYPE_STATIC:
|
||||
m_pa = std::make_shared<StaticPlatformAdapter>(0, services);
|
||||
break;
|
||||
default:
|
||||
@@ -172,7 +172,30 @@ namespace tai::mux {
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
template <> const AttributeInfoMap<TAI_OBJECT_TYPE_MODULE> Config<TAI_OBJECT_TYPE_MODULE>::m_info {};
|
||||
tai_status_t attribute_getter(tai_attribute_t* const attribute, void* user) {
|
||||
auto ctx = reinterpret_cast<context*>(user);
|
||||
auto pa = ctx->pa;
|
||||
return pa->get_mux_attribute(ctx->type, ctx->oid, attribute);
|
||||
}
|
||||
|
||||
tai_status_t attribute_setter(const tai_attribute_t* const attribute, FSMState* state, void* user) {
|
||||
auto ctx = reinterpret_cast<context*>(user);
|
||||
auto pa = ctx->pa;
|
||||
return pa->set_mux_attribute(ctx->type, ctx->oid, attribute, state);
|
||||
}
|
||||
|
||||
using M = AttributeInfo<TAI_OBJECT_TYPE_MODULE>;
|
||||
using N = AttributeInfo<TAI_OBJECT_TYPE_NETWORKIF>;
|
||||
using H = AttributeInfo<TAI_OBJECT_TYPE_HOSTIF>;
|
||||
|
||||
template <> const AttributeInfoMap<TAI_OBJECT_TYPE_MODULE> Config<TAI_OBJECT_TYPE_MODULE>::m_info {
|
||||
mux::M(TAI_MODULE_ATTR_MUX_PLATFORM_ADAPTER_TYPE)
|
||||
.set_getter(&mux::attribute_getter),
|
||||
mux::M(TAI_MODULE_ATTR_MUX_CURRENT_LOADED_TAI_LIBRARY)
|
||||
.set_getter(&mux::attribute_getter),
|
||||
mux::M(TAI_MODULE_ATTR_MUX_REAL_OID)
|
||||
.set_getter(&mux::attribute_getter),
|
||||
};
|
||||
|
||||
Module::Module(uint32_t count, const tai_attribute_t *list, S_PlatformAdapter platform) : Object(platform) {
|
||||
auto mod_addr = find_attribute_in_list(TAI_MODULE_ATTR_LOCATION, count, list);
|
||||
@@ -180,7 +203,7 @@ namespace tai::mux {
|
||||
throw Exception(TAI_STATUS_MANDATORY_ATTRIBUTE_MISSING);
|
||||
}
|
||||
const std::string location(mod_addr->charlist.list, mod_addr->charlist.count);
|
||||
auto adapter = m_pa->get_module_adapter(location);
|
||||
auto adapter = m_context.pa->get_module_adapter(location);
|
||||
if ( adapter == nullptr ) {
|
||||
throw Exception(TAI_STATUS_FAILURE);
|
||||
}
|
||||
@@ -189,12 +212,16 @@ namespace tai::mux {
|
||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||
throw Exception(ret);
|
||||
}
|
||||
if ( platform->create_mapping(&m_id, m_adapter, m_real_id) != 0 ) {
|
||||
if ( platform->create_mapping(&m_context.oid, m_adapter, m_real_id) != 0 ) {
|
||||
throw Exception(TAI_STATUS_FAILURE);
|
||||
}
|
||||
m_context.type = TAI_OBJECT_TYPE_MODULE;
|
||||
}
|
||||
|
||||
template <> const AttributeInfoMap<TAI_OBJECT_TYPE_NETWORKIF> Config<TAI_OBJECT_TYPE_NETWORKIF>::m_info {};
|
||||
template <> const AttributeInfoMap<TAI_OBJECT_TYPE_NETWORKIF> Config<TAI_OBJECT_TYPE_NETWORKIF>::m_info {
|
||||
mux::N(TAI_NETWORK_INTERFACE_ATTR_MUX_REAL_OID)
|
||||
.set_getter(&mux::attribute_getter),
|
||||
};
|
||||
|
||||
NetIf::NetIf(S_Module module, uint32_t count, const tai_attribute_t *list, S_PlatformAdapter platform) : m_module(module), Object(platform) {
|
||||
m_adapter = module->adapter();
|
||||
@@ -205,12 +232,16 @@ namespace tai::mux {
|
||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||
throw Exception(ret);
|
||||
}
|
||||
if ( platform->create_mapping(&m_id, m_adapter, m_real_id) != 0 ) {
|
||||
if ( platform->create_mapping(&m_context.oid, m_adapter, m_real_id) != 0 ) {
|
||||
throw Exception(TAI_STATUS_FAILURE);
|
||||
}
|
||||
m_context.type = TAI_OBJECT_TYPE_NETWORKIF;
|
||||
}
|
||||
|
||||
template <> const AttributeInfoMap<TAI_OBJECT_TYPE_HOSTIF> Config<TAI_OBJECT_TYPE_HOSTIF>::m_info {};
|
||||
template <> const AttributeInfoMap<TAI_OBJECT_TYPE_HOSTIF> Config<TAI_OBJECT_TYPE_HOSTIF>::m_info {
|
||||
mux::H(TAI_HOST_INTERFACE_ATTR_MUX_REAL_OID)
|
||||
.set_getter(&mux::attribute_getter),
|
||||
};
|
||||
|
||||
HostIf::HostIf(S_Module module, uint32_t count, const tai_attribute_t *list, S_PlatformAdapter platform) : m_module(module), Object(platform) {
|
||||
m_adapter = module->adapter();
|
||||
@@ -221,8 +252,9 @@ namespace tai::mux {
|
||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||
throw Exception(ret);
|
||||
}
|
||||
if ( platform->create_mapping(&m_id, m_adapter, m_real_id) != 0 ) {
|
||||
if ( platform->create_mapping(&m_context.oid, m_adapter, m_real_id) != 0 ) {
|
||||
throw Exception(TAI_STATUS_FAILURE);
|
||||
}
|
||||
m_context.type = TAI_OBJECT_TYPE_HOSTIF;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -38,15 +38,25 @@ namespace tai::mux {
|
||||
using S_ConstNetIf = std::shared_ptr<const NetIf>;
|
||||
using S_ConstHostIf = std::shared_ptr<const HostIf>;
|
||||
|
||||
struct context {
|
||||
S_PlatformAdapter pa;
|
||||
tai_object_id_t oid;
|
||||
tai_object_type_t type;
|
||||
};
|
||||
|
||||
tai_status_t attribute_getter(tai_attribute_t* const attribute, void* user);
|
||||
tai_status_t attribute_setter(const tai_attribute_t* const attribute, FSMState* state, void* user);
|
||||
|
||||
template<tai_object_type_t T>
|
||||
class Object : public tai::framework::Object<T> {
|
||||
public:
|
||||
Object(S_PlatformAdapter pa) : m_pa(pa), tai::framework::Object<T>(0, nullptr, std::make_shared<tai::framework::FSM>(), nullptr,
|
||||
Object(S_PlatformAdapter pa) : m_context{pa}, tai::framework::Object<T>(0, nullptr, std::make_shared<tai::framework::FSM>(),
|
||||
reinterpret_cast<void*>(&m_context),
|
||||
std::bind(&Object::default_setter, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5),
|
||||
std::bind(&Object::default_getter, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)) {}
|
||||
|
||||
tai_object_id_t id() const {
|
||||
return m_id;
|
||||
return m_context.oid;
|
||||
}
|
||||
|
||||
tai_object_id_t real_id() const {
|
||||
@@ -54,15 +64,18 @@ namespace tai::mux {
|
||||
}
|
||||
|
||||
protected:
|
||||
tai_object_id_t m_id, m_real_id;
|
||||
S_PlatformAdapter m_pa;
|
||||
tai_object_id_t m_real_id;
|
||||
context m_context;
|
||||
S_ModuleAdapter m_adapter;
|
||||
private:
|
||||
tai_status_t default_setter(uint32_t count, const tai_attribute_t* const attribute, FSMState* fsm, void* const user, const tai::framework::error_info* const info) {
|
||||
return m_pa->set(T, id(), count, attribute);
|
||||
return m_context.pa->set(T, id(), count, attribute);
|
||||
}
|
||||
tai_status_t default_getter(uint32_t count, tai_attribute_t* const attribute, void* const user, const tai::framework::error_info* const info) {
|
||||
return m_pa->get(T, id(), count, attribute);
|
||||
auto ret = m_context.pa->get(T, id(), count, attribute);
|
||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "platform_adapter.hpp"
|
||||
#include "module_adapter.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace tai::mux {
|
||||
|
||||
@@ -181,4 +182,69 @@ namespace tai::mux {
|
||||
}
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
tai_status_t PlatformAdapter::get_mux_attribute(const tai_object_type_t& type, const tai_object_id_t& id, tai_attribute_t* const attr) {
|
||||
S_ModuleAdapter adapter;
|
||||
tai_object_id_t real_id;
|
||||
if ( get_mapping(id, &adapter, &real_id) != 0 ) {
|
||||
return TAI_STATUS_FAILURE;
|
||||
}
|
||||
switch (type) {
|
||||
case TAI_OBJECT_TYPE_MODULE:
|
||||
switch (attr->id) {
|
||||
case TAI_MODULE_ATTR_MUX_PLATFORM_ADAPTER_TYPE:
|
||||
attr->value.u32 = this->type();
|
||||
break;
|
||||
case TAI_MODULE_ATTR_MUX_CURRENT_LOADED_TAI_LIBRARY:
|
||||
{
|
||||
auto n = adapter->name();
|
||||
auto v = attr->value.charlist.count;
|
||||
attr->value.charlist.count = n.size() + 1;
|
||||
if ( v < (n.size() + 1) ) {
|
||||
return TAI_STATUS_BUFFER_OVERFLOW;
|
||||
}
|
||||
std::strncpy(attr->value.charlist.list, n.c_str(), v);
|
||||
break;
|
||||
}
|
||||
case TAI_MODULE_ATTR_MUX_REAL_OID:
|
||||
attr->value.oid = real_id;
|
||||
break;
|
||||
default:
|
||||
return TAI_STATUS_ATTR_NOT_SUPPORTED_0;
|
||||
}
|
||||
break;
|
||||
case TAI_OBJECT_TYPE_NETWORKIF:
|
||||
switch (attr->id) {
|
||||
case TAI_NETWORK_INTERFACE_ATTR_MUX_REAL_OID:
|
||||
attr->value.oid = real_id;
|
||||
break;
|
||||
default:
|
||||
return TAI_STATUS_ATTR_NOT_SUPPORTED_0;
|
||||
}
|
||||
break;
|
||||
case TAI_OBJECT_TYPE_HOSTIF:
|
||||
switch (attr->id) {
|
||||
case TAI_HOST_INTERFACE_ATTR_MUX_REAL_OID:
|
||||
attr->value.oid = real_id;
|
||||
break;
|
||||
default:
|
||||
return TAI_STATUS_ATTR_NOT_SUPPORTED_0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return TAI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
tai_status_t PlatformAdapter::set_mux_attribute(const tai_object_type_t& type, const tai_object_id_t& id, const tai_attribute_t* const attribute, tai::framework::FSMState* state) {
|
||||
S_ModuleAdapter adapter;
|
||||
tai_object_id_t real_id;
|
||||
if ( get_mapping(id, &adapter, &real_id) != 0 ) {
|
||||
return TAI_STATUS_FAILURE;
|
||||
}
|
||||
return TAI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "attribute.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
#include "fsm.hpp"
|
||||
|
||||
namespace tai::mux {
|
||||
|
||||
class ModuleAdapter;
|
||||
@@ -32,11 +34,6 @@ namespace tai::mux {
|
||||
|
||||
using S_NotificationContext = std::shared_ptr<NotificationContext>;
|
||||
|
||||
enum platform_adapter_t {
|
||||
PLATFORM_ADAPTER_UNKNOWN,
|
||||
PLATFORM_ADAPTER_STATIC,
|
||||
};
|
||||
|
||||
static const int TAI_MUX_NUM_MAX_OBJECT = 256;
|
||||
|
||||
class OIDAllocator {
|
||||
@@ -67,6 +64,8 @@ namespace tai::mux {
|
||||
PlatformAdapter(){}
|
||||
virtual ~PlatformAdapter(){}
|
||||
|
||||
virtual tai_mux_platform_adapter_type_t type() const = 0;
|
||||
|
||||
int get_mapping(const tai_object_id_t& id, S_ModuleAdapter *adapter, tai_object_id_t *real_id) {
|
||||
if ( m_map.find(id) == m_map.end() ) {
|
||||
return -1;
|
||||
@@ -114,6 +113,9 @@ namespace tai::mux {
|
||||
tai_status_t get(const tai_object_type_t& type, const tai_object_id_t& id, uint32_t count, tai_attribute_t* const attrs);
|
||||
tai_status_t set(const tai_object_type_t& type, const tai_object_id_t& id, uint32_t count, const tai_attribute_t* const attrs);
|
||||
|
||||
virtual tai_status_t get_mux_attribute(const tai_object_type_t& type, const tai_object_id_t& oid, tai_attribute_t* const attribute);
|
||||
virtual tai_status_t set_mux_attribute(const tai_object_type_t& type, const tai_object_id_t& oid, const tai_attribute_t* const attribute, tai::framework::FSMState* state);
|
||||
|
||||
private:
|
||||
PlatformAdapter(const PlatformAdapter&){}
|
||||
void operator = (const PlatformAdapter&){}
|
||||
|
||||
@@ -33,6 +33,10 @@ namespace tai::mux {
|
||||
}
|
||||
return set;
|
||||
};
|
||||
|
||||
virtual tai_mux_platform_adapter_type_t type() const {
|
||||
return TAI_MUX_PLATFORM_ADAPTER_TYPE_STATIC;
|
||||
}
|
||||
private:
|
||||
std::map<std::string, S_ModuleAdapter> m_ma_map;
|
||||
std::thread m_th;
|
||||
|
||||
Reference in New Issue
Block a user