1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* 23 * Copyright (c) 1994, by Sun Microsytems, Inc. 24 */ 25 26#ifndef _TNF_TNF_H 27#define _TNF_TNF_H 28 29#pragma ident "%Z%%M% %I% %E% SMI" 30 31#include <sys/types.h> 32#include <tnf/com.h> 33 34#ifdef __cplusplus 35extern "C" { 36#endif 37 38/* 39 * Opaque TNF handle 40 */ 41 42typedef struct TNF TNF; 43 44/* 45 * Opaque data handle 46 */ 47 48typedef unsigned long long tnf_datum_t; 49 50#define TNF_DATUM_NULL ((tnf_datum_t)0) 51 52/* 53 * Reader data classification 54 */ 55 56typedef enum { 57 TNF_K_UNKNOWN, /* unknown or error */ 58 TNF_K_SCALAR, /* unclassified scalar */ 59 TNF_K_CHAR, /* char */ 60 TNF_K_INT8, /* int8 */ 61 TNF_K_INT16, /* int16 */ 62 TNF_K_INT32, /* int32 */ 63 TNF_K_UINT8, /* uint8 */ 64 TNF_K_UINT16, /* uint16 */ 65 TNF_K_UINT32, /* uint32 */ 66 TNF_K_INT64, /* int64 */ 67 TNF_K_UINT64, /* uint64 */ 68 TNF_K_FLOAT32, /* float32 */ 69 TNF_K_FLOAT64, /* float64 */ 70 TNF_K_ARRAY, /* array */ 71 TNF_K_STRING, /* string */ 72 TNF_K_STRUCT, /* struct */ 73 TNF_K_TYPE /* type */ 74} tnf_kind_t; 75 76/* 77 * Error codes 78 */ 79 80typedef enum { 81 TNF_ERR_NONE = 0, 82 83 /* 1 through 1023 reserved for errno values */ 84#define TNF_ERRNO_MAX 1023 85 86 TNF_ERR_NOTTNF = 1024, /* not TNF file */ 87 TNF_ERR_BADDATUM = 1025, /* bad or NULL data handle */ 88 TNF_ERR_TYPEMISMATCH = 1026, /* type mismatch */ 89 TNF_ERR_BADINDEX = 1027, /* array index out of bounds */ 90 TNF_ERR_BADSLOT = 1028, /* slot missing */ 91 TNF_ERR_BADREFTYPE = 1029, /* invalid reference type */ 92 TNF_ERR_ALLOCFAIL = 1030, /* memory allocation failure */ 93 TNF_ERR_BADTNF = 1031, /* bad TNF file */ 94 TNF_ERR_INTERNAL = 1032 /* internal error */ 95} tnf_errcode_t; 96 97typedef void tnf_error_handler_t(void *, TNF *, tnf_errcode_t); 98 99/* 100 * TNF file interface 101 */ 102 103tnf_errcode_t tnf_reader_begin(caddr_t, size_t, TNF **); 104tnf_errcode_t tnf_reader_end(TNF *); 105 106/* 107 * Error interface 108 */ 109 110void tnf_set_error_handler(tnf_error_handler_t *, void *); 111char * tnf_error_message(tnf_errcode_t); 112 113tnf_error_handler_t tnf_default_error_handler; 114 115/* 116 * Data block access 117 */ 118 119unsigned tnf_get_block_count(TNF *); 120tnf_datum_t tnf_get_block_absolute(TNF *, unsigned); 121tnf_datum_t tnf_get_block_relative(tnf_datum_t, int); 122int tnf_is_block_header(tnf_datum_t); 123 124/* 125 * Record access 126 */ 127 128tnf_datum_t tnf_get_next_record(tnf_datum_t); 129tnf_datum_t tnf_get_block_header(tnf_datum_t); 130tnf_datum_t tnf_get_file_header(TNF *); 131 132/* 133 * Data classification predicates 134 */ 135 136int tnf_is_inline(tnf_datum_t); 137int tnf_is_scalar(tnf_datum_t); 138int tnf_is_record(tnf_datum_t); 139int tnf_is_array(tnf_datum_t); 140int tnf_is_string(tnf_datum_t); 141int tnf_is_struct(tnf_datum_t); 142int tnf_is_type(tnf_datum_t); 143 144/* 145 * Data operations 146 */ 147 148tnf_kind_t tnf_get_kind(tnf_datum_t); 149size_t tnf_get_size(tnf_datum_t); 150tnf_datum_t tnf_get_type(tnf_datum_t); 151char * tnf_get_type_name(tnf_datum_t); 152caddr_t tnf_get_raw(tnf_datum_t); 153 154/* 155 * Record operations 156 */ 157 158tnf_datum_t tnf_get_tag_arg(tnf_datum_t); 159 160/* 161 * Array operations 162 */ 163 164unsigned tnf_get_element_count(tnf_datum_t); 165tnf_datum_t tnf_get_element(tnf_datum_t, unsigned); 166tnf_datum_t tnf_get_element_type(tnf_datum_t); 167caddr_t tnf_get_elements(tnf_datum_t); 168char * tnf_get_chars(tnf_datum_t); 169 170/* 171 * Struct operations 172 */ 173 174unsigned tnf_get_slot_count(tnf_datum_t); 175char * tnf_get_slot_name(tnf_datum_t, unsigned); 176unsigned tnf_get_slot_index(tnf_datum_t, char *); 177tnf_datum_t tnf_get_slot_named(tnf_datum_t, char *); 178tnf_datum_t tnf_get_slot_indexed(tnf_datum_t, unsigned); 179 180/* 181 * Scalar data conversions 182 */ 183 184char tnf_get_char(tnf_datum_t); 185tnf_int8_t tnf_get_int8(tnf_datum_t); 186tnf_int16_t tnf_get_int16(tnf_datum_t); 187tnf_int32_t tnf_get_int32(tnf_datum_t); 188tnf_int64_t tnf_get_int64(tnf_datum_t); 189tnf_float32_t tnf_get_float32(tnf_datum_t); 190tnf_float64_t tnf_get_float64(tnf_datum_t); 191 192/* 193 * Type (tag) record operations 194 */ 195 196tnf_kind_t tnf_type_get_kind(tnf_datum_t); 197char * tnf_type_get_name(tnf_datum_t); 198size_t tnf_type_get_size(tnf_datum_t); 199tnf_datum_t tnf_type_get_property(tnf_datum_t, char *); 200tnf_datum_t tnf_type_get_base(tnf_datum_t); 201 202#ifdef __cplusplus 203} 204#endif 205 206#endif /* _TNF_TNF_H */ 207