📄 rpt_utils.c
字号:
/** * Resource interface functions *//** * oh_add_resource * @table: Pointer to the RPT to which the RPT entry will be added. * @entry: The RPT entry (resource) to be added to the RPT. * @data: Pointer to private data for storing along with the RPT entry. * @owndata: boolean flag. true (%KEEP_RPT_DATA) to tell the interface *not* * to free the data when the resource is removed. false (%FREE_RPT_DATA) to tell * the interface to free the data when the resource is removed. * * Add a RPT entry to the RPT along with some private data. * If an RPT entry with the same resource id exists int the RPT, it will be * overlayed with the new RPT entry. Also, this function will assign the * resource id as its entry id since it is expected to be unique for the table. * The update count and timestamp will not be updated if the entry being added * already existed in the table and was the same. * * Returns: SA_OK on success Or minus SA_OK on error. SA_ERR_HPI_INVALID_PARAMS will * be returned if @table is NULL, @entry is NULL, ResourceId in @entry equals * SAHPI_FIRST_ENTRY, ResourceId in @entry equals SAHPI_UNSPECIFIED_RESOURCE_ID, * or ResourceEntity in @entry has a malformed entity path (look at the * entity path utils documentation). **/SaErrorT oh_add_resource(RPTable *table, SaHpiRptEntryT *entry, void *data, int owndata){ RPTEntry *rptentry; int update_info = 0; if (!table) { dbg("ERROR: Cannot work on a null table pointer."); return SA_ERR_HPI_INVALID_PARAMS; } else if (!entry) { dbg("Failed to add. RPT entry is NULL."); return SA_ERR_HPI_INVALID_PARAMS; } else if (entry->ResourceId == SAHPI_FIRST_ENTRY) { dbg("Failed to add. RPT entry needs a resource id before being added"); return SA_ERR_HPI_INVALID_PARAMS; } else if (entry->ResourceId == SAHPI_UNSPECIFIED_RESOURCE_ID) { dbg("Failed to add. RPT entry has an invalid/reserved id assigned. (SAHPI_UNSPECIFIED_RESOURCE_ID)"); return SA_ERR_HPI_INVALID_PARAMS; } else if (validate_ep(&(entry->ResourceEntity))) { dbg("Failed to add RPT entry. Entity path does not contain root element."); return SA_ERR_HPI_INVALID_PARAMS; } entry->EntryId = entry->ResourceId; /* Check to see if the entry is in the RPTable already */ rptentry = get_rptentry_by_rid(table, entry->ResourceId); /* If not, create new RPTEntry */ if (!rptentry) { rptentry = (RPTEntry *)g_malloc0(sizeof(RPTEntry)); if (!rptentry) { dbg("Not enough memory to add RPT entry."); return SA_ERR_HPI_OUT_OF_MEMORY; } update_info = 1; /* Have a new changed entry */ /* Put new RPTEntry in RPTable */ table->rptlist = g_slist_append(table->rptlist, (gpointer)rptentry); /* Add to rpt hash table */ if (!table->rptable) /* Create hash table if it doesn't exist */ table->rptable = g_hash_table_new(g_int_hash, g_int_equal); rptentry->rpt_entry.EntryId = entry->ResourceId; g_hash_table_insert(table->rptable, &(rptentry->rpt_entry.EntryId), rptentry); } /* Else, modify existing RPTEntry */ if (rptentry->data && rptentry->data != data && !rptentry->owndata) g_free(rptentry->data); rptentry->data = data; rptentry->owndata = owndata; /* Check if we really have a new/changed entry */ if (update_info || memcmp(entry, &(rptentry->rpt_entry), sizeof(SaHpiRptEntryT))) { update_info = 1; rptentry->rpt_entry = *entry; } if (update_info) update_rptable(table); return SA_OK;}/** * oh_remove_resource * @table: Pointer to the RPT from which an RPT entry will be removed. * @rid: Resource id of the RPT entry to be removed. * * Remove a resource from the RPT. If the @rid is * %SAHPI_FIRST_ENTRY, the first RPT entry in the table will be removed. * The void data will be freed if @owndata was false (%FREE_RPT_DATA) when adding * the resource, otherwise if @owndata was true (%KEEP_RPT_DATA) it will not be freed. * * Returns: SA_OK on success Or minus SA_OK on error. **/SaErrorT oh_remove_resource(RPTable *table, SaHpiResourceIdT rid){ RPTEntry *rptentry; if (!table) { dbg("ERROR: Cannot work on a null table pointer."); return SA_ERR_HPI_INVALID_PARAMS; } rptentry = get_rptentry_by_rid(table, rid); if (!rptentry) { dbg("Failed to remove RPT entry. No Resource found by that id"); return SA_ERR_HPI_NOT_PRESENT; } else { SaHpiRdrT *tmp_rdr; /* Remove all RDRs for the resource first */ while ((tmp_rdr = oh_get_rdr_by_id(table, rid, SAHPI_FIRST_ENTRY)) != NULL) { oh_remove_rdr(table, rid, SAHPI_FIRST_ENTRY); } /* then remove the resource itself. */ table->rptlist = g_slist_remove(table->rptlist, (gpointer)rptentry); if (!rptentry->owndata) g_free(rptentry->data); g_hash_table_remove(table->rptable, &(rptentry->rpt_entry.EntryId)); g_free((gpointer)rptentry); if (!table->rptlist) { g_hash_table_destroy(table->rptable); table->rptable = NULL; } } update_rptable(table); return SA_OK;}/** * oh_get_resource_data * @table: Pointer to the RPT for looking up the RPT entry's private data. * @rid: Resource id of the RPT entry that holds the private data. * * Get the private data for a RPT entry. If the @rid is * %SAHPI_FIRST_ENTRY, the first RPT entry's data in the table will be returned. * * Returns: A void pointer to the private data for the RPT entry requested, or NULL * if the RPT entry was not found or the table was a NULL pointer. **/void *oh_get_resource_data(RPTable *table, SaHpiResourceIdT rid){ RPTEntry *rptentry; if (!table) { dbg("ERROR: Cannot work on a null table pointer."); return NULL; } rptentry = get_rptentry_by_rid(table, rid); if (!rptentry) { /*dbg("Warning: RPT entry not found. Returning NULL.");*/ return NULL; } return rptentry->data;}/** * oh_get_resource_by_id * @table: Pointer to the RPT for looking up the RPT entry. * @rid: Resource id of the RPT entry to be looked up. * * Get a RPT entry from the RPT by using the resource id. * If @rid is %SAHPI_FIRST_ENTRY, the first RPT entry in the table will be returned. * * Returns: * Pointer to the RPT entry found or NULL if an RPT entry by that * id was not found or the table was a NULL pointer. **/SaHpiRptEntryT *oh_get_resource_by_id(RPTable *table, SaHpiResourceIdT rid){ RPTEntry *rptentry; if (!table) { dbg("ERROR: Cannot work on a null table pointer."); return NULL; } rptentry = get_rptentry_by_rid(table, rid); if (!rptentry) { /*dbg("Warning: RPT entry not found. Returning NULL.");*/ return NULL; } return &(rptentry->rpt_entry);}/** * oh_get_resource_by_ep * @table: Pointer to the RPT for looking up the RPT entry. * @ep: Entity path of the RPT entry to be looked up. * * Get a RPT entry from the RPT by using the entity path. * * Returns: * Pointer to the RPT entry found or NULL if an RPT entry by that * entity path was not found or the table was a NULL pointer. **/SaHpiRptEntryT *oh_get_resource_by_ep(RPTable *table, SaHpiEntityPathT *ep){ RPTEntry *rptentry = NULL; GSList *node; if (!(table)) { dbg("ERROR: Cannot work on a null table pointer."); return NULL; } for (node = table->rptlist; node != NULL; node = node->next) { rptentry = (RPTEntry *) node->data; if (!ep_cmp(&(rptentry->rpt_entry.ResourceEntity), ep)) break; else rptentry = NULL; } if (!rptentry) { /*dbg("Warning: RPT entry not found. Returning NULL.");*/ return NULL; } return &(rptentry->rpt_entry);}/** * oh_get_resource_next * @table: Pointer to the RPT for looking up the RPT entry. * @rid_prev: Resource id of the RPT entry previous to the one being looked up. * * Get the RPT entry next to the specified RPT entry * from the RPT. If @rid_prev is %SAHPI_FIRST_ENTRY, the first RPT entry * in the table will be returned. * * Returns: * Pointer to the RPT entry found or NULL if the previous RPT entry by that * id was not found or the table was a NULL pointer. **/SaHpiRptEntryT *oh_get_resource_next(RPTable *table, SaHpiResourceIdT rid_prev){ RPTEntry *rptentry = NULL; GSList *node; if (!(table)) { dbg("ERROR: Cannot work on a null table pointer."); return NULL; } if (rid_prev == SAHPI_FIRST_ENTRY) { if (table->rptlist) { rptentry = (RPTEntry *)(table->rptlist->data); } else { /*dbg("Info: RPT is empty. Returning NULL.");*/ return NULL; } } else { for (node = table->rptlist; node != NULL; node = node->next) { rptentry = (RPTEntry *) node->data; if (rptentry->rpt_entry.ResourceId == rid_prev) { if (node->next) rptentry = (RPTEntry *)(node->next->data); else { /*dbg("Info: Reached end of RPT.");*/ return NULL; } break; } else rptentry = NULL; } } if (!rptentry) { /*dbg("Warning: RPT entry not found. Returning NULL.");*/ return NULL; } return &(rptentry->rpt_entry);}/** * RDR interface functions *//** * oh_add_rdr * @table: Pointer to RPT table containig the RPT entry to which the RDR will belong. * @rid: Id of the RPT entry that will own the RDR to be added. * @rdr: RDR to be added to an RPT entry's RDR repository. * @data: Pointer to private data belonging to the RDR that is being added. * @owndata: boolean flag. true (%KEEP_RPT_DATA) to tell the interface *not* * to free the data when the rdr is removed. false (%FREE_RPT_DATA) to tell * the interface to free the data when the rdr is removed. * * Add an RDR to a RPT entry's RDR repository. * If an RDR is found with the same record id as the one being added, the RDR being * added will overlay the existing one. Also, a unique record id will be assigned * to it based on the RDR type and its type's numeric id. * All rdr interface funtions, except oh_add_rdr() will act in the context of * the first RPT entry in the table, if @rid is %SAHPI_FIRST_ENTRY. * * Returns: SA_OK on success Or minus SA_OK on error. Will return * SA_ERR_HPI_INVALID_PARAMS if instrument id is invalid. An invalid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -