⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rpt_utils.c

📁 HIP 硬件设备管理标准接口
💻 C
📖 第 1 页 / 共 3 页
字号:
 * intrument id for a sensor is in the range of 0x100-0x1FF. An aggregate type * of sensor can have its instrument id in the range of 0x100-0x10F, but * the resource must have the aggregate sensor capabilitiy bit set. **/SaErrorT oh_add_rdr(RPTable *table, SaHpiResourceIdT rid, SaHpiRdrT *rdr, void *data, int owndata){        RPTEntry *rptentry;        RDRecord *rdrecord;        SaHpiInstrumentIdT type_num;        if (!table) {                dbg("Error: Cannot work on a null table pointer.");                return SA_ERR_HPI_INVALID_PARAMS;        } else if (!rdr) {                dbg("Failed to add. RDR is NULL.");                return SA_ERR_HPI_INVALID_PARAMS;        }        rptentry = get_rptentry_by_rid(table, rid);        if (!rptentry){                dbg("Failed to add RDR. Parent RPT entry was not found in table.");                return SA_ERR_HPI_NOT_PRESENT;        }                if (check_instrument_id(&(rptentry->rpt_entry), rdr)) {                dbg("Invalid instrument id found in RDR.");                return SA_ERR_HPI_INVALID_PARAMS;        }        type_num = get_rdr_type_num(rdr);        /* Form correct RecordId. */        rdr->RecordId = get_rdr_uid(rdr->RdrType, type_num);        /* Check if record exists */        rdrecord = get_rdrecord_by_id(rptentry, rdr->RecordId);        /* If not, create new rdr */        if (!rdrecord) {                rdrecord = (RDRecord *)g_malloc0(sizeof(RDRecord));                if (!rdrecord) {                        dbg("Not enough memory to add RDR.");                        return SA_ERR_HPI_OUT_OF_MEMORY;                }                /* Put new rdrecord in rdr repository */                rptentry->rdrlist = g_slist_append(rptentry->rdrlist, (gpointer)rdrecord);                /* Create rdr hash table if first rdr here */                if (!rptentry->rdrtable)                        rptentry->rdrtable = g_hash_table_new(g_int_hash, g_int_equal);                rdrecord->rdr.RecordId = rdr->RecordId;                g_hash_table_insert(rptentry->rdrtable,                                    &(rdrecord->rdr.RecordId),                                    rdrecord);        }        /* Else, modify existing rdrecord */        if (rdrecord->data && rdrecord->data != data && !rdrecord->owndata)                g_free(rdrecord->data);        rdrecord->data = data;        rdrecord->owndata = owndata;        rdrecord->rdr = *rdr;        return SA_OK;}/** * oh_remove_rdr * @table: Pointer to RPT table containig the RPT entry from which the RDR will * be removed. * @rid: Id of the RPT entry from which the RDR will be removed. * @rdrid: Record id of the RDR to remove. * * * Remove an RDR from a RPT entry's RDR repository. * If @rdrid is %SAHPI_FIRST_ENTRY, the first RDR in the repository will be removed. * If @owndata was set to false (%FREE_RPT_DATA) on the rdr when it was added, * the data will be freed, otherwise if it was set to true (%KEEP_RPT_DATA), * it will not be freed. * 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. **/SaErrorT oh_remove_rdr(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid){        RPTEntry *rptentry;        RDRecord *rdrecord;        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 RDR. Parent RPT entry was not found.");                return SA_ERR_HPI_NOT_PRESENT;        }        rdrecord = get_rdrecord_by_id(rptentry, rdrid);        if (!rdrecord) {                dbg("Failed to remove RDR. Could not be found.");                return SA_ERR_HPI_NOT_PRESENT;        } else {                rptentry->rdrlist = g_slist_remove(rptentry->rdrlist, (gpointer)rdrecord);                if (!rdrecord->owndata) g_free(rdrecord->data);                g_hash_table_remove(rptentry->rdrtable, &(rdrecord->rdr.RecordId));                g_free((gpointer)rdrecord);                if (!rptentry->rdrlist) {                        g_hash_table_destroy(rptentry->rdrtable);                        rptentry->rdrtable = NULL;                }        }        return SA_OK;}/** * oh_get_rdr_data * @table: Pointer to RPT table containig the RPT entry from which the RDR's data * will be read. * @rid: Id of the RPT entry from which the RDR's data will be read. * @rdrid: Record id of the RDR to read data from. * * * Get the private data associated to an RDR. * If @rdrid is %SAHPI_FIRST_ENTRY, the first RDR's data in the repository will be returned. * 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: A void pointer to the RDR data, or NULL if no data for that RDR was found or * the table pointer is NULL. **/void *oh_get_rdr_data(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid){        RPTEntry *rptentry;        RDRecord *rdrecord;        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. Cannot find RDR.");                return NULL; /* No resource found by that id */        }        rdrecord = get_rdrecord_by_id(rptentry, rdrid);        if (!rdrecord) {                /*dbg("Warning: RDR not found. Returning NULL.");*/                return NULL;        }        return rdrecord->data;}/** * oh_get_rdr_by_id * @table: Pointer to RPT table containig the RPT entry tha has the RDR * being looked up. * @rid: Id of the RPT entry containing the RDR being looked up. * @rdrid: Record id of the RDR being looked up. * * Get a reference to an RDR by its record id. * If @rdrid is %SAHPI_FIRST_ENTRY, the first RDR in the repository will be returned. * 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: * Reference to the RDR looked up or NULL if no RDR was found. **/SaHpiRdrT *oh_get_rdr_by_id(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid){        RPTEntry *rptentry;        RDRecord *rdrecord;        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. Cannot find RDR.");                return NULL; /* No resource found by that id */        }        rdrecord = get_rdrecord_by_id(rptentry, rdrid);        if (!rdrecord) {                /*dbg("Warning: RDR not found. Returning NULL.");*/                return NULL;        }        return &(rdrecord->rdr);}/** * oh_get_rdr_by_type * @table: Pointer to RPT table containig the RPT entry tha has the RDR * being looked up. * @rid: Id of the RPT entry containing the RDR being looked up. * @type: RDR Type of the RDR being looked up. * @num: RDR id within the RDR type for the specified RPT entry. * * Get a reference to an RDR by its type and number. * 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: * Reference to the RDR looked up or NULL if no RDR was found. **/SaHpiRdrT *oh_get_rdr_by_type(RPTable *table, SaHpiResourceIdT rid,                              SaHpiRdrTypeT type, SaHpiInstrumentIdT num){        RPTEntry *rptentry;        RDRecord *rdrecord;        SaHpiEntryIdT rdr_uid;        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. Cannot find RDR.");                return NULL; /* No resource found by that id */        }        /* Get rdr_uid from type/num combination */        rdr_uid = get_rdr_uid(type, num);        rdrecord = get_rdrecord_by_id(rptentry, rdr_uid);        if (!rdrecord) {                /*dbg("Warning: RDR not found. Returning NULL.");*/                return NULL;        }        return &(rdrecord->rdr);}/** * oh_get_rdr_next * @table: Pointer to the RPT containing the RPT entry to look up the RDR in. * @rid: Id of the RPT entry containing the RDR being looked up. * @rdrid_prev: Record id of the RDR previous to the one being looked up, relative * to the specified RPT entry. * * Get the RDR next to the specified RDR in the specified * RPT entry's repository. If @rdrid_prev is %SAHPI_FIRST_ENTRY, the first RDR * in the repository will be returned. * 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: * Pointer to the RDR found or NULL if the previous RDR by that * id was not found. If the @rdrid_prev was %SAHPI_FIRST_ENTRY, the first RDR in the list * will be returned. **/SaHpiRdrT *oh_get_rdr_next(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid_prev){        RPTEntry *rptentry;        RDRecord *rdrecord = NULL;        GSList *node;        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. Cannot find RDR.");                return NULL; /* No resource found by that id */        }        if (rdrid_prev == SAHPI_FIRST_ENTRY) {                if (rptentry->rdrlist) {                        rdrecord = (RDRecord *)(rptentry->rdrlist->data);                } else {                        /*dbg("Info: RDR repository is empty. Returning NULL.");*/                        return NULL;                }        } else {                for (node = rptentry->rdrlist; node != NULL; node = node->next) {                        rdrecord = (RDRecord *)node->data;                        if (rdrecord->rdr.RecordId == rdrid_prev) {                                if (node->next) rdrecord = (RDRecord *)(node->next->data);                                else {                                        /*dbg("Info: Reached end of RDR repository.")*/                                        return NULL;                                }                                break;                        }                        else rdrecord = NULL;                }        }        if (!rdrecord) {                /*dbg("Warning: RDR not found. Returning NULL.");*/                return NULL;        }        return &(rdrecord->rdr);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -