1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/* -*- linux-c -*-
*
* (C) Copyright IBM Corp. 2005
*
* 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):
* W. David Ashley <dashley@us.ibm.com>
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
extern "C"
{
#include <SaHpi.h>
}
#include "oSaHpiEntity.hpp"
#include "oSaHpiEntityPath.hpp"
/**
* Default constructor.
*/
oSaHpiEntityPath::oSaHpiEntityPath() {
int i;
for (i = 0; i < SAHPI_MAX_ENTITY_PATH; i ++) {
Entry[i].EntityType = SAHPI_ENT_ROOT;
Entry[i].EntityLocation = 0;
}
};
/**
* Constructor.
*
* @param buf The reference to the class to be copied.
*/
oSaHpiEntityPath::oSaHpiEntityPath(const oSaHpiEntityPath& entpath) {
int i;
for (i = 0; i < SAHPI_MAX_ENTITY_PATH; i ++) {
Entry[i].EntityType = entpath.Entry[i].EntityType;
Entry[i].EntityLocation = entpath.Entry[i].EntityLocation;
}
}
/**
* Print the contents of the entity path.
*
* @param stream Target stream.
* @param buffer Address of the SaHpiEntityPathT struct.
*
* @return True if there was an error, otherwise false.
*/
bool oSaHpiEntityPath::fprint(FILE *stream,
const int indent,
const SaHpiEntityPathT *entpath) {
int i, err = 0;
char indent_buf[indent + 1];
const SaHpiEntityT *ent;
if (stream == NULL || entpath == NULL) {
return true;
}
for (i = 0; i < indent; i++) {
indent_buf[i] = ' ';
}
indent_buf[indent] = '\0';
for (i = 0; i < SAHPI_MAX_ENTITY_PATH; i++) {
err = fprintf(stream, "%s", indent_buf);
if (err < 0) {
return true;
}
err = fprintf(stream, "Entry[%d]\n", i);
if (err < 0) {
return true;
}
ent = (const SaHpiEntityT *)&(entpath->Entry[i]);
err = oSaHpiEntity::fprint(stream, indent + 3, ent);
if (err < 0) {
return true;
}
if (entpath->Entry[i].EntityType == SAHPI_ENT_ROOT) {
// no need to print past the root
break;
}
}
return false;
}
/**
* Append one entity path to another.
*
* @param destpath The destination entity path.
* @param appendpath The entity path to be appended to the destpath. If the result
* entity path is too large it will be truncated.
*
* @return True if there was an error, otherwise false.
*/
bool oSaHpiEntityPath::append(SaHpiEntityPathT *destpath,
const SaHpiEntityPathT *appendpath) {
int i, j;
if (!destpath) {
return true;
}
if (!appendpath) {
return false;
}
for (i = 0; i < SAHPI_MAX_ENTITY_PATH; i++) {
if (destpath->Entry[i].EntityType == SAHPI_ENT_ROOT)
break;
}
for (j = 0; i < SAHPI_MAX_ENTITY_PATH; i++) {
destpath->Entry[i].EntityLocation = appendpath->Entry[j].EntityLocation;
destpath->Entry[i].EntityType = appendpath->Entry[j].EntityType;
if (appendpath->Entry[j].EntityType == SAHPI_ENT_ROOT)
break;
j++;
}
return false;
}
/**
* Compare one entity path to another.
*
* @param destpath The destination entity path.
* @param appendpath The entity path to be appended to the destpath. If the result
* entity path is too large it will be truncated.
*
* @return True if the two entity paths are equal, otherwise false.
*/
bool oSaHpiEntityPath::compare(const SaHpiEntityPathT *ep1,
const SaHpiEntityPathT *ep2) {
unsigned int i, j;
if (!ep1 || !ep2) {
return false;
}
for (i = 0; i < SAHPI_MAX_ENTITY_PATH; i++) {
if (ep1->Entry[i].EntityType == SAHPI_ENT_ROOT) {
i++;
break;
}
}
for (j = 0; j < SAHPI_MAX_ENTITY_PATH; j++) {
if (ep2->Entry[j].EntityType == SAHPI_ENT_ROOT) {
j++;
break;
}
}
if (i != j)
return false;
for (i = 0; i < j; i++) {
if (ep1->Entry[i].EntityType != ep2->Entry[i].EntityType ||
ep1->Entry[i].EntityLocation != ep2->Entry[i].EntityLocation) {
return false;
}
}
return true;
}
|