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