Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
Beam Positoning Monitor - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Beam Positoning Monitor - Software
Commits
57f2f6eb
Commit
57f2f6eb
authored
Jun 12, 2015
by
Lucas Russo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src/libs/libhutils/*: add ZCONFIG parsing for hints
parent
0a2f1cf8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
1 deletion
+112
-1
hutils_utils.c
src/libs/libhutils/hutils_utils.c
+81
-1
hutils_utils.h
src/libs/libhutils/hutils_utils.h
+31
-0
No files found.
src/libs/libhutils/hutils_utils.c
View file @
57f2f6eb
...
...
@@ -8,11 +8,11 @@
#include <stdio.h>
#include <sys/wait.h>
/* waitpid */
#include <errno.h>
/* perror */
#include <czmq.h>
#include "hutils.h"
#include "hutils_err.h"
#include "errhand.h"
#include "czmq.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
...
...
@@ -278,3 +278,83 @@ int hutils_copy_str (char *dest, const char *src, size_t size)
int
errs
=
snprintf
(
dest
,
size
,
"%s"
,
src
);
return
errs
;
}
/*******************************************************************/
/********************* ZCONFIG read functions *********************/
/*******************************************************************/
/* Get properties from config file (defined in http://rfc.zeromq.org/spec:4)
* and store them in hash table in the form <property name / property value> */
hutils_err_e
hutils_get_hints
(
zconfig_t
*
root_cfg
,
zhash_t
*
hints_h
)
{
assert
(
root_cfg
);
assert
(
hints_h
);
hutils_err_e
err
=
HUTILS_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
,
HUTILS_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
,
HUTILS_ERR_CFG
);
/* Navigate through all of our board siblings */
for
(;
board_cfg
!=
NULL
;
board_cfg
=
zconfig_next
(
board_cfg
))
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
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
,
HUTILS_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_HAL_UTILS
|
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
,
HUTILS_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
[
HUTILS_CFG_HASH_KEY_MAX_LEN
];
int
errs
=
snprintf
(
hints_key
,
sizeof
(
hints_key
),
HUTILS_CFG_HASH_KEY_PATTERN
,
zconfig_name
(
board_cfg
),
zconfig_name
(
bpm_cfg
),
HUTILS_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
,
HUTILS_ERR_CFG
);
DBE_DEBUG
(
DBG_HAL_UTILS
|
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
,
HUTILS_ERR_CFG
);
}
}
err_cfg_exit:
return
err
;
}
src/libs/libhutils/hutils_utils.h
View file @
57f2f6eb
...
...
@@ -11,6 +11,33 @@
#include <inttypes.h>
#include <stddef.h>
/******************* Configuration file property names ************************/
#define HUTILS_FE_CFG_ENDP_MAX_PATH 256
#define HUTILS_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 HUTILS_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 HUTILS_CFG_BOARD_TYPE "%s"
#define HUTILS_CFG_BOARD_PATTERN "board%u"
#define HUTILS_CFG_BPM_TYPE "%s"
#define HUTILS_CFG_BPM_PATTERN "bpm%u"
#define HUTILS_CFG_DEVIO_MODEL_TYPE "%s"
#define HUTILS_CFG_AFE "afe"
#define HUTILS_CFG_DBE "dbe"
//#define HUTILS_CFG_HASH_KEY_PATTERN "%s/%s/%s"
#define HUTILS_CFG_HASH_KEY_PATTERN HUTILS_CFG_BOARD_TYPE \
"/" HUTILS_CFG_BPM_TYPE "/" \
HUTILS_CFG_DEVIO_MODEL_TYPE
#define HUTILS_CFG_HASH_KEY_PATTERN_COMPL HUTILS_CFG_BOARD_PATTERN \
"/" HUTILS_CFG_BPM_PATTERN "/" \
HUTILS_CFG_DEVIO_MODEL_TYPE
/************************ Our methods *****************************/
/* Returns the necessary string length including the termianting null character
* for a number in a arbitrary base */
uint32_t
hutils_num_to_str_len
(
uint32_t
key
,
uint32_t
base
);
...
...
@@ -74,4 +101,8 @@ char *hutils_clone_str (const char *str);
* a maximum of size bytes */
int
hutils_copy_str
(
char
*
dest
,
const
char
*
src
,
size_t
size
);
/* Get properties from config file (defined in http://rfc.zeromq.org/spec:4)
* and store them in hash table in the form <property name / property value> */
hutils_err_e
hutils_get_hints
(
zconfig_t
*
root_cfg
,
zhash_t
*
hints_h
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment