GCOV Execution Analysis for sahpi_struct_utils.c

The left column is the number of times the code was executed during the unit test suites.

Exec CodeLine #
 
Source:sahpi_struct_utils.c
1
 
Graph:.libs/sahpi_struct_utils.gcno
2
 
Data:.libs/sahpi_struct_utils.gcda
3
 
Runs:378
4
 
Programs:378
5
 
/*      -*- linux-c -*-
6
 
 *
7
 
 * (C) Copyright IBM Corp. 2004
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
12
 
 * file and program are licensed under a BSD style license.  See
13
 
 * the Copying file included with the OpenHPI distribution for
14
 
 * full licensing terms.
15
 
 *
16
 
 * Author(s):
17
 
 *      Sean Dague < address removed >
18
 
 *      Steve Sherman < address removed >
19
 
 * Contributors:
20
 
 *      Racing Guo < address removed >
21
 
 */
22
 
23
 
#include <glib.h>
24
 
#include <stdlib.h>
25
 
#include <stdio.h>
26
 
#include <string.h>
27
 
#include <ctype.h>
28
 
#include <errno.h>
29
 
30
 
#include <SaHpi.h>
31
 
#include <oh_utils.h>
32
 
33
 
static inline SaErrorT oh_init_bigtext(oh_big_textbuffer *big_buffer);
34
 
static inline SaErrorT oh_append_bigtext(oh_big_textbuffer *big_buffer, const char *from);
35
 
static inline SaErrorT oh_copy_bigtext(oh_big_textbuffer *dest, const oh_big_textbuffer *from);
36
 
37
 
static SaErrorT oh_append_offset(oh_big_textbuffer *buffer, int offsets);
38
 
static SaErrorT oh_build_sensorrec(oh_big_textbuffer *buffer, const SaHpiSensorRecT *sensor, int offsets);
39
 
static SaErrorT oh_build_sensordataformat(oh_big_textbuffer *buffer, const SaHpiSensorDataFormatT *format, int offsets);
40
 
static SaErrorT oh_build_sensorthddefn(oh_big_textbuffer *buffer, const SaHpiSensorThdDefnT *tdef, int offsets);
41
 
static SaErrorT oh_build_threshold_mask(oh_big_textbuffer *buffer, const SaHpiSensorThdMaskT tmask, int offsets);
42
 
static SaErrorT oh_build_textbuffer(oh_big_textbuffer *buffer, const SaHpiTextBufferT *textbuffer, int offsets);
43
 
44
 
static SaErrorT oh_build_ctrlrec(oh_big_textbuffer *textbuf, const SaHpiCtrlRecT *ctrlrec, int offsets);
45
 
static SaErrorT oh_build_invrec(oh_big_textbuffer *textbuff, const SaHpiInventoryRecT *invrec, int offsets);
46
 
static SaErrorT oh_build_wdogrec(oh_big_textbuffer *textbuff, const SaHpiWatchdogRecT *wdogrec, int offsets);
47
 
static SaErrorT oh_build_annrec(oh_big_textbuffer *textbuff, const SaHpiAnnunciatorRecT *annrec, int offsets);
48
 
49
 
static SaErrorT oh_build_event(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
50
 
static SaErrorT oh_build_event_resource(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
51
 
static SaErrorT oh_build_event_domain(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
52
 
static SaErrorT oh_build_event_sensor(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
53
 
static SaErrorT oh_build_event_sensor_enable_change(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
54
 
static SaErrorT oh_build_event_hotswap(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
55
 
static SaErrorT oh_build_event_watchdog(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
56
 
static SaErrorT oh_build_event_hpi_sw(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
57
 
static SaErrorT oh_build_event_oem(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
58
 
static SaErrorT oh_build_event_user(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets);
59
 
60
 
/************************************************************************
61
 
 * NOTES!
62
 
 *
63
 
 * - Several error checks can be removed if valid_xxx routines are defined
64
 
 *   for input structures. If this happens, several of the default switch
65
 
 *   statements should also return SA_ERR_HPI_INTERNAL_ERROR instead
66
 
 *   of SA_ERR_HPI_INVALID_PARMS.
67
 
 ************************************************************************/
68
 
69
 
/**
70
 
 * oh_lookup_manufacturerid:
71
 
 * @value: enum value of type SaHpiManufacturerIdT.
72
 
 * @buffer:  Location to store the string.
73
 
 *
74
 
 * Converts @value into a string based on @value's enum definition
75
 
 * in http://www.iana.org/assignments/enterprise-numbers.
76
 
 * String is stored in an SaHpiTextBufferT data structure.
77
 
 * 
78
 
 * Only a few of the manufacturers in that list have been defined.
79
 
 * For all others, this routine returns "Unknown Manufacturer".
80
 
 * Feel free to add your own favorite manufacturer to this routine.
81
 
 * 
82
 
 * Returns:
83
 
 * SA_OK - Normal operation.
84
 
 * SA_ERR_HPI_INVALID_PARAMS - @buffer is  NULL.
85
 
 **/
86
 
SaErrorT oh_decode_manufacturerid(SaHpiManufacturerIdT value, SaHpiTextBufferT *buffer) 
87
0 
{
88
0 
	SaErrorT err;
89
0 
	SaHpiTextBufferT working;
90
 
91
0 
	if (!buffer) {
92
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
93
 
	}
94
 
95
0 
	err = oh_init_textbuffer(&working);
96
0 
	if (err) { return(err); }
97
 
98
0 
	switch(value) {
99
 
	case SAHPI_MANUFACTURER_ID_UNSPECIFIED:
100
0 
		err = oh_append_textbuffer(&working, "UNSPECIFIED Manufacturer");
101
0 
		if (err) { return(err); }
102
0 
		break;
103
 
	case 2:
104
0 
		err = oh_append_textbuffer(&working,"IBM");
105
0 
		if (err) { return(err); }
106
0 
		break;
107
 
	default:
108
0 
		err = oh_append_textbuffer(&working,  "Unknown Manufacturer");
109
0 
		if (err) { return(err); }
110
 
	}
111
 
112
0 
 	oh_copy_textbuffer(buffer, &working);
113
 
114
0 
	return(SA_OK);
115
 
}
116
 
117
 
/**
118
 
 * oh_decode_sensorreading: 
119
 
 * @reading: SaHpiSensorReadingT to convert.
120
 
 * @format: SaHpiDataFormatT for the sensor reading.
121
 
 * @buffer: Location to store the converted string.
122
 
 *
123
 
 * Converts an HPI sensor reading and format into a string. 
124
 
 * String is stored in an SaHpiTextBufferT data structure.
125
 
 * 
126
 
 * Returns: 
127
 
 * SA_OK - Normal operation.
128
 
 * SA_ERR_HPI_INVALID_CMD - @format or @reading have IsSupported == FALSE.
129
 
 * SA_ERR_HPI_INVALID_DATA - @format and @reading types don't match.
130
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL; @reading type != @format type.
131
 
 * SA_ERR_HPI_OUT_OF_SPACE - @buffer not big enough to accomodate appended string
132
 
 **/
133
 
SaErrorT oh_decode_sensorreading(SaHpiSensorReadingT reading,
134
 
				 SaHpiSensorDataFormatT format,
135
 
				 SaHpiTextBufferT *buffer)
136
0 
{
137
0 
	SaErrorT err;
138
0 
	SaHpiTextBufferT working;
139
0 
        char text[SAHPI_MAX_TEXT_BUFFER_LENGTH];
140
0 
	char str[SAHPI_SENSOR_BUFFER_LENGTH + 1];
141
 
142
0 
	if (!buffer) {
143
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
144
 
	}
145
0 
        if (!reading.IsSupported || !format.IsSupported) {
146
0 
                return(SA_ERR_HPI_INVALID_CMD);
147
 
        }
148
0 
        if (reading.Type != format.ReadingType) {
149
 
		
150
 
		/* Check for special case */
151
0 
		if (!( (reading.Type == SAHPI_SENSOR_READING_TYPE_BUFFER) && 
152
 
		    ((strncmp(reading.Value.SensorBuffer,"(No temperature)", sizeof("(No temperature)")) == 0) ||
153
 
		    		(strncmp(reading.Value.SensorBuffer,"Not Readable!", sizeof("Not Readable!")) == 0)) ))
154
0 
                	return(SA_ERR_HPI_INVALID_DATA);
155
 
        }
156
 
	
157
0 
	oh_init_textbuffer(&working);
158
0 
	memset(text, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
159
 
160
0 
        switch(reading.Type) {
161
 
        case SAHPI_SENSOR_READING_TYPE_INT64:
162
0 
                snprintf(text, SAHPI_MAX_TEXT_BUFFER_LENGTH,
163
 
			 "%lld", reading.Value.SensorInt64);
164
0 
		err = oh_append_textbuffer(&working, text);
165
0 
		if (err) { return(err); }
166
0 
                break;
167
 
        case SAHPI_SENSOR_READING_TYPE_UINT64:
168
0 
		snprintf(text, SAHPI_MAX_TEXT_BUFFER_LENGTH,
169
 
			 "%llu", reading.Value.SensorUint64);
170
0 
		err = oh_append_textbuffer(&working, text);
171
0 
		if (err) { return(err); }
172
0 
                break;
173
 
	case SAHPI_SENSOR_READING_TYPE_FLOAT64:
174
0 
                snprintf(text, SAHPI_MAX_TEXT_BUFFER_LENGTH, 
175
 
			 "%le", reading.Value.SensorFloat64);
176
0 
		err = oh_append_textbuffer(&working, text);
177
0 
		if (err) { return(err); }
178
0 
 		break;
179
 
        case SAHPI_SENSOR_READING_TYPE_BUFFER:
180
 
		/* In case Sensor Buffer contains no end of string deliminter */
181
0 
		memset(str, 0, SAHPI_SENSOR_BUFFER_LENGTH + 1);
182
0 
		strncpy(str, reading.Value.SensorBuffer, SAHPI_SENSOR_BUFFER_LENGTH);
183
0 
		err = oh_append_textbuffer(&working, str);
184
0 
		if (err) { return(err); }
185
0 
                break;
186
 
	default:
187
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
188
 
        }
189
 
        
190
0 
        if (format.Percentage) {
191
0 
		err = oh_append_textbuffer(&working, "%"); 
192
0 
		if (err) { return(err); }
193
 
        }
194
 
	else {
195
 
		/* Add units */
196
0 
		if (format.BaseUnits != SAHPI_SU_UNSPECIFIED) {
197
0 
			const char *str;
198
 
199
0 
			err = oh_append_textbuffer(&working, " ");
200
0 
			if (err) { return(err); }
201
0 
			str = oh_lookup_sensorunits(format.BaseUnits);
202
0 
			if (str == NULL) { return(SA_ERR_HPI_INVALID_PARAMS); }
203
0 
			err = oh_append_textbuffer(&working, str);
204
0 
			if (err) { return(err); }
205
 
		}
206
 
		
207
 
		/* Add modifier units, if appropriate */
208
0 
		if (format.BaseUnits != SAHPI_SU_UNSPECIFIED && 
209
 
		    format.ModifierUse != SAHPI_SMUU_NONE) {
210
0 
			const char *str;
211
 
212
0 
			switch(format.ModifierUse) {
213
 
			case SAHPI_SMUU_BASIC_OVER_MODIFIER:
214
0 
				err = oh_append_textbuffer(&working, " / "); 
215
0 
				if (err) { return(err); }
216
0 
				break;
217
 
			case SAHPI_SMUU_BASIC_TIMES_MODIFIER:
218
0 
				err = oh_append_textbuffer(&working, " * "); 
219
0 
				if (err) { return(err); }
220
0 
				break;
221
 
			default:
222
0 
				return(SA_ERR_HPI_INVALID_PARAMS);
223
 
			}
224
0 
			str = oh_lookup_sensorunits(format.ModifierUnits);
225
0 
			if (str == NULL) { return(SA_ERR_HPI_INVALID_PARAMS); }
226
0 
			err = oh_append_textbuffer(&working, str); 		
227
0 
			if (err) { return(err); }
228
 
		}
229
 
	}
230
 
231
0 
 	oh_copy_textbuffer(buffer, &working);
232
 
233
0 
        return(SA_OK);
234
 
}
235
 
236
 
/**
237
 
 * oh_encode_sensorreading:
238
 
 * @buffer: Location of SaHpiTextBufferT containing the string to 
239
 
 *          convert into a SaHpiSensorReadingT.
240
 
 * @type: SaHpiSensorReadingTypeT of converted reading.
241
 
 * @reading: SaHpiSensorReadingT location to store converted string.
242
 
 * 
243
 
 * Converts @buffer->Data string to an HPI SaHpiSensorReadingT structure.
244
 
 * Generally @buffer->Data is created by oh_decode_sensorreading() or has
245
 
 * been built by a plugin, which gets string values for sensor readings (e.g.
246
 
 * through SNMP OID commands). Any non-numeric portion of the string is
247
 
 * discarded. For example, the string "-1.43 Volts" is converted to -1.43
248
 
 * of type @type.
249
 
 * 
250
 
 * If type = SAHPI_SENSOR_READING_TYPE_BUFFER, and @buffer->Data > 
251
 
 * SAHPI_SENSOR_BUFFER_LENGTH, data is truncated to fit into the reading
252
 
 * buffer.
253
 
 *
254
 
 * Notes!
255
 
 * - Numerical strings can contain commas but it is assummed that strings follow
256
 
 *   US format (e.g. "1,000,000" = 1 million; not "1.000.000").
257
 
 * - Decimal points are always preceded by at least one number (e.g. "0.9")
258
 
 * - Numerical percentage strings like "9%" are converted into a float 0.09
259
 
 * - Hex notation is not supported (e.g. "0x23")
260
 
 * - Scientific notation is not supported (e.g. "e+02").
261
 
 *
262
 
 * Returns: 
263
 
 * SA_OK - Normal operation.
264
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL; Invalid @type.
265
 
 * SA_ERR_HPI_INVALID_DATA - Converted @buffer->Data too large for @type; cannot
266
 
 *                           convert string into valid number; @type incorrect
267
 
 *                           for resulting number (e.g. percentage not a float).
268
 
 **/
269
 
SaErrorT oh_encode_sensorreading(SaHpiTextBufferT *buffer,
270
 
				 SaHpiSensorReadingTypeT type,
271
 
				 SaHpiSensorReadingT *reading)
272
0 
{
273
0 
        char  numstr[SAHPI_MAX_TEXT_BUFFER_LENGTH];
274
0 
	char *endptr;
275
0 
        int   i, j;
276
0 
	int   found_sign, found_number, found_float, in_number;
277
0 
	int   is_percent = 0;
278
0 
        SaHpiFloat64T num_float64 = 0.0;
279
0 
        SaHpiInt64T   num_int64 = 0;
280
0 
        SaHpiUint64T  num_uint64 = 0;
281
0 
	SaHpiSensorReadingT working;
282
 
283
0 
	if (!buffer || !reading ||
284
 
	    buffer->Data == NULL || buffer->Data[0] == '\0' ||
285
 
	    !oh_lookup_sensorreadingtype(type)) {
286
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
287
 
	}
288
 
289
0 
        if (type == SAHPI_SENSOR_READING_TYPE_BUFFER) {
290
0 
		reading->IsSupported = SAHPI_TRUE;
291
0 
		reading->Type = type;
292
0 
		strncpy(reading->Value.SensorBuffer, buffer->Data, SAHPI_SENSOR_BUFFER_LENGTH);
293
0 
		return(SA_OK);
294
 
        }
295
 
296
0 
	memset(numstr, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
297
0 
        memset(&working, 0, sizeof(SaHpiSensorReadingT));
298
0 
	working.IsSupported = SAHPI_TRUE;
299
0 
	working.Type = type;
300
 
301
 
	/* Search string and pull out first numeric string.
302
 
         * The strtol type functions below are pretty good at handling
303
 
         * non-numeric junk in string, but they don't handle spaces
304
 
         * after a sign or commas within a number.
305
 
         * So we normalize the string a bit first.
306
 
	 */
307
0 
	j = found_sign = in_number = found_number = found_float = 0;
308
0 
	for (i=0; i<buffer->DataLength && !found_number; i++) {
309
0 
		if (buffer->Data[i] == '+' || buffer->Data[i] == '-') {
310
0 
			if (found_sign) { 
311
0 
				dbg("Cannot parse multiple sign values");
312
0 
				return(SA_ERR_HPI_INVALID_DATA);
313
 
			}
314
0 
			found_sign = 1;
315
0 
			numstr[j] = buffer->Data[i];
316
0 
			j++;
317
 
		}
318
0 
		if (isdigit(buffer->Data[i])) {
319
0 
			if (!found_number) {
320
0 
				in_number = 1;
321
0 
				numstr[j] = buffer->Data[i];
322
0 
				j++;
323
 
			}
324
 
		}
325
 
		else { /* Strip non-numerics */
326
0 
			if (buffer->Data[i] == '.') { /* Unless its a decimal point */
327
0 
				if (in_number) {
328
0 
					if (found_float) { 
329
0 
						dbg("Cannot parse multiple decimal points");
330
0 
						return(SA_ERR_HPI_INVALID_DATA);
331
 
					}
332
0 
					found_float = 1;
333
0 
					numstr[j] = buffer->Data[i];
334
0 
					j++;
335
 
				}
336
 
			}
337
 
			else {
338
 
				/* Delete commas but don't end search for more numbers */
339
0 
				if (in_number && buffer->Data[i] != ',') { 
340
0 
					found_number = 1;
341
 
				}
342
 
			}
343
 
		}
344
 
	}
345
 
	
346
0 
	if (found_number || in_number) { /* in_number means string ended in a digit character */
347
0 
		for (j=i-1; j<buffer->DataLength; j++) {
348
0 
			if (buffer->Data[j] == '%') {
349
0 
				is_percent = 1;
350
0 
				break;
351
 
			}
352
 
		}
353
0 
		found_number = 1;
354
 
	}
355
 
356
0 
	if ((is_percent || found_float) && type != SAHPI_SENSOR_READING_TYPE_FLOAT64) {
357
0 
		dbg("Number and type incompatible");
358
0 
		return(SA_ERR_HPI_INVALID_DATA);
359
 
	}
360
 
361
 
	/* Convert string to number */
362
0 
        switch (type) {
363
 
        case SAHPI_SENSOR_READING_TYPE_INT64:
364
0 
		if (found_number) {
365
0 
			errno = 0;
366
0 
			num_int64 = strtoll(numstr, &endptr, 10);
367
0 
			if (errno) {
368
0 
				dbg("strtoll failed, errno=%d", errno);
369
0 
				return(SA_ERR_HPI_INVALID_DATA);
370
 
			}
371
0 
			if (*endptr != '\0') {
372
0 
				dbg("strtoll failed: End Pointer=%s", endptr);
373
0 
				return(SA_ERR_HPI_INVALID_DATA);
374
 
			}
375
 
		}
376
 
		else { /* No number in string */
377
0 
			num_int64 = 0;
378
 
		}
379
 
380
0 
                working.Value.SensorInt64 = num_int64;
381
0 
                break;
382
 
383
 
        case SAHPI_SENSOR_READING_TYPE_UINT64:
384
0 
		if (found_number) {
385
0 
			errno = 0;
386
0 
			num_uint64 = strtoull(numstr, &endptr, 10);
387
0 
			if (errno) {
388
0 
				dbg("strtoull failed, errno=%d", errno);
389
0 
				return(SA_ERR_HPI_INVALID_DATA);
390
 
			}
391
0 
			if (*endptr != '\0') {
392
0 
				dbg("strtoull failed: End Pointer=%s", endptr);
393
0 
				return(SA_ERR_HPI_INVALID_DATA);
394
 
			}
395
 
		}
396
 
		else { /* No number in string */
397
0 
			num_uint64 = 0;
398
 
		}
399
 
400
0 
                working.Value.SensorUint64 = num_uint64;
401
0 
                break;
402
 
403
 
        case SAHPI_SENSOR_READING_TYPE_FLOAT64:
404
0 
		if (found_number) {		
405
0 
			errno = 0;
406
0 
			num_float64 = strtold(numstr, &endptr);
407
0 
			if (errno) {
408
0 
				dbg("strtold failed, errno=%d", errno);
409
0 
				return(SA_ERR_HPI_INVALID_DATA);
410
 
			}
411
0 
			if (*endptr != '\0') {
412
0 
				dbg("strtold failed: End Pointer=%s", endptr);
413
0 
				return(SA_ERR_HPI_INVALID_DATA);
414
 
			}
415
 
			
416
0 
			if (is_percent) {
417
0 
				working.Value.SensorFloat64 = num_float64/100.0;
418
 
			}
419
 
			else {
420
0 
				working.Value.SensorFloat64 = num_float64;
421
 
			}
422
 
		}
423
 
		else { /* No number in string */
424
0 
			num_float64 = 0;
425
 
		}
426
0 
                break;
427
 
428
 
        default: /* Should never get here */
429
0 
                dbg("Invalid type=%d", type);
430
0 
		return(SA_ERR_HPI_INTERNAL_ERROR);
431
 
        }
432
 
433
0 
	*reading = working;
434
 
435
0 
	return(SA_OK);
436
 
}
437
 
438
 
/**
439
 
 * oh_fprint_text:
440
 
 * @stream: File handle.
441
 
 * @buffer: Pointer to SaHpiTextBufferT to be printed.
442
 
 * 
443
 
 * Prints the text data contained in SaHpiTextBufferT to a file. Data must
444
 
 * be of type SAHPI_TL_TYPE_TEXT. @buffer->DataLength is ignored.
445
 
 * The MACRO oh_print_text(), uses this function to print to STDOUT. 
446
 
 *
447
 
 * Returns:
448
 
 * SA_OK - Normal operation.
449
 
 * SA_ERR_HPI_INVALID_DATA - @buffer->DataType not SAHPI_TL_TYPE_TEXT.
450
 
 **/
451
 
SaErrorT oh_fprint_text(FILE *stream, const SaHpiTextBufferT *buffer)
452
0 
{
453
0 
	SaErrorT err;
454
 
455
0 
        if (buffer->DataType == SAHPI_TL_TYPE_TEXT) {
456
0 
                err = fprintf(stream, "%s\n", buffer->Data);
457
0 
		if (err < 0) {
458
0 
			return(SA_ERR_HPI_INVALID_PARAMS);
459
 
		}
460
 
        }
461
 
	else {
462
0 
		return(SA_ERR_HPI_INVALID_DATA);
463
 
	}
464
 
	
465
0 
	return(SA_OK);
466
 
}
467
 
468
 
/**
469
 
 * oh_fprint_bigtext:
470
 
 * @stream: File handle.
471
 
 * @big_buffer: Pointer to oh_big_textbuffer to be printed.
472
 
 * 
473
 
 * Prints the text data contained in oh_big_textbuffer to a file. Data must
474
 
 * be of type SAHPI_TL_TYPE_TEXT. @big_buffer->DataLength is ignored.
475
 
 * The MACRO oh_print_bigtext(), uses this function to print to STDOUT.
476
 
 * 
477
 
 * Returns:
478
 
 * SA_OK - Normal operation.
479
 
 * SA_ERR_HPI_INVALID_DATA - @big_buffer->DataType not SAHPI_TL_TYPE_TEXT.
480
 
 **/
481
 
SaErrorT oh_fprint_bigtext(FILE *stream, const oh_big_textbuffer *big_buffer)
482
0 
{
483
0 
	SaErrorT err;
484
 
	
485
0 
        if (big_buffer->DataType == SAHPI_TL_TYPE_TEXT) {
486
0 
                err = fprintf(stream, "%s\n", big_buffer->Data);
487
0 
		if (err < 0) {
488
0 
			return(SA_ERR_HPI_INVALID_PARAMS);
489
 
		}
490
 
        }
491
 
	else {
492
0 
		return(SA_ERR_HPI_INVALID_DATA);
493
 
	}
494
 
	
495
0 
	return(SA_OK);
496
 
}
497
 
498
 
/**
499
 
 * oh_init_textbuffer:
500
 
 * @buffer: Pointer to an SaHpiTextBufferT.
501
 
 * 
502
 
 * Initializes an SaHpiTextBufferT. Assumes an English language set.
503
 
 * 
504
 
 * Returns:
505
 
 * SA_OK - Normal operation.
506
 
 * SA_ERR_HPI_INVALID_PARAMS - @buffer is NULL.
507
 
 **/
508
 
SaErrorT oh_init_textbuffer(SaHpiTextBufferT *buffer)
509
0 
{
510
0 
	if (!buffer) {
511
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
512
 
	}
513
 
514
0 
	memset(buffer, 0, sizeof(*buffer));
515
0 
        buffer->DataType = SAHPI_TL_TYPE_TEXT;
516
0 
        buffer->Language = SAHPI_LANG_ENGLISH;
517
0 
        buffer->DataLength = 0;
518
0 
        return(SA_OK);
519
 
}
520
 
521
 
static inline SaErrorT oh_init_bigtext(oh_big_textbuffer *big_buffer)
522
0 
{
523
0 
	if (!big_buffer) {
524
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
525
 
	}
526
 
527
0 
	memset(big_buffer, 0, sizeof(*big_buffer));
528
0 
        big_buffer->DataType = SAHPI_TL_TYPE_TEXT;
529
0 
        big_buffer->Language = SAHPI_LANG_ENGLISH;
530
0 
        big_buffer->DataLength = 0;
531
0 
        return(SA_OK);
532
 
}
533
 
534
 
/**
535
 
 * oh_copy_textbuffer:
536
 
 * @dest: SaHpiTextBufferT to copy into.
537
 
 * @from:SaHpiTextBufferT to copy from.
538
 
 *
539
 
 * Copies one SaHpiTextBufferT structure to another.
540
 
 * 
541
 
 * Returns:
542
 
 * SA_OK - Normal operation.
543
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
544
 
 **/
545
 
SaErrorT oh_copy_textbuffer(SaHpiTextBufferT *dest, const SaHpiTextBufferT *from)
546
0 
{
547
0 
	if (!dest || !from) {
548
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
549
 
	}
550
 
551
0 
        dest->DataType = from->DataType;
552
0 
        dest->Language = from->Language;
553
0 
	dest->DataLength = from->DataLength;
554
0 
        memcpy(dest->Data, from->Data, SAHPI_MAX_TEXT_BUFFER_LENGTH);
555
0 
        return(SA_OK);
556
 
}
557
 
558
 
static inline SaErrorT oh_copy_bigtext(oh_big_textbuffer *dest, const oh_big_textbuffer *from)
559
0 
{
560
0 
	if (!dest || !from) {
561
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
562
 
	}
563
 
564
0 
        dest->DataType = from->DataType;
565
0 
        dest->Language = from->Language;
566
0 
        dest->DataLength = from->DataLength;
567
0 
        memcpy(dest->Data, from->Data, OH_MAX_TEXT_BUFFER_LENGTH);
568
0 
        return(SA_OK);
569
 
}
570
 
571
 
/**
572
 
 * oh_append_textbuffer:
573
 
 * @buffer: SaHpiTextBufferT to append to.
574
 
 * @from: String to be appended.
575
 
 *
576
 
 * Appends a string to @buffer->Data.
577
 
 * 
578
 
 * Returns:
579
 
 * SA_OK - Normal operation.
580
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
581
 
 * SA_ERR_HPI_OUT_OF_SPACE - @buffer not big enough to accomodate appended string.
582
 
 **/
583
 
SaErrorT oh_append_textbuffer(SaHpiTextBufferT *buffer, const char *from)
584
0 
{
585
0 
        SaHpiUint8T *p;
586
0 
	uint size;
587
 
588
0 
	if (!buffer || !from) {
589
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
590
 
	}
591
0 
	size = strlen(from);
592
0 
        if ((size + buffer->DataLength) >= SAHPI_MAX_TEXT_BUFFER_LENGTH) {
593
0 
		dbg("Cannot append to text buffer. Bufsize=%d, size=%u",
594
 
		    buffer->DataLength, size);
595
0 
                return(SA_ERR_HPI_OUT_OF_SPACE);
596
 
        }
597
 
598
 
        /* Can't trust NULLs to be right, so use a targeted strncpy instead */
599
0 
        p = buffer->Data;
600
0 
        p += buffer->DataLength;
601
0 
        strncpy(p, from, size);
602
0 
        buffer->DataLength += size;
603
 
        
604
0 
        return(SA_OK);
605
 
}
606
 
607
 
static inline SaErrorT oh_append_bigtext(oh_big_textbuffer *big_buffer, const char *from)
608
0 
{
609
0 
        SaHpiUint8T *p;
610
0 
	uint size;
611
 
612
0 
	if (!big_buffer || !from) {
613
0 
		dbg("Invalid parameters");
614
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
615
 
	}
616
0 
	size = strlen(from);
617
0 
        if ((size + big_buffer->DataLength) >= OH_MAX_TEXT_BUFFER_LENGTH) {
618
0 
		dbg("Cannot append to buffer. Bufsize=%d, size=%u",
619
 
		    big_buffer->DataLength, size);
620
0 
                return(SA_ERR_HPI_INTERNAL_ERROR);
621
 
        }
622
 
        
623
 
        /* Can't trust NULLs to be right, so use a targeted strncpy instead */
624
0 
        p = big_buffer->Data;
625
0 
        p += big_buffer->DataLength;
626
0 
        strncpy(p, from, size);
627
0 
        big_buffer->DataLength += size;
628
 
        
629
0 
        return(SA_OK);
630
 
}
631
 
632
 
static inline SaErrorT oh_append_data(oh_big_textbuffer *big_buffer, const SaHpiUint8T *from,
633
 
				      SaHpiUint8T len)
634
0 
{
635
0 
	SaHpiUint8T i;
636
 
637
0 
	if (!big_buffer || !from || len == 0) {
638
0 
		dbg("Invalid parameters");
639
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
640
 
	}
641
 
642
0 
	for (i = 0; i < len; i++) {
643
0 
        	SaHpiUint8T *p;
644
0 
		char buff[10];
645
0 
		int slen;
646
 
		
647
0 
		memset(buff, 0 ,sizeof(buff));	
648
0 
		snprintf(buff, 10, "%d ", *(from + i));
649
 
650
0 
		slen = strlen(buff);
651
 
652
0 
        	if ((slen + big_buffer->DataLength) >= OH_MAX_TEXT_BUFFER_LENGTH) {
653
0 
			dbg("Cannot append to buffer. Bufsize=%d, len=%d",
654
 
					big_buffer->DataLength, len);
655
0 
			return(SA_ERR_HPI_INTERNAL_ERROR);
656
 
		}
657
 
658
0 
        	p = big_buffer->Data;
659
0 
        	p += big_buffer->DataLength;
660
0 
        	strncpy(p, buff, slen);
661
0 
        	big_buffer->DataLength += slen;
662
 
	}
663
 
664
0 
        return(SA_OK);
665
 
}
666
 
667
 
/* Append an arbitrary number of fixed offset strings to a big text buffer */
668
 
static SaErrorT oh_append_offset(oh_big_textbuffer *buffer, int offsets)
669
0 
{
670
0 
	int i;
671
 
	
672
0 
	for (i=0; i < offsets; i++) {
673
0 
		oh_append_bigtext(buffer, OH_PRINT_OFFSET);
674
 
	}
675
 
676
0 
	return(SA_OK);
677
 
}
678
 
679
 
/**
680
 
 * oh_fprint_ctrlrec:
681
 
 * @stream: File handle.
682
 
 * @control: Pointer to SaHpiCtrlRecT to be printed.
683
 
 * @offsets: Number of offsets to start printing structure.
684
 
 * 
685
 
 * Prints a control's SaHpiCtrlRecT data to a file. 
686
 
 * The MACRO oh_print_ctrlrec(), uses this function to print to STDOUT. 
687
 
 *
688
 
 * Returns:
689
 
 * SA_OK - Normal operation.
690
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
691
 
 **/
692
 
SaErrorT oh_fprint_ctrlrec(FILE *stream, const SaHpiCtrlRecT *control, int offsets)
693
0 
{
694
0 
	SaErrorT err;
695
0 
	oh_big_textbuffer buffer;
696
 
	
697
0 
	if (!stream || !control) {
698
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
699
 
	}
700
 
	
701
0 
	oh_init_bigtext(&buffer);
702
0 
	err = oh_build_ctrlrec(&buffer, control, offsets);
703
0 
	if (err) { return(err); }
704
 
705
0 
	err = oh_fprint_bigtext(stream, &buffer);
706
0 
	if (err) { return(err); }
707
 
	
708
0 
	return(SA_OK);
709
 
}
710
 
711
 
/**
712
 
 * oh_fprint_watchdogrec:
713
 
 * @stream: File handle.
714
 
 * @watchdog: Pointer to SaHpiWatchdogRecT to be printed.
715
 
 * @offsets: Number of offsets to start printing structure.
716
 
 * 
717
 
 * Prints a watchdog's SaHpiWatchdogRecT data to a file. 
718
 
 * The MACRO oh_print_watchdogrec(), uses this function to print to STDOUT. 
719
 
 *
720
 
 * Returns:
721
 
 * SA_OK - Normal operation.
722
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
723
 
 **/
724
 
SaErrorT oh_fprint_watchdogrec(FILE *stream, const SaHpiWatchdogRecT *watchdog, int offsets)
725
0 
{
726
0 
	SaErrorT err;
727
0 
	oh_big_textbuffer buffer;
728
 
	
729
0 
	if (!stream || !watchdog) {
730
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
731
 
	}
732
 
	
733
0 
	oh_init_bigtext(&buffer);
734
0 
	err = oh_build_wdogrec(&buffer, watchdog, offsets);
735
0 
	if (err) { return(err); }
736
 
737
0 
	err = oh_fprint_bigtext(stream, &buffer);
738
0 
	if (err) { return(err); }
739
 
	
740
0 
	return(SA_OK);
741
 
}
742
 
743
 
/**
744
 
 * oh_fprint_sensorrec:
745
 
 * @stream: File handle.
746
 
 * @sensor: Pointer to SaHpiSensorRecT to be printed.
747
 
 * @offsets: Number of offsets to start printing structure.
748
 
 * 
749
 
 * Prints a sensor's SaHpiSensorRecT data to a file. 
750
 
 * The MACRO oh_print_sensorrec(), uses this function to print to STDOUT. 
751
 
 *
752
 
 * Returns:
753
 
 * SA_OK - Normal operation.
754
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
755
 
 **/
756
 
SaErrorT oh_fprint_sensorrec(FILE *stream, const SaHpiSensorRecT *sensor, int offsets)
757
0 
{
758
0 
	SaErrorT err;
759
0 
	oh_big_textbuffer buffer;
760
 
	
761
0 
	if (!stream || !sensor) {
762
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
763
 
	}
764
 
	
765
0 
	oh_init_bigtext(&buffer);
766
0 
	err = oh_build_sensorrec(&buffer, sensor, offsets);
767
0 
	if (err) { return(err); }
768
 
769
0 
	err = oh_fprint_bigtext(stream, &buffer);
770
0 
	if (err) { return(err); }
771
 
	
772
0 
	return(SA_OK);
773
 
}
774
 
775
 
static SaErrorT oh_build_sensorrec(oh_big_textbuffer *buffer, const SaHpiSensorRecT *sensor, int offsets)
776
0 
{
777
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
778
0 
	SaErrorT err;
779
0 
	SaHpiTextBufferT tmpbuffer;
780
 
781
 
	/* Sensor Num */
782
0 
	oh_append_offset(buffer, offsets);
783
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Sensor Num: %d\n", sensor->Num);
784
0 
	oh_append_bigtext(buffer, str);
785
0 
	offsets++;
786
 
787
 
	/* Sensor Type */
788
0 
	oh_append_offset(buffer, offsets);
789
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Type: %s\n", 
790
 
		 oh_lookup_sensortype(sensor->Type));
791
0 
	oh_append_bigtext(buffer, str);
792
 
793
 
	/* Sensor Category */
794
0 
	oh_append_offset(buffer, offsets);
795
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Category: %s\n", 
796
 
		 oh_lookup_eventcategory(sensor->Category));
797
0 
	oh_append_bigtext(buffer, str);
798
 
799
 
	/* Sensor Enable Control */
800
0 
	oh_append_offset(buffer, offsets);
801
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EnableCtrl: %s\n",
802
 
		(sensor->EnableCtrl == SAHPI_TRUE) ? "TRUE" : "FALSE");
803
0 
	oh_append_bigtext(buffer, str);
804
 
805
 
	/* Sensor Event Control */
806
0 
	oh_append_offset(buffer, offsets);
807
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EventCtrl: %s\n", 
808
 
		 oh_lookup_sensoreventctrl(sensor->EventCtrl));
809
0 
	oh_append_bigtext(buffer, str);
810
 
811
 
	/* Sensor Supported Events */
812
0 
	oh_append_offset(buffer, offsets);
813
0 
	oh_append_bigtext(buffer, "Events: ");
814
0 
	err = oh_decode_eventstate(sensor->Events, sensor->Category, &tmpbuffer);
815
0 
	if (err) {oh_append_bigtext(buffer, "\n"); return(err); }
816
0 
	oh_append_bigtext(buffer, tmpbuffer.Data);
817
0 
	oh_append_bigtext(buffer, "\n");
818
 
	
819
 
	/* Sensor Data Format */
820
0 
	err = oh_build_sensordataformat(buffer, &(sensor->DataFormat), offsets);
821
0 
	if (err) { return(err); }
822
 
823
 
	/* Sensor Threshold Definition */
824
0 
	err = oh_build_sensorthddefn(buffer, &(sensor->ThresholdDefn), offsets);
825
0 
	if (err) { return(err); }
826
 
827
 
	/* Sensor OEM Data */
828
0 
	oh_append_offset(buffer, offsets);
829
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OEM: %x\n", sensor->Oem);
830
0 
	oh_append_bigtext(buffer, str);
831
 
832
 
	/* printf("SENSOR LENGTH = %d\n", strlen(buffer->Data)); */
833
0 
	return(SA_OK);
834
 
}
835
 
836
 
static SaErrorT oh_build_sensordataformat(oh_big_textbuffer *buffer,
837
 
					  const SaHpiSensorDataFormatT *format, 
838
 
					  int offsets)
839
0 
{
840
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
841
0 
	SaErrorT err;
842
0 
	SaHpiTextBufferT reading_buffer;
843
 
844
 
	/* Sensor Data Format Title */
845
0 
	oh_append_offset(buffer, offsets);
846
0 
	oh_append_bigtext(buffer, "Data Format:\n");
847
0 
	offsets++;
848
 
		
849
 
	/* Sensor Data Format IsSupported */
850
0 
	oh_append_offset(buffer, offsets);
851
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "IsSupported: %s\n",
852
 
		 (format->IsSupported == SAHPI_TRUE) ? "TRUE" : "FALSE");
853
0 
	oh_append_bigtext(buffer, str);
854
 
		
855
0 
	if (format->IsSupported) {
856
 
857
 
		/* Sensor Data Format Reading Type */
858
0 
		oh_append_offset(buffer, offsets);
859
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Reading Type: %s\n", 
860
 
			 oh_lookup_sensorreadingtype(format->ReadingType));
861
0 
		oh_append_bigtext(buffer, str);
862
 
		
863
0 
		if (format->ReadingType != SAHPI_SENSOR_READING_TYPE_BUFFER) {
864
 
865
 
			/* Sensor Data Format Base Units */
866
0 
			oh_append_offset(buffer, offsets);
867
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Base Unit: %s\n", 
868
 
				 oh_lookup_sensorunits(format->BaseUnits));
869
0 
			oh_append_bigtext(buffer, str);
870
 
			
871
 
			/* Sensor Data Format Modifier Units */
872
0 
			if (format->ModifierUnits) {
873
0 
				oh_append_offset(buffer, offsets);
874
0 
				snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Modifier Unit: %s\n", 
875
 
					 oh_lookup_sensorunits(format->ModifierUnits));
876
0 
				oh_append_bigtext(buffer, str);
877
 
				/* Sensor Data Format Modifier Use */
878
0 
				oh_append_offset(buffer, offsets);
879
0 
				snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Modifier Use: %s\n",
880
 
					 oh_lookup_sensormodunituse(format->ModifierUse));
881
0 
				oh_append_bigtext(buffer, str);
882
 
			}
883
 
			
884
 
			/* Sensor Data Format Percentage */
885
0 
			oh_append_offset(buffer, offsets);
886
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Percentage: %s\n",
887
 
				 (format->Percentage == SAHPI_TRUE) ? "TRUE" : "FALSE");
888
0 
			oh_append_bigtext(buffer, str);
889
 
		
890
 
			/* Sensor Data Format Max Range */
891
0 
			if (format->Range.Flags & SAHPI_SRF_MAX && 
892
 
			    format->Range.Max.IsSupported) { 
893
0 
				oh_append_offset(buffer, offsets);
894
0 
				oh_append_bigtext(buffer, "Range Max: ");
895
 
				
896
0 
				err = oh_decode_sensorreading(format->Range.Max,
897
 
							      *format,
898
 
							      &reading_buffer);
899
0 
				if (err) { return(err); }
900
0 
				oh_append_bigtext(buffer, reading_buffer.Data);
901
0 
				oh_append_bigtext(buffer, "\n");
902
 
			}
903
 
904
 
			/* Sensor Data Format Min Range */
905
0 
			if (format->Range.Flags & SAHPI_SRF_MIN && 
906
 
			    format->Range.Min.IsSupported) { 
907
0 
				oh_append_offset(buffer, offsets);
908
0 
				oh_append_bigtext(buffer, "Range Min: ");
909
 
				
910
0 
				err = oh_decode_sensorreading(format->Range.Min,
911
 
							      *format,
912
 
							      &reading_buffer);
913
0 
				if (err) { return(err); }
914
0 
				oh_append_bigtext(buffer, reading_buffer.Data);
915
0 
				oh_append_bigtext(buffer, "\n");
916
 
			}
917
 
918
 
			/* Sensor Data Format Nominal Range */
919
0 
			if (format->Range.Flags & SAHPI_SRF_NOMINAL && 
920
 
			    format->Range.Nominal.IsSupported) { 
921
0 
				oh_append_offset(buffer, offsets);
922
0 
				oh_append_bigtext(buffer, "Range Nominal: ");
923
 
				
924
0 
				err = oh_decode_sensorreading(format->Range.Nominal,
925
 
							      *format,
926
 
							      &reading_buffer);
927
0 
				if (err) { return(err); }
928
0 
				oh_append_bigtext(buffer, reading_buffer.Data);
929
0 
				oh_append_bigtext(buffer, "\n");
930
 
			}
931
 
932
 
			/* Sensor Data Format Normal Max Range */
933
0 
			if (format->Range.Flags & SAHPI_SRF_NORMAL_MAX && 
934
 
			    format->Range.NormalMax.IsSupported) { 
935
0 
				oh_append_offset(buffer, offsets);
936
0 
				oh_append_bigtext(buffer, "Range Normal Max: ");
937
 
				
938
0 
				err = oh_decode_sensorreading(format->Range.NormalMax,
939
 
							      *format,
940
 
							      &reading_buffer);
941
0 
				if (err) { return(err); }
942
0 
				oh_append_bigtext(buffer, reading_buffer.Data);
943
0 
				oh_append_bigtext(buffer, "\n");
944
 
			}
945
 
946
 
			/* Sensor Data Format Normal Min Range */
947
0 
			if (format->Range.Flags & SAHPI_SRF_NORMAL_MIN && 
948
 
			    format->Range.NormalMin.IsSupported) { 
949
0 
				oh_append_offset(buffer, offsets);
950
0 
				oh_append_bigtext(buffer, "Range Normal Min: ");
951
 
				
952
0 
				err = oh_decode_sensorreading(format->Range.NormalMin,
953
 
							      *format,
954
 
							      &reading_buffer);
955
0 
				if (err) { return(err); }
956
0 
				oh_append_bigtext(buffer, reading_buffer.Data);
957
0 
				oh_append_bigtext(buffer, "\n");
958
 
			}
959
 
960
 
			/* Sensor Data Format Accuracy Factor */
961
0 
			oh_append_offset(buffer, offsets);
962
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Accuracy: %le\n", format->AccuracyFactor);	
963
0 
			oh_append_bigtext(buffer, str);
964
 
		}
965
 
	}
966
 
	
967
0 
	return(SA_OK);
968
 
}
969
 
970
 
static SaErrorT oh_build_sensorthddefn(oh_big_textbuffer *buffer,
971
 
				       const SaHpiSensorThdDefnT *tdef, 
972
 
				       int offsets)
973
0 
{
974
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
975
0 
	SaErrorT err;
976
 
977
 
	/* Sensor Threshold Definition Title */
978
0 
	oh_append_offset(buffer, offsets);
979
0 
	oh_append_bigtext(buffer, "Threshold Definitions:\n");
980
0 
	offsets++;
981
 
982
 
	/* Sensor Threshold Definition IsAccessible */
983
0 
	oh_append_offset(buffer, offsets);
984
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "IsAccessible: %s\n",
985
 
		 (tdef->IsAccessible == SAHPI_TRUE) ? "TRUE" : "FALSE");
986
0 
	oh_append_bigtext(buffer, str);
987
 
	
988
0 
	if (tdef->IsAccessible) {
989
 
990
 
		/* Sensor Threshold Read Threshold */
991
0 
		if (tdef->ReadThold) {
992
0 
			oh_append_offset(buffer, offsets);
993
0 
			oh_append_bigtext(buffer, "Readable Thresholds:\n"); 
994
 
995
0 
			err = oh_build_threshold_mask(buffer, tdef->ReadThold, offsets + 1);
996
0 
			if (err) { return(err); }
997
 
		}
998
 
		
999
 
		/* Sensor Threshold Write Threshold */
1000
0 
		if (tdef->WriteThold) {
1001
0 
			oh_append_offset(buffer, offsets);
1002
0 
			oh_append_bigtext(buffer, "Writeable Thresholds:\n");
1003
 
1004
0 
			err = oh_build_threshold_mask(buffer, tdef->WriteThold, offsets + 1);
1005
0 
			if (err) { return(err); }
1006
 
		}
1007
 
1008
 
		/* Sensor Threshold Nonlinear */
1009
0 
		oh_append_offset(buffer, offsets);
1010
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Nonlinear: %s\n",
1011
 
			 (tdef->Nonlinear == SAHPI_TRUE) ? "TRUE" : "FALSE");
1012
0 
		oh_append_bigtext(buffer, str);
1013
 
	}	
1014
 
1015
0 
	return(SA_OK);
1016
 
}
1017
 
1018
 
static SaErrorT oh_build_threshold_mask(oh_big_textbuffer *buffer,
1019
 
					const SaHpiSensorThdMaskT tmask, 
1020
 
					int offsets)
1021
0 
{
1022
0 
	int i;
1023
 
1024
0 
	oh_append_offset(buffer, offsets);
1025
 
1026
0 
	if (tmask & SAHPI_STM_LOW_MINOR) {
1027
0 
		oh_append_bigtext(buffer, "LOW_MINOR");
1028
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1029
 
	}
1030
0 
	if (tmask & SAHPI_STM_LOW_MAJOR) {
1031
0 
		oh_append_bigtext(buffer, "LOW_MAJOR");
1032
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1033
 
	}
1034
0 
	if (tmask & SAHPI_STM_LOW_CRIT) {
1035
0 
		oh_append_bigtext(buffer, "LOW_CRIT");
1036
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1037
 
	}
1038
0 
	if (tmask & SAHPI_STM_LOW_HYSTERESIS) {
1039
0 
		oh_append_bigtext(buffer, "LOW_HYSTERESIS");
1040
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1041
 
	}
1042
0 
	if (tmask & SAHPI_STM_UP_MINOR) {
1043
0 
		oh_append_bigtext(buffer, "UP_MINOR");
1044
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1045
 
	}
1046
0 
	if (tmask & SAHPI_STM_UP_MAJOR) {
1047
0 
		oh_append_bigtext(buffer, "UP_MAJOR");
1048
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1049
 
	}
1050
0 
	if (tmask & SAHPI_STM_UP_CRIT) {
1051
0 
		oh_append_bigtext(buffer, "UP_CRIT");
1052
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1053
 
	}
1054
0 
	if (tmask & SAHPI_STM_UP_HYSTERESIS) {
1055
0 
		oh_append_bigtext(buffer, "UP_HYSTERESIS");
1056
0 
		oh_append_bigtext(buffer, OH_ENCODE_DELIMITER);
1057
 
	}
1058
 
1059
 
	/* Remove last delimiter; add NL */
1060
0 
	for (i=0; i<OH_ENCODE_DELIMITER_LENGTH + 1; i++) {
1061
0 
		buffer->Data[buffer->DataLength - i] = 0x00;
1062
 
	}
1063
0 
	buffer->DataLength = buffer->DataLength - (i-1);
1064
0 
	oh_append_bigtext(buffer, "\n");
1065
 
1066
0 
	return(SA_OK);
1067
 
}
1068
 
1069
 
/**
1070
 
 * oh_fprint_idrfield:
1071
 
 * @stream: File handle.
1072
 
 * @thisfield: Pointer to SaHpiIdrFieldT to be printed.
1073
 
 * @offsets: Number of offsets to start printing structure.
1074
 
 * 
1075
 
 * Prints the member data contained in SaHpiIdrFieldT struct to a file.
1076
 
 * The MACRO oh_print_idrfield(), uses this function to print to STDOUT. 
1077
 
 *
1078
 
 * Returns:
1079
 
 * SA_OK - Normal operation.
1080
 
 **/
1081
 
SaErrorT oh_fprint_idrfield(FILE *stream, const SaHpiIdrFieldT *thisfield, int offsets)
1082
0 
{
1083
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1084
0 
	oh_big_textbuffer mybuf;
1085
0 
	SaErrorT err;
1086
 
1087
0 
	if (!stream || !thisfield) return(SA_ERR_HPI_INVALID_PARAMS);
1088
 
					
1089
0 
	oh_init_bigtext(&mybuf);
1090
0 
	oh_append_offset(&mybuf, offsets);
1091
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Field Id: %d\n", thisfield->FieldId);
1092
0 
	oh_append_bigtext(&mybuf, str);
1093
 
						
1094
0 
	oh_append_offset(&mybuf, offsets);
1095
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Field Type: %s\n",
1096
 
		 oh_lookup_idrfieldtype(thisfield->Type));
1097
0 
	oh_append_bigtext(&mybuf, str);
1098
 
						
1099
0 
	oh_append_offset(&mybuf, offsets);
1100
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ReadOnly: %s\n",
1101
 
		 (thisfield->ReadOnly == SAHPI_TRUE) ? "TRUE" : "FALSE");
1102
0 
	oh_append_bigtext(&mybuf, str);
1103
 
						
1104
0 
	oh_append_offset(&mybuf, offsets);
1105
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "DataType: %s\n",
1106
 
		 oh_lookup_texttype(thisfield->Field.DataType));
1107
0 
	oh_append_bigtext(&mybuf, str);
1108
 
						
1109
0 
	oh_append_offset(&mybuf, offsets);
1110
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Language: %s\n",
1111
 
		 oh_lookup_language(thisfield->Field.Language));
1112
0 
	oh_append_bigtext(&mybuf, str);
1113
 
						
1114
0 
	oh_append_offset(&mybuf, offsets);
1115
0 
	oh_append_bigtext(&mybuf, "Content: ");
1116
0 
	if (thisfield->Field.DataLength == 0)
1117
0 
		oh_append_bigtext(&mybuf, "NULL\n");
1118
 
	else {
1119
0 
		if (thisfield->Field.DataType == SAHPI_TL_TYPE_BINARY)
1120
0 
			oh_append_data(&mybuf, thisfield->Field.Data, thisfield->Field.DataLength);
1121
 
		else
1122
0 
			oh_append_bigtext(&mybuf, thisfield->Field.Data);
1123
 
	}
1124
 
							
1125
0 
	err = oh_fprint_bigtext(stream, &mybuf);
1126
 
1127
0 
	return(err);
1128
 
}
1129
 
1130
 
/**
1131
 
 * oh_fprint_idrareaheader:
1132
 
 * @stream: File handle.
1133
 
 * @areaheader: Pointer to SaHpiIdrAreaHeaderT to be printed.
1134
 
 * @offsets: Number of offsets to start printing structure.
1135
 
 * 
1136
 
 * Prints the member data contained in SaHpiIdrAreaHeaderT struct to a file.
1137
 
 * The MACRO oh_print_idrareaheader(), uses this function to print to STDOUT. 
1138
 
 *
1139
 
 * Returns:       
1140
 
 * SA_OK - Normal operation.
1141
 
 **/
1142
 
SaErrorT oh_fprint_idrareaheader(FILE *stream, const SaHpiIdrAreaHeaderT *areaheader, int offsets)
1143
0 
{
1144
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1145
0 
	oh_big_textbuffer mybuf;
1146
0 
	SaErrorT err;
1147
 
1148
0 
	if (!stream || !areaheader) return(SA_ERR_HPI_INVALID_PARAMS);
1149
 
	
1150
0 
	oh_init_bigtext(&mybuf);
1151
0 
	oh_append_offset(&mybuf, offsets);
1152
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "AreaId: %d\n", areaheader->AreaId);
1153
0 
	oh_append_bigtext(&mybuf, str);
1154
 
1155
0 
	oh_append_offset(&mybuf, offsets);
1156
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "AreaType: %s\n",
1157
 
		 oh_lookup_idrareatype(areaheader->Type));
1158
0 
	oh_append_bigtext(&mybuf, str);
1159
 
1160
0 
	oh_append_offset(&mybuf, offsets);
1161
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ReadOnly: %s\n",
1162
 
		 (areaheader->ReadOnly == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1163
0 
	oh_append_bigtext(&mybuf, str);
1164
 
1165
0 
	oh_append_offset(&mybuf, offsets);
1166
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "NumFields: %d\n", areaheader->NumFields);
1167
0 
	oh_append_bigtext(&mybuf, str);
1168
 
1169
0 
	err = oh_fprint_bigtext(stream, &mybuf); 					
1170
0 
	return(err);
1171
 
}
1172
 
1173
 
/**
1174
 
 * oh_fprint_idrinfo:
1175
 
 * @stream: File handle.
1176
 
 * @idrinfo: Pointer to SaHpiIdrInfoT to be printed.
1177
 
 * @offsets: Number of offsets to start printing structure.
1178
 
 * 
1179
 
 * Prints the member data contained in SaHpiIdrInfoT struct to a file.
1180
 
 * The MACRO oh_print_idrinfo(), uses this function to print to STDOUT. 
1181
 
 *
1182
 
 * Returns:       
1183
 
 * SA_OK - Normal operation.
1184
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1185
 
 **/
1186
 
SaErrorT oh_fprint_idrinfo(FILE *stream, const SaHpiIdrInfoT *idrinfo, int offsets)
1187
0 
{
1188
0 
	SaErrorT err;
1189
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1190
0 
	oh_big_textbuffer mybuf;
1191
 
	
1192
0 
	if (!stream || !idrinfo) return(SA_ERR_HPI_INVALID_PARAMS);
1193
 
			
1194
0 
	oh_init_bigtext(&mybuf);
1195
0 
	oh_append_offset(&mybuf, offsets);
1196
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "IdrId: %d\n", idrinfo->IdrId);
1197
0 
	oh_append_bigtext(&mybuf, str);
1198
 
1199
0 
	oh_append_offset(&mybuf, offsets);
1200
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "UpdateCount: %d\n", idrinfo->UpdateCount);
1201
0 
	oh_append_bigtext(&mybuf, str);
1202
 
1203
0 
	oh_append_offset(&mybuf, offsets);
1204
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ReadOnly: %s\n",
1205
 
				(idrinfo->ReadOnly == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1206
0 
	oh_append_bigtext(&mybuf, str);
1207
 
1208
0 
	oh_append_offset(&mybuf, offsets);
1209
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "NumAreas: %d\n", idrinfo->NumAreas);
1210
0 
	oh_append_bigtext(&mybuf, str);
1211
 
1212
0 
	err = oh_fprint_bigtext(stream, &mybuf); 					
1213
0 
	return(err);
1214
 
}
1215
 
1216
0 
SaErrorT oh_fprint_textbuffer(FILE *stream, const SaHpiTextBufferT *textbuffer, int offsets) {
1217
 
1218
0 
	SaErrorT err;
1219
0 
	oh_big_textbuffer buffer;
1220
 
	
1221
0 
	if (!stream || !textbuffer) {
1222
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
1223
 
	}
1224
 
	
1225
0 
	oh_init_bigtext(&buffer);
1226
0 
	err = oh_build_textbuffer(&buffer, textbuffer, offsets);
1227
0 
	if (err) { return(err); }
1228
 
1229
0 
	err = oh_fprint_bigtext(stream, &buffer);
1230
 
1231
0 
	return(err);
1232
 
}
1233
 
1234
 
static SaErrorT oh_build_textbuffer(oh_big_textbuffer *buffer, const SaHpiTextBufferT *textbuffer, int offsets)
1235
0 
{
1236
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1237
 
1238
 
	/* Text Buffer Data Type */
1239
0 
	oh_append_offset(buffer, offsets);
1240
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Data Type: %s\n", 
1241
 
		 oh_lookup_texttype(textbuffer->DataType));
1242
0 
	oh_append_bigtext(buffer, str);
1243
 
1244
 
	/* Text Buffer Language */
1245
0 
	oh_append_offset(buffer, offsets);
1246
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Language: %s\n", 
1247
 
		 oh_lookup_language(textbuffer->Language));
1248
0 
	oh_append_bigtext(buffer, str);
1249
 
	
1250
 
	/* Text Buffer Data Length */
1251
0 
	oh_append_offset(buffer, offsets);
1252
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Data Length: %d\n", 
1253
 
		 textbuffer->DataLength);
1254
0 
	oh_append_bigtext(buffer, str);
1255
 
1256
 
	/* Text Buffer Data */
1257
0 
	if (textbuffer->DataLength) {
1258
0 
		oh_append_offset(buffer, offsets);
1259
0 
		memset(str, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
1260
0 
		oh_append_bigtext(buffer, "Data: ");
1261
0 
		if (textbuffer->DataType == SAHPI_TL_TYPE_BINARY)
1262
0 
			oh_append_data(buffer, textbuffer->Data, textbuffer->DataLength);
1263
 
		else
1264
0 
			oh_append_bigtext(buffer, textbuffer->Data);
1265
0 
		oh_append_bigtext(buffer, "\n");
1266
 
	}
1267
 
1268
0 
	return(SA_OK);
1269
 
}
1270
 
1271
 
/**
1272
 
 * oh_decode_capabilities:
1273
 
 * @ResourceCapabilities: enum value of type SaHpiCapabilitiesT.
1274
 
 * @buffer:  Location to store the string.
1275
 
 *
1276
 
 * Converts @ResourceCapabilities type into a string based on 
1277
 
 * @ResourceCapabilities HPI definition. For example:
1278
 
 * @ResourceCapabilities = SAHPI_CAPABILITY_RESOURCE | SAHPI_CAPABILITY_EVENT_LOG
1279
 
 * returns a string "RESOURCE | EVENT_LOG".
1280
 
 * 
1281
 
 * Returns:
1282
 
 * SA_OK - Normal operation.
1283
 
 * SA_ERR_HPI_INVALID_PARAMS - @buffer is NULL
1284
 
 **/
1285
 
SaErrorT oh_decode_capabilities(SaHpiCapabilitiesT ResourceCapabilities,
1286
 
				SaHpiTextBufferT *buffer)
1287
0 
{
1288
0 
	int found, i;
1289
0 
	SaErrorT err;
1290
0 
	SaHpiTextBufferT working;
1291
 
1292
0 
	if (!buffer) {
1293
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
1294
 
	}
1295
 
1296
0 
	err = oh_init_textbuffer(&working);
1297
0 
	if (err) { return(err); }
1298
 
1299
0 
	found = 0;
1300
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_AGGREGATE_STATUS) {
1301
0 
		found++;
1302
0 
		err = oh_append_textbuffer(&working, "AGGREGATE_STATUS | ");
1303
0 
		if (err) { return(err); }
1304
 
	}
1305
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_ANNUNCIATOR) {
1306
0 
		found++;
1307
0 
		err = oh_append_textbuffer(&working, "ANNUNCIATOR | ");
1308
0 
		if (err) { return(err); }
1309
 
	}
1310
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_CONFIGURATION) {
1311
0 
		found++;
1312
0 
		err = oh_append_textbuffer(&working, "CONFIGURATION | ");
1313
0 
		if (err) { return(err); }
1314
 
	}
1315
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_CONTROL) {
1316
0 
		found++;
1317
0 
		err = oh_append_textbuffer(&working, "CONTROL | ");
1318
0 
		if (err) { return(err); }
1319
 
	}
1320
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG) {
1321
0 
		found++;
1322
0 
		err = oh_append_textbuffer(&working, "EVENT_LOG | ");
1323
0 
		if (err) { return(err); }
1324
 
	}
1325
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_EVT_DEASSERTS) {
1326
0 
		found++;
1327
0 
		err = oh_append_textbuffer(&working, "EVT_DEASSERTS | ");
1328
0 
		if (err) { return(err); }
1329
 
	}
1330
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_FRU) {
1331
0 
		found++;
1332
0 
		err = oh_append_textbuffer(&working, "FRU | ");
1333
0 
		if (err) { return(err); }
1334
 
	}
1335
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA) {
1336
0 
		found++;
1337
0 
		err = oh_append_textbuffer(&working, "INVENTORY_DATA | ");
1338
0 
		if (err) { return(err); }
1339
 
	}
1340
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_MANAGED_HOTSWAP) {
1341
0 
		found++;
1342
0 
		err = oh_append_textbuffer(&working, "MANAGED_HOTSWAP | ");
1343
0 
		if (err) { return(err); }
1344
 
	}
1345
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_POWER) {
1346
0 
		found++;
1347
0 
		err = oh_append_textbuffer(&working, "POWER | ");
1348
0 
		if (err) { return(err); }
1349
 
	}
1350
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_RDR) {
1351
0 
		found++;
1352
0 
		err = oh_append_textbuffer(&working, "RDR | ");
1353
0 
		if (err) { return(err); }
1354
 
	}
1355
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_RESET) {
1356
0 
		found++;
1357
0 
		err = oh_append_textbuffer(&working, "RESET | ");
1358
0 
		if (err) { return(err); }
1359
 
	}
1360
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_RESOURCE) {
1361
0 
		found++;
1362
0 
		err = oh_append_textbuffer(&working, "RESOURCE | ");
1363
0 
		if (err) { return(err); }
1364
 
	}
1365
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_SENSOR) {
1366
0 
		found++;
1367
0 
		err = oh_append_textbuffer(&working, "SENSOR | ");
1368
0 
		if (err) { return(err); }
1369
 
	}
1370
0 
        if (ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG) {
1371
0 
		found++;
1372
0 
		err = oh_append_textbuffer(&working, "WATCHDOG | ");
1373
0 
		if (err) { return(err); }
1374
 
	}
1375
 
1376
0 
	if (found) {
1377
0 
		for (i=0; i<OH_ENCODE_DELIMITER_LENGTH + 1; i++) {
1378
0 
			working.Data[working.DataLength - i] = 0x00;
1379
 
		}
1380
0 
		working.DataLength = working.DataLength - (i+1);
1381
 
	}
1382
 
				
1383
0 
 	oh_copy_textbuffer(buffer, &working);
1384
 
1385
0 
	return(SA_OK);
1386
 
}
1387
 
1388
 
/**
1389
 
 * oh_decode_hscapabilities:
1390
 
 * @HsCapabilities: enum value of type SaHpiHsCapabilitiesT.
1391
 
 * @buffer:  Location to store the string.
1392
 
 *
1393
 
 * Converts @HsCapabilities type into a string based on HPI definition. For example:
1394
 
 * @HsCapabilities = SAHPI_HS_CAPABILITY_AUTOEXTRACT_READ_ONLY | SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED
1395
 
 * returns a string "AUTOEXTRACT_READ_ONLY | INDICATOR_SUPPORTED".
1396
 
 * 
1397
 
 * Returns:
1398
 
 * SA_OK - Normal operation.
1399
 
 * SA_ERR_HPI_INVALID_PARAMS - @buffer is NULL
1400
 
 **/
1401
 
SaErrorT oh_decode_hscapabilities(SaHpiHsCapabilitiesT HsCapabilities,
1402
 
				  SaHpiTextBufferT *buffer)
1403
0 
{
1404
0 
	int found, i;
1405
0 
	SaErrorT err;
1406
0 
	SaHpiTextBufferT working;
1407
 
1408
0 
	if (!buffer) {
1409
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
1410
 
	}
1411
 
1412
0 
	err = oh_init_textbuffer(&working);
1413
0 
	if (err) { return(err); }
1414
 
1415
0 
	found = 0;
1416
0 
        if (HsCapabilities & SAHPI_HS_CAPABILITY_AUTOEXTRACT_READ_ONLY) {
1417
0 
		found++;
1418
0 
		err = oh_append_textbuffer(&working, "AUTOEXTRACT_READ_ONLY | ");
1419
0 
		if (err) { return(err); }
1420
 
	}
1421
0 
        if (HsCapabilities & SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED) {
1422
0 
		found++;
1423
0 
		err = oh_append_textbuffer(&working, "INDICATOR_SUPPORTED | ");
1424
0 
		if (err) { return(err); }
1425
 
	}
1426
 
1427
0 
	if (found) {
1428
0 
		for (i=0; i<OH_ENCODE_DELIMITER_LENGTH + 1; i++) {
1429
0 
			working.Data[working.DataLength - i] = 0x00;
1430
 
		}
1431
0 
		working.DataLength = working.DataLength - (i+1);
1432
 
	}
1433
 
	else {
1434
0 
		oh_append_textbuffer(&working, "None");
1435
 
	}
1436
 
				
1437
0 
 	oh_copy_textbuffer(buffer, &working);
1438
 
1439
0 
	return(SA_OK);
1440
 
}
1441
 
1442
 
/**
1443
 
 * oh_fprint_rptentry:
1444
 
 * @stream: File handle.
1445
 
 * @rptentry: Pointer to SaHpiRptEntryT to be printed.
1446
 
 * @offsets:  Number of offsets to start printing structure.
1447
 
 * 
1448
 
 * Prints the member data contained in SaHpiRptEntryT struct to a file.
1449
 
 * The MACRO oh_print_rptentry(), uses this function to print to STDOUT. 
1450
 
 *
1451
 
 * Returns:       
1452
 
 * SA_OK - Normal operation.
1453
 
 **/
1454
 
SaErrorT oh_fprint_rptentry(FILE *stream, const SaHpiRptEntryT *rptentry, int offsets)
1455
0 
{
1456
0 
	SaErrorT err = SA_OK;
1457
0 
	oh_big_textbuffer mybuf;
1458
0 
	SaHpiTextBufferT tmpbuffer; 
1459
0 
	char* str = tmpbuffer.Data;
1460
 
1461
0 
	if (!stream || !rptentry) return(SA_ERR_HPI_INVALID_PARAMS);
1462
 
	
1463
0 
	oh_init_bigtext(&mybuf);
1464
0 
	offsets++;
1465
 
	
1466
0 
	oh_append_offset(&mybuf, offsets);
1467
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EntryId: %d\n", rptentry->EntryId);
1468
0 
	oh_append_bigtext(&mybuf, str);
1469
 
1470
0 
	oh_append_offset(&mybuf, offsets);
1471
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ResourceId: %d\n", rptentry->ResourceId);
1472
0 
	oh_append_bigtext(&mybuf, str);
1473
 
1474
0 
	oh_append_offset(&mybuf, offsets);
1475
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Entity Path: ");
1476
0 
	oh_append_bigtext(&mybuf, str);
1477
0 
        entitypath2string(&rptentry->ResourceEntity, str, SAHPI_MAX_TEXT_BUFFER_LENGTH);
1478
0 
	oh_append_bigtext(&mybuf, str);
1479
0 
	oh_append_bigtext(&mybuf, "\n");
1480
 
1481
0 
	oh_append_offset(&mybuf, offsets);
1482
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Capabilities: \n");
1483
0 
	oh_append_bigtext(&mybuf, str);
1484
0 
	oh_append_offset(&mybuf, offsets + 1);
1485
0 
	oh_decode_capabilities(rptentry->ResourceCapabilities, &tmpbuffer);
1486
0 
	oh_append_bigtext(&mybuf, tmpbuffer.Data);
1487
0 
	oh_append_bigtext(&mybuf, "\n");	
1488
 
1489
0 
	oh_append_offset(&mybuf, offsets);
1490
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "HotSwap Capabilities: ");
1491
0 
	oh_append_bigtext(&mybuf, str);
1492
0 
	oh_decode_hscapabilities(rptentry->HotSwapCapabilities, &tmpbuffer);
1493
0 
	oh_append_bigtext(&mybuf, tmpbuffer.Data);
1494
0 
	oh_append_bigtext(&mybuf, "\n");
1495
 
1496
0 
	oh_append_offset(&mybuf, offsets);
1497
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ResourceFailed: %s\n",
1498
 
		 (rptentry->ResourceFailed == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1499
0 
	oh_append_bigtext(&mybuf, str);
1500
 
1501
0 
	oh_append_offset(&mybuf, offsets);
1502
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ResourceTag:\n");
1503
0 
	oh_append_bigtext(&mybuf, str);
1504
0 
	oh_build_textbuffer(&mybuf, &(rptentry->ResourceTag), offsets + 1);
1505
 
1506
0 
	err = oh_fprint_bigtext(stream, &mybuf); 					
1507
0 
	return(err);
1508
 
}
1509
 
1510
 
/**
1511
 
 * oh_fprint_rdr:
1512
 
 * @stream: File handle.
1513
 
 * @thisrdr: Pointer to SaHpiRdrT to be printed.
1514
 
 * @offsets: Number of offsets to start printing structure.
1515
 
 * 
1516
 
 * Prints the member data contained in SaHpiRdrT struct to a file.
1517
 
 * The MACRO oh_print_rdr(), uses this function to print to STDOUT. 
1518
 
 *
1519
 
 * Returns:
1520
 
 * SA_OK - Normal operation.
1521
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1522
 
 **/
1523
 
SaErrorT oh_fprint_rdr(FILE *stream, const SaHpiRdrT *thisrdr, int offsets)
1524
0 
{
1525
0 
	SaErrorT err;
1526
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1527
0 
	oh_big_textbuffer mybuf, mybuf1;
1528
 
1529
0 
	if (!stream || !thisrdr) return(SA_ERR_HPI_INVALID_PARAMS);
1530
 
					
1531
0 
	oh_init_bigtext(&mybuf);
1532
 
1533
0 
	oh_append_offset(&mybuf, offsets);
1534
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "RecordId: %d\n", thisrdr->RecordId);
1535
0 
	oh_append_bigtext(&mybuf, str);
1536
 
1537
0 
	oh_append_offset(&mybuf, offsets);
1538
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "RdrType: %s\n", oh_lookup_rdrtype(thisrdr->RdrType));
1539
0 
	oh_append_bigtext(&mybuf, str);
1540
 
1541
0 
	oh_append_offset(&mybuf, offsets);
1542
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Entity Path: ");
1543
0 
	oh_append_bigtext(&mybuf, str);
1544
0 
        entitypath2string(&thisrdr->Entity, str, SAHPI_MAX_TEXT_BUFFER_LENGTH);
1545
0 
	oh_append_bigtext(&mybuf, str);
1546
0 
	oh_append_bigtext(&mybuf, "\n");
1547
 
	
1548
0 
	oh_append_offset(&mybuf, offsets);
1549
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "IsFru: %s\n",
1550
 
		 (thisrdr->IsFru == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1551
0 
	oh_append_bigtext(&mybuf, str);
1552
 
1553
0 
	oh_init_bigtext(&mybuf1);
1554
0 
	switch(thisrdr->RdrType) 
1555
 
	{
1556
 
		case SAHPI_CTRL_RDR:
1557
0 
			err = oh_build_ctrlrec(&mybuf1,
1558
 
				(const SaHpiCtrlRecT*) &thisrdr->RdrTypeUnion.CtrlRec, offsets);
1559
0 
			break;
1560
 
		case SAHPI_SENSOR_RDR:
1561
0 
			err = oh_build_sensorrec(&mybuf1,
1562
 
				(const SaHpiSensorRecT*) &thisrdr->RdrTypeUnion.SensorRec, offsets);
1563
0 
			break;
1564
 
		case SAHPI_INVENTORY_RDR:
1565
0 
			err = oh_build_invrec(&mybuf1,
1566
 
				(const SaHpiInventoryRecT*) &thisrdr->RdrTypeUnion.InventoryRec, offsets);
1567
0 
			break;
1568
 
		case SAHPI_WATCHDOG_RDR:
1569
0 
			err = oh_build_wdogrec(&mybuf1,
1570
 
				(const SaHpiWatchdogRecT*) &thisrdr->RdrTypeUnion.WatchdogRec, offsets); 
1571
0 
			break;
1572
 
		case SAHPI_ANNUNCIATOR_RDR:
1573
0 
			err = oh_build_annrec(&mybuf1,
1574
 
				(const SaHpiAnnunciatorRecT*) &thisrdr->RdrTypeUnion.AnnunciatorRec, offsets);
1575
0 
			break;
1576
 
		case SAHPI_NO_RECORD:
1577
0 
			oh_append_offset(&mybuf1, offsets);
1578
0 
			oh_append_bigtext(&mybuf1,oh_lookup_rdrtype(thisrdr->RdrType));
1579
0 
			break;
1580
 
		default:
1581
0 
			oh_append_bigtext(&mybuf1,"Invalid/Unknown RDR Type\n");
1582
 
1583
 
	}
1584
 
1585
0 
	oh_append_bigtext(&mybuf, mybuf1.Data);
1586
 
1587
0 
	oh_append_offset(&mybuf, offsets);
1588
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "IdString:\n");
1589
0 
	oh_append_bigtext(&mybuf, str);
1590
0 
	oh_build_textbuffer(&mybuf, &(thisrdr->IdString), offsets + 1);
1591
 
1592
0 
	err = oh_fprint_bigtext(stream, &mybuf); 					
1593
0 
	return(err);
1594
 
}
1595
 
1596
 
/**
1597
 
 * oh_build_ctrlrec:
1598
 
 * @textbuff: Buffer into which to store flattened ctrl rec structure.
1599
 
 * @thisrdrunion: Pointer to SaHpiRdrTypeUnionT to be flattened.
1600
 
 * @offsets: Number of offsets to start printing structure.
1601
 
 * 
1602
 
 * Flatten member data contained in SaHpiCtrlRecT struct to a text buffer.
1603
 
 *
1604
 
 * Returns:
1605
 
 * SA_OK - Normal operation.
1606
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1607
 
 **/
1608
 
static SaErrorT oh_build_ctrlrec(oh_big_textbuffer *textbuf, const SaHpiCtrlRecT *ctrlrec, int offsets)
1609
0 
{
1610
0 
	SaErrorT err;
1611
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1612
0 
	oh_big_textbuffer mybuf;
1613
0 
	SaHpiTextBufferT  smallbuf;
1614
 
1615
0 
	if (!textbuf || !ctrlrec) return(SA_ERR_HPI_INVALID_PARAMS);
1616
 
1617
0 
	oh_init_bigtext(&mybuf);
1618
 
1619
0 
	oh_append_offset(&mybuf, offsets);
1620
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Control Number: %d\n", ctrlrec->Num);
1621
0 
	oh_append_bigtext(&mybuf, str);
1622
 
	
1623
0 
	oh_append_offset(&mybuf, offsets);
1624
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Control Output Type: %s\n",
1625
 
		 oh_lookup_ctrloutputtype(ctrlrec->OutputType));
1626
0 
	oh_append_bigtext(&mybuf, str);
1627
 
1628
0 
	oh_append_offset(&mybuf, offsets);
1629
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Control Type: %s\n",
1630
 
		 oh_lookup_ctrltype(ctrlrec->Type));
1631
0 
	oh_append_bigtext(&mybuf, str);
1632
0 
	oh_append_offset(&mybuf, offsets);
1633
 
1634
0 
	switch(ctrlrec->Type) {
1635
 
	case SAHPI_CTRL_TYPE_DIGITAL:
1636
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Digital Default: %s\n",
1637
 
			 oh_lookup_ctrlstatedigital(ctrlrec->TypeUnion.Digital.Default));
1638
0 
		oh_append_bigtext(&mybuf, str);
1639
0 
		break;
1640
 
	case SAHPI_CTRL_TYPE_DISCRETE:
1641
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Discrete Default: %d\n",
1642
 
			 ctrlrec->TypeUnion.Discrete.Default);
1643
0 
		oh_append_bigtext(&mybuf, str);
1644
0 
		break;
1645
 
	case SAHPI_CTRL_TYPE_ANALOG:
1646
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Analog Min: %d\n",
1647
 
			 ctrlrec->TypeUnion.Analog.Min);
1648
0 
		oh_append_bigtext(&mybuf, str);
1649
0 
		oh_append_offset(&mybuf, offsets);
1650
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Analog Max: %d\n",
1651
 
			 ctrlrec->TypeUnion.Analog.Max);
1652
0 
		oh_append_bigtext(&mybuf, str);
1653
0 
		oh_append_offset(&mybuf, offsets);
1654
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Analog Default: %d\n",
1655
 
			 ctrlrec->TypeUnion.Analog.Default);
1656
0 
		oh_append_bigtext(&mybuf, str);
1657
0 
		break;
1658
 
	case SAHPI_CTRL_TYPE_STREAM:
1659
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Stream Default:\n");
1660
0 
		oh_append_bigtext(&mybuf, str);
1661
0 
		oh_append_offset(&mybuf, offsets + 1);
1662
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Repeat: %s\n",
1663
 
			 (ctrlrec->TypeUnion.Stream.Default.Repeat == SAHPI_TRUE) ? "TRUE" : "FALSE");
1664
0 
		oh_append_bigtext(&mybuf, str);
1665
0 
		oh_append_offset(&mybuf, offsets + 1);
1666
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "StreamLength: %d\n",
1667
 
			 ctrlrec->TypeUnion.Stream.Default.StreamLength);
1668
0 
		oh_append_bigtext(&mybuf, str);
1669
0 
		oh_append_offset(&mybuf, offsets + 1);
1670
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Stream Default: %s\n",
1671
 
			 ctrlrec->TypeUnion.Stream.Default.Stream);
1672
0 
		oh_append_bigtext(&mybuf, str);
1673
0 
		break;
1674
 
	case SAHPI_CTRL_TYPE_TEXT:
1675
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Max Chars: %d\n",
1676
 
			 ctrlrec->TypeUnion.Text.MaxChars);
1677
0 
		oh_append_bigtext(&mybuf, str);
1678
0 
		oh_append_offset(&mybuf, offsets);
1679
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Max Lines: %d\n",
1680
 
			 ctrlrec->TypeUnion.Text.MaxLines);
1681
0 
		oh_append_bigtext(&mybuf, str);
1682
0 
		oh_append_offset(&mybuf, offsets);
1683
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Language: %s\n",
1684
 
			 oh_lookup_language(ctrlrec->TypeUnion.Text.Language));
1685
0 
		oh_append_bigtext(&mybuf, str);
1686
0 
		oh_append_offset(&mybuf, offsets);
1687
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Data Type: %s\n",
1688
 
			 oh_lookup_texttype(ctrlrec->TypeUnion.Text.DataType));
1689
0 
		oh_append_bigtext(&mybuf, str);
1690
0 
		oh_append_offset(&mybuf, offsets);
1691
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Default:\n");
1692
0 
		oh_append_bigtext(&mybuf, str);
1693
0 
		oh_append_offset(&mybuf, offsets + 1);
1694
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Line: %d\n",
1695
 
			 ctrlrec->TypeUnion.Text.Default.Line);
1696
0 
		oh_append_bigtext(&mybuf, str);
1697
0 
		oh_build_textbuffer(&mybuf, &(ctrlrec->TypeUnion.Text.Default.Text), offsets + 1);
1698
0 
		break;
1699
 
	case SAHPI_CTRL_TYPE_OEM:
1700
0 
		err = oh_decode_manufacturerid(ctrlrec->TypeUnion.Oem.MId, &smallbuf);
1701
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ManufacturerId: %s\n",
1702
 
			 smallbuf.Data);
1703
0 
		oh_append_bigtext(&mybuf, str);
1704
0 
		oh_append_offset(&mybuf, offsets);
1705
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ConfigData: %s\n",
1706
 
			 ctrlrec->TypeUnion.Oem.ConfigData);
1707
0 
		oh_append_bigtext(&mybuf, str);
1708
0 
		oh_append_offset(&mybuf, offsets);
1709
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Default:\n");
1710
0 
		oh_append_bigtext(&mybuf, str);
1711
0 
		oh_append_offset(&mybuf, offsets + 1);
1712
0 
		err = oh_decode_manufacturerid(ctrlrec->TypeUnion.Oem.Default.MId, &smallbuf);
1713
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ManufacturerId: %s\n",
1714
 
			 smallbuf.Data);
1715
0 
		oh_append_bigtext(&mybuf, str);
1716
0 
		oh_append_offset(&mybuf, offsets + 1);
1717
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "BodyLength: %d\n",
1718
 
			 ctrlrec->TypeUnion.Oem.Default.BodyLength);
1719
0 
		oh_append_bigtext(&mybuf, str);
1720
0 
		oh_append_offset(&mybuf, offsets + 1);
1721
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Body: %s\n",
1722
 
			 ctrlrec->TypeUnion.Oem.Default.Body);
1723
0 
		oh_append_bigtext(&mybuf, str);
1724
0 
		break;
1725
 
	default:
1726
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Invalid ControlType Detected\n");
1727
0 
		oh_append_bigtext(&mybuf, str);
1728
 
	}	
1729
 
1730
0 
	oh_append_offset(&mybuf, offsets);
1731
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "DefaultMode:\n");
1732
0 
	oh_append_bigtext(&mybuf, str);
1733
 
1734
0 
	oh_append_offset(&mybuf, offsets + 1);
1735
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Mode: %s\n", 
1736
 
		 oh_lookup_ctrlmode(ctrlrec->DefaultMode.Mode));
1737
0 
	oh_append_bigtext(&mybuf, str);
1738
 
1739
0 
	oh_append_offset(&mybuf, offsets + 1);
1740
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ReadOnly: %s\n", 
1741
 
			(ctrlrec->DefaultMode.ReadOnly == SAHPI_TRUE) ? "TRUE" : "FALSE");
1742
0 
	oh_append_bigtext(&mybuf, str);
1743
 
1744
0 
	oh_append_offset(&mybuf, offsets);
1745
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WriteOnly: %s\n", 
1746
 
			(ctrlrec->WriteOnly == SAHPI_TRUE) ? "TRUE" : "FALSE");
1747
0 
	oh_append_bigtext(&mybuf, str);
1748
 
1749
0 
	oh_append_offset(&mybuf, offsets);
1750
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OEM: %d\n", ctrlrec->Oem);
1751
0 
	oh_append_bigtext(&mybuf, str);
1752
 
1753
0 
	err = oh_copy_bigtext(textbuf, &mybuf);
1754
 
1755
0 
	return(err);
1756
 
}
1757
 
1758
 
/**
1759
 
 * oh_build_invrec:
1760
 
 * @textbuff: Buffer into which to store flattened ctrl rdr structure.
1761
 
 * @invrec: Pointer to SaHpiInventoryRecT to be flattened.
1762
 
 * @offsets: Number of offsets to start printing structure.
1763
 
 * 
1764
 
 * Flatten member data contained in SaHpiInventoryRecT struct to a text buffer.
1765
 
 *
1766
 
 * Returns:
1767
 
 * SA_OK - Normal operation.
1768
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1769
 
 **/
1770
 
static SaErrorT oh_build_invrec(oh_big_textbuffer *textbuff,const SaHpiInventoryRecT *invrec, int offsets)
1771
0 
{
1772
0 
	SaErrorT err;
1773
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1774
0 
	oh_big_textbuffer mybuf;
1775
 
1776
0 
	if (!textbuff || !invrec) return(SA_ERR_HPI_INVALID_PARAMS);
1777
 
1778
0 
	oh_init_bigtext(&mybuf);
1779
 
1780
0 
	oh_append_offset(&mybuf, offsets);
1781
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "IdrId: %d\n",invrec->IdrId);
1782
0 
	oh_append_bigtext(&mybuf, str);
1783
 
1784
0 
	oh_append_offset(&mybuf, offsets);
1785
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Persistent: %s\n",
1786
 
		 (invrec->Persistent == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1787
0 
	oh_append_bigtext(&mybuf, str);
1788
 
1789
0 
	oh_append_offset(&mybuf, offsets);
1790
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Oem: %d\n",invrec->Oem);
1791
0 
	oh_append_bigtext(&mybuf, str);
1792
 
1793
0 
	err = oh_copy_bigtext(textbuff, &mybuf);
1794
0 
	return(err);
1795
 
}
1796
 
1797
 
/**
1798
 
 * oh_build_wdogrec:
1799
 
 * @textbuff: Buffer into which to store flattened watchdog rec structure.
1800
 
 * @wdogrec: Pointer to SaHpiWatchdogRecT to be flattened.
1801
 
 * @offsets: Number of offsets to start printing structure.
1802
 
 * 
1803
 
 * Flatten member data contained in SaHpiWatchdogRecT struct to a text buffer.
1804
 
 *
1805
 
 * Returns:
1806
 
 * SA_OK - Normal operation.
1807
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1808
 
 **/
1809
 
static SaErrorT oh_build_wdogrec(oh_big_textbuffer *textbuff,const SaHpiWatchdogRecT *wdogrec, int offsets)
1810
0 
{
1811
 
1812
0 
	SaErrorT err;
1813
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1814
0 
	oh_big_textbuffer mybuf;
1815
 
1816
0 
	if (!textbuff || !wdogrec) return(SA_ERR_HPI_INVALID_PARAMS);
1817
 
1818
0 
	oh_init_bigtext(&mybuf);
1819
0 
	oh_append_offset(&mybuf, offsets);
1820
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WatchdogNum: %d\n",wdogrec->WatchdogNum);
1821
0 
	oh_append_bigtext(&mybuf, str);
1822
 
1823
0 
	oh_append_offset(&mybuf, offsets);
1824
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Oem: %d\n",wdogrec->Oem);
1825
0 
	oh_append_bigtext(&mybuf, str);
1826
 
1827
0 
	err = oh_copy_bigtext(textbuff, &mybuf);
1828
0 
	return(err);
1829
 
}
1830
 
1831
 
/**
1832
 
 * oh_build_annrec:
1833
 
 * @textbuff: Buffer into which to store flattened structure.
1834
 
 * @annrec: Pointer to SaHpiAnnunciatorRecT to be flattened.
1835
 
 * @offsets:  Number of offsets to start printing structure.
1836
 
 * 
1837
 
 * Flatten member data contained in SaHpiAnnunciatorRecT struct to a text buffer.
1838
 
 *
1839
 
 * Returns:
1840
 
 * SA_OK - Normal operation.
1841
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1842
 
 **/
1843
 
static SaErrorT oh_build_annrec(oh_big_textbuffer *textbuff,const SaHpiAnnunciatorRecT *annrec, int offsets)
1844
0 
{
1845
0 
	SaErrorT err;
1846
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1847
0 
	oh_big_textbuffer mybuf;
1848
 
1849
0 
	if (!textbuff || !annrec) return(SA_ERR_HPI_INVALID_PARAMS);
1850
 
1851
0 
	oh_init_bigtext(&mybuf);
1852
0 
	oh_append_offset(&mybuf, offsets);
1853
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "AnnunciatorNum: %d\n", annrec->AnnunciatorNum);
1854
0 
	oh_append_bigtext(&mybuf, str);
1855
 
1856
0 
	oh_append_offset(&mybuf, offsets);
1857
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "AnnunciatorType: %s\n",
1858
 
		 oh_lookup_annunciatortype(annrec->AnnunciatorType));
1859
0 
	oh_append_bigtext(&mybuf, str);
1860
 
1861
0 
	oh_append_offset(&mybuf, offsets);
1862
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ModeReadOnly: %s\n",
1863
 
		 (annrec->ModeReadOnly == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1864
0 
	oh_append_bigtext(&mybuf, str);
1865
 
1866
0 
	oh_append_offset(&mybuf, offsets);
1867
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "MaxCondition: %d\n", annrec->MaxConditions);
1868
0 
	oh_append_bigtext(&mybuf, str);
1869
 
1870
0 
	oh_append_offset(&mybuf, offsets);
1871
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Oem: %d\n", annrec->Oem);
1872
0 
	oh_append_bigtext(&mybuf, str);
1873
 
1874
0 
	err = oh_copy_bigtext(textbuff, &mybuf);
1875
0 
	return(err);
1876
 
}
1877
 
1878
 
/**
1879
 
 * oh_fprint_eventloginfo:
1880
 
 * @stream: File handle.
1881
 
 * @thiselinfo: Pointer to SaHpiEventLogInfoT to be printed.
1882
 
 * @offsets: Number of offsets to start printing structure.
1883
 
 * 
1884
 
 * Prints the member data contained in SaHpiEventLogInfoT struct to a file.
1885
 
 * The MACRO oh_print_evenloginfo(), uses this function to print to STDOUT. 
1886
 
 *
1887
 
 * Returns:
1888
 
 * SA_OK - Normal operation.
1889
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1890
 
 **/
1891
 
SaErrorT oh_fprint_eventloginfo(FILE *stream, const SaHpiEventLogInfoT *thiselinfo, int offsets)
1892
0 
{	
1893
0 
	SaErrorT err;
1894
0 
	oh_big_textbuffer mybuf;
1895
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1896
0 
	SaHpiTextBufferT  minibuf;
1897
 
1898
0 
	if (!stream || !thiselinfo) {
1899
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
1900
 
	}
1901
 
	
1902
0 
	oh_init_bigtext(&mybuf);
1903
 
1904
0 
	oh_append_offset(&mybuf, offsets);
1905
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Entries: %d\n", thiselinfo->Entries);
1906
0 
	oh_append_bigtext(&mybuf, str);
1907
 
1908
0 
	oh_append_offset(&mybuf, offsets);
1909
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Size: %d\n", thiselinfo->Size);
1910
0 
	oh_append_bigtext(&mybuf, str);
1911
 
1912
0 
	oh_append_offset(&mybuf, offsets);
1913
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "UserEventMaxSize: %d\n", thiselinfo->UserEventMaxSize);
1914
0 
	oh_append_bigtext(&mybuf, str);
1915
 
	
1916
0 
	oh_append_offset(&mybuf, offsets);
1917
0 
	err = oh_decode_time(thiselinfo->UpdateTimestamp, &minibuf);
1918
0 
	if (err) memcpy(minibuf.Data, "SAHPI_TIME_UNSPECIFIED", 
1919
 
			sizeof("SAHPI_TIME_UNSPECIFIED"));
1920
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "UpdateTimestamp: %s\n", minibuf.Data);
1921
0 
	oh_append_bigtext(&mybuf, str);	
1922
 
	
1923
0 
	oh_append_offset(&mybuf, offsets);
1924
0 
	err = oh_decode_time(thiselinfo->CurrentTime, &minibuf);
1925
0 
	if (err) memcpy(minibuf.Data, "SAHPI_TIME_UNSPECIFIED", 
1926
 
			sizeof("SAHPI_TIME_UNSPECIFIED"));
1927
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "CurrentTime: %s\n", minibuf.Data);
1928
0 
	oh_append_bigtext(&mybuf, str);	
1929
 
1930
0 
	oh_append_offset(&mybuf, offsets);
1931
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Enabled: %s\n",
1932
 
		 (thiselinfo->Enabled == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1933
0 
	oh_append_bigtext(&mybuf, str);
1934
 
1935
0 
	oh_append_offset(&mybuf, offsets);
1936
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OverflowFlag: %s\n",
1937
 
		 (thiselinfo->OverflowFlag == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1938
0 
	oh_append_bigtext(&mybuf, str);
1939
 
1940
0 
	oh_append_offset(&mybuf, offsets);
1941
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OverflowResetable: %s\n",
1942
 
		 (thiselinfo->OverflowResetable == SAHPI_TRUE) ? "TRUE" : "FALSE" );
1943
0 
	oh_append_bigtext(&mybuf, str);
1944
 
1945
0 
	oh_append_offset(&mybuf, offsets);
1946
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OverflowAction: %s\n",
1947
 
		 oh_lookup_eventlogoverflowaction(thiselinfo->OverflowAction));
1948
0 
	oh_append_bigtext(&mybuf, str);
1949
 
	
1950
0 
	err = oh_fprint_bigtext(stream, &mybuf);
1951
0 
	return(err);
1952
 
}
1953
 
1954
 
/**
1955
 
 * oh_fprint_eventlogentry:
1956
 
 * @stream: File handle.
1957
 
 * @thiseventlog: Pointer to SaHpiEventLogEntryT to be printed.
1958
 
 * @offsets: Number of offsets to start printing structure.
1959
 
 * 
1960
 
 * Prints the member data contained in SaHpiEventLogEntryT struct to a file.
1961
 
 * The MACRO oh_print_evenlogentry(), uses this function to print to STDOUT. 
1962
 
 *
1963
 
 * Returns:
1964
 
 * SA_OK - Normal operation.
1965
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
1966
 
 **/
1967
 
SaErrorT oh_fprint_eventlogentry(FILE *stream, const SaHpiEventLogEntryT *thiseventlog, int offsets)
1968
0 
{	
1969
0 
	SaErrorT err;
1970
0 
	oh_big_textbuffer mybuf, mybufX;
1971
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
1972
0 
	SaHpiTextBufferT  minibuf;
1973
 
1974
0 
	if (!stream || !thiseventlog) {
1975
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
1976
 
	}
1977
 
	
1978
0 
	oh_init_bigtext(&mybuf);
1979
 
1980
0 
	oh_append_offset(&mybuf, offsets);
1981
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EntryId: %d\n", thiseventlog->EntryId);
1982
0 
	oh_append_bigtext(&mybuf, str);
1983
0 
	oh_append_offset(&mybuf, offsets);
1984
0 
	err = oh_decode_time(thiseventlog->Timestamp, &minibuf);
1985
0 
	if (err)
1986
0 
		memcpy(minibuf.Data, "SAHPI_TIME_UNSPECIFIED", 
1987
 
					sizeof("SAHPI_TIME_UNSPECIFIED"));
1988
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Timestamp: %s\n", minibuf.Data);
1989
0 
	oh_append_bigtext(&mybuf, str);	
1990
 
	
1991
0 
	oh_init_bigtext(&mybufX);
1992
0 
	err = oh_build_event(&mybufX, &thiseventlog->Event, offsets);
1993
0 
	oh_append_bigtext(&mybuf, mybufX.Data);	
1994
 
	
1995
0 
	err = oh_fprint_bigtext(stream, &mybuf);
1996
0 
	return(err);
1997
 
}
1998
 
1999
 
/**
2000
 
 * oh_fprint_event:
2001
 
 * @stream: File handle.
2002
 
 * @event: Pointer to SaHpiEventT to be printed.
2003
 
 * @offsets: Number of offsets to start printing structure.
2004
 
 * 
2005
 
 * Prints the member data contained in SaHpiEventT struct to a file.
2006
 
 * The MACRO oh_print_event(), uses this function to print to STDOUT. 
2007
 
 *
2008
 
 * Returns:
2009
 
 * SA_OK - Normal operation.
2010
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2011
 
 **/
2012
 
SaErrorT oh_fprint_event(FILE *stream, const SaHpiEventT *event, int offsets) 
2013
0 
{
2014
0 
	SaErrorT err;
2015
0 
	oh_big_textbuffer buffer;
2016
 
	
2017
0 
	if (!stream || !event) {
2018
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2019
 
	}
2020
 
	
2021
0 
	oh_init_bigtext(&buffer);
2022
 
2023
0 
	err = oh_build_event(&buffer, event, offsets);
2024
0 
	if (err) { return(err); }
2025
 
2026
0 
	err = oh_fprint_bigtext(stream, &buffer);
2027
0 
	if (err) { return(err); }
2028
 
2029
0 
	return(SA_OK);
2030
 
}
2031
 
2032
 
/**
2033
 
 * oh_build_event:
2034
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2035
 
 * @event: Pointer to the event to be deciphered
2036
 
 * @offset: Number of offsets to start printing structure.
2037
 
 * 
2038
 
 * Builds SaHpiEventT data into a string buffer.
2039
 
 *  
2040
 
 * Returns:
2041
 
 * SA_OK - Normal operation.
2042
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2043
 
 **/
2044
 
static SaErrorT oh_build_event(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2045
0 
{
2046
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2047
0 
	SaErrorT err;
2048
0 
	SaHpiTextBufferT tmpbuffer;
2049
 
2050
0 
	memset( buffer->Data, 0, OH_MAX_TEXT_BUFFER_LENGTH );
2051
0 
	memset( tmpbuffer.Data, 0, sizeof( tmpbuffer.Data ) );
2052
 
	
2053
 
	/* Event Type */
2054
0 
	oh_append_offset(buffer, offsets);
2055
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Type: %s\n", 
2056
 
		 oh_lookup_eventtype(event->EventType));
2057
0 
	oh_append_bigtext(buffer, str);
2058
0 
	offsets++;
2059
 
	
2060
 
	/* Event Source */
2061
0 
	oh_append_offset(buffer, offsets);
2062
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Resource: %d\n", event->Source);
2063
0 
	oh_append_bigtext(buffer, str);
2064
 
2065
 
	/* Event Time */
2066
0 
	oh_append_offset(buffer, offsets);
2067
0 
	oh_decode_time(event->Timestamp, &tmpbuffer);
2068
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Timestamp: %s\n", tmpbuffer.Data);
2069
0 
	oh_append_bigtext(buffer, str);
2070
 
2071
 
	/* Event Severity */
2072
0 
	oh_append_offset(buffer, offsets);
2073
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Severity: %s\n",
2074
 
		 oh_lookup_severity(event->Severity));
2075
0 
	oh_append_bigtext(buffer, str);
2076
 
	
2077
0 
	switch (event->EventType) {
2078
 
	case SAHPI_ET_RESOURCE:
2079
0 
		err = oh_build_event_resource(buffer, event, offsets);
2080
0 
		break;
2081
 
	case SAHPI_ET_DOMAIN:
2082
0 
		err = oh_build_event_domain(buffer, event, offsets);
2083
0 
		break;
2084
 
	case SAHPI_ET_SENSOR:
2085
0 
		err = oh_build_event_sensor(buffer, event, offsets);
2086
0 
		break;
2087
 
	case SAHPI_ET_SENSOR_ENABLE_CHANGE:
2088
0 
		err = oh_build_event_sensor_enable_change(buffer, event, offsets);
2089
0 
		break;
2090
 
	case SAHPI_ET_HOTSWAP:
2091
0 
		err = oh_build_event_hotswap(buffer, event, offsets);
2092
0 
		break;
2093
 
	case SAHPI_ET_WATCHDOG:
2094
0 
		err = oh_build_event_watchdog(buffer, event, offsets);
2095
0 
		break;
2096
 
	case SAHPI_ET_HPI_SW:
2097
0 
		err = oh_build_event_hpi_sw(buffer, event, offsets);
2098
0 
		break;
2099
 
	case SAHPI_ET_OEM:
2100
0 
		err = oh_build_event_oem(buffer, event, offsets);
2101
0 
		break;
2102
 
	case SAHPI_ET_USER:
2103
0 
		err = oh_build_event_user(buffer, event, offsets);
2104
0 
		break;
2105
 
	default:
2106
0 
		dbg("Unrecognized Event Type=%d.", event->EventType);
2107
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2108
 
	}
2109
 
			
2110
0 
	if (err) { return(err); }
2111
0 
	return(SA_OK);
2112
 
}
2113
 
2114
 
/**
2115
 
 * oh_build_event_resource:
2116
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2117
 
 * @event: Pointer to the event to be deciphered
2118
 
 * @offset: Number of offsets to start printing structure.
2119
 
 * 
2120
 
 * Builds ResourceEventTypeT data into string buffer.
2121
 
 *
2122
 
 * Returns:
2123
 
 * SA_OK - Normal operation.
2124
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2125
 
 **/
2126
 
static SaErrorT oh_build_event_resource(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2127
0 
{
2128
 
2129
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2130
 
2131
0 
	if (!buffer || !event)
2132
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2133
 
2134
0 
	oh_append_offset(buffer, offsets);
2135
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ResourceEventType: %s\n", 
2136
 
		 	oh_lookup_resourceeventtype(event->EventDataUnion.ResourceEvent.ResourceEventType));
2137
0 
	oh_append_bigtext(buffer, str);
2138
 
2139
0 
	return(SA_OK);
2140
 
}
2141
 
2142
 
/**
2143
 
 * oh_build_event_domain:
2144
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2145
 
 * @event: Pointer to the event to be deciphered
2146
 
 * @offset: Number of offsets to start printing structure.
2147
 
 * 
2148
 
 * Build event domain value structure values into string buffer.
2149
 
 *
2150
 
 * Returns:
2151
 
 * SA_OK - Normal operation.
2152
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2153
 
 **/
2154
 
static SaErrorT oh_build_event_domain(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2155
0 
{
2156
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2157
 
2158
0 
	if (!buffer || !event)
2159
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2160
 
2161
0 
	oh_append_offset(buffer, offsets);
2162
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "DomainEvent:\n"); 
2163
0 
	oh_append_bigtext(buffer, str);
2164
 
2165
0 
	oh_append_offset(buffer, offsets + 1);
2166
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Type: %s\n", 
2167
 
		 oh_lookup_domaineventtype(event->EventDataUnion.DomainEvent.Type));
2168
0 
	oh_append_bigtext(buffer, str);
2169
 
2170
0 
	oh_append_offset(buffer, offsets + 1);
2171
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "DomainId: %d\n", 
2172
 
		 event->EventDataUnion.DomainEvent.DomainId);
2173
0 
	oh_append_bigtext(buffer, str);
2174
 
2175
0 
	return(SA_OK);
2176
 
}
2177
 
2178
 
#define OH_MAX_SENSOROPTIONALDATA 6
2179
 
2180
 
typedef struct {
2181
 
    SaHpiSensorOptionalDataT datadef;
2182
 
    unsigned char *str;
2183
 
} oh_sensor_opt_data_map;
2184
 
2185
 
oh_sensor_opt_data_map sensor_event_optdata_strings[] = {
2186
 
{SAHPI_SOD_TRIGGER_READING, "TRIGGER_READING"},
2187
 
{SAHPI_SOD_TRIGGER_THRESHOLD, "TRIGGER_THRESHOLD"},
2188
 
{SAHPI_SOD_OEM, "OEM"},
2189
 
{SAHPI_SOD_PREVIOUS_STATE, "PREVIOUS_STATE"},
2190
 
{SAHPI_SOD_CURRENT_STATE, "CURRENT_STATE"},
2191
 
{SAHPI_SOD_SENSOR_SPECIFIC, "SENSOR_SPECIFIC"},
2192
 
};
2193
 
2194
 
/**
2195
 
 * oh_encode_sensoroptionaldata:
2196
 
 * @buffer: Pointer to space to decipher SaHpiSensorOptionalDataT struct
2197
 
 * @sensor_opt_data: Sensor's optional data bit mask.
2198
 
 * 
2199
 
 * Converts a sensor's optional data bit mask field into a string. For example,
2200
 
 * if the optional data bit mask is SAHPI_SOD_TRIGGER_READING | SAHPI_SOD_CURRENT_STATE,
2201
 
 * this routine returns the string "TRIGGER_READING | CURRENT_STATE" in a
2202
 
 * SaHpiTextBufferT structure.
2203
 
 *
2204
 
 * Returns:
2205
 
 * SA_OK - Normal operation.
2206
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2207
 
 **/
2208
 
SaErrorT oh_decode_sensoroptionaldata(SaHpiSensorOptionalDataT sensor_opt_data,
2209
 
				      SaHpiTextBufferT *buffer)
2210
0 
{
2211
0 
	int i, found;
2212
0 
	SaErrorT err;
2213
0 
	SaHpiTextBufferT working;
2214
 
2215
0 
	if (!buffer) return(SA_ERR_HPI_INVALID_PARAMS);
2216
 
2217
0 
	err = oh_init_textbuffer(&working);
2218
0 
	if (err) { return(err); }
2219
 
2220
0 
	found = 0;
2221
 
	/* Look for sensor optional data definitions */
2222
0 
	for (i=0; i<OH_MAX_SENSOROPTIONALDATA; i++) {
2223
0 
		if (sensor_event_optdata_strings[i].datadef & sensor_opt_data) {
2224
0 
			found++;
2225
0 
			err = oh_append_textbuffer(&working, sensor_event_optdata_strings[i].str);
2226
0 
			if (err) { return(err); }
2227
0 
			err = oh_append_textbuffer(&working, OH_ENCODE_DELIMITER);
2228
0 
			if (err) { return(err); }
2229
 
		}
2230
 
	}
2231
 
2232
 
	/* Remove last delimiter */
2233
0 
	if (found) {
2234
0 
		for (i=0; i<OH_ENCODE_DELIMITER_LENGTH + 1; i++) {
2235
0 
			working.Data[working.DataLength - i] = 0x00;
2236
 
		}
2237
0 
		working.DataLength = working.DataLength - (i+1);
2238
 
	}
2239
 
	else {
2240
0 
		err = oh_append_textbuffer(&working, "None");
2241
0 
		if (err) { return(err); }
2242
 
	}
2243
 
2244
0 
	err = oh_copy_textbuffer(buffer, &working);
2245
 
2246
0 
	return(SA_OK);
2247
 
}
2248
 
2249
 
#define OH_MAX_SENSORENABLEOPTDATA 1
2250
 
2251
 
typedef struct {
2252
 
    SaHpiSensorEnableOptDataT datadef;
2253
 
    unsigned char *str;
2254
 
} oh_sensor_enable_opt_data_map;
2255
 
2256
 
oh_sensor_enable_opt_data_map sensor_enable_optdata_strings[] = {
2257
 
{SAHPI_SEOD_CURRENT_STATE, "CURRENT_STATE"},
2258
 
};
2259
 
2260
 
/**
2261
 
 * oh_encode_sensorenableoptdata:
2262
 
 * @buffer: Pointer to space to decipher SaHpiSensorEnableOptDataT struct
2263
 
 * @sensor_opt_data: Sensor Enable Event's optional data bit mask.
2264
 
 * 
2265
 
 * Converts a sensor's enable event's optional data bit mask field into a string. For example,
2266
 
 * if the optional data bit mask is SAHPI_SEOD_CURRENT_STATE
2267
 
 * this routine returns the string "CURRENT_STATE" in a
2268
 
 * SaHpiTextBufferT structure.
2269
 
 *
2270
 
 * Returns:
2271
 
 * SA_OK - Normal operation.
2272
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2273
 
 **/
2274
 
SaErrorT oh_decode_sensorenableoptdata(SaHpiSensorEnableOptDataT sensor_enable_opt_data,
2275
 
				       SaHpiTextBufferT *buffer)
2276
0 
{
2277
0 
	int i, found;
2278
0 
	SaErrorT err;
2279
0 
	SaHpiTextBufferT working;
2280
 
2281
0 
	if (!buffer) return(SA_ERR_HPI_INVALID_PARAMS);
2282
 
2283
0 
	err = oh_init_textbuffer(&working);
2284
0 
	if (err) { return(err); }
2285
 
2286
0 
	found = 0;
2287
 
	/* Look for sensor optional data definitions */
2288
0 
	for (i=0; i<OH_MAX_SENSORENABLEOPTDATA; i++) {
2289
0 
		if (sensor_enable_optdata_strings[i].datadef & sensor_enable_opt_data) {
2290
0 
			found++;
2291
0 
			err = oh_append_textbuffer(&working, sensor_enable_optdata_strings[i].str);
2292
0 
			if (err) { return(err); }
2293
0 
			err = oh_append_textbuffer(&working, OH_ENCODE_DELIMITER);
2294
0 
			if (err) { return(err); }
2295
 
		}
2296
 
	}
2297
 
2298
 
	/* Remove last delimiter */
2299
0 
	if (found) {
2300
0 
		for (i=0; i<OH_ENCODE_DELIMITER_LENGTH + 1; i++) {
2301
0 
			working.Data[working.DataLength - i] = 0x00;
2302
 
		}
2303
0 
		working.DataLength = working.DataLength - (i+1);
2304
 
	}
2305
 
	else {
2306
0 
		err = oh_append_textbuffer(&working, "None");
2307
0 
		if (err) { return(err); }
2308
 
	}
2309
 
2310
0 
	err = oh_copy_textbuffer(buffer, &working);
2311
 
2312
0 
	return(SA_OK);
2313
 
}
2314
 
2315
 
/**
2316
 
 * oh_build_event_resource:
2317
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2318
 
 * @event: Pointer to the event to be deciphered
2319
 
 * @offset: Number of offsets to start printing structure.
2320
 
 * 
2321
 
 * Converts a sensor event structure into a string.
2322
 
 * String is stored in an oh_big_textbuffer data structure.
2323
 
 *
2324
 
 * Returns:
2325
 
 * SA_OK - Normal operation.
2326
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2327
 
 **/
2328
 
static SaErrorT oh_build_event_sensor(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2329
0 
{
2330
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2331
0 
	SaErrorT err;
2332
0 
	SaHpiTextBufferT tmpbuffer;
2333
 
2334
0 
	if ( !buffer || !event)
2335
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2336
 
2337
 
	/* Event Sensor Num */
2338
0 
	oh_append_offset(buffer, offsets);
2339
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Sensor Num: %d\n", 
2340
 
		 event->EventDataUnion.SensorEvent.SensorNum);
2341
0 
	oh_append_bigtext(buffer, str);
2342
 
2343
 
	/* Event Sensor Type */
2344
0 
	oh_append_offset(buffer, offsets);
2345
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Sensor Type: %s\n",
2346
 
		 oh_lookup_sensortype(event->EventDataUnion.SensorEvent.SensorType));
2347
0 
	oh_append_bigtext(buffer, str);
2348
 
2349
 
	/* Event Sensor Category */
2350
0 
	oh_append_offset(buffer, offsets);
2351
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Sensor Category: %s\n", 
2352
 
		 oh_lookup_eventcategory(event->EventDataUnion.SensorEvent.EventCategory));
2353
0 
	oh_append_bigtext(buffer, str);
2354
 
2355
 
	/* Event Sensor Assertion */
2356
0 
	oh_append_offset(buffer, offsets);
2357
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Event Sensor Assertion: %s\n",
2358
 
		(event->EventDataUnion.SensorEvent.Assertion == SAHPI_TRUE) ? "TRUE" : "FALSE");
2359
0 
	oh_append_bigtext(buffer, str);
2360
 
2361
 
	/* Event Sensor State */
2362
0 
	oh_append_offset(buffer, offsets);
2363
0 
	oh_append_bigtext(buffer, "Event Sensor State: ");
2364
0 
	err = oh_decode_eventstate(event->EventDataUnion.SensorEvent.EventState,
2365
 
				   event->EventDataUnion.SensorEvent.EventCategory,
2366
 
				   &tmpbuffer);
2367
0 
	if (err) { return(err); }
2368
0 
	oh_append_bigtext(buffer, tmpbuffer.Data);
2369
0 
	oh_append_bigtext(buffer, "\n");
2370
 
2371
 
	/* Sensor Event - Sensor Optional Data */
2372
0 
	oh_append_offset(buffer, offsets);
2373
0 
	oh_append_bigtext(buffer, "Optional Data: ");
2374
 
2375
0 
	err = oh_decode_sensoroptionaldata(event->EventDataUnion.SensorEvent.OptionalDataPresent,
2376
 
					   &tmpbuffer);
2377
0 
	if (err) { return(err); }
2378
0 
	oh_append_bigtext(buffer, tmpbuffer.Data);
2379
0 
	oh_append_bigtext(buffer, "\n");
2380
 
2381
 
        /* Sensor Event - Sensor Optional Trigger Reading Data */
2382
0 
	if (event->EventDataUnion.SensorEvent.OptionalDataPresent & SAHPI_SOD_TRIGGER_READING) {
2383
0 
		SaHpiSensorDataFormatT format;
2384
 
		
2385
0 
		memset(&format, 0, sizeof(SaHpiSensorDataFormatT));
2386
0 
		oh_append_offset(buffer, offsets + 1);
2387
0 
		oh_append_bigtext(buffer, "Trigger Reading: ");
2388
 
		
2389
0 
		format.IsSupported = SAHPI_TRUE;
2390
0 
		format.ReadingType = event->EventDataUnion.SensorEvent.TriggerReading.Type;
2391
0 
		format.BaseUnits = SAHPI_SU_UNSPECIFIED;
2392
 
2393
0 
		err = oh_decode_sensorreading(event->EventDataUnion.SensorEvent.TriggerReading,
2394
 
					      format, &tmpbuffer);
2395
0 
		if (err) { return(err); }
2396
 
2397
0 
		oh_append_bigtext(buffer, tmpbuffer.Data);
2398
0 
		oh_append_bigtext(buffer, "\n");
2399
 
	}
2400
 
2401
 
        /* Sensor Event - Sensor Optional Trigger Threshold Data */
2402
0 
	if (event->EventDataUnion.SensorEvent.OptionalDataPresent & SAHPI_SOD_TRIGGER_THRESHOLD) {
2403
0 
		SaHpiSensorDataFormatT format;
2404
 
		
2405
0 
		memset(&format, 0, sizeof(SaHpiSensorDataFormatT));
2406
0 
		oh_append_offset(buffer, offsets + 1);
2407
0 
		oh_append_bigtext(buffer, "Trigger Threshold: ");
2408
 
		
2409
0 
		format.IsSupported = SAHPI_TRUE;
2410
0 
		format.ReadingType = event->EventDataUnion.SensorEvent.TriggerThreshold.Type;
2411
0 
		format.BaseUnits = SAHPI_SU_UNSPECIFIED;
2412
 
2413
0 
		err = oh_decode_sensorreading(event->EventDataUnion.SensorEvent.TriggerThreshold,
2414
 
					      format, &tmpbuffer);
2415
0 
		if (err) { return(err); }
2416
 
2417
0 
		oh_append_bigtext(buffer, tmpbuffer.Data);
2418
0 
		oh_append_bigtext(buffer, "\n");
2419
 
	}
2420
 
2421
 
        /* Sensor Event - Sensor Optional Previous State Data */
2422
0 
	if (event->EventDataUnion.SensorEvent.OptionalDataPresent & SAHPI_SOD_PREVIOUS_STATE) {
2423
0 
		oh_append_offset(buffer, offsets + 1);
2424
0 
		oh_append_bigtext(buffer, "Previous Sensor State: ");
2425
0 
		err = oh_decode_eventstate(event->EventDataUnion.SensorEvent.PreviousState,
2426
 
					   event->EventDataUnion.SensorEvent.EventCategory,
2427
 
					   &tmpbuffer);
2428
0 
		if (err) { return(err); }
2429
0 
		oh_append_bigtext(buffer, tmpbuffer.Data);
2430
0 
		oh_append_bigtext(buffer, "\n");
2431
 
	}
2432
 
2433
 
        /* Sensor Event - Sensor Optional Current State Data */
2434
0 
	if (event->EventDataUnion.SensorEvent.OptionalDataPresent & SAHPI_SOD_CURRENT_STATE) {
2435
0 
		oh_append_offset(buffer, offsets + 1);
2436
0 
		oh_append_bigtext(buffer, "Current Sensor State: ");
2437
0 
		err = oh_decode_eventstate(event->EventDataUnion.SensorEvent.CurrentState,
2438
 
					   event->EventDataUnion.SensorEvent.EventCategory,
2439
 
					   &tmpbuffer);
2440
0 
		if (err) { return(err); }
2441
0 
		oh_append_bigtext(buffer, tmpbuffer.Data);
2442
0 
		oh_append_bigtext(buffer, "\n");
2443
 
	}
2444
 
        /* Sensor Event - Sensor Optional OEM Data */
2445
0 
	if (event->EventDataUnion.SensorEvent.OptionalDataPresent & SAHPI_SOD_OEM) {
2446
0 
		oh_append_offset(buffer, offsets + 1);
2447
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OEM: %x\n", 
2448
 
			 event->EventDataUnion.SensorEvent.Oem);
2449
0 
		oh_append_bigtext(buffer, str);
2450
 
	}
2451
 
2452
 
        /* Sensor Event - Sensor Optional Sensor Specific Data */
2453
0 
	if (event->EventDataUnion.SensorEvent.OptionalDataPresent & SAHPI_SOD_SENSOR_SPECIFIC) {
2454
0 
		oh_append_offset(buffer, offsets + 1);
2455
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Sensor Specific: %x\n",
2456
 
			 event->EventDataUnion.SensorEvent.SensorSpecific );
2457
0 
		oh_append_bigtext(buffer, str);
2458
 
	}
2459
 
2460
0 
	return(SA_OK);
2461
 
}
2462
 
2463
 
/**
2464
 
 * oh_build_event_sensor_enable_change:
2465
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2466
 
 * @event: Pointer to the event to be deciphered
2467
 
 * @offset: Number of offsets to start printing structure.
2468
 
 * 
2469
 
 * Build SaHpiSensorEnableChangeEventT data into a string buffer. 
2470
 
 *
2471
 
 * Returns:
2472
 
 * SA_OK - Normal operation.
2473
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2474
 
 **/
2475
 
static SaErrorT oh_build_event_sensor_enable_change(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2476
0 
{
2477
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2478
0 
	SaErrorT err;
2479
0 
	SaHpiTextBufferT tmpbuffer;	
2480
 
2481
0 
	if ( !buffer || !event)
2482
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2483
 
2484
0 
	oh_append_offset(buffer, offsets);
2485
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "SensorEnableChangeEvent: \n"); 
2486
0 
	oh_append_bigtext(buffer, str);
2487
 
2488
 
	/* Sensor Enable Change Event - Sensor Number */
2489
0 
	oh_append_offset(buffer, offsets + 1);
2490
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "SensorNum: %d\n", 
2491
 
		 	event->EventDataUnion.SensorEnableChangeEvent.SensorNum);
2492
0 
	oh_append_bigtext(buffer, str);
2493
 
2494
 
	/* Sensor Enable Change Event - Sensor Type */
2495
0 
	oh_append_offset(buffer, offsets + 1);
2496
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "SensorType: %s\n", 
2497
 
		 	oh_lookup_sensortype(event->EventDataUnion.SensorEnableChangeEvent.SensorType));
2498
0 
	oh_append_bigtext(buffer, str);
2499
 
2500
 
	/* Sensor Enable Change Event - Sensor Category */
2501
0 
	oh_append_offset(buffer, offsets + 1);
2502
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EventCategory: %s\n",
2503
 
		 	oh_lookup_eventcategory(event->EventDataUnion.SensorEnableChangeEvent.EventCategory));
2504
0 
	oh_append_bigtext(buffer, str);
2505
 
	
2506
 
	/* Sensor Enable Change Event - Sensor Enabled */
2507
0 
	oh_append_offset(buffer, offsets + 1);
2508
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "SensorEnable: %s\n",
2509
 
		(event->EventDataUnion.SensorEnableChangeEvent.SensorEnable == SAHPI_TRUE) ? "TRUE" : "FALSE");
2510
0 
	oh_append_bigtext(buffer, str);
2511
 
	
2512
 
	/* Sensor Enable Change Event - Sensor Events Enabled */
2513
0 
	oh_append_offset(buffer, offsets + 1);
2514
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "SensorEventEnable: %s\n",
2515
 
		(event->EventDataUnion.SensorEnableChangeEvent.SensorEventEnable == SAHPI_TRUE) ? "TRUE" : "FALSE");
2516
0 
	oh_append_bigtext(buffer, str);
2517
 
2518
 
	/* Sensor Enable Change Event - Event Assert Mask */
2519
0 
	oh_append_offset(buffer, offsets + 1);
2520
0 
	oh_append_bigtext(buffer, "AssertEventMask: ");
2521
0 
	err = oh_decode_eventstate(event->EventDataUnion.SensorEnableChangeEvent.AssertEventMask,
2522
 
				   event->EventDataUnion.SensorEnableChangeEvent.EventCategory,
2523
 
				   &tmpbuffer);
2524
0 
	if (err) { return(err); }
2525
0 
	oh_append_bigtext(buffer, tmpbuffer.Data);
2526
0 
	oh_append_bigtext(buffer, "\n");
2527
 
2528
 
	/* Sensor Enable Change Event - Event Deassert Mask */
2529
0 
	oh_append_offset(buffer, offsets + 1);
2530
0 
	oh_append_bigtext(buffer, "DeassertEventMask: ");
2531
0 
	err = oh_decode_eventstate(event->EventDataUnion.SensorEnableChangeEvent.DeassertEventMask,
2532
 
				   event->EventDataUnion.SensorEnableChangeEvent.EventCategory,
2533
 
				   &tmpbuffer);
2534
0 
	if (err) { return(err); }
2535
0 
	oh_append_bigtext(buffer, tmpbuffer.Data);
2536
0 
	oh_append_bigtext(buffer, "\n");
2537
 
2538
 
	/* Sensor Enable Change Event - Optional Data */
2539
0 
	oh_append_offset(buffer, offsets + 1);
2540
0 
	oh_append_bigtext(buffer, "Optional Data: ");
2541
0 
	err = oh_decode_sensorenableoptdata(event->EventDataUnion.SensorEnableChangeEvent.OptionalDataPresent,
2542
 
					    &tmpbuffer);
2543
0 
	if (err) { return(err); }
2544
0 
	oh_append_bigtext(buffer, tmpbuffer.Data);
2545
0 
	oh_append_bigtext(buffer, "\n");
2546
 
2547
 
	/* Sensor Enable Change Event - Optional Data - Current State */
2548
0 
	if (event->EventDataUnion.SensorEnableChangeEvent.OptionalDataPresent & SAHPI_SEOD_CURRENT_STATE) {
2549
0 
		oh_append_offset(buffer, offsets + 2);
2550
0 
		oh_append_bigtext(buffer, "Current State: ");
2551
0 
		err = oh_decode_eventstate(event->EventDataUnion.SensorEnableChangeEvent.CurrentState,
2552
 
					   event->EventDataUnion.SensorEnableChangeEvent.EventCategory,
2553
 
					   &tmpbuffer);
2554
0 
		if (err) { return(err); }
2555
0 
		oh_append_bigtext(buffer, tmpbuffer.Data);
2556
0 
		oh_append_bigtext(buffer, "\n");
2557
 
	}
2558
 
2559
0 
	return(SA_OK);
2560
 
}
2561
 
2562
 
/**
2563
 
 * oh_build_event_hotswap:
2564
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2565
 
 * @event: Pointer to the event to be deciphered
2566
 
 * @offset: Number of offsets to start printing structure.
2567
 
 * 
2568
 
 * Builds SaHpiHotSwapEventT data into a string buffer.
2569
 
 * 
2570
 
 * Returns:
2571
 
 * SA_OK - Normal operation.
2572
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2573
 
 **/
2574
 
static SaErrorT oh_build_event_hotswap(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2575
0 
{
2576
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2577
 
2578
0 
	if ( !buffer || !event)
2579
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2580
 
2581
0 
	oh_append_offset(buffer, offsets);
2582
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "HotswapEvent: \n"); 
2583
0 
	oh_append_bigtext(buffer, str);
2584
 
2585
0 
	oh_append_offset(buffer, offsets + 1);
2586
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "HotSwapState: %s\n", 
2587
 
		 	oh_lookup_hsstate(event->EventDataUnion.HotSwapEvent.HotSwapState));
2588
0 
	oh_append_bigtext(buffer, str);
2589
 
2590
0 
	oh_append_offset(buffer, offsets + 1);
2591
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "PreviousHotSwapState: %s\n", 
2592
 
		 	oh_lookup_hsstate(event->EventDataUnion.HotSwapEvent.PreviousHotSwapState));
2593
0 
	oh_append_bigtext(buffer, str);
2594
 
2595
0 
	return(SA_OK);
2596
 
}
2597
 
2598
 
/**
2599
 
 * oh_build_event_watchdog:
2600
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2601
 
 * @event: Pointer to the event to be deciphered
2602
 
 * @offset: Number of offsets to start printing structure.
2603
 
 * 
2604
 
 * Builds SaHpiWatchdogEventT data into a string buffer.
2605
 
 *
2606
 
 * Returns:
2607
 
 * SA_OK - Normal operation.
2608
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2609
 
 **/
2610
 
static SaErrorT oh_build_event_watchdog(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2611
0 
{
2612
 
2613
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2614
0 
	int i;
2615
0 
	SaHpiBoolT matchFound = SAHPI_FALSE;
2616
 
	
2617
 
2618
0 
	if ( !buffer || !event)
2619
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2620
 
	
2621
0 
	oh_append_offset(buffer, offsets);
2622
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WatchdogEvent: \n"); 
2623
0 
	oh_append_bigtext(buffer, str);
2624
 
2625
0 
	oh_append_offset(buffer, offsets + 1);
2626
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WatchdogNum: %d\n",
2627
 
					event->EventDataUnion.WatchdogEvent.WatchdogNum); 
2628
0 
	oh_append_bigtext(buffer, str);
2629
 
2630
0 
	oh_append_offset(buffer, offsets + 1);
2631
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WatchdogNum: %s\n",
2632
 
			oh_lookup_watchdogactionevent(event->EventDataUnion.WatchdogEvent.WatchdogAction)); 
2633
0 
	oh_append_bigtext(buffer, str);
2634
 
2635
0 
	oh_append_offset(buffer, offsets + 1);
2636
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WatchdogPreTimerAction: %s\n",
2637
 
			oh_lookup_watchdogpretimerinterrupt(event->EventDataUnion.WatchdogEvent.WatchdogPreTimerAction)); 
2638
0 
	oh_append_bigtext(buffer, str);
2639
 
2640
0 
	oh_append_offset(buffer, offsets + 1);
2641
0 
	for (i = 0; i < OH_MAX_WATCHDOGTIMERUSE; i++) {
2642
0 
		if (event->EventDataUnion.WatchdogEvent.WatchdogUse == 
2643
 
		    watchdogtimeruse_strings[i].entity_type) {
2644
0 
			matchFound = SAHPI_TRUE;
2645
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WatchdogUse: %s\n",
2646
 
				 watchdogtimeruse_strings[i].str);
2647
0 
			break;
2648
 
		}
2649
 
	}
2650
 
	
2651
0 
	if (!matchFound)  
2652
0 
		snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "WatchdogUse: %s\n",
2653
 
			  "Invalid data");
2654
0 
	oh_append_bigtext(buffer, str);
2655
 
	
2656
0 
	return(SA_OK);
2657
 
}
2658
 
2659
 
/**
2660
 
 * oh_build_event_hpi_sw:
2661
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2662
 
 * @event: Pointer to the event to be deciphered
2663
 
 * @offset: Number of offsets to start printing structure.
2664
 
 *
2665
 
 * Builds SaHpiHpiSwEventT data into a string buffer. 
2666
 
 *
2667
 
 * Returns:
2668
 
 * SA_OK - Normal operation.
2669
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2670
 
 **/
2671
 
static SaErrorT oh_build_event_hpi_sw(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2672
0 
{
2673
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2674
0 
	SaHpiTextBufferT tmpbuffer;
2675
0 
	SaErrorT err;
2676
 
2677
0 
	if ( !buffer || !event)
2678
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2679
 
	
2680
0 
	oh_append_offset(buffer, offsets);
2681
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "HpiSwEvent: \n"); 
2682
0 
	oh_append_bigtext(buffer, str);
2683
0 
	offsets++;
2684
 
2685
0 
	oh_append_offset(buffer, offsets);
2686
0 
	err = oh_decode_manufacturerid(event->EventDataUnion.HpiSwEvent.MId, &tmpbuffer);
2687
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ManufacturerId: %s\n", tmpbuffer.Data);
2688
0 
	oh_append_bigtext(buffer, str);
2689
 
2690
0 
	oh_append_offset(buffer, offsets);
2691
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EventData: \n"); 
2692
0 
	oh_append_bigtext(buffer, str);
2693
0 
	offsets++;
2694
 
	
2695
0 
	oh_build_textbuffer(buffer, &event->EventDataUnion.HpiSwEvent.EventData, offsets);
2696
0 
	return(SA_OK);
2697
 
}
2698
 
2699
 
/**
2700
 
 * oh_build_event_oem:
2701
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2702
 
 * @event: Pointer to the event to be deciphered
2703
 
 * @offset: Number of offsets to start printing structure.
2704
 
 * 
2705
 
 * Builds SaHpiOemEventT data into a string buffer.
2706
 
 *
2707
 
 * Returns:
2708
 
 * SA_OK - Normal operation.
2709
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2710
 
 **/
2711
 
static SaErrorT oh_build_event_oem(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2712
0 
{
2713
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2714
0 
	SaErrorT err;
2715
0 
	SaHpiTextBufferT tmpbuffer;
2716
 
2717
0 
	if ( !buffer || !event)
2718
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2719
 
	
2720
0 
	oh_append_offset(buffer, offsets);
2721
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OemEvent:\n"); 
2722
0 
	oh_append_bigtext(buffer, str);
2723
0 
	offsets++;
2724
 
2725
0 
	oh_append_offset(buffer, offsets);
2726
0 
	err = oh_decode_manufacturerid(event->EventDataUnion.OemEvent.MId, &tmpbuffer);
2727
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ManufacturerId: %s\n", tmpbuffer.Data);
2728
0 
	oh_append_bigtext(buffer, str);
2729
 
2730
0 
	oh_append_offset(buffer, offsets);
2731
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OemEventData:\n"); 
2732
0 
	oh_append_bigtext(buffer, str);
2733
0 
	offsets++;
2734
 
2735
0 
	oh_build_textbuffer(buffer, &event->EventDataUnion.OemEvent.OemEventData, offsets);
2736
 
2737
0 
	return(SA_OK);
2738
 
}
2739
 
2740
 
/**
2741
 
 * oh_build_event_user:
2742
 
 * @buffer: Pointer to space to decipher SaHpiEventT struct
2743
 
 * @event: Pointer to the event to be deciphered
2744
 
 * @offset: Number of offsets to start printing structure.
2745
 
 * 
2746
 
 *
2747
 
 * Returns:
2748
 
 * SA_OK - Normal operation.
2749
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2750
 
 **/
2751
 
static SaErrorT oh_build_event_user(oh_big_textbuffer *buffer, const SaHpiEventT *event, int offsets)
2752
0 
{
2753
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2754
 
2755
0 
	if ( !buffer || !event)
2756
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2757
 
	
2758
 
/*
2759
 
 *	oh_append_offset(buffer, offsets);
2760
 
 *	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "UserEvent:\n"); 
2761
 
 *	oh_append_bigtext(buffer, str);
2762
 
 * 	offsets++
2763
 
 */
2764
0 
	oh_append_offset(buffer, offsets);
2765
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "UserEventData:\n"); 
2766
0 
	oh_append_bigtext(buffer, str);
2767
0 
	offsets++;
2768
 
2769
0 
	oh_build_textbuffer(buffer, &event->EventDataUnion.UserEvent.UserEventData, offsets);
2770
0 
	return(SA_OK);
2771
 
}
2772
 
2773
 
/**
2774
 
 * oh_fprint_ctrlstate:
2775
 
 * @stream: File handle.
2776
 
 * @event: Pointer to SaHpitrlStateT to be printed.
2777
 
 * @offsets: Number of offsets to start printing structure.
2778
 
 * 
2779
 
 * Prints the member data contained in SaHpiCtrlStateT struct to a file.
2780
 
 * The MACRO oh_print_ctrlstate(), uses this function to print to STDOUT. 
2781
 
 *
2782
 
 * Returns:
2783
 
 * SA_OK - Normal operation.
2784
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
2785
 
 **/
2786
 
SaErrorT oh_fprint_ctrlstate(FILE *stream, const SaHpiCtrlStateT *thisctrlstate, int offsets)
2787
0 
{
2788
 
2789
0 
	SaErrorT rv = SA_OK;
2790
0 
	oh_big_textbuffer buffer;
2791
0 
	SaHpiTextBufferT smallbuf;
2792
0 
	char str[SAHPI_MAX_TEXT_BUFFER_LENGTH];
2793
 
	
2794
0 
	if (!stream || !thisctrlstate) {
2795
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
2796
 
	}
2797
 
	
2798
0 
	oh_init_bigtext(&buffer);
2799
0 
	oh_append_offset(&buffer, offsets);
2800
0 
	snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Type: %s\n",
2801
 
				oh_lookup_ctrltype(thisctrlstate->Type));
2802
0 
	oh_append_bigtext(&buffer, str);
2803
0 
	oh_append_offset(&buffer, offsets);
2804
 
	
2805
0 
	switch(thisctrlstate->Type) {
2806
 
		case SAHPI_CTRL_TYPE_DIGITAL:
2807
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "State: %s\n",
2808
 
				oh_lookup_ctrlstatedigital(thisctrlstate->StateUnion.Digital));
2809
0 
			break;
2810
 
		case SAHPI_CTRL_TYPE_DISCRETE:
2811
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "State: %d\n",
2812
 
							thisctrlstate->StateUnion.Discrete);
2813
0 
			break;
2814
 
		case SAHPI_CTRL_TYPE_ANALOG:
2815
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Analog: %d\n",
2816
 
							thisctrlstate->StateUnion.Analog);
2817
0 
			break;
2818
 
		case SAHPI_CTRL_TYPE_STREAM:
2819
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Stream:\n");
2820
0 
			oh_append_bigtext(&buffer, str);
2821
0 
			oh_append_offset(&buffer, offsets + 1);
2822
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Repeat: %s\n",
2823
 
				(thisctrlstate->StateUnion.Stream.Repeat == SAHPI_TRUE) ? "TRUE" : "FALSE");
2824
0 
			oh_append_bigtext(&buffer, str);
2825
0 
			oh_append_offset(&buffer, offsets + 1);
2826
0 
			snprintf(str, thisctrlstate->StateUnion.Stream.StreamLength, "%s\n",
2827
 
				 			thisctrlstate->StateUnion.Stream.Stream);
2828
 
					
2829
0 
			break;
2830
 
		case SAHPI_CTRL_TYPE_TEXT:
2831
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Line: %d\n", 
2832
 
						thisctrlstate->StateUnion.Text.Line);
2833
0 
			oh_append_bigtext(&buffer, str);
2834
0 
			oh_append_offset(&buffer, offsets);
2835
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "%s\n", 
2836
 
						thisctrlstate->StateUnion.Text.Text.Data);		
2837
0 
			break;
2838
 
		case SAHPI_CTRL_TYPE_OEM:
2839
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Oem:\n");
2840
0 
			oh_append_bigtext(&buffer, str);
2841
0 
			oh_append_offset(&buffer, offsets + 1);
2842
0 
			rv = oh_decode_manufacturerid(thisctrlstate->StateUnion.Oem.MId, &smallbuf);
2843
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "ManufacturerId: %s\n",
2844
 
										 smallbuf.Data);
2845
0 
			oh_append_bigtext(&buffer, str);
2846
0 
			oh_append_offset(&buffer, offsets + 1);
2847
0 
			snprintf(str, thisctrlstate->StateUnion.Oem.BodyLength, "%s\n",
2848
 
							thisctrlstate->StateUnion.Oem.Body);
2849
 
			
2850
0 
			break;
2851
 
		default:
2852
0 
			snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Invalid Control Type\n");
2853
0 
			rv = SA_ERR_HPI_INVALID_DATA;
2854
0 
			break;
2855
 
	} 
2856
0 
	oh_append_bigtext(&buffer, str);
2857
0 
	rv = oh_fprint_bigtext(stream, &buffer);
2858
0 
	return(rv);
2859
 
}
2860
 
2861
 
/**
2862
 
 * oh_valid_textbuffer:
2863
 
 * @buffer: Pointer to a SaHpiTextBufferT structure.
2864
 
 * 
2865
 
 * Verifies @buffer is a valid SaHpiTextBufferT structure.
2866
 
 * Used in routines where the user can set SaHpiTextBufferT values.
2867
 
 *
2868
 
 * Returns:
2869
 
 * SAHPI_TRUE - if @buffer is valid.
2870
 
 * SAHPI_FALSE - if @buffer not valid.
2871
 
 **/
2872
 
SaHpiBoolT oh_valid_textbuffer(SaHpiTextBufferT *buffer)
2873
18 
{
2874
18 
	int i;
2875
18 
        if (!buffer) return SAHPI_FALSE;
2876
18 
	if (oh_lookup_texttype(buffer->DataType) == NULL) return SAHPI_FALSE;
2877
 
	/* Compiler checks DataLength <= SAHPI_MAX_TEXT_BUFFER_LENGTH */
2878
 
2879
15 
	switch (buffer->DataType) {
2880
 
	case SAHPI_TL_TYPE_UNICODE:                
2881
0 
		if (oh_lookup_language(buffer->Language) == NULL) return SAHPI_FALSE;
2882
0 
		if (buffer->DataLength % 2 != 0) return SAHPI_FALSE;
2883
 
                /* FIXME: Need to find a way to validate UTF-16 strings.
2884
 
                 * Using http://www.campusprogram.com/reference/en/wikipedia/u/ut/utf_16.html
2885
 
                 * as reference. -- RM 09/29/04
2886
 
                 */                
2887
0 
		break;
2888
 
	case SAHPI_TL_TYPE_BCDPLUS:                
2889
 
                /* 8-bit ASCII, '0'-'9', space, dash, period, colon, comma, or
2890
 
		   underscore. Always encoded in HPI as 8-bit values */
2891
0 
                for (i = 0;
2892
 
                     i < SAHPI_MAX_TEXT_BUFFER_LENGTH || buffer->Data[i] != '\0';
2893
 
                     i++)
2894
 
                {
2895
0 
                        if ((buffer->Data[i] < 0x30 || buffer->Data[i] > 0x39) &&
2896
 
                             buffer->Data[i] != 0x20 && buffer->Data[i] != 0x2d &&
2897
 
                             buffer->Data[i] != 0x2e && buffer->Data[i] != 0x3a &&
2898
 
                             buffer->Data[i] != 0x2c && buffer->Data[i] != 0x5f)
2899
0 
                                return SAHPI_FALSE;
2900
 
                }
2901
2 
		break;
2902
 
	case SAHPI_TL_TYPE_ASCII6:		                
2903
 
                /* reduced set, 0x20-0x5f only. Always encoded in HPI as 8-bit values */
2904
4 
                for (i = 0;
2905
 
                     i < SAHPI_MAX_TEXT_BUFFER_LENGTH || buffer->Data[i] != '\0';
2906
 
                     i++)
2907
 
                {
2908
4 
                        if (buffer->Data[i] < 0x20 || buffer->Data[i] > 0x5f)
2909
2 
                                return SAHPI_FALSE;
2910
 
                }
2911
13 
		break;
2912
 
	case SAHPI_TL_TYPE_TEXT:
2913
13 
		if (oh_lookup_language(buffer->Language) == NULL) { return(SAHPI_FALSE); }
2914
 
                /* all character values are good 0x00 - 0xff */		
2915
0 
		break;
2916
 
	case SAHPI_TL_TYPE_BINARY: /* No check possible */
2917
0 
		break;
2918
 
	default:
2919
0 
		dbg("Invalid data type");
2920
0 
		return(SAHPI_FALSE);
2921
 
	}
2922
 
2923
10 
	return(SAHPI_TRUE);
2924
 
}
2925
 
2926
 
#define validate_threshold(thdname, thdmask) \
2927
 
do { \
2928
 
if (thds->thdname.IsSupported) { \
2929
 
	if (!(writable_thds & thdmask)) return(SA_ERR_HPI_INVALID_CMD); \
2930
 
	if (format->ReadingType != thds->thdname.Type) return(SA_ERR_HPI_INVALID_CMD); \
2931
 
	switch (format->ReadingType) { \
2932
 
	case SAHPI_SENSOR_READING_TYPE_INT64: \
2933
 
		if (format->Range.Flags & SAHPI_SRF_MAX) { \
2934
 
			if (thds->thdname.Value.SensorInt64 > format->Range.Max.Value.SensorInt64) \
2935
 
                                return(SA_ERR_HPI_INVALID_CMD); \
2936
 
		} \
2937
 
		if (format->Range.Flags & SAHPI_SRF_MIN) { \
2938
 
			if (thds->thdname.Value.SensorInt64 < format->Range.Min.Value.SensorInt64) \
2939
 
				return(SA_ERR_HPI_INVALID_CMD); \
2940
 
		} \
2941
 
		if (thds->PosThdHysteresis.IsSupported) { \
2942
 
			if (thds->PosThdHysteresis.Value.SensorInt64 < 0) return(SA_ERR_HPI_INVALID_DATA); \
2943
 
		} \
2944
 
		if (thds->NegThdHysteresis.IsSupported) { \
2945
 
			if (thds->NegThdHysteresis.Value.SensorInt64 < 0) return(SA_ERR_HPI_INVALID_DATA); \
2946
 
		} \
2947
 
		break; \
2948
 
	case SAHPI_SENSOR_READING_TYPE_FLOAT64: \
2949
 
		if (format->Range.Flags & SAHPI_SRF_MAX) { \
2950
 
			if (thds->thdname.Value.SensorFloat64 > format->Range.Max.Value.SensorFloat64) \
2951
 
				return(SA_ERR_HPI_INVALID_CMD); \
2952
 
		} \
2953
 
		if (format->Range.Flags & SAHPI_SRF_MIN) { \
2954
 
			if (thds->thdname.Value.SensorFloat64 < format->Range.Min.Value.SensorFloat64) \
2955
 
				return(SA_ERR_HPI_INVALID_CMD); \
2956
 
		} \
2957
 
		if (thds->PosThdHysteresis.IsSupported) { \
2958
 
			if (thds->PosThdHysteresis.Value.SensorFloat64 < 0) return(SA_ERR_HPI_INVALID_DATA); \
2959
 
		} \
2960
 
		if (thds->NegThdHysteresis.IsSupported) { \
2961
 
			if (thds->NegThdHysteresis.Value.SensorFloat64 < 0) return(SA_ERR_HPI_INVALID_DATA); \
2962
 
		} \
2963
 
		break; \
2964
 
	case SAHPI_SENSOR_READING_TYPE_UINT64: \
2965
 
		if (format->Range.Flags & SAHPI_SRF_MAX) { \
2966
 
			if (thds->thdname.Value.SensorUint64 > format->Range.Max.Value.SensorUint64) \
2967
 
				return(SA_ERR_HPI_INVALID_CMD); \
2968
 
		} \
2969
 
		if (format->Range.Flags & SAHPI_SRF_MIN) { \
2970
 
			if (thds->thdname.Value.SensorUint64 < format->Range.Min.Value.SensorUint64) \
2971
 
				return(SA_ERR_HPI_INVALID_CMD); \
2972
 
		} \
2973
 
		break; \
2974
 
	case SAHPI_SENSOR_READING_TYPE_BUFFER: \
2975
 
	default: \
2976
 
		dbg("Invalid threshold reading type."); \
2977
 
		return(SA_ERR_HPI_INVALID_CMD); \
2978
 
	} \
2979
 
} \
2980
 
} while(0)
2981
 
2982
 
#define validate_threshold_order(thdtype) \
2983
 
do { \
2984
 
if (thds->UpCritical.IsSupported == SAHPI_TRUE) { \
2985
 
	if (thds->UpMajor.IsSupported == SAHPI_TRUE) { \
2986
 
		if (thds->UpCritical.Value.thdtype < thds->UpMajor.Value.thdtype) \
2987
 
                        return(SA_ERR_HPI_INVALID_DATA); \
2988
 
	} \
2989
 
	if (thds->UpMinor.IsSupported == SAHPI_TRUE) { \
2990
 
		if (thds->UpCritical.Value.thdtype < thds->UpMinor.Value.thdtype) \
2991
 
                        return(SA_ERR_HPI_INVALID_DATA); \
2992
 
	} \
2993
 
	if (thds->LowMinor.IsSupported == SAHPI_TRUE) { \
2994
 
		if (thds->UpCritical.Value.thdtype < thds->LowMinor.Value.thdtype) \
2995
 
			return(SA_ERR_HPI_INVALID_DATA); \
2996
 
	} \
2997
 
	if (thds->LowMajor.IsSupported == SAHPI_TRUE) { \
2998
 
		if (thds->UpCritical.Value.thdtype < thds->LowMajor.Value.thdtype) \
2999
 
			return(SA_ERR_HPI_INVALID_DATA); \
3000
 
	} \
3001
 
	if (thds->LowCritical.IsSupported == SAHPI_TRUE) { \
3002
 
		if (thds->UpCritical.Value.thdtype < thds->LowCritical.Value.thdtype) \
3003
 
			return(SA_ERR_HPI_INVALID_DATA); \
3004
 
	} \
3005
 
} \
3006
 
if (thds->UpMajor.IsSupported == SAHPI_TRUE) { \
3007
 
	if (thds->UpMinor.IsSupported == SAHPI_TRUE) { \
3008
 
		if (thds->UpMajor.Value.thdtype < thds->UpMinor.Value.thdtype) \
3009
 
                               return(SA_ERR_HPI_INVALID_DATA); \
3010
 
	} \
3011
 
	if (thds->LowMinor.IsSupported == SAHPI_TRUE) { \
3012
 
		if (thds->UpMajor.Value.thdtype < thds->LowMinor.Value.thdtype) \
3013
 
			return(SA_ERR_HPI_INVALID_DATA); \
3014
 
	} \
3015
 
	if (thds->LowMajor.IsSupported == SAHPI_TRUE) { \
3016
 
		if (thds->UpMajor.Value.thdtype < thds->LowMajor.Value.thdtype) \
3017
 
			return(SA_ERR_HPI_INVALID_DATA); \
3018
 
	} \
3019
 
	if (thds->LowCritical.IsSupported == SAHPI_TRUE) { \
3020
 
		if (thds->UpMajor.Value.thdtype < thds->LowCritical.Value.thdtype) \
3021
 
			return(SA_ERR_HPI_INVALID_DATA); \
3022
 
	} \
3023
 
} \
3024
 
if (thds->UpMinor.IsSupported == SAHPI_TRUE) { \
3025
 
	if (thds->LowMinor.IsSupported == SAHPI_TRUE) { \
3026
 
		if (thds->UpMinor.Value.thdtype < thds->LowMinor.Value.thdtype) \
3027
 
			return(SA_ERR_HPI_INVALID_DATA); \
3028
 
	} \
3029
 
	if (thds->LowMajor.IsSupported == SAHPI_TRUE) { \
3030
 
		if (thds->UpMinor.Value.thdtype < thds->LowMajor.Value.thdtype) \
3031
 
			return(SA_ERR_HPI_INVALID_DATA); \
3032
 
	} \
3033
 
	if (thds->LowCritical.IsSupported == SAHPI_TRUE) { \
3034
 
		if (thds->UpMinor.Value.thdtype < thds->LowCritical.Value.thdtype) \
3035
 
			return(SA_ERR_HPI_INVALID_DATA); \
3036
 
	} \
3037
 
} \
3038
 
if (thds->LowMinor.IsSupported == SAHPI_TRUE) { \
3039
 
	if (thds->LowMajor.IsSupported == SAHPI_TRUE) { \
3040
 
		if (thds->LowMinor.Value.thdtype < thds->LowMajor.Value.thdtype) \
3041
 
			return(SA_ERR_HPI_INVALID_DATA); \
3042
 
	} \
3043
 
	if (thds->LowCritical.IsSupported == SAHPI_TRUE) { \
3044
 
		if (thds->LowMinor.Value.thdtype < thds->LowCritical.Value.thdtype) \
3045
 
			return(SA_ERR_HPI_INVALID_DATA); \
3046
 
	} \
3047
 
} \
3048
 
if (thds->LowMajor.IsSupported == SAHPI_TRUE) { \
3049
 
	if (thds->LowCritical.IsSupported == SAHPI_TRUE) { \
3050
 
		if (thds->LowMajor.Value.thdtype < thds->LowCritical.Value.thdtype) \
3051
 
			return(SA_ERR_HPI_INVALID_DATA); \
3052
 
	} \
3053
 
} \
3054
 
} while(0)
3055
 
 
3056
 
/**
3057
 
 * oh_valid_thresholds:
3058
 
 * @thds: Location of threshold definitions to verify.
3059
 
 * @format: Location of sensor's data format structure.
3060
 
 * @writable_thds: List of sensor's writeable thresholds.
3061
 
 *
3062
 
 * Validates that the threshold values defined in @thds are valid for a sensor with
3063
 
 * a data format described in @format. Callers to this routine still need to
3064
 
 * verify that the sensor has a category of SAHPI_EC_THRESHOLD and has writable thresholds
3065
 
 * (ThresholdDefn.IsAccessible and ThresholdDefn.WriteThold non-zero). 
3066
 
 *
3067
 
 * In addition, the caller may need to read the sensor's existing sensors first, since
3068
 
 * @thds may only contain a subset of the possible writable thresholds.
3069
 
 *
3070
 
 * Return values:
3071
 
 * SA_OK - normal case.
3072
 
 * SA_ERR_HPI_INVALID_CMD - Non-writable thresholds, invalid thresholds values, or invalid data type.
3073
 
 * SA_ERR_HPI_INVALID_DATA - Threshold values out of order; negative hysteresis.
3074
 
 * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL.
3075
 
 **/
3076
 
SaErrorT oh_valid_thresholds(SaHpiSensorThresholdsT *thds,
3077
 
			     SaHpiSensorDataFormatT *format,
3078
 
			     SaHpiSensorThdMaskT writable_thds)
3079
0 
{
3080
0 
	if (!thds || !format) {
3081
0 
		dbg("Invalid parameter.");
3082
0 
		return(SA_ERR_HPI_INVALID_PARAMS);
3083
 
	}
3084
 
3085
0 
	validate_threshold(LowCritical, SAHPI_STM_LOW_CRIT);
3086
0 
	validate_threshold(LowMajor, SAHPI_STM_LOW_MAJOR);
3087
0 
	validate_threshold(LowMinor, SAHPI_STM_LOW_MINOR);
3088
0 
	validate_threshold(UpCritical, SAHPI_STM_UP_CRIT);
3089
0 
	validate_threshold(UpMajor, SAHPI_STM_UP_MAJOR);
3090
0 
	validate_threshold(UpMinor, SAHPI_STM_UP_MINOR);
3091
0 
	validate_threshold(PosThdHysteresis, SAHPI_STM_UP_HYSTERESIS);
3092
0 
	validate_threshold(NegThdHysteresis, SAHPI_STM_LOW_HYSTERESIS);
3093
 
3094
 
        /* Validate defined thresholds are in order:
3095
 
	 * upper critical >= upper major >= upper minor >= 
3096
 
	 * lower minor >= lower major >= lower critical
3097
 
	 */
3098
0 
	switch (format->ReadingType) {
3099
 
	case SAHPI_SENSOR_READING_TYPE_INT64:
3100
0 
		validate_threshold_order(SensorInt64);
3101
0 
		break;
3102
 
	case SAHPI_SENSOR_READING_TYPE_FLOAT64:
3103
0 
		validate_threshold_order(SensorFloat64);
3104
0 
		break;
3105
 
	case SAHPI_SENSOR_READING_TYPE_UINT64:
3106
0 
		validate_threshold_order(SensorUint64);
3107
0 
		break;
3108
 
	case SAHPI_SENSOR_READING_TYPE_BUFFER:
3109
 
	default:
3110
0 
		dbg("Invalid threshold reading type.");
3111
0 
		return(SA_ERR_HPI_INVALID_CMD);
3112
 
	}
3113
 
3114
0 
	return(SA_OK);
3115
 
}
3116
 
3117
 
/**
3118
 
 * oh_compare_sensorreading:
3119
 
 * @type: Type of both sensor readings.
3120
 
 * @reading1: Pointer to sensor reading.
3121
 
 * @reading1: Pointer to sensor reading.
3122
 
 *
3123
 
 * Compares the Value field of two sensor readings. Sensor readings must be of the
3124
 
 * same Type.
3125
 
 *
3126
 
 * Return values:
3127
 
 * -1 - @reading1 < @reading2
3128
 
 *  0 - @reading1 = @reading2
3129
 
 * +1 - @reading1 > @reading2
3130
 
 **/
3131
 
int oh_compare_sensorreading(SaHpiSensorReadingTypeT type,
3132
 
			     SaHpiSensorReadingT *reading1,
3133
 
			     SaHpiSensorReadingT *reading2)
3134
0 
{
3135
0 
	switch(type) {
3136
 
	case SAHPI_SENSOR_READING_TYPE_INT64:
3137
0 
		if (reading1->Value.SensorInt64 < reading2->Value.SensorInt64) { return -1; }
3138
 
		else {
3139
0 
			if (reading1->Value.SensorInt64 == reading2->Value.SensorInt64) { return 0; }
3140
0 
			else { return 1; }
3141
 
		}
3142
0 
		break;
3143
 
	case SAHPI_SENSOR_READING_TYPE_UINT64:
3144
0 
		if (reading1->Value.SensorUint64 < reading2->Value.SensorUint64) { return -1; }
3145
 
		else {
3146
0 
			if (reading1->Value.SensorUint64 == reading2->Value.SensorUint64) { return 0; }
3147
0 
			else { return 1; }
3148
 
		}
3149
0 
		break;
3150
 
	case SAHPI_SENSOR_READING_TYPE_FLOAT64:
3151
0 
		if (reading1->Value.SensorFloat64 < reading2->Value.SensorFloat64) { return -1; }
3152
 
		else {
3153
0 
			if (reading1->Value.SensorFloat64 == reading2->Value.SensorFloat64) { return 0; }
3154
0 
			else { return 1; }
3155
 
		}
3156
0 
		break;
3157
 
	case SAHPI_SENSOR_READING_TYPE_BUFFER:
3158
0 
		return(memcmp(reading1->Value.SensorBuffer, reading2->Value.SensorBuffer,
3159
 
			      sizeof(SAHPI_SENSOR_BUFFER_LENGTH)));
3160
 
		break;
3161
 
	default:
3162
0 
		dbg("Invalid sensor reading type.");
3163
0 
		return 0;
3164
 
	}
3165
 
}
3166
 
3167
 
/**
3168
 
 * oh_valid_ctrl_state_mode:
3169
 
 * @ctrl_rdr: Pointer to control's RDR information.
3170
 
 * @mode: Control's mode.
3171
 
 * @state: Pointer to contol's state.
3172
 
 *
3173
 
 * Verifies that the @mode and @state data are compatible with a control's RDR information.
3174
 
 * This routine performs all the static checks defined in the HPI spec but the call must
3175
 
 * perform the following checks:
3176
 
 *   - Verify control's resource has SAHPI_CAPABILITY_CONTROL set.
3177
 
 *   - Check to see if control is on, if SAHPI_STATE_PULSE_ON is supported and set;
3178
 
 *     Check to see if control is off, if SAHPI_STATE_PULSE_OFF is supported and set.
3179
 
 *     Caller needs to return SA_ERR_HPI_INVALID_REQUEST in either of these cases.
3180
 
 *
3181
 
 * As specified in the HPI spec, if @mode = SAHPI_CTRL_MODE_AUTO, this routine 
3182
 
 * ignores @state.
3183
 
 *
3184
 
 * Return values:
3185
 
 * SA_OK - Normal operation.
3186
 
 * SA_ERR_HPI_INVALID_PARAMS - See HPI spec.
3187
 
 * SA_ERR_HPI_INVALID_DATA - See HPI spec.
3188
 
 **/
3189
 
SaErrorT oh_valid_ctrl_state_mode(SaHpiCtrlRecT *ctrl_rdr,
3190
 
				  SaHpiCtrlModeT mode,
3191
 
				  SaHpiCtrlStateT *state)
3192
0 
{
3193
 
	/* Check for valid mode operations */
3194
0 
	if (NULL == oh_lookup_ctrlmode(mode)) return(SA_ERR_HPI_INVALID_PARAMS);
3195
0 
	if (ctrl_rdr->DefaultMode.ReadOnly == SAHPI_TRUE) {
3196
0 
		if (mode != ctrl_rdr->DefaultMode.Mode) return(SA_ERR_HPI_READ_ONLY);
3197
 
	}
3198
0 
	if (mode != SAHPI_CTRL_MODE_AUTO && !state) return(SA_ERR_HPI_INVALID_PARAMS);
3199
 
3200
 
	/* Check for valid state operations */
3201
0 
	if (mode != SAHPI_CTRL_MODE_AUTO && state) {
3202
0 
		if (ctrl_rdr->Type != state->Type) return(SA_ERR_HPI_INVALID_DATA);
3203
0 
		if (NULL == oh_lookup_ctrltype(state->Type)) return(SA_ERR_HPI_INVALID_DATA);
3204
 
3205
0 
		switch(state->Type) {
3206
 
		case SAHPI_CTRL_TYPE_DIGITAL:
3207
0 
			if (NULL == oh_lookup_ctrlstatedigital(state->StateUnion.Digital))
3208
0 
				return(SA_ERR_HPI_INVALID_PARAMS);
3209
0 
			break;
3210
 
		case SAHPI_CTRL_TYPE_DISCRETE:
3211
 
			/* No HPI spec error check - leave to caller, if needed */
3212
0 
			break;
3213
 
		case SAHPI_CTRL_TYPE_ANALOG:
3214
0 
			if (state->StateUnion.Analog < ctrl_rdr->TypeUnion.Analog.Min)
3215
0 
				return(SA_ERR_HPI_INVALID_DATA);
3216
0 
			if (state->StateUnion.Analog > ctrl_rdr->TypeUnion.Analog.Max)
3217
0 
				return(SA_ERR_HPI_INVALID_DATA);
3218
0 
			break;
3219
 
		case SAHPI_CTRL_TYPE_STREAM:
3220
0 
			if (state->StateUnion.Stream.StreamLength > SAHPI_CTRL_MAX_STREAM_LENGTH)
3221
0 
				return(SA_ERR_HPI_INVALID_PARAMS);
3222
0 
			break;
3223
 
		case SAHPI_CTRL_TYPE_TEXT:
3224
0 
			if (state->StateUnion.Text.Text.DataType != 
3225
 
			    ctrl_rdr->TypeUnion.Text.DataType)
3226
0 
				return(SA_ERR_HPI_INVALID_DATA);
3227
0 
			if (state->StateUnion.Text.Text.DataType == SAHPI_TL_TYPE_UNICODE ||
3228
 
			    state->StateUnion.Text.Text.DataType == SAHPI_TL_TYPE_TEXT) {
3229
0 
				if (state->StateUnion.Text.Text.Language != 
3230
 
				    ctrl_rdr->TypeUnion.Text.Language)
3231
0 
					return(SA_ERR_HPI_INVALID_DATA);
3232
 
			}
3233
0 
			if (!oh_valid_textbuffer(&(state->StateUnion.Text.Text)))
3234
0 
				return (SA_ERR_HPI_INVALID_PARAMS);
3235
 
			{ 	/* Check for text buffer overflow */
3236
0 
				int char_num;
3237
 
3238
0 
				if (state->StateUnion.Text.Line >
3239
 
				    ctrl_rdr->TypeUnion.Text.MaxLines)
3240
0 
					return(SA_ERR_HPI_INVALID_DATA);
3241
 
				
3242
0 
				if (state->StateUnion.Text.Text.DataType == SAHPI_TL_TYPE_UNICODE) {
3243
0 
					char_num = state->StateUnion.Text.Text.DataLength/2;
3244
 
				}
3245
 
				else {
3246
0 
					char_num = state->StateUnion.Text.Text.DataLength;
3247
 
				}
3248
 
3249
0 
				if (char_num) {
3250
0 
					int max_chars;	
3251
 
					
3252
0 
					if (state->StateUnion.Text.Line == SAHPI_TLN_ALL_LINES) {
3253
0 
						max_chars =
3254
 
							ctrl_rdr->TypeUnion.Text.MaxLines *
3255
 
							ctrl_rdr->TypeUnion.Text.MaxChars;
3256
 
					}
3257
 
					else {
3258
0 
						max_chars = 
3259
 
							(ctrl_rdr->TypeUnion.Text.MaxLines *
3260
 
							 ctrl_rdr->TypeUnion.Text.MaxChars) -
3261
 
							((state->StateUnion.Text.Line - 1) *
3262
 
							ctrl_rdr->TypeUnion.Text.MaxChars);
3263
 
					}
3264
 
					
3265
0 
					if (char_num > max_chars) return(SA_ERR_HPI_INVALID_DATA);
3266
 
				}
3267
 
			}
3268
0 
			break;
3269
 
		case SAHPI_CTRL_TYPE_OEM:
3270
 
			/* No HPI spec error check - leave to caller, if needed */
3271
0 
			break;
3272
 
		default:
3273
0 
			dbg("Invalid control state");
3274
0 
			return(SA_ERR_HPI_INTERNAL_ERROR);
3275
 
		}
3276
 
	}
3277
 
	
3278
0 
	return(SA_OK);
3279
 
}
3280