pkg.h

Go to the documentation of this file.
00001 /*                           P K G . H
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 /** @addtogroup libpkg */
00022 /*@{*/
00023 /** @file pkg.h
00024  *@brief
00025  *  Data structures and manifest constants for use with the PKG library.
00026  *
00027  *
00028  *  @author     Michael John Muuss
00029  *  @author     Charles M. Kennedy
00030  *  @author     Phillip Dykstra
00031  *
00032  *  @par Source
00033  *      The U. S. Army Research Laboratory
00034  *@n    Aberdeen Proving Ground, Maryland  21005-5068  USA
00035  */
00036 #ifndef lint
00037 #define PKG_H_VERSION "@(#)$Header: /cvsroot/brlcad/brlcad/include/pkg.h,v 14.14 2006/09/18 05:24:07 lbutler Exp $ (ARL)"
00038 #endif
00039 
00040 #ifndef PKG_H_SEENYET
00041 #define PKG_H_SEENYET
00042 
00043 #ifndef PKG_EXPORT
00044 #  if defined(_WIN32) && !defined(__CYGWIN__) && defined(BRLCAD_DLL)
00045 #    ifdef PKG_EXPORT_DLL
00046 #      define PKG_EXPORT __declspec(dllexport)
00047 #    else
00048 #      define PKG_EXPORT __declspec(dllimport)
00049 #    endif
00050 #  else
00051 #    define PKG_EXPORT
00052 #  endif
00053 #endif
00054 
00055 /*
00056  *  Macros for providing function prototypes, regardless of whether
00057  *  the compiler understands them or not.
00058  *  It is vital that the argument list given for "args" be enclosed
00059  *  in parens.
00060  *  The setting of USE_PROTOTYPES is done in machine.h
00061  */
00062 #if USE_PROTOTYPES
00063 #       define  PKG_EXTERN(type_and_name,args)  extern type_and_name args
00064 #       define  PKG_ARGS(args)                  args
00065 #else
00066 #       define  PKG_EXTERN(type_and_name,args)  extern type_and_name()
00067 #       define  PKG_ARGS(args)                  ()
00068 #endif
00069 
00070 
00071 #ifdef __cplusplus
00072 extern "C" {
00073 #endif
00074 
00075 struct pkg_conn;
00076 
00077 struct pkg_switch {
00078     unsigned short      pks_type;       /**< @brief Type code */
00079     void        (*pks_handler)PKG_ARGS((struct pkg_conn*, char*));  /**< @brief Message Handler */
00080     char        *pks_title;             /**< @brief Description of message type */
00081 };
00082 
00083 /**
00084  *  Format of the message header as it is transmitted over the network
00085  *  connection.  Internet network order is used.
00086  *  User Code should access pkc_len and pkc_type rather than
00087  *  looking into the header directly.
00088  *  Users should never need to know what this header looks like.
00089  */
00090 #define PKG_MAGIC       0x41FE
00091 struct pkg_header {
00092     unsigned char       pkh_magic[2];           /**< @brief Ident */
00093     unsigned char       pkh_type[2];            /**< @brief Message Type */
00094     unsigned char       pkh_len[4];             /**< @brief Byte count of remainder */
00095 };
00096 
00097 #define PKG_STREAMLEN   (32*1024)
00098 struct pkg_conn {
00099     int         pkc_fd;         /**< @brief TCP connection fd */
00100     const struct pkg_switch *pkc_switch;        /**< @brief Array of message handlers */
00101     void        (*pkc_errlog)PKG_ARGS((char *msg)); /**< @brief Error message logger */
00102     struct pkg_header pkc_hdr;  /**< @brief hdr of cur msg */
00103     long        pkc_len;        /**< @brief pkg_len, in host order */
00104     unsigned short      pkc_type;       /**< @brief pkg_type, in host order */
00105     /* OUTPUT BUFFER */
00106     char        pkc_stream[PKG_STREAMLEN]; /**< @brief output stream */
00107     int         pkc_magic;      /**< @brief for validating pointers */
00108     int         pkc_strpos;     /**< @brief index into stream buffer */
00109     /* FIRST LEVEL INPUT BUFFER */
00110     char                *pkc_inbuf;     /**< @brief input stream buffer */
00111     int         pkc_incur;      /**< @brief current pos in inbuf */
00112     int         pkc_inend;      /**< @brief first unused pos in inbuf */
00113     int         pkc_inlen;      /**< @brief length of pkc_inbuf */
00114     /* DYNAMIC BUFFER FOR USER */
00115     int         pkc_left;       /**< @brief #  bytes pkg_get expects */
00116     /* neg->read new hdr, 0->all here, >0 ->more to come */
00117     char                *pkc_buf;       /**< @brief start of dynamic buf */
00118     char                *pkc_curpos;    /**< @brief current position in pkg_buf */
00119 };
00120 #define PKC_NULL        ((struct pkg_conn *)0)
00121 #define PKC_ERROR       ((struct pkg_conn *)(-1L))
00122 
00123 
00124 #define pkg_send_vls(type,vlsp,pkg)     \
00125         pkg_send( (type), bu_vls_addr((vlsp)), bu_vls_strlen((vlsp))+1, (pkg) )
00126 
00127 
00128 PKG_EXPORT PKG_EXTERN(int pkg_init, ());
00129 PKG_EXPORT PKG_EXTERN(void pkg_terminate, ());
00130 PKG_EXPORT PKG_EXTERN(int pkg_process, (register struct pkg_conn *));
00131 PKG_EXPORT PKG_EXTERN(int pkg_suckin, (register struct pkg_conn *));
00132 PKG_EXPORT PKG_EXTERN(struct pkg_conn *pkg_open, (const char *host, const char *service, const char *protocol, const char *uname, const char *passwd, const struct pkg_switch* switchp, void (*errlog)PKG_ARGS((char *msg))));
00133 PKG_EXPORT PKG_EXTERN(struct pkg_conn *pkg_transerver, (const struct pkg_switch* switchp, void (*errlog)PKG_ARGS((char *msg))));
00134 PKG_EXPORT PKG_EXTERN(int pkg_permserver, (char *service, char *protocol, int backlog, void (*errlog)PKG_ARGS((char *msg))));
00135 PKG_EXPORT PKG_EXTERN(int pkg_permserver_ip, (char *ipOrHostname, char *service, char *protocol, int backlog, void (*errlog)PKG_ARGS((char *msg))));
00136 PKG_EXPORT PKG_EXTERN(struct pkg_conn *pkg_getclient, (int fd, const struct pkg_switch *switchp, void (*errlog)PKG_ARGS((char *msg)), int nodelay));
00137 PKG_EXPORT PKG_EXTERN(void pkg_close, (struct pkg_conn* pc));
00138 PKG_EXPORT PKG_EXTERN(int pkg_send, (int type, char *buf, int len, struct pkg_conn* pc));
00139 PKG_EXPORT PKG_EXTERN(int pkg_2send, (int type, char *buf1, int len1, char *buf2, int len2, struct pkg_conn* pc));
00140 PKG_EXPORT PKG_EXTERN(int pkg_stream, (int type, char *buf, int len, struct pkg_conn* pc));
00141 PKG_EXPORT PKG_EXTERN(int pkg_flush, (struct pkg_conn* pc));
00142 PKG_EXPORT PKG_EXTERN(int pkg_waitfor, (int type, char *buf, int len, struct pkg_conn* pc));
00143 PKG_EXPORT PKG_EXTERN(char *pkg_bwaitfor, (int type, struct pkg_conn* pc));
00144 PKG_EXPORT PKG_EXTERN(int pkg_block, (struct pkg_conn* pc));
00145 
00146 /* Data conversion routines */
00147 PKG_EXPORT PKG_EXTERN(unsigned short pkg_gshort, (char *buf));
00148 PKG_EXPORT PKG_EXTERN(unsigned long pkg_glong, (char *buf));
00149 PKG_EXPORT PKG_EXTERN(char *pkg_pshort, (char *buf, short unsigned int s));
00150 PKG_EXPORT PKG_EXTERN(char *pkg_plong, (char *buf, long unsigned int l));
00151 
00152 #ifdef __cplusplus
00153 }
00154 #endif
00155 
00156 #endif /* PKG_H_SEENYET */
00157 /*@}*/
00158 /*
00159  * Local Variables:
00160  * mode: C
00161  * tab-width: 8
00162  * c-basic-offset: 4
00163  * indent-tabs-mode: t
00164  * End:
00165  * ex: shiftwidth=4 tabstop=8
00166  */
00167 

Generated on Mon Sep 18 01:24:41 2006 for BRL-CAD by  doxygen 1.4.6