|
DTNMA Reference Tools v2.1.0 - 13.gc5c0bac
Delay-Tolerant Networking Management Architecture (DTNMA) Tool Suite
|
This file is only included in the build when either ::HAVE_POSTGRESQL or ::HAVE_MYSQL are defined. More...
#include <stdio.h>#include <unistd.h>#include <cace/util/defs.h>#include <cace/ari.h>#include <cace/amm/msg_if.h>#include "agents.h"#include "mgr.h"
Include dependency graph for nm_sql.h:
This graph shows which files directly or indirectly include this file:Macros | |
| #define | RET_PASS 0 |
| Return code that indicates normal completion. | |
| #define | RET_FAIL_UNDEFINED 1 |
| Return code that indicates the input resolves to an undefined result. | |
| #define | RET_FAIL_UNEXPECTED 2 |
| Return code that indicates the input resolves to an unexpected/abnormal state. | |
| #define | RET_FAIL_BAD_ARGS 3 |
| Return code that indicates that bad input arguments were passed. | |
| #define | RET_FAIL_DATABASE 10 |
| Return code that there was a database (generic) error. | |
| #define | RET_FAIL_DATABASE_CONNECTION 11 |
| Return code that there was a database connection error. | |
| #define | SQL_RECONN_TIME_MSEC 500 |
| #define | SQL_CONN_TRIES 10 |
| #define | CHKCONN refdm_db_mgt_connected(); |
| #define | DB_LOG_INFO(...) refdm_db_log_msg(__FILE__, __LINE__, __func__, LOG_INFO, __VA_ARGS__) |
| #define | DB_LOG_WARN(...) refdm_db_log_msg(__FILE__, __LINE__, __func__, LOG_WARNING, __VA_ARGS__) |
| #define | DB_LOG_ERR(...) refdm_db_log_msg(__FILE__, __LINE__, __func__, LOG_ERR, __VA_ARGS__) |
Functions | |
| int32_t | db_add_agent (const cace_data_t *agent_eid) |
| uint32_t | refdm_db_mgt_init (refdm_db_t *parms, uint32_t clear, uint32_t log) |
| uint32_t | refdm_db_mgt_init_con (size_t idx, refdm_db_t *parms) |
| Initialize specified (thread-specific) SQL connection and prepared queries Prepared queries are connection specific. | |
| void | refdm_db_mgt_close (void) |
| void | refdm__db_mgt_close_conn (size_t i) |
| int | refdm_db_mgt_connected (size_t i) |
| int32_t | refdm_db_mgt_query_insert (int db_idx, uint32_t *idx, char *format,...) |
| uint32_t | refdm_db_insert_rptset (const cace_ari_t *val, const refdm_agent_t *agent) |
| uint32_t | refdm_db_insert_agent (const m_string_t eid) |
| uint32_t | refdm_db_insert_execset (const cace_ari_t *val, const refdm_agent_t *agent) |
| refdm_agent_t * | refdm_db_fetch_agent (int32_t id) |
| int32_t | refdm_db_fetch_agent_idx (const char *eid) |
| Get the index of an Agent from its endpoint name. | |
| int | refdm_db_clear_rptset (int32_t agent_idx) |
| Runs a clear request on the rptset database table. | |
| int | refdm_db_fetch_rptset_count (int32_t agent_idx, size_t *count) |
| Runs a query on the database and retrieves the number of RPTSETs. | |
| int | refdm_db_fetch_rptset_list (int32_t agent_idx, cace_ari_list_t *rptsets) |
| Runs a query on the database and retrieves the list of RPTSETs. | |
| void | refdm_db_log_msg (const char *filename, int lineno, const char *funcname, int level, size_t dbidx, const char *format,...) |
| Utility function to insert debug or error informational messages into the database. | |
This file is only included in the build when either ::HAVE_POSTGRESQL or ::HAVE_MYSQL are defined.
| #define CHKCONN refdm_db_mgt_connected(); |
| #define DB_LOG_ERR | ( | ... | ) | refdm_db_log_msg(__FILE__, __LINE__, __func__, LOG_ERR, __VA_ARGS__) |
| #define DB_LOG_INFO | ( | ... | ) | refdm_db_log_msg(__FILE__, __LINE__, __func__, LOG_INFO, __VA_ARGS__) |
| #define DB_LOG_WARN | ( | ... | ) | refdm_db_log_msg(__FILE__, __LINE__, __func__, LOG_WARNING, __VA_ARGS__) |
| #define RET_FAIL_BAD_ARGS 3 |
Return code that indicates that bad input arguments were passed.
| #define RET_FAIL_DATABASE 10 |
Return code that there was a database (generic) error.
| #define RET_FAIL_DATABASE_CONNECTION 11 |
Return code that there was a database connection error.
| #define RET_FAIL_UNDEFINED 1 |
Return code that indicates the input resolves to an undefined result.
| #define RET_FAIL_UNEXPECTED 2 |
Return code that indicates the input resolves to an unexpected/abnormal state.
| #define RET_PASS 0 |
Return code that indicates normal completion.
| #define SQL_CONN_TRIES 10 |
| #define SQL_RECONN_TIME_MSEC 500 |
| int32_t db_add_agent | ( | const cace_data_t * | agent_eid | ) |
| void refdm__db_mgt_close_conn | ( | size_t | i | ) |
References MGR_NUM_QUERIES.
Referenced by refdm_db_mgt_close().
| int refdm_db_clear_rptset | ( | int32_t | agent_idx | ) |
Runs a clear request on the rptset database table.
All rows will be removed.
RET_FAIL_* on failure. Referenced by refdm_mgr_clear_reports().
| refdm_agent_t * refdm_db_fetch_agent | ( | int32_t | id | ) |
References CACE_LOG_ERR, CACE_LOG_INFO, DB_REST_CON, refdm_agent_init(), result, and RET_PASS.
| int32_t refdm_db_fetch_agent_idx | ( | const char * | eid | ) |
Get the index of an Agent from its endpoint name.
| [in] | sender | The agent EID. |
References CACE_FREE, CACE_LOG_ERR, CACE_LOG_INFO, CACE_MALLOC, DB_REST_CON, DB_RPT_CON, result, and RET_PASS.
Referenced by agentsGetHandler(), agentShowHexReports(), agentShowTextReports(), and refdm_mgr_clear_reports().
| int refdm_db_fetch_rptset_count | ( | int32_t | agent_idx, |
| size_t * | count | ||
| ) |
Runs a query on the database and retrieves the number of RPTSETs.
| agent_idx | The row index of the source Agent. | |
| [out] | count | Argument used to return the number of RPTSETs. |
RET_FAIL_* on failure. Referenced by agentsGetHandler().
| int refdm_db_fetch_rptset_list | ( | int32_t | agent_idx, |
| cace_ari_list_t * | rptsets | ||
| ) |
Runs a query on the database and retrieves the list of RPTSETs.
| agent_idx | The row index of the source Agent. | |
| [out] | rptsets | The list used to hold the retrieved RPTSETs. |
RET_FAIL_* on failure. Referenced by agentShowHexReports(), and agentShowTextReports().
| uint32_t refdm_db_insert_agent | ( | const m_string_t | eid | ) |
| eid | agent eid being added |
| status | Set to 0 if parsing fails, but not modified on success |
References ARI_AGENT_INSERT, CACE_LOG_INFO, and DB_RPT_CON.
Referenced by refdm_mgr_agent_add().
| uint32_t refdm_db_insert_execset | ( | const cace_ari_t * | val, |
| const refdm_agent_t * | agent | ||
| ) |
References agent, ARI_EXECSET_INSERT, cace_ari_cbor_encode(), cace_ari_cget_execset(), CACE_ARI_TEXT_ENC_OPTS_DEFAULT, cace_ari_text_encode(), cace_data_deinit(), cace_data_init(), CACE_DATA_INIT_NULL, CACE_LOG_DEBUG, cace_log_is_enabled_for(), DB_RPT_CON, cace_data_t::len, cace_ari_execset_t::nonce, cace_data_t::ptr, and cace_ari_execset_t::targets.
Referenced by agentSendItems().
| uint32_t refdm_db_insert_rptset | ( | const cace_ari_t * | val, |
| const refdm_agent_t * | agent | ||
| ) |
| val | Report |
| agent | agent table set being inserted in |
| status | Set to 0 if parsing fails, but not modified on success |
References agent, ARI_RPTSET_INSERT, cace_ari_cbor_encode(), cace_ari_cget_rptset(), cace_ari_get_tp(), CACE_ARI_TEXT_ENC_OPTS_DEFAULT, cace_ari_text_encode(), cace_data_deinit(), cace_data_init(), CACE_DATA_INIT_NULL, CACE_LOG_DEBUG, CACE_LOG_ERR, CACE_LOG_INFO, cace_log_is_enabled_for(), cace_utctime_encode(), DB_RPT_CON, cace_data_t::len, cace_ari_rptset_t::nonce, cace_data_t::ptr, and cace_ari_rptset_t::reftime.
Referenced by handle_recv().
| void refdm_db_log_msg | ( | const char * | filename, |
| int | lineno, | ||
| const char * | funcname, | ||
| int | level, | ||
| size_t | dbidx, | ||
| const char * | format, | ||
| ... | |||
| ) |
Utility function to insert debug or error informational messages into the database.
NOTE: If operating within a transaction, caller is responsible for committing transaction.
References MGR_NUM_SQL_CONNECTIONS, REFDM_DB_LOG_MSG, va_end(), and va_start().
| void refdm_db_mgt_close | ( | void | ) |
References CACE_LOG_INFO, db_rest_con_use, MGR_NUM_SQL_CONNECTIONS, and refdm__db_mgt_close_conn().
Referenced by refdm_mgr_deinit().
| int refdm_db_mgt_connected | ( | size_t | i | ) |
References DB_LOG_INFO, DB_RPT_CON, gParms, refdm_db_mgt_init_con(), result, and SQL_CONN_TRIES.
Referenced by refdm_db_mgt_query_insert().
| uint32_t refdm_db_mgt_init | ( | refdm_db_t * | parms, |
| uint32_t | clear, | ||
| uint32_t | log | ||
| ) |
References CACE_LOG_INFO, DB_CTRL_CON, DB_REST_CON, db_rest_con_use, DB_RPT_CON, and refdm_db_mgt_init_con().
Referenced by refdm_mgr_init().
| uint32_t refdm_db_mgt_init_con | ( | size_t | idx, |
| refdm_db_t * | parms | ||
| ) |
Initialize specified (thread-specific) SQL connection and prepared queries Prepared queries are connection specific.
While we may not use all prepared statements for all connections, initializing the same sets everywhere simplifies management.
References ARI_AGENT_INSERT, ARI_EXECSET_INSERT, ARI_RPTSET_INSERT, CACE_LOG_INFO, CACE_LOG_WARNING, gParms, and REFDM_DB_LOG_MSG.
Referenced by refdm_db_mgt_connected(), and refdm_db_mgt_init().
| int32_t refdm_db_mgt_query_insert | ( | int | db_idx, |
| uint32_t * | idx, | ||
| char * | format, | ||
| ... | |||
| ) |
References CACE_LOG_ERR, CACE_LOG_INFO, errm, m_string_init_vprintf(), query, refdm_db_mgt_connected(), va_end(), and va_start().