exacct_common.xh revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Common includes and defines for Sun::Solaris::Exacct.
*/
#ifndef _EXACCT_COMMON_H
#define _EXACCT_COMMON_H
#pragma ident "%Z%%M% %I% %E% SMI"
/* Exacct related includes. */
#include <exacct.h>
/*
* On i386 Solaris defines SP, which conflicts with the perl definition of SP
* We don't need the Solaris one, so get rid of it to avoid warnings.
*/
#undef SP
/* Perl XS includes. */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Root of the Exacct namespace. */
#define PKGBASE "Sun::Solaris::Exacct"
/* Debugging assertion macros. */
#ifdef EXACCT_DEBUG
#define PERL_ASSERT(EXPR) ((void)((EXPR) || \
(croak("%s(%d) assertion failed: %s", __FILE__, __LINE__, #EXPR), 0), \
0))
#define PERL_ASSERTMSG(EXPR, MSG) ((void)((EXPR) || \
(croak("%s(%d) %s", __FILE__ __LINE__, MSG), 0), 0))
#else
#define PERL_ASSERT(EXP) ((void)0)
#define PERL_ASSERTMSG(EXP, MSG) ((void)0)
#endif
/*
* Object stash pointers - caching these speeds up the creation and
* typechecking of perl objects by removing the need to do a hash lookup.
* The peculiar variable names are so that typemaps can generate the correct
* package name using the typemap '$Package' variable as the root of the name.
*/
extern HV *Sun_Solaris_Exacct_Catalog_stash;
extern HV *Sun_Solaris_Exacct_File_stash;
extern HV *Sun_Solaris_Exacct_Object_Item_stash;
extern HV *Sun_Solaris_Exacct_Object_Group_stash;
extern HV *Sun_Solaris_Exacct_Object__Array_stash;
/* Populate the stash pointers, provided by Exacct.xs. */
extern void init_stashes(void);
/*
* Pointer to part of the hash tree built by define_catalog_constants in
* Catalog.xs. This is used by catalog_id_str() in Exacct.xs when mapping
* from a catalog to an id string.
*/
extern HV *IdValueHash;
extern char *catalog_id_str(ea_catalog_t catalog);
/*
* Structure for holding an ::Exacct::Object. Different bits of this structure
* will be populated depending on the type of Object (Item or Group), and on
* how the Object was created (read from file or by the script).
*
* Simple Items
* Only the ea_obj part is populated, and that points to an ea_object_t
* that is used to hold the Item.
*
* Items containing embedded Objects
* If an Item of this type has been read from file and has not been accessed,
* just the ea_obj part will be populated. If the object has been accessed, or
* if it has been created from within the script, the perl_obj part will be
* populated.
*
* Groups
* If a Group has been read from file and has not been accessed, just the
* ea_obj part will be populated. If the object has been accessed, or if it has
* been created from within the script, the perl_obj part will be populated.
*/
typedef struct {
ea_object_t *ea_obj; /* Underlying exacct object. */
SV *perl_obj; /* Underlying perl object. */
uchar_t flags; /* Object type and status. */
} xs_ea_object_t;
/* Macros for manipulating flag bits. */
#define TYPE_MASK 0x03
#define PLAIN_ITEM 0x00
#define EMBED_ITEM 0x01
#define GROUP 0x02
#define GET_TYPE_BITS(X) ((X)->flags & TYPE_MASK)
#define SET_TYPE_BITS(X, Y) ((X)->flags = (((X)->flags & ~TYPE_MASK) | Y)
#define SET_PLAIN_ITEM(X) (SET_TYPE_BITS(X, PLAIN_ITEM))
#define SET_EMBED_ITEM(X) (SET_TYPE_BITS(X, EMBED_ITEM))
#define SET_GROUP(X) (SET_TYPE_BITS(X, GROUP))
#define IS_ITEM(X) (GET_TYPE_BITS(X) < GROUP)
#define IS_PLAIN_ITEM(X) (GET_TYPE_BITS(X) == PLAIN_ITEM)
#define IS_EMBED_ITEM(X) (GET_TYPE_BITS(X) == EMBED_ITEM)
#define IS_GROUP(X) (GET_TYPE_BITS(X) == GROUP)
#define INIT_PLAIN_ITEM_FLAGS(X) ((X)->flags = PLAIN_ITEM)
#define INIT_EMBED_ITEM_FLAGS(X) ((X)->flags = EMBED_ITEM)
#define INIT_GROUP_FLAGS(X) ((X)->flags = GROUP)
/* Fast way to make catalog objects, provided by Exacct.xs. */
extern SV *new_catalog(ea_catalog_t cat);
/* Return the integer catalog value from the passed object or SV. */
extern ea_catalog_t catalog_value(SV *catalog);
/* Fast way to make exacct objects, provided by Exacct.xs. */
extern SV *new_xs_ea_object(ea_object_t *obj);
/* Deflate an xs_ea_object, provided by Exacct.xs. */
extern ea_object_t *deflate_xs_ea_object(SV *sv);
/*
* Structure and associated function for creating perl constants
* and populating @_Constants, used for constant lookup by the modules.
* See Exacct.xs for the definition of define_constants().
*/
typedef enum { other = 0, type, catlg, id } consttype_t;
typedef struct {
const char *name;
const int len;
const consttype_t consttype;
const unsigned int value;
} constval_t;
extern void define_constants(const char *pkg, constval_t *dvp);
#endif /* _EXACCT_COMMON_H */