Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

tuple.h

Go to the documentation of this file.
00001 /*****************************************************************
00002  *
00003  * LinuxTuples - an open-source tuple system for Linux clusters
00004  * Copyright (c) 2003, Will Ware <wware@alum.mit.edu>
00005  * All rights reserved.
00006  * 
00007  *    Redistribution and use in source and binary forms, with or
00008  *    without modification, are permitted provided that the following
00009  *    conditions are met:
00010  * 
00011  *    + Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  *    + Redistributions in binary form must reproduce the above
00015  *    copyright notice, this list of conditions and the following
00016  *    disclaimer in the documentation and/or other materials provided
00017  *    with the distribution.
00018  *
00019  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
00020  *    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00021  *    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00022  *    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00024  *    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00026  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00027  *    USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  *    AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  *    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00030  *    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00031  *    THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  *****************************************************************/
00034 
00035 #ifndef TUPLE_H_INCLUDED
00036 #define TUPLE_H_INCLUDED
00037 
00038 #ifndef va_list
00039 #define va_list __gnuc_va_list
00040 #endif
00041 
00042 #ifdef DEBUG
00043 #define _DBG_(x)  x
00044 #else
00045 #define _DBG_(x)
00046 #endif
00047 
00048 #define ASSERT(cond)   \
00049    _DBG_(if (!(cond)) { DBGPRINTF("assert failed: %s\n", \
00050                                   #cond); exit(1); })
00051 
00052 #define DBGPRINTF(fmt,a...)   \
00053    _DBG_(fprintf(stderr, "%d " __FILE__ ":%d " fmt, \
00054                  debug_counter++, __LINE__, ##a))
00055 
00056 #define TELL(x) \
00057    DBGPRINTF(#x " = %d\n", x)
00058 
00059 #if defined(DEBUG)
00060 static inline void * mymalloc(int size, char *file, int line)
00061 {
00062         void *p;
00063         p = malloc(size);
00064         fprintf(stderr, "%s:%d malloc %08x\n",
00065                 file, line, (unsigned int) p);
00066         return p;
00067 }
00068 static inline void myfree(void *p, char *file, int line)
00069 {
00070         fprintf(stderr, "%s:%d free %08x\n",
00071                 file, line, (unsigned int) p);
00072         free(p);
00073 }
00074 #define MALLOC(n) mymalloc(n,__FILE__,__LINE__)
00075 #define FREE(n) myfree(n,__FILE__,__LINE__)
00076 #else
00077 #define MALLOC malloc
00078 #define FREE free
00079 #endif
00080 
00081 #ifdef DEBUG
00082 /* Get a stack trace for GDB*/
00083 #define EXIT()   *((int*) 0) = 11
00084 #else
00085 #define EXIT()   exit(1)
00086 #endif
00087 
00088 /* Time difference between two struct timevals.
00089  */
00090 #define TIMEVAL_DIFF(before,after)  \
00091         ((after.tv_sec - before.tv_sec) + \
00092         1.0e-6 * (after.tv_usec - before.tv_usec))
00093 
00094 
00095 
00096 /* Environment variables */
00097 #define SERVERNAME_ENVVAR  "LINUXTUPLES_HOST"
00098 #define PORTNUMBER_ENVVAR  "LINUXTUPLES_PORT"
00099 
00100 enum message_op {
00101         PUT = 0,
00102         GET = 1,
00103         READ = 2,
00104         GET_NB = 3,
00105         READ_NB = 4,
00106         DUMP = 5,
00107         LOG = 6,
00108 };
00109 
00114 struct element {
00131         int tag;
00137         union {
00142                 int i;
00147                 double d;
00154                 struct {
00158                         char *ptr;
00166                         int len;
00167                 } s;
00168         } data;
00169 };
00170 
00174 #define I_AM_A_TUPLE 0x31415926
00175 
00181 struct tuple {
00192         int tag;
00196         int num_elts;
00201         int string_length;
00205         struct element *elements;
00215         char *string_space;
00216 };
00217 
00222 struct tuple_list {
00223         struct tuple_list *next;
00224         struct tuple *tup;
00225 };
00226 
00227 
00237 struct context {
00242         char servername[100];
00247         int portnumber;
00251         int sock;
00257         pthread_t thr;
00258 };
00259 
00260 
00261 
00262 /* ================= tuple.c ================= */
00263 
00264 #ifdef DEBUG
00265 extern int debug_counter;
00266 #endif
00267 extern int i_am_server;
00268 extern char logbuf[8192];
00269 extern int logptr;
00270 extern int get_server_portnumber(struct context *ctx);
00271 extern void print_element(struct element *e);
00272 extern void print_tuple(struct tuple *s);
00273 extern struct tuple *make_tuple(char *fmt, ...);
00274 extern void destroy_tuple(struct tuple *t);
00275 extern int tuples_match(struct tuple *s, struct tuple *t);
00276 extern unsigned int random_int(void);
00277 extern int send_chunk(struct context *ctx, char *buf, int bytes_to_send);
00278 extern int send_tuple(struct context *ctx, struct tuple *t);
00279 extern int recv_chunk(struct context *ctx, char *buf, int size);
00280 extern struct tuple *recv_tuple(struct context *ctx);
00281 extern int put_tuple(struct tuple *s, struct context *ctx);
00282 extern struct tuple *get_tuple(struct tuple *s, struct context *ctx);
00283 extern struct tuple *read_tuple(struct tuple *s, struct context *ctx);
00284 extern struct tuple *get_nb_tuple(struct tuple *s, struct context *ctx);
00285 extern struct tuple *read_nb_tuple(struct tuple *s, struct context *ctx);
00286 extern struct tuple_list *dump_tuple_space(struct tuple_list *templates,
00287                                            struct context *ctx);
00288 extern int tuple_server_log(FILE *stream, struct context *ctx);
00289 extern int tuple_int_field(struct tuple *s, int n);
00290 extern double tuple_double_field(struct tuple *s, int n);
00291 extern char *tuple_string_field(struct tuple *s, int *len, int n);
00292 
00293 #endif /* TUPLE_H_INCLUDED */

Generated on Sun Mar 30 23:46:50 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002