Commit 71f04b02 authored by Lucas Russo's avatar Lucas Russo

{include,src/dev_mngr}/dev_mngr.*: use libhutils ZCONFIG parsing

parent 57f2f6eb
......@@ -78,9 +78,6 @@ dmngr_err_e dmngr_scan_devs (dmngr_t *self, uint32_t *num_devs_found);
dmngr_err_e dmngr_spawn_all_devios (dmngr_t *self, char *broker_endp,
char *devio_log_filename, bool respawn_killed_devio);
/* Utility functions */
dmngr_err_e dmngr_get_hints (zconfig_t *root_cfg, zhash_t *hints_h);
#ifdef __cplusplus
}
#endif
......
......@@ -150,8 +150,8 @@ int main (int argc, char *argv[])
/* Read DEVIO suggested bind endpoints and fill the hash table with
* the corresponding keys */
dmngr_err_e err = dmngr_get_hints (root_cfg, dmngr_hints);
if (err != DMNGR_SUCCESS) {
hutils_err_e herr = hutils_get_hints (root_cfg, dmngr_hints);
if (herr != HUTILS_SUCCESS) {
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_FATAL, "[dev_mngr] Could not get hints "
"from configuration file\n");
goto err_cfg_exit;
......@@ -227,7 +227,7 @@ int main (int argc, char *argv[])
dmngr_set_wait_clhd_handler (dmngr, &hutils_wait_chld);
dmngr_set_spawn_clhd_handler (dmngr, &hutils_spawn_chld);
err = dmngr_register_sig_handlers (dmngr);
dmngr_err_e err = dmngr_register_sig_handlers (dmngr);
if (err != DMNGR_SUCCESS) {
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_FATAL, "[dev_mngr] dmngr_register_sig_handler error!\n");
goto err_sig_handlers;
......
......@@ -40,33 +40,6 @@
#define DEVIO_BE_DEV_PATTERN "/dev/fpga%d"
#define DEVIO_BE_DEV_GLOB "/dev/fpga*"
/******************* Configuration file property names ************************/
#define DMNGR_FE_CFG_ENDP_MAX_PATH 256
#define DMNGR_FE_CFG_ENDP_PATH_PATTERN \
"/dev_io/board%u/bpm%u/afe/bind"
/* We don't expect our hash key to be bigger than this */
#define DMNGR_CFG_HASH_KEY_MAX_LEN 64
/* Our config hash key is composed of this pattern: board%u/bpm%u/afe
* or board%u/bpm%u/dbe */
#define DMNGR_CFG_BOARD_TYPE "%s"
#define DMNGR_CFG_BOARD_PATTERN "board%u"
#define DMNGR_CFG_BPM_TYPE "%s"
#define DMNGR_CFG_BPM_PATTERN "bpm%u"
#define DMNGR_CFG_DEVIO_MODEL_TYPE "%s"
#define DMNGR_CFG_AFE "afe"
#define DMNGR_CFG_DBE "dbe"
//#define DMNGR_CFG_HASH_KEY_PATTERN "%s/%s/%s"
#define DMNGR_CFG_HASH_KEY_PATTERN DMNGR_CFG_BOARD_TYPE \
"/" DMNGR_CFG_BPM_TYPE "/" \
DMNGR_CFG_DEVIO_MODEL_TYPE
#define DMNGR_CFG_HASH_KEY_PATTERN_COMPL \
DMNGR_CFG_BOARD_PATTERN \
"/" DMNGR_CFG_BPM_PATTERN "/" \
DMNGR_CFG_DEVIO_MODEL_TYPE
/* Arbitrary hard limit for the maximum number of AFE DEVIOs
* for each DBE DEVIO */
#define DEVIO_MAX_FE_DEVIOS 16
......@@ -540,12 +513,12 @@ static dmngr_err_e _dmngr_scan_devs (dmngr_t *self, uint32_t *num_devs_found)
/* Stringify ID */
/* DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_TRACE,
"[dev_mngr_core:scan_devs] Stringify hash ID\n"); */
char key [DMNGR_CFG_HASH_KEY_MAX_LEN];
char key [HUTILS_CFG_HASH_KEY_MAX_LEN];
/* This follows the hierarchy found in the config file */
int errs = snprintf (key, sizeof (key), DMNGR_CFG_HASH_KEY_PATTERN_COMPL,
int errs = snprintf (key, sizeof (key), HUTILS_CFG_HASH_KEY_PATTERN_COMPL,
devio_info_id, /* BPM ID does not matter for DBE DEVIOs */ 0,
DMNGR_CFG_DBE);
HUTILS_CFG_DBE);
/* Only when the number of characters written is less than the whole buffer,
* it is guaranteed that the string was written successfully */
......@@ -647,76 +620,3 @@ err_devio_info_alloc:
return err;
}
dmngr_err_e dmngr_get_hints (zconfig_t *root_cfg, zhash_t *hints_h)
{
assert (root_cfg);
assert (hints_h);
dmngr_err_e err = DMNGR_SUCCESS;
/* Read DEVIO suggested bind endpoints and fill the hash table with
* the corresponding keys */
/* First find the dev_io property */
zconfig_t *devio_cfg = zconfig_locate (root_cfg, "/dev_io");
ASSERT_TEST (devio_cfg != NULL, "Could not find "
"dev_io property in configuration file", err_cfg_exit,
DMNGR_ERR_CFG);
/* Now, find all of our child */
zconfig_t *board_cfg = zconfig_child (devio_cfg);
ASSERT_TEST (board_cfg != NULL, "Could not find "
"board* property in configuration file", err_cfg_exit,
DMNGR_ERR_CFG);
/* Navigate through all of our board siblings */
for (; board_cfg != NULL; board_cfg = zconfig_next (board_cfg)) {
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_TRACE, "Config file: "
"board_cfg name: %s\n", zconfig_name (board_cfg));
zconfig_t *bpm_cfg = zconfig_child (board_cfg);
ASSERT_TEST (bpm_cfg != NULL, "Could not find "
"bpm* property in configuration file", err_cfg_exit,
DMNGR_ERR_CFG);
/* Navigate through all of our bpm siblings and fill the hash table */
for (; bpm_cfg != NULL; bpm_cfg = zconfig_next (bpm_cfg)) {
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_TRACE, "Config file: "
"bpm_cfg name: %s\n", zconfig_name (bpm_cfg));
/* Now, we expect to find the bind address of this bpm/board instance
* in the configuration file */
char *hints_value = zconfig_resolve (bpm_cfg, "/afe/bind",
NULL);
ASSERT_TEST (hints_value != NULL, "[dev_mngr] Could not find "
"AFE bind address in configuration file", err_cfg_exit,
DMNGR_ERR_CFG);
/* Now, we only need to generate a valid key to insert in the hash.
* we choose the combination of the type "board%u/bpm%u/afe" or
* board%u/bpm%u/dbe */
char hints_key [DMNGR_CFG_HASH_KEY_MAX_LEN];
int errs = snprintf (hints_key, sizeof (hints_key),
DMNGR_CFG_HASH_KEY_PATTERN, zconfig_name (board_cfg),
zconfig_name (bpm_cfg), DMNGR_CFG_AFE);
/* Only when the number of characters written is less than the whole buffer,
* it is guaranteed that the string was written successfully */
ASSERT_TEST (errs >= 0 && (size_t) errs < sizeof (hints_key),
"[dev_mngr] Could not generate AFE bind address from "
"configuration file\n", err_cfg_exit, DMNGR_ERR_CFG);
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_INFO, "[dev_mngr_core] AFE hint endpoint "
"hash key: \"%s\", value: \"%s\"\n", hints_key, hints_value);
/* Insert this value in the hash table */
errs = zhash_insert (hints_h, hints_key, hints_value);
ASSERT_TEST (errs == 0, "Could not find insert AFE endpoint to "
"hash table", err_cfg_exit, DMNGR_ERR_CFG);
}
}
err_cfg_exit:
return err;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment