diff --git a/include/tdi/common/tdi_defs.h b/include/tdi/common/tdi_defs.h index b9a8f4f..01e5c89 100644 --- a/include/tdi/common/tdi_defs.h +++ b/include/tdi/common/tdi_defs.h @@ -89,8 +89,10 @@ enum tdi_table_api_type_e { TDI_TABLE_API_TYPE_KEY_GET = 15, /** Get entry handle from key. */ TDI_TABLE_API_TYPE_HANDLE_GET = 16, + /** Get entry handle from key. */ + TDI_TABLE_API_TYPE_NOTIFICATION = 17, /** Invalid not supported API. */ - TDI_TABLE_API_TYPE_INVALID_API = 17 + TDI_TABLE_API_TYPE_INVALID_API = 18 }; // The same name can be used with or without enum keyword. Advantage of being // compatible with C++ diff --git a/include/tdi/common/tdi_notifications.hpp b/include/tdi/common/tdi_notifications.hpp new file mode 100644 index 0000000..05fb025 --- /dev/null +++ b/include/tdi/common/tdi_notifications.hpp @@ -0,0 +1,88 @@ +/* + * Copyright(c) 2023 Intel Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this software except as stipulated in the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** @file tdi_table_notifications.hpp + * + * @brief Contains TDI Table Notifications APIs + */ +#ifndef _TDI_TABLE_NOTIFICATIONS_HPP +#define _TDI_TABLE_NOTIFICATIONS_HPP + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace tdi { + +class Table; + +/** + * @brief Contains Parmaters info of Notification + * get and set the value with a field_id + */ +class NotificationOutParams { +public: + virtual ~NotificationOutParams() = default; + NotificationOutParams(const Table* table, const tdi_id_t &tdi_id_type) + : table_(table), notification_id_(tdi_id_type){}; + + virtual tdi_status_t setValue(const tdi_id_t & /*field_id*/, + const uint64_t & /*value*/) const { + return TDI_NOT_SUPPORTED; + }; + virtual tdi_status_t getValue(const tdi_id_t & /*field_id*/, + uint64_t * /*value*/) const { + return TDI_NOT_SUPPORTED; + }; + + virtual tdi_status_t setValue(const tdi_id_t & /*field_id*/, + const std::vector & /*value*/) const { + return TDI_NOT_SUPPORTED; + }; + virtual tdi_status_t getValue(const tdi_id_t & /*field_id*/, + std::vector * /*value*/) const { + return TDI_NOT_SUPPORTED; + }; + + virtual tdi_status_t getValue(const tdi_id_t & /*field_id*/, + uint8_t*const* /*value*/, + size_t * /*size*/) const { + return TDI_NOT_SUPPORTED; + }; + + private: + const Table* table_; + tdi_id_t notification_id_; +}; + +/** + * @brief Contains TDI Notification callback function + */ +typedef std::function key, + std::unique_ptr data, + std::unique_ptr params, + void *cookie)> tdiNotificationCallback; +} // tdi + +#endif // _TDI_TABLE_NOTIFICATIONS_HPP diff --git a/include/tdi/common/tdi_table.hpp b/include/tdi/common/tdi_table.hpp index 72ac5c1..d69ff71 100644 --- a/include/tdi/common/tdi_table.hpp +++ b/include/tdi/common/tdi_table.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -652,6 +653,14 @@ class Table { const TdiInfo *tdiInfoGet() const { return tdi_info_; }; + virtual tdi_status_t notificationRegister(tdi::Target &target, + const tdi_id_t ¬ification_id, + tdiNotificationCallback &callback, + void *cookie); + + virtual tdi_status_t notificationDeregister(tdi::Target &target, + const tdi_id_t ¬ification_id) const; + protected: // Targets can choose to use any ctor to create tables. The 2nd one // assists with setting table APIs during runtime rather than diff --git a/src/tdi_table.cpp b/src/tdi_table.cpp index 94778ce..f99dc93 100644 --- a/src/tdi_table.cpp +++ b/src/tdi_table.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ #include +#include #include // local includes @@ -348,6 +349,20 @@ tdi_status_t Table::tableAttributesGet( return TDI_NOT_SUPPORTED; } +tdi_status_t Table::notificationRegister(tdi::Target &,//target, + const tdi_id_t &,//notification_id, + tdiNotificationCallback &,//callback, + void * /*cookie*/) { + LOG_ERROR("%s:%d Not supported", __func__, __LINE__); + return TDI_NOT_SUPPORTED; +} + +tdi_status_t Table::notificationDeregister(tdi::Target &,//target, + const tdi_id_t & /*notification_id*/) const{ + LOG_ERROR("%s:%d Not supported", __func__, __LINE__); + return TDI_NOT_SUPPORTED; +} + tdi_status_t Table::operationsAllocate( const tdi_operations_type_e &op_type, std::unique_ptr *table_ops) const {