GCOV Execution Analysis for rpt_utils.c
The left column is the number of times the code was executed
during the unit test suites.
| Exec | Code | Line # | |
|---|---|---|---|
Source:rpt_utils.c | 1 | ||
Object:t/rpt/rpt_utils.bb | 2 | ||
/* -*- linux-c -*- | 3 | ||
* | 4 | ||
* (C) Copyright IBM Corp. 2003, 2005 | 5 | ||
* | 6 | ||
* This program is distributed in the hope that it will be useful, | 7 | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This | 9 | ||
* file and program are licensed under a BSD style license. See | 10 | ||
* the Copying file included with the OpenHPI distribution for | 11 | ||
* full licensing terms. | 12 | ||
* | 13 | ||
* Author(s): | 14 | ||
* Renier Morales < address removed > | 15 | ||
*/ | 16 | ||
| 17 | |||
#include <string.h> | 18 | ||
#include <sys/time.h> | 19 | ||
| 20 | |||
#include <oh_utils.h> | 21 | ||
| 22 | |||
static RPTEntry *get_rptentry_by_rid(RPTable *table, SaHpiResourceIdT rid) | 23 | ||
| 10654 | { | 24 | |
| 10654 | RPTEntry *rptentry = NULL; | 25 | |
| 26 | |||
| 10654 | if (!table) { | 27 | |
| 0 | dbg("ERROR: Cannot work on a null table pointer."); | 28 | |
| 0 | return NULL; | 29 | |
} | 30 | ||
| 31 | |||
| 10654 | if (!(table->rptlist)) { | 32 | |
/*dbg("Info: RPT is empty.");*/ | 33 | ||
| 80 | return NULL; | 34 | |
} | 35 | ||
| 36 | |||
| 10574 | if (rid == SAHPI_FIRST_ENTRY) { | 37 | |
| 123 | rptentry = (RPTEntry *) (table->rptlist->data); | 38 | |
} else { | 39 | ||
| 10451 | rptentry = (RPTEntry *)g_hash_table_lookup(table->rptable, &rid); | 40 | |
} | 41 | ||
| 42 | |||
| 10574 | return rptentry; | 43 | |
} | 44 | ||
| 45 | |||
static RDRecord *get_rdrecord_by_id(RPTEntry *rptentry, SaHpiEntryIdT id) | 46 | ||
| 212 | { | 47 | |
| 212 | RDRecord *rdrecord = NULL; | 48 | |
| 49 | |||
| 212 | if (!rptentry) { | 50 | |
| 0 | dbg("ERROR: Cannot lookup rdr inside null resource."); | 51 | |
| 0 | return NULL; | 52 | |
} | 53 | ||
| 54 | |||
| 212 | if (!rptentry->rdrlist) { | 55 | |
/*dbg("Info: RDR repository is empty.");*/ | 56 | ||
| 52 | return NULL; | 57 | |
} | 58 | ||
| 59 | |||
| 160 | if (id == SAHPI_FIRST_ENTRY) { | 60 | |
| 49 | rdrecord = (RDRecord *) (rptentry->rdrlist->data); | 61 | |
} else { | 62 | ||
| 111 | rdrecord = (RDRecord *)g_hash_table_lookup(rptentry->rdrtable, &id); | 63 | |
} | 64 | ||
| 65 | |||
| 160 | return rdrecord; | 66 | |
} | 67 | ||
| 68 | |||
static int check_instrument_id(SaHpiRptEntryT *rptentry, SaHpiRdrT *rdr) | 69 | ||
| 131 | { | 70 | |
| 131 | int result = 0; | 71 | |
| 131 | static const SaHpiInstrumentIdT SENSOR_AGGREGATE_MAX = 0x0000010F; | 72 | |
| 73 | |||
| 131 | switch (rdr->RdrType) { | 74 | |
case SAHPI_SENSOR_RDR: | 75 | ||
| 131 | if (rdr->RdrTypeUnion.SensorRec.Num >= SAHPI_STANDARD_SENSOR_MIN && | 76 | |
rdr->RdrTypeUnion.SensorRec.Num <= SAHPI_STANDARD_SENSOR_MAX) { | 77 | ||
| 2 | if (rdr->RdrTypeUnion.SensorRec.Num > SENSOR_AGGREGATE_MAX) { | 78 | |
| 1 | result = -1; | 79 | |
| 1 | } else if (rptentry->ResourceCapabilities & | 80 | |
SAHPI_CAPABILITY_AGGREGATE_STATUS) { | 81 | ||
| 0 | result = 0; | 82 | |
} else { | 83 | ||
| 1 | result = -1; | 84 | |
} | 85 | ||
} else { | 86 | ||
| 129 | result = 0; | 87 | |
} | 88 | ||
| 129 | break; | 89 | |
default: | 90 | ||
| 0 | result = 0; | 91 | |
} | 92 | ||
| 93 | |||
| 131 | return result; | 94 | |
} | 95 | ||
| 96 | |||
static SaHpiInstrumentIdT get_rdr_type_num(SaHpiRdrT *rdr) | 97 | ||
| 129 | { | 98 | |
| 129 | SaHpiInstrumentIdT num = 0; | 99 | |
| 100 | |||
| 129 | switch (rdr->RdrType) { | 101 | |
case SAHPI_CTRL_RDR: | 102 | ||
| 0 | num = rdr->RdrTypeUnion.CtrlRec.Num; | 103 | |
| 0 | break; | 104 | |
case SAHPI_SENSOR_RDR: | 105 | ||
| 129 | num = rdr->RdrTypeUnion.SensorRec.Num; | 106 | |
| 129 | break; | 107 | |
case SAHPI_INVENTORY_RDR: | 108 | ||
| 0 | num = rdr->RdrTypeUnion.InventoryRec.IdrId; | 109 | |
| 0 | break; | 110 | |
case SAHPI_WATCHDOG_RDR: | 111 | ||
| 0 | num = rdr->RdrTypeUnion.WatchdogRec.WatchdogNum; | 112 | |
| 0 | break; | 113 | |
case SAHPI_ANNUNCIATOR_RDR: | 114 | ||
| 0 | num = rdr->RdrTypeUnion.AnnunciatorRec.AnnunciatorNum; | 115 | |
| 0 | break; | 116 | |
default: | 117 | ||
| 0 | num = 0; | 118 | |
} | 119 | ||
| 120 | |||
| 129 | return num; | 121 | |
} | 122 | ||
| 123 | |||
| 10375 | static void update_rptable(RPTable *table) { | 124 | |
| 10375 | struct timeval tv; | 125 | |
| 10375 | SaHpiTimeT time; | 126 | |
| 127 | |||
| 10375 | if (!table) { | 128 | |
| 0 | dbg("ERROR: Cannot work on a null table pointer."); | 129 | |
| 0 | return; | 130 | |
} | 131 | ||
| 132 | |||
| 10375 | gettimeofday(&tv, NULL); | 133 | |
| 10375 | time = (SaHpiTimeT) tv.tv_sec * 1000000000 + tv.tv_usec * 1000; | 134 | |
| 135 | |||
| 10375 | table->update_timestamp = time; | 136 | |
| 10375 | table->update_count++; | 137 | |
} | 138 | ||
| 139 | |||
/** | 140 | ||
* get_rdr_uid | 141 | ||
* @type: type of rdr | 142 | ||
* @num: id number of the RDR unique withing the RDR type for that resource | 143 | ||
* | 144 | ||
* Helper function to derive the Record id of an rdr from its @type and @num | 145 | ||
* | 146 | ||
* Returns: a derived Record Id used to identify RDRs within Resources | 147 | ||
*/ | 148 | ||
SaHpiEntryIdT get_rdr_uid(SaHpiRdrTypeT type, SaHpiInstrumentIdT num) | 149 | ||
| 148 | { | 150 | |
| 148 | SaHpiEntryIdT uid; | 151 | |
| 152 | |||
| 148 | uid = ((SaHpiEntryIdT)type) << 16; | 153 | |
| 148 | uid = uid + (SaHpiEntryIdT)num; | 154 | |
| 155 | |||
| 148 | return uid; | 156 | |
} | 157 | ||
| 158 | |||
/** | 159 | ||
* General RPT calls | 160 | ||
**/ | 161 | ||
| 162 | |||
/** | 163 | ||
* oh_init_rpt | 164 | ||
* @table: Pointer to RPTable structure to be initialized. | 165 | ||
* | 166 | ||
* | 167 | ||
* Returns: SA_OK on success Or minus SA_OK on error. | 168 | ||
**/ | 169 | ||
SaErrorT oh_init_rpt(RPTable *table) | 170 | ||
| 82 | { | 171 | |
| 82 | if (!table) { | 172 | |
| 1 | dbg("ERROR: Cannot work on a null table pointer."); | 173 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 174 | |
} | 175 | ||
| 176 | |||
| 81 | table->update_timestamp = SAHPI_TIME_UNSPECIFIED; | 177 | |
| 81 | table->update_count = 0; | 178 | |
| 81 | table->rptlist = NULL; | 179 | |
| 81 | table->rptable = NULL; | 180 | |
| 181 | |||
| 81 | return SA_OK; | 182 | |
} | 183 | ||
| 184 | |||
/** | 185 | ||
* oh_flush_rpt | 186 | ||
* @table: Pointer to the RPT to flush. | 187 | ||
* | 188 | ||
* Cleans RPT from all entries and RDRs and frees the memory | 189 | ||
* associated with them. | 190 | ||
* | 191 | ||
* Returns: SA_OK on success Or minus SA_OK on error. | 192 | ||
**/ | 193 | ||
SaErrorT oh_flush_rpt(RPTable *table) | 194 | ||
| 2 | { | 195 | |
| 2 | SaHpiRptEntryT *tmp_entry; | 196 | |
| 197 | |||
| 2 | if (!table) { | 198 | |
| 1 | dbg("ERROR: Cannot work on a null table pointer."); | 199 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 200 | |
} | 201 | ||
| 202 | |||
| 11 | while ((tmp_entry = oh_get_resource_by_id(table, SAHPI_FIRST_ENTRY)) != NULL) { | 203 | |
| 10 | oh_remove_resource(table, SAHPI_FIRST_ENTRY); | 204 | |
} | 205 | ||
| 206 | |||
| 1 | return SA_OK; | 207 | |
} | 208 | ||
| 209 | |||
/** | 210 | ||
* rpt_diff | 211 | ||
* @cur_rpt: IN. Pointer to RPTable that represents the current state of resources | 212 | ||
* and rdrs. | 213 | ||
* @new_rpt: IN. Pointer to RPTable that contains rpt entries and rdrs just recently | 214 | ||
* discovered. | 215 | ||
* @res_new: OUT. List of new or changed rpt entries | 216 | ||
* @rdr_new: OUT. List of new or changed rdrs | 217 | ||
* @res_gone: OUT. List of old and not present resources. | 218 | ||
* @rdr_gone: OUT. List of old and not present rdrs. | 219 | ||
* | 220 | ||
* Extracts from current the resources and rdrs that are not found | 221 | ||
* in new and puts them in res_gone and rdr_gone. Also, puts in res_new and rdr_new | 222 | ||
* the resources and rdrs that are not already in current Or that are not identical | 223 | ||
* to the ones in current. | 224 | ||
* | 225 | ||
* Returns: void. | 226 | ||
**/ | 227 | ||
void rpt_diff(RPTable *cur_rpt, RPTable *new_rpt, | 228 | ||
GSList **res_new, GSList **rdr_new, | 229 | ||
| 6 | GSList **res_gone, GSList **rdr_gone) { | 230 | |
| 231 | |||
| 6 | SaHpiRptEntryT *res = NULL; | 232 | |
| 233 | |||
| 6 | if (!cur_rpt || !new_rpt || | 234 | |
| 1 | !res_new || !rdr_new || !res_gone || !rdr_gone) return; | 235 | |
| 236 | |||
/* Look for absent resources and rdrs */ | 237 | ||
| 0 | for (res = oh_get_resource_by_id(cur_rpt, SAHPI_FIRST_ENTRY); | 238 | |
res != NULL; | 239 | ||
res = oh_get_resource_next(cur_rpt, res->ResourceId)) { | 240 | ||
| 241 | |||
| 0 | SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(new_rpt, res->ResourceId); | 242 | |
| 243 | |||
| 0 | if (tmp_res == NULL) *res_gone = g_slist_append(*res_gone, (gpointer)res); | 244 | |
else { | 245 | ||
| 0 | SaHpiRdrT *rdr = NULL; | 246 | |
| 247 | |||
| 0 | for (rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, SAHPI_FIRST_ENTRY); | 248 | |
rdr != NULL; | 249 | ||
rdr = oh_get_rdr_next(cur_rpt, res->ResourceId, rdr->RecordId)) { | 250 | ||
| 251 | |||
| 0 | SaHpiRdrT *tmp_rdr = | 252 | |
| 0 | oh_get_rdr_by_id(new_rpt, res->ResourceId, rdr->RecordId); | 253 | |
| 254 | |||
| 0 | if (tmp_rdr == NULL) | 255 | |
| 0 | *rdr_gone = g_slist_append(*rdr_gone, (gpointer)rdr); | 256 | |
} | 257 | ||
} | 258 | ||
} | 259 | ||
| 260 | |||
/* Look for new resources and rdrs*/ | 261 | ||
| 0 | for (res = oh_get_resource_by_id(new_rpt, SAHPI_FIRST_ENTRY); | 262 | |
res != NULL; | 263 | ||
res = oh_get_resource_next(new_rpt, res->ResourceId)) { | 264 | ||
| 265 | |||
| 0 | SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(cur_rpt, res->ResourceId); | 266 | |
| 0 | SaHpiRdrT *rdr = NULL; | 267 | |
| 0 | if (tmp_res == NULL || memcmp(res, tmp_res, sizeof(SaHpiRptEntryT))) { | 268 | |
| 0 | *res_new = g_slist_append(*res_new, (gpointer)res); | 269 | |
} | 270 | ||
| 271 | |||
| 0 | for (rdr = oh_get_rdr_by_id(new_rpt, res->ResourceId, SAHPI_FIRST_ENTRY); | 272 | |
rdr != NULL; | 273 | ||
rdr = oh_get_rdr_next(new_rpt, res->ResourceId, rdr->RecordId)) { | 274 | ||
| 275 | |||
| 0 | SaHpiRdrT *tmp_rdr = NULL; | 276 | |
| 277 | |||
| 0 | if (tmp_res != NULL) | 278 | |
| 0 | tmp_rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, rdr->RecordId); | 279 | |
| 280 | |||
| 0 | if (tmp_rdr == NULL || memcmp(rdr, tmp_rdr, sizeof(SaHpiRdrT))) | 281 | |
| 0 | *rdr_new = g_slist_append(*rdr_new, (gpointer)rdr); | 282 | |
| 283 | |||
} | 284 | ||
} | 285 | ||
} | 286 | ||
| 287 | |||
/** | 288 | ||
* oh_get_rpt_info | 289 | ||
* @table: pointer to RPT | 290 | ||
* @update_count: pointer of where to place the rpt's update count | 291 | ||
* @update_timestamp: pointer of where to place the rpt's update timestamp | 292 | ||
* | 293 | ||
* Returns: SA_OK on success Or minus SA_OK on error. | 294 | ||
**/ | 295 | ||
SaErrorT oh_get_rpt_info(RPTable *table, | 296 | ||
SaHpiUint32T *update_count, | 297 | ||
SaHpiTimeT *update_timestamp) | 298 | ||
| 4 | { | 299 | |
| 4 | if (!table || !update_count || !update_timestamp) { | 300 | |
| 1 | dbg("ERROR: Invalid parameters."); | 301 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 302 | |
} | 303 | ||
| 304 | |||
| 3 | *update_count = table->update_count; | 305 | |
| 3 | *update_timestamp = table->update_timestamp; | 306 | |
| 307 | |||
| 3 | return SA_OK; | 308 | |
} | 309 | ||
| 310 | |||
/** | 311 | ||
* Resource interface functions | 312 | ||
*/ | 313 | ||
| 314 | |||
/** | 315 | ||
* oh_add_resource | 316 | ||
* @table: Pointer to the RPT to which the RPT entry will be added. | 317 | ||
* @entry: The RPT entry (resource) to be added to the RPT. | 318 | ||
* @data: Pointer to private data for storing along with the RPT entry. | 319 | ||
* @owndata: boolean flag. true (%KEEP_RPT_DATA) to tell the interface *not* | 320 | ||
* to free the data when the resource is removed. false (%FREE_RPT_DATA) to tell | 321 | ||
* the interface to free the data when the resource is removed. | 322 | ||
* | 323 | ||
* Add a RPT entry to the RPT along with some private data. | 324 | ||
* If an RPT entry with the same resource id exists int the RPT, it will be | 325 | ||
* overlayed with the new RPT entry. Also, this function will assign the | 326 | ||
* resource id as its entry id since it is expected to be unique for the table. | 327 | ||
* The update count and timestamp will not be updated if the entry being added | 328 | ||
* already existed in the table and was the same. | 329 | ||
* | 330 | ||
* Returns: SA_OK on success Or minus SA_OK on error. SA_ERR_HPI_INVALID_PARAMS will | 331 | ||
* be returned if @table is NULL, @entry is NULL, ResourceId in @entry equals | 332 | ||
* SAHPI_FIRST_ENTRY, ResourceId in @entry equals SAHPI_UNSPECIFIED_RESOURCE_ID, | 333 | ||
* or ResourceEntity in @entry has a malformed entity path (look at the | 334 | ||
* entity path utils documentation). | 335 | ||
**/ | 336 | ||
SaErrorT oh_add_resource(RPTable *table, SaHpiRptEntryT *entry, void *data, int owndata) | 337 | ||
| 10367 | { | 338 | |
| 10367 | RPTEntry *rptentry; | 339 | |
| 10367 | int update_info = 0; | 340 | |
| 341 | |||
| 10367 | if (!table) { | 342 | |
| 2 | dbg("ERROR: Cannot work on a null table pointer."); | 343 | |
| 2 | return SA_ERR_HPI_INVALID_PARAMS; | 344 | |
| 10365 | } else if (!entry) { | 345 | |
| 1 | dbg("Failed to add. RPT entry is NULL."); | 346 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 347 | |
| 10364 | } else if (entry->ResourceId == SAHPI_FIRST_ENTRY) { | 348 | |
| 1 | dbg("Failed to add. RPT entry needs a resource id before being added"); | 349 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 350 | |
| 10363 | } else if (entry->ResourceId == SAHPI_UNSPECIFIED_RESOURCE_ID) { | 351 | |
| 1 | dbg("Failed to add. RPT entry has an invalid/reserved id assigned. (SAHPI_UNSPECIFIED_RESOURCE_ID)"); | 352 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 353 | |
| 10362 | } else if (!oh_valid_ep(&(entry->ResourceEntity))) { | 354 | |
| 0 | dbg("Failed to add RPT entry. Entity path does not contain root element."); | 355 | |
| 0 | return SA_ERR_HPI_INVALID_PARAMS; | 356 | |
} | 357 | ||
| 358 | |||
| 10362 | entry->EntryId = entry->ResourceId; | 359 | |
/* Check to see if the entry is in the RPTable already */ | 360 | ||
| 10362 | rptentry = get_rptentry_by_rid(table, entry->ResourceId); | 361 | |
/* If not, create new RPTEntry */ | 362 | ||
| 10362 | if (!rptentry) { | 363 | |
| 10361 | rptentry = (RPTEntry *)g_malloc0(sizeof(RPTEntry)); | 364 | |
| 10361 | if (!rptentry) { | 365 | |
| 0 | dbg("Not enough memory to add RPT entry."); | 366 | |
| 0 | return SA_ERR_HPI_OUT_OF_MEMORY; | 367 | |
} | 368 | ||
| 10361 | update_info = 1; /* Have a new changed entry */ | 369 | |
/* Put new RPTEntry in RPTable */ | 370 | ||
| 10361 | table->rptlist = g_slist_append(table->rptlist, (gpointer)rptentry); | 371 | |
| 372 | |||
/* Add to rpt hash table */ | 373 | ||
| 10361 | if (!table->rptable) /* Create hash table if it doesn't exist */ | 374 | |
| 78 | table->rptable = g_hash_table_new(g_int_hash, g_int_equal); | 375 | |
| 376 | |||
| 10361 | rptentry->rpt_entry.EntryId = entry->ResourceId; | 377 | |
| 10361 | g_hash_table_insert(table->rptable, | 378 | |
&(rptentry->rpt_entry.EntryId), | 379 | ||
rptentry); | 380 | ||
} | 381 | ||
/* Else, modify existing RPTEntry */ | 382 | ||
| 10362 | if (rptentry->data && rptentry->data != data && !rptentry->owndata) | 383 | |
| 0 | g_free(rptentry->data); | 384 | |
| 10362 | rptentry->data = data; | 385 | |
| 10362 | rptentry->owndata = owndata; | 386 | |
/* Check if we really have a new/changed entry */ | 387 | ||
| 10362 | if (update_info || memcmp(entry, &(rptentry->rpt_entry), sizeof(SaHpiRptEntryT))) { | 388 | |
| 10361 | update_info = 1; | 389 | |
| 10361 | rptentry->rpt_entry = *entry; | 390 | |
} | 391 | ||
| 392 | |||
| 10362 | if (update_info) update_rptable(table); | 393 | |
| 394 | |||
| 10362 | return SA_OK; | 395 | |
} | 396 | ||
| 397 | |||
/** | 398 | ||
* oh_remove_resource | 399 | ||
* @table: Pointer to the RPT from which an RPT entry will be removed. | 400 | ||
* @rid: Resource id of the RPT entry to be removed. | 401 | ||
* | 402 | ||
* Remove a resource from the RPT. If the @rid is | 403 | ||
* %SAHPI_FIRST_ENTRY, the first RPT entry in the table will be removed. | 404 | ||
* The void data will be freed if @owndata was false (%FREE_RPT_DATA) when adding | 405 | ||
* the resource, otherwise if @owndata was true (%KEEP_RPT_DATA) it will not be freed. | 406 | ||
* | 407 | ||
* Returns: SA_OK on success Or minus SA_OK on error. | 408 | ||
**/ | 409 | ||
SaErrorT oh_remove_resource(RPTable *table, SaHpiResourceIdT rid) | 410 | ||
| 17 | { | 411 | |
| 17 | RPTEntry *rptentry; | 412 | |
| 413 | |||
| 17 | if (!table) { | 414 | |
| 1 | dbg("ERROR: Cannot work on a null table pointer."); | 415 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 416 | |
} | 417 | ||
| 418 | |||
| 16 | rptentry = get_rptentry_by_rid(table, rid); | 419 | |
| 16 | if (!rptentry) { | 420 | |
| 2 | dbg("Failed to remove RPT entry. No Resource found by that id"); | 421 | |
| 2 | return SA_ERR_HPI_NOT_PRESENT; | 422 | |
} else { | 423 | ||
| 36 | SaHpiRdrT *tmp_rdr; | 424 | |
/* Remove all RDRs for the resource first */ | 425 | ||
| 36 | while ((tmp_rdr = oh_get_rdr_by_id(table, rid, SAHPI_FIRST_ENTRY)) != NULL) { | 426 | |
| 22 | oh_remove_rdr(table, rid, SAHPI_FIRST_ENTRY); | 427 | |
} | 428 | ||
/* then remove the resource itself. */ | 429 | ||
| 14 | table->rptlist = g_slist_remove(table->rptlist, (gpointer)rptentry); | 430 | |
| 14 | if (!rptentry->owndata) g_free(rptentry->data); | 431 | |
| 14 | g_hash_table_remove(table->rptable, &(rptentry->rpt_entry.EntryId)); | 432 | |
| 14 | g_free((gpointer)rptentry); | 433 | |
| 14 | if (!table->rptlist) { | 434 | |
| 1 | g_hash_table_destroy(table->rptable); | 435 | |
| 1 | table->rptable = NULL; | 436 | |
} | 437 | ||
} | 438 | ||
| 439 | |||
| 14 | update_rptable(table); | 440 | |
| 441 | |||
| 14 | return SA_OK; | 442 | |
} | 443 | ||
| 444 | |||
/** | 445 | ||
* oh_get_resource_data | 446 | ||
* @table: Pointer to the RPT for looking up the RPT entry's private data. | 447 | ||
* @rid: Resource id of the RPT entry that holds the private data. | 448 | ||
* | 449 | ||
* Get the private data for a RPT entry. If the @rid is | 450 | ||
* %SAHPI_FIRST_ENTRY, the first RPT entry's data in the table will be returned. | 451 | ||
* | 452 | ||
* Returns: A void pointer to the private data for the RPT entry requested, or NULL | 453 | ||
* if the RPT entry was not found or the table was a NULL pointer. | 454 | ||
**/ | 455 | ||
void *oh_get_resource_data(RPTable *table, SaHpiResourceIdT rid) | 456 | ||
| 15 | { | 457 | |
| 458 | |||
| 15 | RPTEntry *rptentry; | 459 | |
| 460 | |||
| 15 | if (!table) { | 461 | |
| 1 | dbg("ERROR: Cannot work on a null table pointer."); | 462 | |
| 1 | return NULL; | 463 | |
} | 464 | ||
| 465 | |||
| 14 | rptentry = get_rptentry_by_rid(table, rid); | 466 | |
| 14 | if (!rptentry) { | 467 | |
/*dbg("Warning: RPT entry not found. Returning NULL.");*/ | 468 | ||
| 1 | return NULL; | 469 | |
} | 470 | ||
| 471 | |||
| 13 | return rptentry->data; | 472 | |
} | 473 | ||
| 474 | |||
/** | 475 | ||
* oh_get_resource_by_id | 476 | ||
* @table: Pointer to the RPT for looking up the RPT entry. | 477 | ||
* @rid: Resource id of the RPT entry to be looked up. | 478 | ||
* | 479 | ||
* Get a RPT entry from the RPT by using the resource id. | 480 | ||
* If @rid is %SAHPI_FIRST_ENTRY, the first RPT entry in the table will be returned. | 481 | ||
* | 482 | ||
* Returns: | 483 | ||
* Pointer to the RPT entry found or NULL if an RPT entry by that | 484 | ||
* id was not found or the table was a NULL pointer. | 485 | ||
**/ | 486 | ||
SaHpiRptEntryT *oh_get_resource_by_id(RPTable *table, SaHpiResourceIdT rid) | 487 | ||
| 31 | { | 488 | |
| 31 | RPTEntry *rptentry; | 489 | |
| 490 | |||
| 31 | if (!table) { | 491 | |
| 1 | dbg("ERROR: Cannot work on a null table pointer."); | 492 | |
| 1 | return NULL; | 493 | |
} | 494 | ||
| 495 | |||
| 30 | rptentry = get_rptentry_by_rid(table, rid); | 496 | |
| 30 | if (!rptentry) { | 497 | |
/*dbg("Warning: RPT entry not found. Returning NULL.");*/ | 498 | ||
| 4 | return NULL; | 499 | |
} | 500 | ||
| 501 | |||
| 26 | return &(rptentry->rpt_entry); | 502 | |
} | 503 | ||
| 504 | |||
/** | 505 | ||
* oh_get_resource_by_ep | 506 | ||
* @table: Pointer to the RPT for looking up the RPT entry. | 507 | ||
* @ep: Entity path of the RPT entry to be looked up. | 508 | ||
* | 509 | ||
* Get a RPT entry from the RPT by using the entity path. | 510 | ||
* | 511 | ||
* Returns: | 512 | ||
* Pointer to the RPT entry found or NULL if an RPT entry by that | 513 | ||
* entity path was not found or the table was a NULL pointer. | 514 | ||
**/ | 515 | ||
SaHpiRptEntryT *oh_get_resource_by_ep(RPTable *table, SaHpiEntityPathT *ep) | 516 | ||
| 15 | { | 517 | |
| 15 | RPTEntry *rptentry = NULL; | 518 | |
| 15 | GSList *node; | 519 | |
| 520 | |||
| 15 | if (!(table)) { | 521 | |
| 1 | dbg("ERROR: Cannot work on a null table pointer."); | 522 | |
| 1 | return NULL; | 523 | |
} | 524 | ||
| 525 | |||
| 10069 | for (node = table->rptlist; node != NULL; node = node->next) { | 526 | |
| 10067 | rptentry = (RPTEntry *) node->data; | 527 | |
| 10067 | if (oh_cmp_ep(&(rptentry->rpt_entry.ResourceEntity), ep)) | 528 | |
| 12 | break; | 529 | |
| 10055 | else rptentry = NULL; | 530 | |
} | 531 | ||
| 532 | |||
| 14 | if (!rptentry) { | 533 | |
/*dbg("Warning: RPT entry not found. Returning NULL.");*/ | 534 | ||
| 2 | return NULL; | 535 | |
} | 536 | ||
| 537 | |||
| 12 | return &(rptentry->rpt_entry); | 538 | |
} | 539 | ||
| 540 | |||
/** | 541 | ||
* oh_get_resource_next | 542 | ||
* @table: Pointer to the RPT for looking up the RPT entry. | 543 | ||
* @rid_prev: Resource id of the RPT entry previous to the one being looked up. | 544 | ||
* | 545 | ||
* Get the RPT entry next to the specified RPT entry | 546 | ||
* from the RPT. If @rid_prev is %SAHPI_FIRST_ENTRY, the first RPT entry | 547 | ||
* in the table will be returned. | 548 | ||
* | 549 | ||
* Returns: | 550 | ||
* Pointer to the RPT entry found or NULL if the previous RPT entry by that | 551 | ||
* id was not found or the table was a NULL pointer. | 552 | ||
**/ | 553 | ||
SaHpiRptEntryT *oh_get_resource_next(RPTable *table, SaHpiResourceIdT rid_prev) | 554 | ||
| 35 | { | 555 | |
| 35 | RPTEntry *rptentry = NULL; | 556 | |
| 35 | GSList *node; | 557 | |
| 558 | |||
| 35 | if (!(table)) { | 559 | |
| 1 | dbg("ERROR: Cannot work on a null table pointer."); | 560 | |
| 1 | return NULL; | 561 | |
} | 562 | ||
| 563 | |||
| 34 | if (rid_prev == SAHPI_FIRST_ENTRY) { | 564 | |
| 1 | if (table->rptlist) { | 565 | |
| 1 | rptentry = (RPTEntry *)(table->rptlist->data); | 566 | |
} else { | 567 | ||
/*dbg("Info: RPT is empty. Returning NULL.");*/ | 568 | ||
| 0 | return NULL; | 569 | |
} | 570 | ||
} else { | 571 | ||
| 195 | for (node = table->rptlist; node != NULL; node = node->next) { | 572 | |
| 194 | rptentry = (RPTEntry *) node->data; | 573 | |
| 194 | if (rptentry->rpt_entry.ResourceId == rid_prev) { | 574 | |
| 32 | if (node->next) rptentry = (RPTEntry *)(node->next->data); | 575 | |
else { | 576 | ||
/*dbg("Info: Reached end of RPT.");*/ | 577 | ||
| 5 | return NULL; | 578 | |
} | 579 | ||
| 162 | break; | 580 | |
| 162 | } else rptentry = NULL; | 581 | |
} | 582 | ||
} | 583 | ||
| 584 | |||
| 29 | if (!rptentry) { | 585 | |
/*dbg("Warning: RPT entry not found. Returning NULL.");*/ | 586 | ||
| 1 | return NULL; | 587 | |
} | 588 | ||
| 589 | |||
| 28 | return &(rptentry->rpt_entry); | 590 | |
} | 591 | ||
| 592 | |||
/** | 593 | ||
* RDR interface functions | 594 | ||
*/ | 595 | ||
| 596 | |||
/** | 597 | ||
* oh_add_rdr | 598 | ||
* @table: Pointer to RPT table containig the RPT entry to which the RDR will belong. | 599 | ||
* @rid: Id of the RPT entry that will own the RDR to be added. | 600 | ||
* @rdr: RDR to be added to an RPT entry's RDR repository. | 601 | ||
* @data: Pointer to private data belonging to the RDR that is being added. | 602 | ||
* @owndata: boolean flag. true (%KEEP_RPT_DATA) to tell the interface *not* | 603 | ||
* to free the data when the rdr is removed. false (%FREE_RPT_DATA) to tell | 604 | ||
* the interface to free the data when the rdr is removed. | 605 | ||
* | 606 | ||
* Add an RDR to a RPT entry's RDR repository. | 607 | ||
* If an RDR is found with the same record id as the one being added, the RDR being | 608 | ||
* added will overlay the existing one. Also, a unique record id will be assigned | 609 | ||
* to it based on the RDR type and its type's numeric id. | 610 | ||
* All rdr interface funtions, except oh_add_rdr() will act in the context of | 611 | ||
* the first RPT entry in the table, if @rid is %SAHPI_FIRST_ENTRY. | 612 | ||
* | 613 | ||
* Returns: SA_OK on success Or minus SA_OK on error. Will return | 614 | ||
* SA_ERR_HPI_INVALID_PARAMS if instrument id is invalid. An invalid | 615 | ||
* intrument id for a sensor is in the range of 0x100-0x1FF. An aggregate type | 616 | ||
* of sensor can have its instrument id in the range of 0x100-0x10F, but | 617 | ||
* the resource must have the aggregate sensor capabilitiy bit set. | 618 | ||
**/ | 619 | ||
SaErrorT oh_add_rdr(RPTable *table, SaHpiResourceIdT rid, SaHpiRdrT *rdr, void *data, int owndata) | 620 | ||
| 135 | { | 621 | |
| 135 | RPTEntry *rptentry; | 622 | |
| 135 | RDRecord *rdrecord; | 623 | |
| 135 | SaHpiInstrumentIdT type_num; | 624 | |
| 625 | |||
| 135 | if (!table) { | 626 | |
| 2 | dbg("Error: Cannot work on a null table pointer."); | 627 | |
| 2 | return SA_ERR_HPI_INVALID_PARAMS; | 628 | |
| 133 | } else if (!rdr) { | 629 | |
| 1 | dbg("Failed to add. RDR is NULL."); | 630 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 631 | |
} | 632 | ||
| 633 | |||
| 132 | rptentry = get_rptentry_by_rid(table, rid); | 634 | |
| 132 | if (!rptentry){ | 635 | |
| 1 | dbg("Failed to add RDR. Parent RPT entry was not found in table."); | 636 | |
| 1 | return SA_ERR_HPI_NOT_PRESENT; | 637 | |
} | 638 | ||
| 639 | |||
| 131 | if (check_instrument_id(&(rptentry->rpt_entry), rdr)) { | 640 | |
| 2 | dbg("Invalid instrument id found in RDR."); | 641 | |
| 2 | return SA_ERR_HPI_INVALID_PARAMS; | 642 | |
} | 643 | ||
| 644 | |||
| 129 | type_num = get_rdr_type_num(rdr); | 645 | |
| 646 | |||
/* Form correct RecordId. */ | 647 | ||
| 129 | rdr->RecordId = get_rdr_uid(rdr->RdrType, type_num); | 648 | |
/* Check if record exists */ | 649 | ||
| 129 | rdrecord = get_rdrecord_by_id(rptentry, rdr->RecordId); | 650 | |
/* If not, create new rdr */ | 651 | ||
| 129 | if (!rdrecord) { | 652 | |
| 129 | rdrecord = (RDRecord *)g_malloc0(sizeof(RDRecord)); | 653 | |
| 129 | if (!rdrecord) { | 654 | |
| 0 | dbg("Not enough memory to add RDR."); | 655 | |
| 0 | return SA_ERR_HPI_OUT_OF_MEMORY; | 656 | |
} | 657 | ||
/* Put new rdrecord in rdr repository */ | 658 | ||
| 129 | rptentry->rdrlist = g_slist_append(rptentry->rdrlist, (gpointer)rdrecord); | 659 | |
/* Create rdr hash table if first rdr here */ | 660 | ||
| 129 | if (!rptentry->rdrtable) | 661 | |
| 38 | rptentry->rdrtable = g_hash_table_new(g_int_hash, g_int_equal); | 662 | |
| 663 | |||
| 129 | rdrecord->rdr.RecordId = rdr->RecordId; | 664 | |
| 129 | g_hash_table_insert(rptentry->rdrtable, | 665 | |
&(rdrecord->rdr.RecordId), | 666 | ||
rdrecord); | 667 | ||
} | 668 | ||
/* Else, modify existing rdrecord */ | 669 | ||
| 129 | if (rdrecord->data && rdrecord->data != data && !rdrecord->owndata) | 670 | |
| 0 | g_free(rdrecord->data); | 671 | |
| 129 | rdrecord->data = data; | 672 | |
| 129 | rdrecord->owndata = owndata; | 673 | |
| 129 | rdrecord->rdr = *rdr; | 674 | |
| 675 | |||
| 129 | return SA_OK; | 676 | |
} | 677 | ||
| 678 | |||
/** | 679 | ||
* oh_remove_rdr | 680 | ||
* @table: Pointer to RPT table containig the RPT entry from which the RDR will | 681 | ||
* be removed. | 682 | ||
* @rid: Id of the RPT entry from which the RDR will be removed. | 683 | ||
* @rdrid: Record id of the RDR to remove. | 684 | ||
* | 685 | ||
* | 686 | ||
* Remove an RDR from a RPT entry's RDR repository. | 687 | ||
* If @rdrid is %SAHPI_FIRST_ENTRY, the first RDR in the repository will be removed. | 688 | ||
* If @owndata was set to false (%FREE_RPT_DATA) on the rdr when it was added, | 689 | ||
* the data will be freed, otherwise if it was set to true (%KEEP_RPT_DATA), | 690 | ||
* it will not be freed. | 691 | ||
* All rdr interface funtions, except oh_add_rdr() will act in the context of | 692 | ||
* the first RPT entry in the table, if @rid is %SAHPI_FIRST_ENTRY. | 693 | ||
* | 694 | ||
* Returns: SA_OK on success Or minus SA_OK on error. | 695 | ||
**/ | 696 | ||
SaErrorT oh_remove_rdr(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid) | 697 | ||
| 29 | { | 698 | |
| 29 | RPTEntry *rptentry; | 699 | |
| 29 | RDRecord *rdrecord; | 700 | |
| 701 | |||
| 29 | if (!table) { | 702 | |
| 1 | dbg("Error: Cannot work on a null table pointer."); | 703 | |
| 1 | return SA_ERR_HPI_INVALID_PARAMS; | 704 | |
} | 705 | ||
| 706 | |||
| 28 | rptentry = get_rptentry_by_rid(table, rid); | 707 | |
| 28 | if (!rptentry) { | 708 | |
| 1 | dbg("Failed to remove RDR. Parent RPT entry was not found."); | 709 | |
| 1 | return SA_ERR_HPI_NOT_PRESENT; | 710 | |
} | 711 | ||
| 712 | |||
| 27 | rdrecord = get_rdrecord_by_id(rptentry, rdrid); | 713 | |
| 27 | if (!rdrecord) { | 714 | |
| 1 | dbg("Failed to remove RDR. Could not be found."); | 715 | |
| 1 | return SA_ERR_HPI_NOT_PRESENT; | 716 | |
} else { | 717 | ||
| 26 | rptentry->rdrlist = g_slist_remove(rptentry->rdrlist, (gpointer)rdrecord); | 718 | |
| 26 | if (!rdrecord->owndata) g_free(rdrecord->data); | 719 | |
| 26 | g_hash_table_remove(rptentry->rdrtable, &(rdrecord->rdr.RecordId)); | 720 | |
| 26 | g_free((gpointer)rdrecord); | 721 | |
| 26 | if (!rptentry->rdrlist) { | 722 | |
| 6 | g_hash_table_destroy(rptentry->rdrtable); | 723 | |
| 6 | rptentry->rdrtable = NULL; | 724 | |
} | 725 | ||
} | 726 | ||
| 727 | |||
| 26 | return SA_OK; | 728 | |
} | 729 | ||
| 730 | |||
/** | 731 | ||
* oh_get_rdr_data | 732 | ||
* @table: Pointer to RPT table containig the RPT entry from which the RDR's data | 733 | ||
* will be read. | 734 | ||
* @rid: Id of the RPT entry from which the RDR's data will be read. | 735 | ||
* @rdrid: Record id of the RDR to read data from. | 736 | ||
* | 737 | ||
* | 738 | ||
* Get the private data associated to an RDR. | 739 | ||
* If @rdrid is %SAHPI_FIRST_ENTRY, the first RDR's data in the repository will be returned. | 740 | ||
* All rdr interface funtions, except oh_add_rdr() will act in the context of | 741 | ||
* the first RPT entry in the table, if @rid is %SAHPI_FIRST_ENTRY. | 742 | ||
* | 743 | ||
* Returns: A void pointer to the RDR data, or NULL if no data for that RDR was found or | 744 | ||
* the table pointer is NULL. | 745 | ||
**/ | 746 | ||
void *oh_get_rdr_data(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid) | 747 | ||
| 4 | { | 748 | |
| 4 | RPTEntry *rptentry; | 749 | |
| 4 | RDRecord *rdrecord; | 750 | |
| 751 | |||
| 4 | if (!table) { | 752 | |
| 1 | dbg("Error: Cannot work on a null table pointer."); | 753 | |
| 1 | return NULL; | 754 | |
} | 755 | ||
| 756 | |||
| 3 | rptentry = get_rptentry_by_rid(table, rid); | 757 | |
| 3 | if (!rptentry) { | 758 | |
| 1 | dbg("Warning: RPT entry not found. Cannot find RDR."); | 759 | |
| 1 | return NULL; /* No resource found by that id */ | 760 | |
} | 761 | ||
| 762 | |||
| 2 | rdrecord = get_rdrecord_by_id(rptentry, rdrid); | 763 | |
| 2 | if (!rdrecord) { | 764 | |
/*dbg("Warning: RDR not found. Returning NULL.");*/ | 765 | ||
| 1 | return NULL; | 766 | |
} | 767 | ||
| 768 | |||
| 1 | return rdrecord->data; | 769 | |
} | 770 | ||
| 771 | |||
/** | 772 | ||
* oh_get_rdr_by_id | 773 | ||
* @table: Pointer to RPT table containig the RPT entry tha has the RDR | 774 | ||
* being looked up. | 775 | ||
* @rid: Id of the RPT entry containing the RDR being looked up. | 776 | ||
* @rdrid: Record id of the RDR being looked up. | 777 | ||
* | 778 | ||
* Get a reference to an RDR by its record id. | 779 | ||
* If @rdrid is %SAHPI_FIRST_ENTRY, the first RDR in the repository will be returned. | 780 | ||
* All rdr interface funtions, except oh_add_rdr() will act in the context of | 781 | ||
* the first RPT entry in the table, if @rid is %SAHPI_FIRST_ENTRY. | 782 | ||
* | 783 | ||
* Returns: | 784 | ||
* Reference to the RDR looked up or NULL if no RDR was found. | 785 | ||
**/ | 786 | ||
SaHpiRdrT *oh_get_rdr_by_id(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid) | 787 | ||
| 49 | { | 788 | |
| 49 | RPTEntry *rptentry; | 789 | |
| 49 | RDRecord *rdrecord; | 790 | |
| 791 | |||
| 49 | if (!table) { | 792 | |
| 1 | dbg("Error: Cannot work on a null table pointer."); | 793 | |
| 1 | return NULL; | 794 | |
} | 795 | ||
| 796 | |||
| 48 | rptentry = get_rptentry_by_rid(table, rid); | 797 | |
| 48 | if (!rptentry) { | 798 | |
| 1 | dbg("Warning: RPT entry not found. Cannot find RDR."); | 799 | |
| 1 | return NULL; /* No resource found by that id */ | 800 | |
} | 801 | ||
| 802 | |||
| 47 | rdrecord = get_rdrecord_by_id(rptentry, rdrid); | 803 | |
| 47 | if (!rdrecord) { | 804 | |
/*dbg("Warning: RDR not found. Returning NULL.");*/ | 805 | ||
| 16 | return NULL; | 806 | |
} | 807 | ||
| 808 | |||
| 31 | return &(rdrecord->rdr); | 809 | |
} | 810 | ||
| 811 | |||
/** | 812 | ||
* oh_get_rdr_by_type | 813 | ||
* @table: Pointer to RPT table containig the RPT entry tha has the RDR | 814 | ||
* being looked up. | 815 | ||
* @rid: Id of the RPT entry containing the RDR being looked up. | 816 | ||
* @type: RDR Type of the RDR being looked up. | 817 | ||
* @num: RDR id within the RDR type for the specified RPT entry. | 818 | ||
* | 819 | ||
* Get a reference to an RDR by its type and number. | 820 | ||
* All rdr interface funtions, except oh_add_rdr() will act in the context of | 821 | ||
* the first RPT entry in the table, if @rid is %SAHPI_FIRST_ENTRY. | 822 | ||
* | 823 | ||
* Returns: | 824 | ||
* Reference to the RDR looked up or NULL if no RDR was found. | 825 | ||
**/ | 826 | ||
SaHpiRdrT *oh_get_rdr_by_type(RPTable *table, SaHpiResourceIdT rid, | 827 | ||
SaHpiRdrTypeT type, SaHpiInstrumentIdT num) | 828 | ||
| 9 | { | 829 | |
| 9 | RPTEntry *rptentry; | 830 | |
| 9 | RDRecord *rdrecord; | 831 | |
| 9 | SaHpiEntryIdT rdr_uid; | 832 | |
| 833 | |||
| 9 | if (!table) { | 834 | |
| 1 | dbg("Error: Cannot work on a null table pointer."); | 835 | |
| 1 | return NULL; | 836 | |
} | 837 | ||
| 838 | |||
| 8 | rptentry = get_rptentry_by_rid(table, rid); | 839 | |
| 8 | if (!rptentry) { | 840 | |
| 1 | dbg("Warning: RPT entry not found. Cannot find RDR."); | 841 | |
| 1 | return NULL; /* No resource found by that id */ | 842 | |
} | 843 | ||
| 844 | |||
/* Get rdr_uid from type/num combination */ | 845 | ||
| 7 | rdr_uid = get_rdr_uid(type, num); | 846 | |
| 7 | rdrecord = get_rdrecord_by_id(rptentry, rdr_uid); | 847 | |
| 7 | if (!rdrecord) { | 848 | |
/*dbg("Warning: RDR not found. Returning NULL.");*/ | 849 | ||
| 1 | return NULL; | 850 | |
} | 851 | ||
| 852 | |||
| 6 | return &(rdrecord->rdr); | 853 | |
} | 854 | ||
| 855 | |||
/** | 856 | ||
* oh_get_rdr_next | 857 | ||
* @table: Pointer to the RPT containing the RPT entry to look up the RDR in. | 858 | ||
* @rid: Id of the RPT entry containing the RDR being looked up. | 859 | ||
* @rdrid_prev: Record id of the RDR previous to the one being looked up, relative | 860 | ||
* to the specified RPT entry. | 861 | ||
* | 862 | ||
* Get the RDR next to the specified RDR in the specified | 863 | ||
* RPT entry's repository. If @rdrid_prev is %SAHPI_FIRST_ENTRY, the first RDR | 864 | ||
* in the repository will be returned. | 865 | ||
* All rdr interface funtions, except oh_add_rdr() will act in the context of | 866 | ||
* the first RPT entry in the table, if @rid is %SAHPI_FIRST_ENTRY. | 867 | ||
* | 868 | ||
* Returns: | 869 | ||
* Pointer to the RDR found or NULL if the previous RDR by that | 870 | ||
* id was not found. If the @rdrid_prev was %SAHPI_FIRST_ENTRY, the first RDR in the list | 871 | ||
* will be returned. | 872 | ||
**/ | 873 | ||
SaHpiRdrT *oh_get_rdr_next(RPTable *table, SaHpiResourceIdT rid, SaHpiEntryIdT rdrid_prev) | 874 | ||
| 14 | { | 875 | |
| 14 | RPTEntry *rptentry; | 876 | |
| 14 | RDRecord *rdrecord = NULL; | 877 | |
| 14 | GSList *node; | 878 | |
| 879 | |||
| 14 | if (!table) { | 880 | |
| 1 | dbg("Error: Cannot work on a null table pointer."); | 881 | |
| 1 | return NULL; | 882 | |
} | 883 | ||
| 884 | |||
| 13 | rptentry = get_rptentry_by_rid(table, rid); | 885 | |
| 13 | if (!rptentry) { | 886 | |
| 1 | dbg("Warning: RPT entry not found. Cannot find RDR."); | 887 | |
| 1 | return NULL; /* No resource found by that id */ | 888 | |
} | 889 | ||
| 890 | |||
| 12 | if (rdrid_prev == SAHPI_FIRST_ENTRY) { | 891 | |
| 1 | if (rptentry->rdrlist) { | 892 | |
| 1 | rdrecord = (RDRecord *)(rptentry->rdrlist->data); | 893 | |
} else { | 894 | ||
/*dbg("Info: RDR repository is empty. Returning NULL.");*/ | 895 | ||
| 0 | return NULL; | 896 | |
} | 897 | ||
} else { | 898 | ||
| 36 | for (node = rptentry->rdrlist; node != NULL; node = node->next) { | 899 | |
| 35 | rdrecord = (RDRecord *)node->data; | 900 | |
| 35 | if (rdrecord->rdr.RecordId == rdrid_prev) { | 901 | |
| 10 | if (node->next) rdrecord = (RDRecord *)(node->next->data); | 902 | |
else { | 903 | ||
/*dbg("Info: Reached end of RDR repository.")*/ | 904 | ||
| 3 | return NULL; | 905 | |
} | 906 | ||
| 25 | break; | 907 | |
} | 908 | ||
| 25 | else rdrecord = NULL; | 909 | |
} | 910 | ||
} | 911 | ||
| 912 | |||
| 9 | if (!rdrecord) { | 913 | |
/*dbg("Warning: RDR not found. Returning NULL.");*/ | 914 | ||
| 1 | return NULL; | 915 | |
} | 916 | ||
| 917 | |||
| 8 | return &(rdrecord->rdr); | 918 | |
} | 919 |