ldmcpp.h

00001 // New ldm include file
00002 // The standard LDM includes don't work too well with the GCC C++ compiler
00003 // So this is a hacked version
00004 // This is all credit to and copyright of UCAR
00005 
00006 #ifdef USE_SYSTEM_LDM_HEADERS
00007 #include <pq.h>
00008 #define _LDMCPP_H
00009 #endif
00010 
00011 #ifndef _LDMCPP_H
00012 #define _LDMCPP_H
00013 
00014 
00015 //#include <rpc/rpc.h>
00016 #include <sys/types.h>  /* off_t, mode_t */
00017 #include <stddef.h>     /* size_t */
00018 #include <stdlib.h>
00019 #include <sys/types.h>
00020 #include <netinet/in.h>
00021 #include <arpa/inet.h>
00022 #include <sys/time.h>
00023 #include <regex.h>
00024 
00025 
00026 
00027 /*
00028  *   Copyright 1994, University Corporation for Atmospheric Research
00029  *   See ../COPYRIGHT file for copying and redistribution conditions.
00030  */
00031 /* $Id: prod_class.h,v 1.17.18.1 2005/01/21 21:34:57 steve Exp $ */
00032 
00033 
00034 extern const char* ldm_version;
00035 
00036 
00037 typedef struct timeval timestampt;
00038 
00039 extern const struct timeval TS_NONE; /* an invalid time */
00040 extern const struct timeval TS_ZERO; /* the beginning of time */
00041 extern const struct timeval TS_ENDT; /* the end of time */
00042 
00043 
00044 
00045 typedef u_int feedtypet;
00046 
00047 struct prod_spec {
00048         feedtypet feedtype;
00049         char *pattern;
00050         regex_t rgx;    /* volatile, not sent over the wire */
00051 };
00052 typedef struct prod_spec prod_spec;
00053 
00054 /*
00055  * prod_class is a set of products
00056  */
00057 
00058 struct prod_class {
00059         timestampt from;
00060         timestampt to;
00061         struct {
00062                 u_int psa_len;
00063                 prod_spec *psa_val;
00064         } psa;
00065 };
00066 typedef struct prod_class prod_class;
00067 
00068 typedef unsigned char signaturet[16];
00069 
00070 /*
00071  * pkey: product identification string (Not used as a key anymore).
00072  * max length of pkey, _POSIX_PATH_MAX.
00073  */
00074 typedef char *keyt;
00075 
00076 
00077 /*
00078  * prod_info describes a specific data product.
00079  * (not a class of products).
00080  *
00081  */
00082 
00083 struct prod_info {
00084         timestampt arrival;
00085         signaturet signature;
00086         char *origin;
00087         feedtypet feedtype;
00088         u_int seqno;
00089         keyt ident;
00090         u_int sz;
00091 };
00092 typedef struct prod_info prod_info;
00093 
00094 
00095 #ifndef _PROD_CLASS_H_
00096 #define _PROD_CLASS_H_
00097 
00098 /*
00099  * Define a set of products
00100  */
00101 extern const prod_class _clss_all;
00102 #define PQ_CLASS_ALL    (&_clss_all)
00103 extern const prod_spec _spec_all;
00104 #define PQ_SPEC_ALL     (&_spec_all)
00105 
00106 
00107 extern void
00108 free_prod_class(prod_class *clssp);
00109 
00110 extern prod_class *
00111 new_prod_class(u_int psa_len);
00112 
00113 #endif /* !_PROD_CLASS_H_ */
00114 
00115 
00116 #ifndef _PQ_H
00117 #define _PQ_H
00118 
00119 /*
00120  * The functions below return ENOERR upon success.
00121  * Upon failure, the return something else :-).
00122  * (Usually, that something else will be the a system
00123  * error (errno.h), don't count on it making sense.)
00124  */
00125 #ifndef ENOERR
00126 #define ENOERR 0
00127 #endif 
00129 #define PQ_CORRUPT      -1
00130 
00131 typedef struct pqueue pqueue; /* private, implemented in pq.c */
00132 
00133 
00134 /*
00135  * pflags arg to pq_open() and pq_create()
00136  */
00137 #define PQ_DEFAULT      0x00
00138 #define PQ_NOCLOBBER    0x01    /* Don't destroy existing file on create */
00139 #define PQ_READONLY     0x02    /* Default is read/write */
00140 #define PQ_NOLOCK       0x04    /* Disable locking */
00141 #define PQ_PRIVATE      0x08    /* mmap() the file MAP_PRIVATE, default MAP_SHARED */
00142 #define PQ_NOGROW       0x10    /* If pq_create(), must have intialsz */
00143 #define PQ_NOMAP        0x20    /* Use malloc/read/write/free instead of mmap() */
00144 #define PQ_MAPRGNS      0x40    /* Map region by region, default whole file */
00145 #define PQ_SPARSE       0x80    /* Created as sparse file, zero blocks unallocated */
00146 /* N.B.: bits 0x1000 (and above) in use internally */
00147 
00148 extern int
00149 pq_create(const char *path, mode_t mode, int pflags,
00150         size_t align, off_t initialsz, size_t nproducts,
00151         pqueue **pqp);
00152 
00153 extern int
00154 pq_open(const char *path,
00155         int pflags,
00156         pqueue **pqp);
00157 
00158 extern int 
00159 pq_close(pqueue *pq);
00160 
00161 
00162 
00163 /* prototype for 4th arg to pq_sequence() */
00164 typedef int pq_seqfunc(const prod_info *infop, const void *datap,
00165         void *xprod, size_t len,
00166         void *otherargs);
00167 
00168 /*
00169  * Which direction the cursor moves in pq_sequence().
00170  */
00171 typedef enum {
00172         TV_LT = -1,
00173         TV_EQ =  0,
00174         TV_GT =  1
00175 } pq_match;
00176 
00177 
00178 /*
00179  * Step thru the time sorted inventory according to 'mt',
00180  * and the current cursor value.
00181  *
00182  * If(mt == TV_LT), pq_sequence() will get a product
00183  * whose queue insertion timestamp is strictly less than
00184  * the current cursor value.
00185  *
00186  * If(mt == TV_GT), pq_sequence() will get a product
00187  * whose queue insertion timestamp is strictly greater than
00188  * the current cursor value.
00189  *
00190  * If(mt == TV_EQ), pq_sequence() will get a product
00191  * whose queue insertion timestamp is equal to
00192  * the current cursor value.
00193  *
00194  * If no product is in the inventory which which meets the
00195  * above spec, return PQUEUE_END.
00196  *
00197  * Otherwise, if the product info matches class,
00198  * execute ifMatch(xprod, len, otherargs) and return the
00199  * return value from ifMatch().
00200  */
00201 #define PQUEUE_END (-1) /* return value indicating end of queue */
00202 extern int
00203 pq_sequence(pqueue *pq, pq_match mt,
00204         const prod_class *clssp, pq_seqfunc *ifMatch, void *otherargs);
00205 
00206 /*
00207  * Suspend yourself (sleep) until
00208  * one of the following events occurs:
00209  *   You recieve a signal that you handle.
00210  *   You recieve SIGCONT (as send from an insert proc indicating
00211  *      data is available).
00212  *   "maxsleep" seconds elapse.
00213  *   If "maxsleep" is zero, you could sleep forever. 
00214  */
00215 extern unsigned
00216 pq_suspend(unsigned int maxsleep);
00217 #endif /* !_PQ_H */
00218 
00219 
00220 
00221 #endif
00222 

Generated on Tue Jul 1 20:25:26 2008 for libradar_stp by  doxygen 1.4.7