📄 snmp_bc_inventory.c
字号:
/* -*- 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):
* peter d phan <pdphan@sourceforge.net>
* Renier Morales <renierm@users.sf.net>
*
* 07/19/04 HPI-B Inventory
*/
#include <snmp_bc_plugin.h>
static
SaErrorT snmp_bc_build_idr( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
struct bc_inventory_record *i_record);
static
SaErrorT snmp_bc_idr_build_field(struct snmp_bc_hnd *custom_handle,
gchar *oid,
SaHpiIdrFieldT *thisField,
struct bc_idr_area *thisInventoryArea);
/************************************************************************/
/* Inventory functions */
/************************************************************************/
/**
* snmp_bc_get_idr_info:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @IdrInfo: Pointer to the information describing the requested Inventory Data Repository
*
* Build the Inventory Data Record for the inputed resource id, idr id.
* Copy the IdrInfo found for the input resource id and idr id
*
* Return value:
* SA_OK - Normal
* SA_ERR_HPI_INVALID_PARAMS - NULL input pointers, hnd or IdrInfo
* SA_ERR_HPI_NOT_PRESENT - If can not find idr with matched requested IdrId
**/
SaErrorT snmp_bc_get_idr_info( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiIdrInfoT *IdrInfo)
{
SaErrorT rv = SA_OK;
struct bc_inventory_record *i_record;
if (!hnd || !IdrInfo)
return(SA_ERR_HPI_INVALID_PARAMS);
i_record = (struct bc_inventory_record *)g_malloc0(sizeof(struct bc_inventory_record));
if (!i_record) {
dbg("Cannot allocate working buffer memory");
return(SA_ERR_HPI_OUT_OF_MEMORY);
}
rv = snmp_bc_build_idr(hnd, ResourceId, IdrId, i_record);
if (rv == SA_OK) {
if (IdrId == i_record->idrinfo.IdrId)
memcpy(IdrInfo, &(i_record->idrinfo), sizeof(SaHpiIdrInfoT));
else
rv = SA_ERR_HPI_NOT_PRESENT;
}
g_free(i_record);
return rv;
}
/**
* snmp_bc_get_idr_area_header:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @AreaType: Type of Inventory Data Area
* @AreaId: Identifier of Area entry to retrieve from the IDR
* @NextAreaId: Pointer to location to store the AreaId of the next area
* of the requested type within the IDR
* @Header: Pointer to Inventory Data Area Header into which the header
information is placed
*
* Build the Inventory Data Record for the inputed resource id, idr id.
* Copy the Inventory Data Area Header to the space provided by user.
*
* Internal code makes an assumption that there is only one (1) Idr per
* resource in snmp_bc plugin. For this to be expanded to more than one
* Idr per resource, the base bc_resources.c/h has to be changed together
* with the rest of inventory code.
*
* Return value:
* SA_OK - Normal
* SA_ERR_HPI_INVALID_PARAMS - NULL input pointers, hnd or NextAreaId or Header
* SA_ERR_HPI_OUT_OF_MEMORY - If can not allocate temp work space
* SA_ERR_HPI_NOT_PRESENT - If can not find idr area with matched requested AreaId
**/
SaErrorT snmp_bc_get_idr_area_header( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiIdrAreaTypeT AreaType,
SaHpiEntryIdT AreaId,
SaHpiEntryIdT *NextAreaId,
SaHpiIdrAreaHeaderT *Header)
{
SaErrorT rv = SA_OK;
struct bc_inventory_record *i_record;
if (!hnd || !NextAreaId || !Header)
return(SA_ERR_HPI_INVALID_PARAMS);
i_record = (struct bc_inventory_record *)g_malloc0(sizeof(struct bc_inventory_record));
if (!i_record) {
dbg("Cannot allocate working buffer memory");
return(SA_ERR_HPI_OUT_OF_MEMORY);
}
rv = snmp_bc_build_idr(hnd, ResourceId, IdrId, i_record);
if (rv == SA_OK) {
rv = SA_ERR_HPI_NOT_PRESENT;
if (IdrId == i_record->idrinfo.IdrId) {
if ( (i_record->area[0].idrareas.Type == AreaType) ||
(SAHPI_IDR_AREATYPE_UNSPECIFIED == AreaType) )
{
if ( (i_record->area[0].idrareas.AreaId == AreaId) ||
(SAHPI_FIRST_ENTRY == AreaId) )
{
memcpy(Header, &(i_record->area[0].idrareas), sizeof(SaHpiIdrAreaHeaderT));
*NextAreaId = SAHPI_LAST_ENTRY;
rv = SA_OK;
}
}
}
}
g_free(i_record);
return (rv);
}
/**
* snmp_bc_add_idr_area:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @AreaType: Type of Inventory Data Area
* @AreaId: Pointer to store the identifier of the newly allocated Inventory Area
*
* This function is not suported/implemented for snmp_bc plugin
*
* Return value:
* SA_ERR_HPI_READ_ONLY - Normal - snmp_bc does not allow Inventory Update
**/
SaErrorT snmp_bc_add_idr_area( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiIdrAreaTypeT AreaType,
SaHpiEntryIdT *AreaId)
{
return SA_ERR_HPI_READ_ONLY;
}
/**
* snmp_bc_del_idr_area:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @AreaId: Identifier of Area entry to delete from the IDR
*
* This function is not suported/implemented for snmp_bc plugin
*
* Return value:
* SA_ERR_HPI_READ_ONLY - Normal - snmp_bc does not allow Inventory Update
**/
SaErrorT snmp_bc_del_idr_area( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiEntryIdT AreaId)
{
return SA_ERR_HPI_READ_ONLY;
}
/**
* snmp_bc_get_idr_field:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @AreaId: Identifier of Area for the IDA
* @FieldType: Type of Inventory Data Field
* @FieldId: Identier of Field to retrieve from the IDA
* @NextFieldId: Pointer to location to store the FieldId
* of the next field of the requested type in IDA
* @Field: Pointer to Inventory Data Field into which the field information will be placed.
*
* Return value:
* SA_OK - Normal
* SA_ERR_HPI_INVALID_PARAMS - NULL input pointers, hnd or IdrInfo
* SA_ERR_HPI_NOT_PRESENT - If can not find requested field
**/
SaErrorT snmp_bc_get_idr_field( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiEntryIdT AreaId,
SaHpiIdrFieldTypeT FieldType,
SaHpiEntryIdT FieldId,
SaHpiEntryIdT *NextFieldId,
SaHpiIdrFieldT *Field)
{
SaErrorT rv = SA_OK;
struct bc_inventory_record *i_record;
int i;
SaHpiBoolT foundit = SAHPI_FALSE;
if (!hnd || !NextFieldId || !Field)
return(SA_ERR_HPI_INVALID_PARAMS);
i_record = (struct bc_inventory_record *)g_malloc0(sizeof(struct bc_inventory_record));
if (!i_record) {
dbg("Cannot allocate working buffer memory");
return(SA_ERR_HPI_OUT_OF_MEMORY);
}
rv = snmp_bc_build_idr(hnd, ResourceId, IdrId, i_record);
if (rv == SA_OK) {
rv = SA_ERR_HPI_NOT_PRESENT;
if (i_record->area[0].idrareas.AreaId == AreaId) {
/* Search for fieldId here */
for (i=0; i < i_record->area[0].idrareas.NumFields; i++) {
if ( ((i_record->area[0].field[i].FieldId == FieldId) ||
(SAHPI_FIRST_ENTRY == FieldId))
&& ((i_record->area[0].field[i].Type == FieldType) ||
(SAHPI_IDR_FIELDTYPE_UNSPECIFIED == FieldType)) )
{
memcpy(Field, &(i_record->area[0].field[i]), sizeof(SaHpiIdrFieldT));
foundit = SAHPI_TRUE;
rv = SA_OK;
break;
}
}
*NextFieldId = SAHPI_LAST_ENTRY;
i++;
if (foundit) {
if (i < i_record->area[0].idrareas.NumFields) {
do {
if ((i_record->area[0].field[i].Type == FieldType) ||
(SAHPI_IDR_FIELDTYPE_UNSPECIFIED == FieldType))
{
*NextFieldId = i_record->area[0].field[i].FieldId;
break;
}
i++;
} while (i < i_record->area[0].idrareas.NumFields);
}
}
}
}
g_free(i_record);
return rv;
}
/**
* snmp_bc_add_idr_field:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @Field: Pointer to Inventory Data Field which contains field information to be added.
*
* This function is not suported/implemented for snmp_bc plugin
*
* Return value:
* SA_ERR_HPI_READ_ONLY - Normal - snmp_bc does not allow Inventory Update
**/
SaErrorT snmp_bc_add_idr_field( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiIdrFieldT *Field)
{
return SA_ERR_HPI_READ_ONLY;
}
/**
* snmp_bc_set_idr_field:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @Field: Pointer to Inventory Data Field which contains updated field information.
*
* This function is not suported/implemented for snmp_bc plugin
*
* Return value:
* SA_ERR_HPI_READ_ONLY - Normal - snmp_bc does not allow Inventory Update
**/
SaErrorT snmp_bc_set_idr_field( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiIdrFieldT *Field)
{
return SA_ERR_HPI_READ_ONLY;
}
/**
* snmp_bc_del_idr_field:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @AreaId: Identifier of Inventory Area whose field is to bo deleted
* @FieldId: Identifier of field to be deleted
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -