Commit d08e75c4 authored by Lucas Russo's avatar Lucas Russo

hal/*: WIP 2 on github issue #79

parent 662deb67
......@@ -289,8 +289,13 @@ devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint32_t base,
/* Stringify ID */
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE,
"[dev_io_core:register_sm] Stringify hash ID\n");
char *key = halutils_concat_strings (smio_mod_dispatch[th_args->smio_id].name,
inst_id, '');
char *inst_id_str = halutils_stringify_dec_key (inst_id);
ASSERT_ALLOC(inst_id_str, err_inst_id_str_alloc);
char *key = halutils_concat_strings_no_sep (smio_mod_dispatch[th_args->smio_id].name,
inst_id_str);
/* We don't need this anymore */
free (inst_id_str);
inst_id_str = NULL;
ASSERT_ALLOC (key, err_key_alloc);
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE,
......@@ -342,6 +347,8 @@ err_smio_service_alloc:
err_pipe_hash_insert:
free (key);
err_key_alloc:
free (inst_id_str);
err_inst_id_str_alloc:
/* This is safe to call more than once */
_devio_destroy_smio (self, smio_id);
err_spawn_smio_thread:
......@@ -358,13 +365,11 @@ devio_err_e devio_register_all_sm (devio_t *self)
return DEVIO_ERR_FUNC_NOT_IMPL;
}
devio_err_e devio_unregister_sm (devio_t *self, uint32_t smio_id, uint32_t inst_id)
devio_err_e devio_unregister_sm (devio_t *self, const char *smio_key)
{
(void) self;
(void) smio_id;
(void) inst_id;
return DEVIO_ERR_FUNC_NOT_IMPL;
_devio_destroy_smio (self, smio_key);
return DEVIO_ERR_FUNC_NOT_IMPL;
}
devio_err_e devio_unregister_all_sm (devio_t *self)
......@@ -540,6 +545,8 @@ err_hash_keys_alloc:
return;
}
/* smio_key is the name of the SMIO + instance number, e.g.,
* FMC130M_4CH0*/
static void _devio_destroy_smio (devio_t *self, const char *smio_key)
{
assert (self);
......@@ -559,14 +566,16 @@ static void _devio_destroy_smio (devio_t *self, const char *smio_key)
ASSERT_TEST (zerr == 0, "Could not send self-destruct message to SMIO instance",
err_send_msg);
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_INFO, "[dev_io_core] Self-destruct message "
"to SMIO %s sent", smio_key);
/* Finally, remove the pipe from hash */
zhash_delete (self->sm_io_h, key_c);
zhash_delete (self->sm_io_h, smio_key);
err_send_msg:
zmsg_destroy (&send_msg);
err_msg_alloc:
err_hash_lookup:
free (key_c);
err_key_alloc:
return;
}
......
......@@ -36,7 +36,7 @@
halutils_err_str (err_type))
static char *_halutils_concat_strings_raw (const char *str1, const char* str2,
const char *str3, char sep);
const char *str3, bool with_sep, char sep)
uint32_t num_to_str_len (uint32_t key, uint32_t base)
{
......@@ -91,23 +91,37 @@ char *halutils_stringify_hex_key (uint32_t key)
#define SEPARATOR_BYTES 1
/* FIXME: poorly written */
static char *_halutils_concat_strings_raw (const char *str1, const char* str2,
const char *str3, char sep)
const char *str3, bool with_sep, char sep)
{
assert (str1);
assert (str2);
uint32_t num_sep_bytes = (with_sep)? SEPARATOR_BYTES : 0;
char *str = NULL;
if (str3 != NULL) {
str = zmalloc (strlen (str1) + strlen (str2) + strlen (str3) +
SEPARATOR_BYTES /* separator length */+ 1 /* \0 */);
num_sep_bytes /* separator length */+ 1 /* \0 */);
ASSERT_ALLOC(str, err_str3_alloc);
sprintf (str, "%s%c%s%s", str1, sep, str2, str3);
if (with_sep) {
sprintf (str, "%s%c%s%s", str1, sep, str2, str3);
}
else {
sprintf (str, "%s%s%s", str1, str2, str3);
}
}
else {
str = zmalloc (strlen(str1) + strlen(str2) +
SEPARATOR_BYTES /* separator length */+ 1 /* \0 */);
num_sep_bytes /* separator length */+ 1 /* \0 */);
ASSERT_ALLOC(str, err_str2_alloc);
sprintf (str, "%s%c%s", str1, sep, str2);
if (with_sep) {
sprintf (str, "%s%c%s", str1, sep, str2);
}
else {
sprintf (str, "%s%s", str1, str2);
}
}
return str;
......@@ -119,11 +133,16 @@ err_str2_alloc:
char *halutils_concat_strings (const char *str1, const char* str2, char sep)
{
return _halutils_concat_strings_raw (str1, str2, NULL, sep);
return _halutils_concat_strings_raw (str1, str2, NULL, true, sep);
}
char *halutils_concat_strings_no_sep (const char *str1, const char* str2)
{
return _halutils_concat_strings_raw (str1, str2, NULL, false, 0);
}
char *halutils_concat_strings3 (const char *str1, const char* str2,
const char* str3, char sep)
{
return _halutils_concat_strings_raw (str1, str2, str3, sep);
return _halutils_concat_strings_raw (str1, str2, str3, true, sep);
}
......@@ -31,11 +31,15 @@ char *halutils_stringify_dec_key (uint32_t key);
/* Allocates a string with the necessary size to fit an hexadecimal key */
char *halutils_stringify_hex_key (uint32_t key);
/* Concatenates 2 strings togheter with a separator. returns the string if
/* Concatenates 2 strings together with a separator. returns the string if
* OK, NULL in case of error */
char *halutils_concat_strings (const char *str1, const char* str2, char sep);
/* Concatenates 3 strings togheter with a separator between the first and second
/* Concatenates 2 strings together without a separator. returns the string if
* OK, NULL in case of error */
char *halutils_concat_strings_no_sep (const char *str1, const char* str2);
/* Concatenates 3 strings together with a separator between the first and second
* strings. returns the string if OK, NULL in case of error */
char *halutils_concat_strings3 (const char *str1, const char* str2,
const char* str3, char sep);
......
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