10Sstevel@tonic-gate/* 2*12388SJohn.Sonnenschein@Sun.COM * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * Common includes and defines for Sun::Solaris::Exacct. 50Sstevel@tonic-gate */ 60Sstevel@tonic-gate 70Sstevel@tonic-gate#ifndef _EXACCT_COMMON_H 80Sstevel@tonic-gate#define _EXACCT_COMMON_H 90Sstevel@tonic-gate 100Sstevel@tonic-gate/* Exacct related includes. */ 110Sstevel@tonic-gate#include <exacct.h> 120Sstevel@tonic-gate 130Sstevel@tonic-gate/* 140Sstevel@tonic-gate * On i386 Solaris defines SP, which conflicts with the perl definition of SP 150Sstevel@tonic-gate * We don't need the Solaris one, so get rid of it to avoid warnings. 160Sstevel@tonic-gate */ 170Sstevel@tonic-gate#undef SP 180Sstevel@tonic-gate 190Sstevel@tonic-gate/* Perl XS includes. */ 200Sstevel@tonic-gate#include "EXTERN.h" 210Sstevel@tonic-gate#include "perl.h" 220Sstevel@tonic-gate#include "XSUB.h" 230Sstevel@tonic-gate 240Sstevel@tonic-gate/* Root of the Exacct namespace. */ 250Sstevel@tonic-gate#define PKGBASE "Sun::Solaris::Exacct" 260Sstevel@tonic-gate 270Sstevel@tonic-gate/* Debugging assertion macros. */ 280Sstevel@tonic-gate#ifdef EXACCT_DEBUG 290Sstevel@tonic-gate#define PERL_ASSERT(EXPR) ((void)((EXPR) || \ 300Sstevel@tonic-gate (croak("%s(%d) assertion failed: %s", __FILE__, __LINE__, #EXPR), 0), \ 310Sstevel@tonic-gate 0)) 320Sstevel@tonic-gate#define PERL_ASSERTMSG(EXPR, MSG) ((void)((EXPR) || \ 330Sstevel@tonic-gate (croak("%s(%d) %s", __FILE__ __LINE__, MSG), 0), 0)) 340Sstevel@tonic-gate#else 350Sstevel@tonic-gate#define PERL_ASSERT(EXP) ((void)0) 360Sstevel@tonic-gate#define PERL_ASSERTMSG(EXP, MSG) ((void)0) 370Sstevel@tonic-gate#endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate/* 400Sstevel@tonic-gate * Object stash pointers - caching these speeds up the creation and 410Sstevel@tonic-gate * typechecking of perl objects by removing the need to do a hash lookup. 420Sstevel@tonic-gate * The peculiar variable names are so that typemaps can generate the correct 430Sstevel@tonic-gate * package name using the typemap '$Package' variable as the root of the name. 440Sstevel@tonic-gate */ 450Sstevel@tonic-gateextern HV *Sun_Solaris_Exacct_Catalog_stash; 460Sstevel@tonic-gateextern HV *Sun_Solaris_Exacct_File_stash; 470Sstevel@tonic-gateextern HV *Sun_Solaris_Exacct_Object_Item_stash; 480Sstevel@tonic-gateextern HV *Sun_Solaris_Exacct_Object_Group_stash; 490Sstevel@tonic-gateextern HV *Sun_Solaris_Exacct_Object__Array_stash; 500Sstevel@tonic-gate 510Sstevel@tonic-gate/* Populate the stash pointers, provided by Exacct.xs. */ 520Sstevel@tonic-gateextern void init_stashes(void); 530Sstevel@tonic-gate 540Sstevel@tonic-gate/* 550Sstevel@tonic-gate * Pointer to part of the hash tree built by define_catalog_constants in 560Sstevel@tonic-gate * Catalog.xs. This is used by catalog_id_str() in Exacct.xs when mapping 570Sstevel@tonic-gate * from a catalog to an id string. 580Sstevel@tonic-gate */ 590Sstevel@tonic-gateextern HV *IdValueHash; 600Sstevel@tonic-gateextern char *catalog_id_str(ea_catalog_t catalog); 610Sstevel@tonic-gate 620Sstevel@tonic-gate/* 630Sstevel@tonic-gate * Structure for holding an ::Exacct::Object. Different bits of this structure 640Sstevel@tonic-gate * will be populated depending on the type of Object (Item or Group), and on 650Sstevel@tonic-gate * how the Object was created (read from file or by the script). 660Sstevel@tonic-gate * 670Sstevel@tonic-gate * Simple Items 680Sstevel@tonic-gate * Only the ea_obj part is populated, and that points to an ea_object_t 690Sstevel@tonic-gate * that is used to hold the Item. 700Sstevel@tonic-gate * 710Sstevel@tonic-gate * Items containing embedded Objects 720Sstevel@tonic-gate * If an Item of this type has been read from file and has not been accessed, 730Sstevel@tonic-gate * just the ea_obj part will be populated. If the object has been accessed, or 740Sstevel@tonic-gate * if it has been created from within the script, the perl_obj part will be 750Sstevel@tonic-gate * populated. 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * Groups 780Sstevel@tonic-gate * If a Group has been read from file and has not been accessed, just the 790Sstevel@tonic-gate * ea_obj part will be populated. If the object has been accessed, or if it has 800Sstevel@tonic-gate * been created from within the script, the perl_obj part will be populated. 810Sstevel@tonic-gate */ 820Sstevel@tonic-gatetypedef struct { 830Sstevel@tonic-gate ea_object_t *ea_obj; /* Underlying exacct object. */ 840Sstevel@tonic-gate SV *perl_obj; /* Underlying perl object. */ 850Sstevel@tonic-gate uchar_t flags; /* Object type and status. */ 860Sstevel@tonic-gate} xs_ea_object_t; 870Sstevel@tonic-gate 880Sstevel@tonic-gate/* Macros for manipulating flag bits. */ 890Sstevel@tonic-gate#define TYPE_MASK 0x03 900Sstevel@tonic-gate#define PLAIN_ITEM 0x00 910Sstevel@tonic-gate#define EMBED_ITEM 0x01 920Sstevel@tonic-gate#define GROUP 0x02 930Sstevel@tonic-gate 940Sstevel@tonic-gate#define GET_TYPE_BITS(X) ((X)->flags & TYPE_MASK) 950Sstevel@tonic-gate#define SET_TYPE_BITS(X, Y) ((X)->flags = (((X)->flags & ~TYPE_MASK) | Y) 960Sstevel@tonic-gate#define SET_PLAIN_ITEM(X) (SET_TYPE_BITS(X, PLAIN_ITEM)) 970Sstevel@tonic-gate#define SET_EMBED_ITEM(X) (SET_TYPE_BITS(X, EMBED_ITEM)) 980Sstevel@tonic-gate#define SET_GROUP(X) (SET_TYPE_BITS(X, GROUP)) 990Sstevel@tonic-gate#define IS_ITEM(X) (GET_TYPE_BITS(X) < GROUP) 1000Sstevel@tonic-gate#define IS_PLAIN_ITEM(X) (GET_TYPE_BITS(X) == PLAIN_ITEM) 1010Sstevel@tonic-gate#define IS_EMBED_ITEM(X) (GET_TYPE_BITS(X) == EMBED_ITEM) 1020Sstevel@tonic-gate#define IS_GROUP(X) (GET_TYPE_BITS(X) == GROUP) 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate#define INIT_PLAIN_ITEM_FLAGS(X) ((X)->flags = PLAIN_ITEM) 1050Sstevel@tonic-gate#define INIT_EMBED_ITEM_FLAGS(X) ((X)->flags = EMBED_ITEM) 1060Sstevel@tonic-gate#define INIT_GROUP_FLAGS(X) ((X)->flags = GROUP) 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate/* Fast way to make catalog objects, provided by Exacct.xs. */ 1090Sstevel@tonic-gateextern SV *new_catalog(ea_catalog_t cat); 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate/* Return the integer catalog value from the passed object or SV. */ 1120Sstevel@tonic-gateextern ea_catalog_t catalog_value(SV *catalog); 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate/* Fast way to make exacct objects, provided by Exacct.xs. */ 1150Sstevel@tonic-gateextern SV *new_xs_ea_object(ea_object_t *obj); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate/* Deflate an xs_ea_object, provided by Exacct.xs. */ 1180Sstevel@tonic-gateextern ea_object_t *deflate_xs_ea_object(SV *sv); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate/* 1210Sstevel@tonic-gate * Structure and associated function for creating perl constants 1220Sstevel@tonic-gate * and populating @_Constants, used for constant lookup by the modules. 1230Sstevel@tonic-gate * See Exacct.xs for the definition of define_constants(). 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gatetypedef enum { other = 0, type, catlg, id } consttype_t; 1260Sstevel@tonic-gatetypedef struct { 1270Sstevel@tonic-gate const char *name; 1280Sstevel@tonic-gate const int len; 1290Sstevel@tonic-gate const consttype_t consttype; 1300Sstevel@tonic-gate const unsigned int value; 1310Sstevel@tonic-gate} constval_t; 1320Sstevel@tonic-gateextern void define_constants(const char *pkg, constval_t *dvp); 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate#endif /* _EXACCT_COMMON_H */ 135