1 /* 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 3 * 4 * Common includes and defines for Sun::Solaris::Exacct. 5 */ 6 7 #ifndef _EXACCT_COMMON_H 8 #define _EXACCT_COMMON_H 9 10 /* Exacct related includes. */ 11 #include <exacct.h> 12 13 /* 14 * On i386 Solaris defines SP, which conflicts with the perl definition of SP 15 * We don't need the Solaris one, so get rid of it to avoid warnings. 16 */ 17 #undef SP 18 19 /* Perl XS includes. */ 20 #include "EXTERN.h" 21 #include "perl.h" 22 #include "XSUB.h" 23 24 /* Root of the Exacct namespace. */ 25 #define PKGBASE "Sun::Solaris::Exacct" 26 27 /* Debugging assertion macros. */ 28 #ifdef EXACCT_DEBUG 29 #define PERL_ASSERT(EXPR) ((void)((EXPR) || \ 30 (croak("%s(%d) assertion failed: %s", __FILE__, __LINE__, #EXPR), 0), \ 31 0)) 32 #define PERL_ASSERTMSG(EXPR, MSG) ((void)((EXPR) || \ 33 (croak("%s(%d) %s", __FILE__ __LINE__, MSG), 0), 0)) 34 #else 35 #define PERL_ASSERT(EXP) ((void)0) 36 #define PERL_ASSERTMSG(EXP, MSG) ((void)0) 37 #endif 38 39 /* 40 * Object stash pointers - caching these speeds up the creation and 41 * typechecking of perl objects by removing the need to do a hash lookup. 42 * The peculiar variable names are so that typemaps can generate the correct 43 * package name using the typemap '$Package' variable as the root of the name. 44 */ 45 extern HV *Sun_Solaris_Exacct_Catalog_stash; 46 extern HV *Sun_Solaris_Exacct_File_stash; 47 extern HV *Sun_Solaris_Exacct_Object_Item_stash; 48 extern HV *Sun_Solaris_Exacct_Object_Group_stash; 49 extern HV *Sun_Solaris_Exacct_Object__Array_stash; 50 51 /* Populate the stash pointers, provided by Exacct.xs. */ 52 extern void init_stashes(void); 53 54 /* 55 * Pointer to part of the hash tree built by define_catalog_constants in 56 * Catalog.xs. This is used by catalog_id_str() in Exacct.xs when mapping 57 * from a catalog to an id string. 58 */ 59 extern HV *IdValueHash; 60 extern char *catalog_id_str(ea_catalog_t catalog); 61 62 /* 63 * Structure for holding an ::Exacct::Object. Different bits of this structure 64 * will be populated depending on the type of Object (Item or Group), and on 65 * how the Object was created (read from file or by the script). 66 * 67 * Simple Items 68 * Only the ea_obj part is populated, and that points to an ea_object_t 69 * that is used to hold the Item. 70 * 71 * Items containing embedded Objects 72 * If an Item of this type has been read from file and has not been accessed, 73 * just the ea_obj part will be populated. If the object has been accessed, or 74 * if it has been created from within the script, the perl_obj part will be 75 * populated. 76 * 77 * Groups 78 * If a Group has been read from file and has not been accessed, just the 79 * ea_obj part will be populated. If the object has been accessed, or if it has 80 * been created from within the script, the perl_obj part will be populated. 81 */ 82 typedef struct { 83 ea_object_t *ea_obj; /* Underlying exacct object. */ 84 SV *perl_obj; /* Underlying perl object. */ 85 uchar_t flags; /* Object type and status. */ 86 } xs_ea_object_t; 87 88 /* Macros for manipulating flag bits. */ 89 #define TYPE_MASK 0x03 90 #define PLAIN_ITEM 0x00 91 #define EMBED_ITEM 0x01 92 #define GROUP 0x02 93 94 #define GET_TYPE_BITS(X) ((X)->flags & TYPE_MASK) 95 #define SET_TYPE_BITS(X, Y) ((X)->flags = (((X)->flags & ~TYPE_MASK) | Y) 96 #define SET_PLAIN_ITEM(X) (SET_TYPE_BITS(X, PLAIN_ITEM)) 97 #define SET_EMBED_ITEM(X) (SET_TYPE_BITS(X, EMBED_ITEM)) 98 #define SET_GROUP(X) (SET_TYPE_BITS(X, GROUP)) 99 #define IS_ITEM(X) (GET_TYPE_BITS(X) < GROUP) 100 #define IS_PLAIN_ITEM(X) (GET_TYPE_BITS(X) == PLAIN_ITEM) 101 #define IS_EMBED_ITEM(X) (GET_TYPE_BITS(X) == EMBED_ITEM) 102 #define IS_GROUP(X) (GET_TYPE_BITS(X) == GROUP) 103 104 #define INIT_PLAIN_ITEM_FLAGS(X) ((X)->flags = PLAIN_ITEM) 105 #define INIT_EMBED_ITEM_FLAGS(X) ((X)->flags = EMBED_ITEM) 106 #define INIT_GROUP_FLAGS(X) ((X)->flags = GROUP) 107 108 /* Fast way to make catalog objects, provided by Exacct.xs. */ 109 extern SV *new_catalog(ea_catalog_t cat); 110 111 /* Return the integer catalog value from the passed object or SV. */ 112 extern ea_catalog_t catalog_value(SV *catalog); 113 114 /* Fast way to make exacct objects, provided by Exacct.xs. */ 115 extern SV *new_xs_ea_object(ea_object_t *obj); 116 117 /* Deflate an xs_ea_object, provided by Exacct.xs. */ 118 extern ea_object_t *deflate_xs_ea_object(SV *sv); 119 120 /* 121 * Structure and associated function for creating perl constants 122 * and populating @_Constants, used for constant lookup by the modules. 123 * See Exacct.xs for the definition of define_constants(). 124 */ 125 typedef enum { other = 0, type, catlg, id } consttype_t; 126 typedef struct { 127 const char *name; 128 const int len; 129 const consttype_t consttype; 130 const unsigned int value; 131 } constval_t; 132 extern void define_constants(const char *pkg, constval_t *dvp); 133 134 #endif /* _EXACCT_COMMON_H */