If there is an object template of a YANG node, the complete object ID (yang path from top parent to the current object node) of the object can be fetched with the below functions:
- obj_gen_object_id (const obj_template_t *obj, xmlChar **buff)
- obj_gen_object_id_prefix (const obj_template_t *obj, xmlChar **buff)
- obj_gen_object_id_xpath (const obj_template_t *obj, xmlChar **buff)
- obj_gen_object_id_oid (ncx_module_t *mod, const obj_template_t *obj, xmlChar **buff)
/********************************************************************
* FUNCTION obj_gen_object_id
*
* Malloc and Generate the object ID for an object node
*
* INPUTS:
* obj == the node to generate the instance ID for
* buff == pointer to address of buffer to use
*
* RETURNS:
* status
*********************************************************************/
status_t
obj_gen_object_id (const obj_template_t *obj,
xmlChar **buff)/********************************************************************
* FUNCTION obj_gen_object_id_prefix
*
* Malloc and Generate the object ID for an object node
* Use the prefix in every node
*
* INPUTS:
* obj == the node to generate the instance ID for
* buff == pointer to address of buffer to use
*
* RETURNS:
* status
*********************************************************************/
status_t
obj_gen_object_id_prefix (const obj_template_t *obj,
xmlChar **buff)/********************************************************************
* FUNCTION obj_gen_object_id_xpath
*
* Malloc and Generate the object ID for an object node
* Remove all conceptual OBJ_TYP_CHOICE and OBJ_TYP_CASE nodes
* so the resulting string will represent the structure of the
* value tree for XPath searching
*
* INPUTS:
* obj == the node to generate the instance ID for
* buff == pointer to address of buffer to use
*
* RETURNS:
* status
*********************************************************************/
status_t
obj_gen_object_id_xpath (const obj_template_t *obj,
xmlChar **buff)/********************************************************************
* FUNCTION obj_gen_object_id_oid
*
* Malloc and Generate the object ID for an object node
* Used for canonical ID string comparison to generate OID number
*
* Uses the JSON/YANG module-name for prefix convention
* Only print module name when namespace changes
*
* INPUTS:
* mod == the module containing the object
* obj == the node to generate the instance ID for
* buff == pointer to address of buffer to use
*
* RETURNS:
* status
*********************************************************************/
status_t
obj_gen_object_id_oid (ncx_module_t *mod,
const obj_template_t *obj,
xmlChar **buff)Below is an example of using one of the APIs above:
/********************************************************************
* FUNCTION dump_get2cb
*
* Print the interesting fields in a get2cb and msg
*
* INPUTS:
* get2cb == get2 control block to use
* msg == message header control block to use
*
*********************************************************************/
static void
dump_get2cb (getcb_get2_t *get2cb,
xml_msg_hdr_t *msg)
{
if (!get2cb || !msg) {
SET_ERROR(ERR_INTERNAL_PTR);
return;
}
log_info("\n\n------------------------");
log_info("\nCallback information:");
obj_template_t *obj = GETCB_GET2_OBJ(get2cb);
if (obj) {
log_info("\n object: '%s:%s'",
obj_get_mod_name(obj),
obj_get_name(obj));
xmlChar *buff = NULL;
status_t res = obj_gen_object_id_prefix(obj, &buff);
if (res == NO_ERR && buff) {
log_info_append("\n path: %s", buff);
}
if (buff) {
m__free(buff);
}
} else {
log_info("\n object: NONE");
}
log_info("\n------------------------\n");
} /* dump_get2cb */