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

📄 rpt_utils.c

📁 HIP 硬件设备管理标准接口
💻 C
📖 第 1 页 / 共 3 页
字号:
/*      -*- linux-c -*- * * (C) Copyright IBM Corp. 2003, 2004 * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This * file and program are licensed under a BSD style license.  See * the Copying file included with the OpenHPI distribution for * full licensing terms. * * Author(s): *      Renier Morales <renierm@users.sf.net> */#include <string.h>#include <sys/time.h>#include <oh_utils.h>static RPTEntry *get_rptentry_by_rid(RPTable *table, SaHpiResourceIdT rid){        RPTEntry *rptentry = NULL;        if (!table) {                dbg("ERROR: Cannot work on a null table pointer.");                return NULL;        }        if (!(table->rptlist)) {                /*dbg("Info: RPT is empty.");*/                return NULL;        }        if (rid == SAHPI_FIRST_ENTRY) {                rptentry = (RPTEntry *) (table->rptlist->data);        } else {                rptentry = (RPTEntry *)g_hash_table_lookup(table->rptable, &rid);        }        return rptentry;}static RDRecord *get_rdrecord_by_id(RPTEntry *rptentry, SaHpiEntryIdT id){        RDRecord *rdrecord = NULL;        if (!rptentry) {                dbg("ERROR: Cannot lookup rdr inside null resource.");                return NULL;        }        if (!rptentry->rdrlist) {                /*dbg("Info: RDR repository is empty.");*/                return NULL;        }        if (id == SAHPI_FIRST_ENTRY) {                rdrecord = (RDRecord *) (rptentry->rdrlist->data);        } else {                rdrecord = (RDRecord *)g_hash_table_lookup(rptentry->rdrtable, &id);        }        return rdrecord;}static int check_instrument_id(SaHpiRptEntryT *rptentry, SaHpiRdrT *rdr){        int result = 0;        static const SaHpiInstrumentIdT SENSOR_AGGREGATE_MAX = 0x0000010F;                switch (rdr->RdrType) {                case SAHPI_SENSOR_RDR:                        if (rdr->RdrTypeUnion.SensorRec.Num >= SAHPI_STANDARD_SENSOR_MIN &&                            rdr->RdrTypeUnion.SensorRec.Num <= SAHPI_STANDARD_SENSOR_MAX) {                                if (rdr->RdrTypeUnion.SensorRec.Num > SENSOR_AGGREGATE_MAX) {                                        result = -1;                                } else if (rptentry->ResourceCapabilities &                                           SAHPI_CAPABILITY_AGGREGATE_STATUS) {                                        result = 0;                                                                        } else {                                        result = -1;                                }                        } else {                                result = 0;                        }                        break;                default:                        result = 0;        }                return result;}static SaHpiInstrumentIdT get_rdr_type_num(SaHpiRdrT *rdr){        SaHpiInstrumentIdT num = 0;        switch (rdr->RdrType) {                case SAHPI_CTRL_RDR:                        num = rdr->RdrTypeUnion.CtrlRec.Num;                        break;                case SAHPI_SENSOR_RDR:                        num = rdr->RdrTypeUnion.SensorRec.Num;                        break;                case SAHPI_INVENTORY_RDR:                        num = rdr->RdrTypeUnion.InventoryRec.IdrId;                        break;                case SAHPI_WATCHDOG_RDR:                        num = rdr->RdrTypeUnion.WatchdogRec.WatchdogNum;                        break;                case SAHPI_ANNUNCIATOR_RDR:                        num = rdr->RdrTypeUnion.AnnunciatorRec.AnnunciatorNum;                        break;                default:                        num = 0;        }        return num;}static void update_rptable(RPTable *table) {        struct timeval tv;        SaHpiTimeT time;        if (!table) {                dbg("ERROR: Cannot work on a null table pointer.");                return;        }        gettimeofday(&tv, NULL);        time = (SaHpiTimeT) tv.tv_sec * 1000000000 + tv.tv_usec * 1000;        table->update_timestamp = time;        table->update_count++;}/** * get_rdr_uid * @type: type of rdr * @num: id number of the RDR unique withing the RDR type for that resource * * Helper function to derive the Record id of an rdr from its @type and @num * * Returns: a derived Record Id used to identify RDRs within Resources */SaHpiEntryIdT get_rdr_uid(SaHpiRdrTypeT type, SaHpiInstrumentIdT num){        SaHpiEntryIdT uid;        uid = ((SaHpiEntryIdT)type) << 16;        uid = uid + (SaHpiEntryIdT)num;        return uid;}/** * General RPT calls **//** * oh_init_rpt * @table: Pointer to RPTable structure to be initialized. * * * Returns: SA_OK on success Or minus SA_OK on error. **/SaErrorT oh_init_rpt(RPTable *table){        if (!table) {                dbg("ERROR: Cannot work on a null table pointer.");                return SA_ERR_HPI_INVALID_PARAMS;        }        table->update_timestamp = SAHPI_TIME_UNSPECIFIED;        table->update_count = 0;        table->rptlist = NULL;        table->rptable = NULL;                return SA_OK;} /** * oh_flush_rpt * @table: Pointer to the RPT to flush. * * Cleans RPT from all entries and RDRs and frees the memory * associated with them. * * Returns: SA_OK on success Or minus SA_OK on error. **/SaErrorT oh_flush_rpt(RPTable *table){        SaHpiRptEntryT *tmp_entry;        if (!table) {                dbg("ERROR: Cannot work on a null table pointer.");                return SA_ERR_HPI_INVALID_PARAMS;        }        while ((tmp_entry = oh_get_resource_by_id(table, SAHPI_FIRST_ENTRY)) != NULL) {                oh_remove_resource(table, SAHPI_FIRST_ENTRY);        }        return SA_OK;}/** * rpt_diff * @cur_rpt: IN. Pointer to RPTable that represents the current state of resources * and rdrs. * @new_rpt: IN. Pointer to RPTable that contains rpt entries and rdrs just recently * discovered. * @res_new: OUT. List of new or changed rpt entries * @rdr_new: OUT. List of new or changed rdrs * @res_gone: OUT. List of old and not present resources. * @rdr_gone: OUT. List of old and not present rdrs. * * Extracts from current the resources and rdrs that are not found * in new and puts them in res_gone and rdr_gone. Also, puts in res_new and rdr_new * the resources and rdrs that are not already in current Or that are not identical * to the ones in current. * * Returns: void. **/void rpt_diff(RPTable *cur_rpt, RPTable *new_rpt,              GSList **res_new, GSList **rdr_new,              GSList **res_gone, GSList **rdr_gone) {        SaHpiRptEntryT *res = NULL;        /* Look for absent resources and rdrs */        for (res = oh_get_resource_by_id(cur_rpt, SAHPI_FIRST_ENTRY);             res != NULL;             res = oh_get_resource_next(cur_rpt, res->ResourceId)) {                SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(new_rpt, res->ResourceId);                if (tmp_res == NULL) *res_gone = g_slist_append(*res_gone, (gpointer)res);                else {                        SaHpiRdrT *rdr = NULL;                        for (rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, SAHPI_FIRST_ENTRY);                             rdr != NULL;                             rdr = oh_get_rdr_next(cur_rpt, res->ResourceId, rdr->RecordId)) {                                SaHpiRdrT *tmp_rdr =                                        oh_get_rdr_by_id(new_rpt, res->ResourceId, rdr->RecordId);                                if (tmp_rdr == NULL)                                        *rdr_gone = g_slist_append(*rdr_gone, (gpointer)rdr);                        }                }        }        /* Look for new resources and rdrs*/        for (res = oh_get_resource_by_id(new_rpt, SAHPI_FIRST_ENTRY);             res != NULL;             res = oh_get_resource_next(new_rpt, res->ResourceId)) {                SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(cur_rpt, res->ResourceId);                SaHpiRdrT *rdr = NULL;                if (!tmp_res || memcmp(res, tmp_res, sizeof(SaHpiRptEntryT))) {                        *res_new = g_slist_append(*res_new, (gpointer)res);                }                for (rdr = oh_get_rdr_by_id(new_rpt, res->ResourceId, SAHPI_FIRST_ENTRY);                     rdr != NULL;                     rdr = oh_get_rdr_next(new_rpt, res->ResourceId, rdr->RecordId)) {                        SaHpiRdrT *tmp_rdr = NULL;                        if (tmp_res != NULL)                                tmp_rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, rdr->RecordId);                        if (tmp_rdr == NULL || memcmp(rdr, tmp_rdr, sizeof(SaHpiRdrT)))                                *rdr_new = g_slist_append(*rdr_new, (gpointer)rdr);                }        }}/** * oh_get_rpt_info * @table: pointer to RPT * @update_count: pointer of where to place the rpt's update count * @update_timestamp: pointer of where to place the rpt's update timestamp * * Returns: SA_OK on success Or minus SA_OK on error. **/SaErrorT oh_get_rpt_info(RPTable *table,                         SaHpiUint32T *update_count,                         SaHpiTimeT *update_timestamp){        if (!table || !update_count || !update_timestamp) {                dbg("ERROR: Invalid parameters.");                return SA_ERR_HPI_INVALID_PARAMS;        }        *update_count = table->update_count;        *update_timestamp = table->update_timestamp;        return SA_OK;}

⌨️ 快捷键说明

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