Commit 0265c597 authored by Lucas Russo's avatar Lucas Russo

hal/*/protocols/sm_pr*: add set/unset protocol ops

parent df096ee8
...@@ -97,6 +97,37 @@ smpr_err_e smpr_destroy (smpr_t **self_p) ...@@ -97,6 +97,37 @@ smpr_err_e smpr_destroy (smpr_t **self_p)
return SMPR_SUCCESS; return SMPR_SUCCESS;
} }
/* Register Specific Protocol operations to smpr instance */
smpr_err_e smpr_set_handler (smpr_t *self, void *handler)
{
assert (self);
assert (handler);
smpr_err_e err = SMPR_SUCCESS;
ASSERT_TEST(self->proto_handler == NULL, "Trying to set another handler to "
"SMPR instance", err_dup_handler, SMPR_ERR_DUP_HANDLER);
DBE_DEBUG (DBG_SM_PR | DBG_LVL_INFO, "[sm_pr] Setting protocol handler: %s\n",
self->name);
self->proto_handler = handler;
err_dup_handler:
return err;
}
/* Unregister Specific Protocol operations to smpr instance */
void *smpr_unset_handler (smpr_t *self)
{
assert (self);
void *proto_handler = self->proto_handler;
DBE_DEBUG (DBG_SM_PR | DBG_LVL_INFO, "[sm_pr] Unsetting protocol handler: %s\n",
self->name);
self->proto_handler = NULL;
return proto_handler;
}
/**************** Helper Functions ***************/ /**************** Helper Functions ***************/
/* Register Specific Protocol operations to smpr instance. Helper function */ /* Register Specific Protocol operations to smpr instance. Helper function */
......
...@@ -102,6 +102,10 @@ typedef enum _smpr_type_e smpr_type_e; ...@@ -102,6 +102,10 @@ typedef enum _smpr_type_e smpr_type_e;
smpr_t * smpr_new (char *name, smio_t *parent, smpr_type_e type, int verbose); smpr_t * smpr_new (char *name, smio_t *parent, smpr_type_e type, int verbose);
/* Destroy an instance of the Low-level I/O */ /* Destroy an instance of the Low-level I/O */
smpr_err_e smpr_destroy (smpr_t **self_p); smpr_err_e smpr_destroy (smpr_t **self_p);
/* Register Specific Protocol operations to smpr instance */
smpr_err_e smpr_set_handler (smpr_t *self, void *handler);
/* Unregister Specific Protocol operations to smpr instance */
void *smpr_unset_handler (smpr_t *self);
/************************************************************/ /************************************************************/
/***************** Thsafe generic methods API ***************/ /***************** Thsafe generic methods API ***************/
......
...@@ -16,7 +16,8 @@ static const char *smpr_err [SMPR_ERR_END] = ...@@ -16,7 +16,8 @@ static const char *smpr_err [SMPR_ERR_END] =
[SMPR_ERR_ALLOC] = "Could not allocate memory", [SMPR_ERR_ALLOC] = "Could not allocate memory",
[SMPR_ERR_INV_FUNC_PARAM] = "Invalid function parameter", [SMPR_ERR_INV_FUNC_PARAM] = "Invalid function parameter",
[SMPR_ERR_RW_SMIO] = "Could not Read/Write to/from SMIO", [SMPR_ERR_RW_SMIO] = "Could not Read/Write to/from SMIO",
[SMPR_ERR_FUNC_NOT_IMPL] = "Function not implemented" [SMPR_ERR_FUNC_NOT_IMPL] = "Function not implemented",
[SMPR_ERR_DUP_HANDLER] = "Protocol handler already set"
}; };
/* Convert enumeration type to string */ /* Convert enumeration type to string */
......
...@@ -15,9 +15,10 @@ enum _smpr_err_e ...@@ -15,9 +15,10 @@ enum _smpr_err_e
{ {
SMPR_SUCCESS = 0, /* No error */ SMPR_SUCCESS = 0, /* No error */
SMPR_ERR_ALLOC, /* Could not allocate memory */ SMPR_ERR_ALLOC, /* Could not allocate memory */
SMPR_ERR_INV_FUNC_PARAM, /* Invalid function paramter */ SMPR_ERR_INV_FUNC_PARAM, /* Invalid function parameter */
SMPR_ERR_FUNC_NOT_IMPL, /* Fucntions not implemented */ SMPR_ERR_FUNC_NOT_IMPL, /* Functions not implemented */
SMPR_ERR_RW_SMIO, /* Invalid function parameter */ SMPR_ERR_RW_SMIO, /* Invalid function parameter */
SMPR_ERR_DUP_HANDLER, /* Protocol handler already set */
SMPR_ERR_END /* End of enum marker */ SMPR_ERR_END /* End of enum marker */
}; };
......
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