mirror of
https://github.com/Telecominfraproject/oopt-tai-implementations.git
synced 2025-10-30 01:32:42 +00:00
mux: convert oid for notifications
Signed-off-by: Wataru Ishida <ishida@nel-america.com>
This commit is contained in:
committed by
Wataru Ishida
parent
54155f66f7
commit
f3e5d3fb35
@@ -234,6 +234,49 @@ tai_status_t Multiplexier::tai_log_set(_In_ tai_api_t api, _In_ tai_log_level_t
|
|||||||
return TAI_STATUS_SUCCESS;
|
return TAI_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void notification_callback(void* context, tai_object_id_t oid, tai_attribute_t const * const attribute) {
|
||||||
|
if ( context == nullptr || attribute == nullptr ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto ctx = static_cast<notification_context*>(context);
|
||||||
|
ctx->mux->notify(ctx, oid, attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Multiplexier::notify(notification_context* ctx, tai_object_id_t real_oid, tai_attribute_t const * const src) {
|
||||||
|
auto oid = get_reverse_mapping(real_oid, ctx->adapter);
|
||||||
|
if ( oid == TAI_NULL_OBJECT_ID ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto key = std::pair<tai_object_id_t, tai_attr_id_t>(oid, ctx->notify_id);
|
||||||
|
tai_attribute_t dst;
|
||||||
|
tai_alloc_info_t info;
|
||||||
|
info.reference = src;
|
||||||
|
auto t = object_type_query(oid);
|
||||||
|
|
||||||
|
auto meta = tai_metadata_get_attr_metadata(t, src->id);
|
||||||
|
if ( meta == nullptr ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.id = src->id;
|
||||||
|
|
||||||
|
if ( tai_metadata_alloc_attr_value(meta, &dst, &info) != 0 ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( tai_metadata_deepcopy_attr_value(meta, src, &dst) != 0 ) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( convert_oid(oid, &dst, &dst, true) != TAI_STATUS_SUCCESS ) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->handler.notify(ctx->handler.context, oid, &dst);
|
||||||
|
err:
|
||||||
|
tai_metadata_free_attr_value(meta, &dst, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
tai_status_t Multiplexier::set_attributes( std::function<tai_status_t(ModuleAdapter*, tai_object_id_t, uint32_t, const tai_attribute_t*)> f, tai_object_id_t oid, uint32_t attr_count, const tai_attribute_t *attr_list) {
|
tai_status_t Multiplexier::set_attributes( std::function<tai_status_t(ModuleAdapter*, tai_object_id_t, uint32_t, const tai_attribute_t*)> f, tai_object_id_t oid, uint32_t attr_count, const tai_attribute_t *attr_list) {
|
||||||
tai_object_id_t id;
|
tai_object_id_t id;
|
||||||
ModuleAdapter *m_adapter;
|
ModuleAdapter *m_adapter;
|
||||||
@@ -251,6 +294,10 @@ tai_status_t Multiplexier::set_attributes( std::function<tai_status_t(ModuleAdap
|
|||||||
auto t = object_type_query(oid);
|
auto t = object_type_query(oid);
|
||||||
for ( auto i = 0; i < attr_count; i++ ) {
|
for ( auto i = 0; i < attr_count; i++ ) {
|
||||||
auto meta = tai_metadata_get_attr_metadata(t, attr_list[i].id);
|
auto meta = tai_metadata_get_attr_metadata(t, attr_list[i].id);
|
||||||
|
if ( meta == nullptr ) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
tai_attribute_t attr;
|
tai_attribute_t attr;
|
||||||
attr.id = attr_list[i].id;
|
attr.id = attr_list[i].id;
|
||||||
info.reference = &attr_list[i];
|
info.reference = &attr_list[i];
|
||||||
@@ -260,7 +307,7 @@ tai_status_t Multiplexier::set_attributes( std::function<tai_status_t(ModuleAdap
|
|||||||
if ( tai_metadata_deepcopy_attr_value(meta, &attr_list[i], &attr) != 0 ) {
|
if ( tai_metadata_deepcopy_attr_value(meta, &attr_list[i], &attr) != 0 ) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
ret = convert_oid(m_adapter, t, &attr, &attr, false);
|
ret = convert_oid(oid, &attr, &attr, false);
|
||||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@@ -292,7 +339,7 @@ tai_status_t Multiplexier::get_attributes( std::function<tai_status_t(ModuleAdap
|
|||||||
|
|
||||||
auto t = object_type_query(oid);
|
auto t = object_type_query(oid);
|
||||||
for ( auto i = 0; i < attr_count; i++ ) {
|
for ( auto i = 0; i < attr_count; i++ ) {
|
||||||
ret = convert_oid(m_adapter, t, &attr_list[i], &attr_list[i], true);
|
ret = convert_oid(oid, &attr_list[i], &attr_list[i], true);
|
||||||
if ( ret != TAI_STATUS_SUCCESS ) {
|
if ( ret != TAI_STATUS_SUCCESS ) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -300,7 +347,12 @@ tai_status_t Multiplexier::get_attributes( std::function<tai_status_t(ModuleAdap
|
|||||||
return TAI_STATUS_SUCCESS;
|
return TAI_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
tai_status_t Multiplexier::convert_oid(ModuleAdapter *adapter, tai_object_type_t t, const tai_attribute_t *src, tai_attribute_t *dst, bool reversed) {
|
tai_status_t Multiplexier::convert_oid(tai_object_id_t oid, const tai_attribute_t *src, tai_attribute_t *dst, bool reversed) {
|
||||||
|
ModuleAdapter* adapter;
|
||||||
|
auto t = object_type_query(oid);
|
||||||
|
if ( g_mux->get_mapping(oid, &adapter, nullptr) != 0 ) {
|
||||||
|
return TAI_STATUS_FAILURE;
|
||||||
|
}
|
||||||
auto meta = tai_metadata_get_attr_metadata(t, src->id);
|
auto meta = tai_metadata_get_attr_metadata(t, src->id);
|
||||||
const tai_object_map_list_t *oml;
|
const tai_object_map_list_t *oml;
|
||||||
auto convert = [&](tai_object_id_t s) -> tai_object_id_t {
|
auto convert = [&](tai_object_id_t s) -> tai_object_id_t {
|
||||||
@@ -313,6 +365,7 @@ tai_status_t Multiplexier::convert_oid(ModuleAdapter *adapter, tai_object_type_t
|
|||||||
}
|
}
|
||||||
return oid;
|
return oid;
|
||||||
};
|
};
|
||||||
|
auto key = std::pair<tai_object_id_t, tai_attr_id_t>(oid, src->id);
|
||||||
|
|
||||||
switch (meta->attrvaluetype) {
|
switch (meta->attrvaluetype) {
|
||||||
case TAI_ATTR_VALUE_TYPE_OID:
|
case TAI_ATTR_VALUE_TYPE_OID:
|
||||||
@@ -344,6 +397,30 @@ tai_status_t Multiplexier::convert_oid(ModuleAdapter *adapter, tai_object_type_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TAI_ATTR_VALUE_TYPE_NOTIFICATION:
|
||||||
|
if ( reversed ) {
|
||||||
|
if ( m_notification_map.find(key) != m_notification_map.end() ) {
|
||||||
|
auto n = m_notification_map[key];
|
||||||
|
dst->value.notification.context = n->handler.context;
|
||||||
|
dst->value.notification.notify = n->handler.notify;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( src->value.notification.notify == nullptr ) {
|
||||||
|
delete m_notification_map[key];
|
||||||
|
m_notification_map.erase(key);
|
||||||
|
} else {
|
||||||
|
if ( m_notification_map.find(key) == m_notification_map.end() ) {
|
||||||
|
m_notification_map[key] = new notification_context();
|
||||||
|
}
|
||||||
|
auto n = m_notification_map[key];
|
||||||
|
n->mux = this;
|
||||||
|
n->adapter = adapter;
|
||||||
|
n->handler = src->value.notification;
|
||||||
|
n->notify_id = src->id;
|
||||||
|
dst->value.notification.context = n;
|
||||||
|
dst->value.notification.notify = notification_callback;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return TAI_STATUS_SUCCESS;
|
return TAI_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ class OIDAllocator {
|
|||||||
std::bitset<256> m_bitset;
|
std::bitset<256> m_bitset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Multiplexier;
|
||||||
|
|
||||||
|
struct notification_context {
|
||||||
|
Multiplexier* mux;
|
||||||
|
ModuleAdapter* adapter;
|
||||||
|
tai_notification_handler_t handler;
|
||||||
|
tai_attr_id_t notify_id;
|
||||||
|
};
|
||||||
|
|
||||||
// singleton
|
// singleton
|
||||||
class Multiplexier {
|
class Multiplexier {
|
||||||
public:
|
public:
|
||||||
@@ -54,6 +63,8 @@ class Multiplexier {
|
|||||||
return m_pa->get_module_adapter(location);
|
return m_pa->get_module_adapter(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void notify(notification_context* ctx, tai_object_id_t real_oid, tai_attribute_t const * const src);
|
||||||
|
|
||||||
tai_status_t create_module(
|
tai_status_t create_module(
|
||||||
_Out_ tai_object_id_t *module_id,
|
_Out_ tai_object_id_t *module_id,
|
||||||
_In_ uint32_t attr_count,
|
_In_ uint32_t attr_count,
|
||||||
@@ -122,6 +133,8 @@ class Multiplexier {
|
|||||||
void operator = (const Multiplexier&){}
|
void operator = (const Multiplexier&){}
|
||||||
PlatformAdapter *m_pa;
|
PlatformAdapter *m_pa;
|
||||||
std::map<tai_object_id_t, std::pair<tai_object_id_t, ModuleAdapter* >> m_map;
|
std::map<tai_object_id_t, std::pair<tai_object_id_t, ModuleAdapter* >> m_map;
|
||||||
|
std::map<std::pair<tai_object_id_t, tai_attr_id_t>, notification_context*> m_notification_map;
|
||||||
|
|
||||||
OIDAllocator m_oid_allocator;
|
OIDAllocator m_oid_allocator;
|
||||||
|
|
||||||
tai_status_t set_attributes( std::function<tai_status_t(ModuleAdapter*, tai_object_id_t, uint32_t, const tai_attribute_t*)> f, tai_object_id_t oid, uint32_t attr_count, const tai_attribute_t *attr_list);
|
tai_status_t set_attributes( std::function<tai_status_t(ModuleAdapter*, tai_object_id_t, uint32_t, const tai_attribute_t*)> f, tai_object_id_t oid, uint32_t attr_count, const tai_attribute_t *attr_list);
|
||||||
@@ -166,7 +179,7 @@ class Multiplexier {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tai_status_t convert_oid(ModuleAdapter *adapter, tai_object_type_t t, const tai_attribute_t *src, tai_attribute_t *dst, bool reversed);
|
tai_status_t convert_oid(tai_object_id_t oid, const tai_attribute_t *src, tai_attribute_t *dst, bool reversed);
|
||||||
int free_attributes(tai_object_type_t t, std::vector<tai_attribute_t>& attributes);
|
int free_attributes(tai_object_type_t t, std::vector<tai_attribute_t>& attributes);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user