mirror of
https://github.com/Telecominfraproject/oopt-tai-implementations.git
synced 2026-01-27 02:21:54 +00:00
mux: support TAI meta APIs
Signed-off-by: Wataru Ishida <wataru.ishid@gmail.com>
This commit is contained in:
@@ -43,6 +43,12 @@ namespace tai::mux {
|
||||
if ( status != TAI_STATUS_SUCCESS ) {
|
||||
throw Exception(status);
|
||||
}
|
||||
|
||||
status = tai_api_query(TAI_API_META, (void **)(&m_meta_api));
|
||||
if ( status != TAI_STATUS_SUCCESS ) {
|
||||
TAI_WARN("no meta api: %s", name.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ModuleAdapter::~ModuleAdapter() {
|
||||
|
||||
@@ -194,6 +194,54 @@ namespace tai::mux {
|
||||
return m_hostif_api->clear_host_interface_attributes(host_interface_id, attr_count, attr_list);
|
||||
}
|
||||
|
||||
tai_status_t list_metadata(
|
||||
_In_ const tai_metadata_key_t * const key,
|
||||
_Out_ uint32_t *count,
|
||||
_Out_ const tai_attr_metadata_t * const **list) {
|
||||
if ( m_meta_api == nullptr || m_meta_api->list_metadata == nullptr ) {
|
||||
auto type = key->type;
|
||||
if ( key->oid != TAI_NULL_OBJECT_ID ) {
|
||||
type = tai_object_type_query(key->oid);
|
||||
}
|
||||
auto info = tai_metadata_all_object_type_infos[type];
|
||||
if ( info == nullptr ) {
|
||||
*count = tai_metadata_attr_sorted_by_id_name_count;
|
||||
*list = tai_metadata_attr_sorted_by_id_name;
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
*count = info->attrmetadatalength;
|
||||
*list = info->attrmetadata;
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
// TODO list_metadata is not returning mux custom attributes
|
||||
return m_meta_api->list_metadata(key, count, list);
|
||||
}
|
||||
|
||||
const tai_attr_metadata_t* get_attr_metadata(
|
||||
_In_ const tai_metadata_key_t * const key,
|
||||
_In_ tai_attr_id_t attr_id) {
|
||||
if ( m_meta_api == nullptr || m_meta_api->get_attr_metadata == nullptr || ( TAI_MODULE_ATTR_CUSTOM_MUX_START <= attr_id && attr_id <= TAI_MODULE_ATTR_CUSTOM_MUX_END )) {
|
||||
auto type = key->type;
|
||||
if ( key->oid != TAI_NULL_OBJECT_ID ) {
|
||||
type = tai_object_type_query(key->oid);
|
||||
}
|
||||
return tai_metadata_get_attr_metadata(type, attr_id);
|
||||
}
|
||||
return m_meta_api->get_attr_metadata(key, attr_id);
|
||||
}
|
||||
|
||||
const tai_object_type_info_t* get_object_info(
|
||||
_In_ const tai_metadata_key_t *const key) {
|
||||
if ( m_meta_api == nullptr || m_meta_api->get_object_info == nullptr ) {
|
||||
auto type = key->type;
|
||||
if ( key->oid != TAI_NULL_OBJECT_ID ) {
|
||||
type = tai_object_type_query(key->oid);
|
||||
}
|
||||
return tai_metadata_get_object_type_info(type);
|
||||
}
|
||||
return m_meta_api->get_object_info(key);
|
||||
}
|
||||
|
||||
private:
|
||||
void* m_dl;
|
||||
const std::string m_name;
|
||||
@@ -207,6 +255,7 @@ namespace tai::mux {
|
||||
tai_module_api_t* m_module_api;
|
||||
tai_host_interface_api_t* m_hostif_api;
|
||||
tai_network_interface_api_t* m_netif_api;
|
||||
tai_meta_api_t* m_meta_api;
|
||||
};
|
||||
|
||||
using S_ModuleAdapter = std::shared_ptr<ModuleAdapter>;
|
||||
|
||||
@@ -184,6 +184,71 @@ namespace tai::mux {
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
tai_status_t Platform::get_ma_and_meta_key(const tai_metadata_key_t *const key, tai_metadata_key_t& new_key, S_ModuleAdapter *ma) {
|
||||
new_key = *key;
|
||||
if ( key->location.count > 0 ) {
|
||||
std::string loc(key->location.list, key->location.count);
|
||||
*ma = m_pa->get_module_adapter(loc);
|
||||
} else if ( key->oid != TAI_NULL_OBJECT_ID ) {
|
||||
tai_object_id_t real_id;
|
||||
if ( m_pa->get_mapping(key->oid, ma, &real_id) < 0 ) {
|
||||
return TAI_STATUS_FAILURE;
|
||||
}
|
||||
new_key.oid = real_id;
|
||||
}
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
tai_status_t Platform::list_metadata(const tai_metadata_key_t *const key, uint32_t *count, const tai_attr_metadata_t *const **list) {
|
||||
S_ModuleAdapter ma;
|
||||
tai_metadata_key_t new_key;
|
||||
auto ret = get_ma_and_meta_key(key, new_key, &ma);
|
||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ( ma ) {
|
||||
return ma->list_metadata(&new_key, count, list);
|
||||
}
|
||||
|
||||
auto type = key->type;
|
||||
auto info = tai_metadata_all_object_type_infos[type];
|
||||
if ( info == nullptr ) {
|
||||
*count = tai_metadata_attr_sorted_by_id_name_count;
|
||||
*list = tai_metadata_attr_sorted_by_id_name;
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
*count = info->attrmetadatalength;
|
||||
*list = info->attrmetadata;
|
||||
return TAI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
const tai_attr_metadata_t* Platform::get_attr_metadata(const tai_metadata_key_t *const key, tai_attr_id_t attr_id) {
|
||||
S_ModuleAdapter ma;
|
||||
tai_metadata_key_t new_key;
|
||||
auto ret = get_ma_and_meta_key(key, new_key, &ma);
|
||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||
return nullptr;
|
||||
}
|
||||
if ( ma ) {
|
||||
return ma->get_attr_metadata(&new_key, attr_id);
|
||||
}
|
||||
return tai_metadata_get_attr_metadata(new_key.type, attr_id);
|
||||
}
|
||||
|
||||
const tai_object_type_info_t* Platform::get_object_info(const tai_metadata_key_t *const key) {
|
||||
S_ModuleAdapter ma;
|
||||
tai_metadata_key_t new_key;
|
||||
auto ret = get_ma_and_meta_key(key, new_key, &ma);
|
||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||
return nullptr;
|
||||
}
|
||||
if ( ma ) {
|
||||
return ma->get_object_info(&new_key);
|
||||
}
|
||||
return tai_metadata_get_object_type_info(key->type);
|
||||
}
|
||||
|
||||
tai_status_t attribute_getter(tai_attribute_t* const attribute, void* user) {
|
||||
auto ctx = reinterpret_cast<context*>(user);
|
||||
auto pa = ctx->pa;
|
||||
|
||||
@@ -22,7 +22,14 @@ namespace tai::mux {
|
||||
tai_object_type_t get_object_type(tai_object_id_t id);
|
||||
tai_object_id_t get_module_id(tai_object_id_t id);
|
||||
tai_status_t set_log(tai_api_t tai_api_id, tai_log_level_t log_level, tai_log_fn log_fn);
|
||||
|
||||
tai_status_t list_metadata(const tai_metadata_key_t *const key, uint32_t *count, const tai_attr_metadata_t *const **list);
|
||||
const tai_attr_metadata_t* get_attr_metadata(const tai_metadata_key_t *const key, tai_attr_id_t attr_id);
|
||||
const tai_object_type_info_t* get_object_info(const tai_metadata_key_t *const key);
|
||||
private:
|
||||
|
||||
tai_status_t get_ma_and_meta_key(const tai_metadata_key_t *const key, tai_metadata_key_t& new_key, S_ModuleAdapter *ma);
|
||||
|
||||
S_PlatformAdapter m_pa;
|
||||
log_setting m_log_setting;
|
||||
};
|
||||
|
||||
Submodule tai_mux/oopt-tai updated: 0a483c5c95...7711e2332d
@@ -18,9 +18,15 @@ namespace tai::mux {
|
||||
void PlatformAdapter::notify(NotificationContext* ctx, tai_object_id_t real_oid, uint32_t attr_count, tai_attribute_t const * const attr_list) {
|
||||
auto oid = ctx->muxed_oid;
|
||||
std::vector<S_Attribute> attrs;
|
||||
S_ModuleAdapter adapter;
|
||||
auto ret = get_mapping(oid, &adapter, nullptr);
|
||||
if ( ret < 0 ) {
|
||||
return;
|
||||
}
|
||||
for ( int i = 0; i < attr_count; i++ ) {
|
||||
auto src = attr_list[i];
|
||||
auto meta = tai_metadata_get_attr_metadata(ctx->object_type, src.id);
|
||||
tai_metadata_key_t key{.oid=real_oid};
|
||||
auto meta = adapter->get_attr_metadata(&key, src.id);
|
||||
if ( meta == nullptr ) {
|
||||
continue;
|
||||
}
|
||||
@@ -43,12 +49,18 @@ namespace tai::mux {
|
||||
}
|
||||
|
||||
tai_status_t PlatformAdapter::convert_oid(const tai_object_type_t& type, const tai_object_id_t& id, const tai_attribute_t * const src, tai_attribute_t * const dst, bool reversed) {
|
||||
auto meta = tai_metadata_get_attr_metadata(type, src->id);
|
||||
const tai_object_map_list_t *oml;
|
||||
S_ModuleAdapter adapter;
|
||||
if ( get_mapping(id, &adapter, nullptr) != 0 ) {
|
||||
tai_object_id_t real_id;
|
||||
if ( get_mapping(id, &adapter, &real_id) != 0 ) {
|
||||
return TAI_STATUS_FAILURE;
|
||||
}
|
||||
tai_metadata_key_t key{.oid=real_id};
|
||||
auto meta = adapter->get_attr_metadata(&key, src->id);
|
||||
if ( meta == nullptr ) {
|
||||
return TAI_STATUS_FAILURE;
|
||||
}
|
||||
|
||||
auto convert = [&](tai_object_id_t s) -> tai_object_id_t {
|
||||
if ( reversed ) {
|
||||
return get_reverse_mapping(s, adapter);
|
||||
@@ -156,7 +168,8 @@ namespace tai::mux {
|
||||
|
||||
for ( auto i = 0; i < count; i++ ) {
|
||||
auto attribute = &attrs[i];
|
||||
auto meta = tai_metadata_get_attr_metadata(type, attribute->id);
|
||||
tai_metadata_key_t key{.oid=real_id};
|
||||
auto meta = adapter->get_attr_metadata(&key, attribute->id);
|
||||
if ( meta == nullptr ) {
|
||||
return TAI_STATUS_FAILURE;
|
||||
}
|
||||
@@ -246,5 +259,4 @@ namespace tai::mux {
|
||||
return TAI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,11 +6,31 @@ ifndef TAI_LIB_DIR
|
||||
TAI_LIB_DIR := $(TAI_DIR)/tools/framework
|
||||
endif
|
||||
|
||||
all: ../libtai.so static.json $(TAI_LIB_DIR)/examples/basic/libtai.so
|
||||
TAI_MUX_STATIC_CONFIG_FILE=$(abspath static.json) TAI_TEST_TARGET=$(abspath ../libtai.so) $(MAKE) -C $(TAI_DIR)/tests
|
||||
all: libtai.so static.json libtai-a.so libtai-b.so
|
||||
TAI_MUX_STATIC_CONFIG_FILE=$(abspath static.json) TAI_TEST_TARGET=$(abspath libtai.so) $(MAKE) -C $(TAI_DIR)/tests
|
||||
|
||||
../libtai.so:
|
||||
$(MAKE) -C $(@D)
|
||||
libtai.so:
|
||||
$(MAKE) -C ..
|
||||
ln -sf ../$@ $@
|
||||
|
||||
$(TAI_LIB_DIR)/examples/basic/libtai.so:
|
||||
$(MAKE) -C $(@D)
|
||||
libtai-a.so:
|
||||
TAI_META_CUSTOM_FILES="$(abspath $(wildcard custom_a/*.h))" $(MAKE) -C $(TAI_DIR)/meta clean
|
||||
TAI_META_CUSTOM_FILES="$(abspath $(wildcard custom_a/*.h))" $(MAKE) -C $(TAI_LIB_DIR)/examples/basic clean
|
||||
TAI_META_CUSTOM_FILES="$(abspath $(wildcard custom_a/*.h))" $(MAKE) -C $(TAI_LIB_DIR)/examples/basic
|
||||
cp $(TAI_LIB_DIR)/examples/basic/libtai.so $@
|
||||
|
||||
libtai-b.so:
|
||||
TAI_META_CUSTOM_FILES="$(abspath $(wildcard custom_b/*.h))" $(MAKE) -C $(TAI_DIR)/meta clean
|
||||
TAI_META_CUSTOM_FILES="$(abspath $(wildcard custom_b/*.h))" $(MAKE) -C $(TAI_LIB_DIR)/examples/basic clean
|
||||
TAI_META_CUSTOM_FILES="$(abspath $(wildcard custom_b/*.h))" $(MAKE) -C $(TAI_LIB_DIR)/examples/basic
|
||||
cp $(TAI_LIB_DIR)/examples/basic/libtai.so $@
|
||||
|
||||
run: libtai-a.so libtai-b.so taish
|
||||
TAI_MUX_STATIC_CONFIG_FILE=static.json LD_LIBRARY_PATH=..:$(abspath .) $(TAI_DIR)/tools/taish/taish_server -vn
|
||||
|
||||
taish:
|
||||
$(MAKE) -C $(TAI_DIR)/tools/taish
|
||||
|
||||
clean:
|
||||
$(RM) libtai-a.so libtai-b.so
|
||||
$(MAKE) -C $(TAI_DIR)/tools/taish clean
|
||||
|
||||
27
tai_mux/tests/custom_a/module.h
Normal file
27
tai_mux/tests/custom_a/module.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef __TAI_BASIC_MODULE__
|
||||
#define __TAI_BASIC_MODULE__
|
||||
|
||||
#include <tai.h>
|
||||
|
||||
typedef enum _basic_module_attr_t
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Custom attribute example
|
||||
*
|
||||
* @type bool
|
||||
* @flags CREATE_AND_SET
|
||||
*/
|
||||
TAI_MODULE_ATTR_CUSTOM = TAI_MODULE_ATTR_CUSTOM_RANGE_START,
|
||||
|
||||
/**
|
||||
* @brief Custom attribute example
|
||||
*
|
||||
* @type bool
|
||||
* @flags CREATE_AND_SET
|
||||
*/
|
||||
TAI_MODULE_ATTR_CUSTOM_A,
|
||||
|
||||
} basic_module_attr_t;
|
||||
|
||||
#endif
|
||||
27
tai_mux/tests/custom_b/module.h
Normal file
27
tai_mux/tests/custom_b/module.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef __TAI_BASIC_MODULE__
|
||||
#define __TAI_BASIC_MODULE__
|
||||
|
||||
#include <tai.h>
|
||||
|
||||
typedef enum _basic_module_attr_t
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Custom attribute example
|
||||
*
|
||||
* @type bool
|
||||
* @flags CREATE_AND_SET
|
||||
*/
|
||||
TAI_MODULE_ATTR_CUSTOM = TAI_MODULE_ATTR_CUSTOM_RANGE_START,
|
||||
|
||||
/**
|
||||
* @brief Custom attribute example
|
||||
*
|
||||
* @type bool
|
||||
* @flags CREATE_AND_SET
|
||||
*/
|
||||
TAI_MODULE_ATTR_CUSTOM_B,
|
||||
|
||||
} basic_module_attr_t;
|
||||
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"0": "../tools/framework/examples/basic/libtai.so"
|
||||
"0": "libtai-a.so",
|
||||
"1": "libtai-b.so"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user