/* * Delete all sensor nodes and related properties created by the * add_sensor_prop() for each sensor node in the PICL tree. */ static void delete_sensor_nodes_and_props(void) { sensor_node_t *snodep; /* * Delete/destroy any property created in the sensed device * as well as the sensor node and all properties under it. * Note that deleiing/destroying a node deletes/destroys * all properties within that node. */ for (snodep = sensor_nodes; snodep->sensor_name != NULL; snodep++) { if (snodep->sdev_proph != NULL) { (void) ptree_delete_prop(snodep->sdev_proph); (void) ptree_destroy_prop(snodep->sdev_proph); snodep->sdev_proph = NULL; } if (snodep->nodeh != NULL) { /* delete node and all properties under it */ (void) ptree_delete_node(snodep->nodeh); (void) ptree_destroy_node(snodep->nodeh); snodep->nodeh = NULL; snodep->proph = NULL; } } }
/* * This function is identical to the one in the picldevtree plugin. * Unfortunately we can't just reuse that code. */ int add_string_list_prop(picl_nodehdl_t nodeh, char *name, char *strlist, unsigned int nrows) { ptree_propinfo_t propinfo; picl_prophdl_t proph; picl_prophdl_t tblh; int err; unsigned int i; unsigned int j; picl_prophdl_t *proprow; int len; #define NCOLS_IN_STRING_TABLE 1 err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, PICL_PTYPE_TABLE, PICL_READ, sizeof (picl_prophdl_t), name, NULL, NULL); if (err != PICL_SUCCESS) return (err); err = ptree_create_table(&tblh); if (err != PICL_SUCCESS) return (err); err = ptree_create_and_add_prop(nodeh, &propinfo, &tblh, &proph); if (err != PICL_SUCCESS) return (err); proprow = alloca(sizeof (picl_prophdl_t) * nrows); if (proprow == NULL) { (void) ptree_destroy_prop(proph); return (PICL_FAILURE); } for (j = 0; j < nrows; ++j) { len = strlen(strlist) + 1; err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, PICL_PTYPE_CHARSTRING, PICL_READ, len, name, NULL, NULL); if (err != PICL_SUCCESS) break; err = ptree_create_prop(&propinfo, strlist, &proprow[j]); if (err != PICL_SUCCESS) break; strlist += len; err = ptree_add_row_to_table(tblh, NCOLS_IN_STRING_TABLE, &proprow[j]); if (err != PICL_SUCCESS) break; } if (err != PICL_SUCCESS) { for (i = 0; i < j; ++i) (void) ptree_destroy_prop(proprow[i]); (void) ptree_delete_prop(proph); (void) ptree_destroy_prop(proph); return (err); } return (PICL_SUCCESS); }