Skip to content

Commit

Permalink
Tdi operations and notifications (#126)
Browse files Browse the repository at this point in the history
* tdi::operations

* notifications: compiling

* tdi operations, notifications without parsing

* notifications parsing

* code clean up

* c frontend changes for operations and notifications

* c frontend for notifications

* notification, operations minor fixes

* cleaning up dead code

* minor fix to take uint64 values

* minor fixs

* addressing review comments

* cleaning up logging
  • Loading branch information
satish153 authored Sep 12, 2023
1 parent 22cb07a commit 6d5bcfe
Show file tree
Hide file tree
Showing 19 changed files with 856 additions and 83 deletions.
63 changes: 63 additions & 0 deletions include/tdi/common/c_frontend/tdi_notifications.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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_notifications.h
*
* @brief Contains TDI Table notifications APIs
*/
#ifndef _TDI_NOTIFICATIONS_H
#define _TDI_NOTIFICATIONS_H

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*tdi_notification_callback)(
const tdi_table_key_hdl *key,
const tdi_table_data_hdl *data,
const tdi_notification_param_hdl *params,
void *cookie);

tdi_status_t tdi_notifications_set_value(
tdi_notification_param_hdl *notifications_hdl,
const tdi_id_t field_id,
const uint64_t value);

tdi_status_t tdi_notifications_set_value_array(
tdi_notification_param_hdl *notifications_hdl,
const tdi_id_t field_id,
const uint64_t *value,
const uint32_t array_sz);

tdi_status_t tdi_notifications_get_value(
const tdi_notification_param_hdl *notifications_hdl,
const tdi_id_t field_id,
uint64_t *value);

tdi_status_t tdi_notifications_get_value_array_size(
const tdi_notification_param_hdl *notification_hdl,
const tdi_id_t field_id,
uint32_t *array_size);

tdi_status_t tdi_notifications_get_value_array(
const tdi_notification_param_hdl *notification_hdl,
const tdi_id_t field_id,
uint64_t *val);

#ifdef __cplusplus
}
#endif

#endif // _TDI_NOTIFICATIONS_H
4 changes: 2 additions & 2 deletions include/tdi/common/c_frontend/tdi_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
extern "C" {
#endif

tdi_status_t tdi_operations_set_value(tdi_operations_hdl operations,
tdi_status_t tdi_operations_set_value(tdi_operations_hdl *operations,
tdi_operations_field_type_e type,
const uint64_t value);

tdi_status_t tdi_operations_get_value(tdi_operations_hdl operations,
tdi_status_t tdi_operations_get_value(const tdi_operations_hdl *operations,
tdi_operations_field_type_e type,
uint64_t *value);

Expand Down
28 changes: 26 additions & 2 deletions include/tdi/common/c_frontend/tdi_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <tdi/common/c_frontend/tdi_attributes.h>
#include <tdi/common/c_frontend/tdi_operations.h>
#include <tdi/common/c_frontend/tdi_notifications.h>
#include <tdi/common/c_frontend/tdi_table_data.h>
#include <tdi/common/c_frontend/tdi_table_key.h>
#include <tdi/common/tdi_defs.h>
Expand Down Expand Up @@ -781,8 +782,31 @@ tdi_status_t tdi_operations_deallocate(tdi_operations_hdl *tbl_op_hdl);
*
* @return Status of the API call
*/
tdi_status_t tdi_table_operations_execute(const tdi_table_hdl *table_hdl,
const tdi_operations_hdl *tbl_ops);
tdi_status_t tdi_operations_execute(const tdi_table_hdl *table_hdl,
const tdi_target_hdl *target,
const tdi_operations_hdl *tbl_ops);

tdi_status_t tdi_notifications_registration_params_allocate(
const tdi_table_hdl *table_hdl,
const tdi_id_t notification_id,
tdi_notification_param_hdl **tbl_notification_hdl);

tdi_status_t tdi_notifications_registration_params_deallocate(
tdi_notification_param_hdl *tbl_notification_hdl);

tdi_status_t tdi_notifications_register(
const tdi_table_hdl *table_hdl,
const tdi_target_hdl *target,
const tdi_id_t notification_id,
const tdi_notification_callback callback_fn,
const tdi_notification_param_hdl *tbl_notification_hdl,
void *cookie);

tdi_status_t tdi_notifications_deregister(
const tdi_table_hdl *table_hdl,
const tdi_target_hdl *target,
const tdi_id_t notification_id,
const tdi_notification_param_hdl *tbl_notification_hdl);

#ifdef __cplusplus
}
Expand Down
8 changes: 8 additions & 0 deletions include/tdi/common/c_frontend/tdi_table_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,14 @@ tdi_status_t tdi_table_operations_supported(
tdi_operations_type_e *operations,
uint32_t *num_returned);

tdi_status_t tdi_table_num_notifications_supported(
const tdi_table_info_hdl *table_info_hdl, uint32_t *num);

tdi_status_t tdi_table_notifications_supported(
const tdi_table_info_hdl *table_info_hdl,
const char *notifications[],
uint32_t *num_returned);

/**
* @brief Get size of list of tables that the given table is dependent on
*
Expand Down
9 changes: 9 additions & 0 deletions include/tdi/common/tdi_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ enum tdi_operations_field_type_e {
};
typedef enum tdi_operations_field_type_e tdi_operations_field_type_e;

enum tdi_notifications_type_e {
TDI_NOTIFICATIONS_TYPE_CORE = 0,
TDI_NOTIFICATIONS_TYPE_ARCH = 0x08,
TDI_NOTIFICATIONS_TYPE_DEVICE = 0x80,
};
typedef enum tdi_notifications_type_e tdi_notifications_type_e;


/** Identifies an error code. */
typedef int tdi_status_t;

Expand Down Expand Up @@ -328,6 +336,7 @@ DECLARE_HANDLE(tdi_learn_info_hdl);
DECLARE_HANDLE(tdi_learn_field_info_hdl);
DECLARE_HANDLE(tdi_operations_hdl);
DECLARE_HANDLE(tdi_dev_config_hdl);
DECLARE_HANDLE(tdi_notification_param_hdl);

/**
* @brief learn_data_hdl and table_data_hdl are the same,
Expand Down
11 changes: 11 additions & 0 deletions include/tdi/common/tdi_json_parser/tdi_info_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ const std::string LEARN_ID = "id";
const std::string LEARN_ANNOTATIONS = "annotations";
const std::string LEARN_FIELDS = "fields";

const std::string TABLE_NOTIFICATIONS = "notifications";
const std::string TABLE_NOTIFICATIONS_ID = "id";
const std::string TABLE_NOTIFICATIONS_NAME = "name";
const std::string TABLE_NOTIFICATIONS_REPEATED = "repeated";
const std::string TABLE_NOTIFICATIONS_MANDATORY = "mandatory";
const std::string TABLE_NOTIFICATIONS_ANNOTATIONS = "annotations";
const std::string TABLE_NOTIFICATIONS_REGISTRATION_PARAMS = "registration_params";
const std::string TABLE_NOTIFICATIONS_CALLBACK_PARAMS = "callback_params";

} // namespace tdi_json

// Forward declarations
Expand Down Expand Up @@ -104,6 +113,8 @@ class TdiInfoParser {
std::unique_ptr<DataFieldInfo> parseDataField(const tdi::Cjson &data_json,
const uint64_t &oneof_index);
std::unique_ptr<ActionInfo> parseAction(const tdi::Cjson &action_json);
std::unique_ptr<NotificationInfo> parseNotificationInfo(const tdi::Cjson &notification_json);
std::unique_ptr<NotificationParamInfo> parseNotificationParams(const tdi::Cjson &notification_param_json);
std::set<tdi::Annotation> parseAnnotations(
const tdi::Cjson &annotation_cjson);
void parseFieldWidth(const tdi::Cjson &node,
Expand Down
Loading

0 comments on commit 6d5bcfe

Please sign in to comment.