Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members  

/home/micah/picogui/pg1/client/c/src/clientlib.h

Go to the documentation of this file.
00001 /* $Id: clientlib.h 3806 2003-05-04 06:11:21Z micah $
00002  *
00003  * clientlib.h - definitions used only within the client library code itself
00004  *
00005  * PicoGUI small and efficient client/server GUI
00006  * Copyright (C) 2000 Micah Dowty <micahjd@users.sourceforge.net>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  * 
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021  * 
00022  * Contributors: 
00023  * Philippe Ney <philippe.ney@smartdata.ch>
00024  * Brandon Smith <lottabs2@yahoo.com>
00025  * 
00026  * 
00027  */
00028 
00029 #ifndef _CLIENTLIB_H
00030 #define _CLIENTLIB_H
00031 
00032 
00033 /* System includes */
00034 #include <sys/types.h>
00035 #ifndef __NetBSD__
00036 #include <fcntl.h>
00037 #include <sys/types.h>
00038 #include <sys/time.h>
00039 #include <sys/socket.h>
00040 #include <sys/ioctl.h>
00041 #include <unistd.h>
00042 #include <netinet/tcp.h>
00043 #include <sys/stat.h>
00044 #else
00045 #include <sys/types.h>
00046 #include <sys/time.h>  /* for time_t type (used in timeval structure) */
00047 #include <sys/stat.h>
00048 #include <netinet/tcp.h>
00049 #include <sys/socket.h>
00050 #endif
00051 #include <fcntl.h>
00052 #ifndef CONFIG_UNIX_SOCKET
00053 #include <netinet/in.h>
00054 #else
00055 #include <sys/un.h>
00056 #endif
00057 #include <netdb.h>
00058 #include <stdio.h>    /* for fprintf() */
00059 
00060 /* FIXME: Check for Mac OS X using autoconf */
00061 #if (defined(__APPLE__) && defined(__MACH__)) // Mac OS X and Darwin 
00062 #include <sys/malloc.h>
00063 #else
00064 #include <malloc.h>
00065 #endif
00066 
00067 #include <signal.h>
00068 #include <unistd.h>   /* select() */
00069 #include <string.h>   /* for memcpy(), memset(), strcpy() */
00070 #include <stdarg.h>   /* needed for pgRegisterApp and pgSetWidget */
00071 #include <stdlib.h>   /* for getenv() */
00072 
00073 #ifdef __NetBSD__
00074 #include <unistd.h>
00075 #endif
00076 
00077 /* PicoGUI */
00078 #include <picogui.h>            /* Basic PicoGUI include */
00079 #include <picogui/network.h>    /* Network interface to the server */
00080 
00081 //#define DEBUG
00082 //#define DEBUG_EVT
00083 
00084 /* Default server */
00085 #ifndef CONFIG_UNIX_SOCKET 
00086 #  define PG_REQUEST_SERVER       "127.0.0.1"
00087 #else
00088 #  define PG_REQUEST_SERVER       "/var/tmp/.pgui"
00089 #endif
00090 
00091 /* Buffer size. When packets don't need to be sent immediately,
00092  * they accumulate in this buffer. It doesn't need to be very big
00093  * because most packets are quite small. Large packets like bitmaps
00094  * won't fit here anyway, so they are sent immediately.
00095  */
00096 #define PG_REQBUFSIZE           512
00097 
00098 /* A node in the list of event handlers set with pgBind */
00099 struct _pghandlernode {
00100   pghandle widgetkey;
00101   s16 eventkey;
00102   pgevthandler handler;
00103   void *extra;
00104   struct _pghandlernode *next;
00105 };
00106 
00107 /* Structure for a retrieved and validated response code,
00108    the data collected by _pg_flushpackets is stored here. */
00109 struct _pg_return_type {
00110   s16 type;
00111   union {
00112 
00113     /* if type == PG_RESPONSE_RET */
00114     u32 retdata;
00115 
00116     /* if type == PG_RESPONSE_EVENT */
00117     struct pgEvent event;
00118 
00119     /* if type == PG_RESPONSE_DATA */
00120     struct {
00121       u32 size;
00122       void *data;         /* Dynamically allocated - should be freed and
00123                              set to NULL when done, or it will be freed
00124                              next time flushpackets is called */
00125     } data;
00126 
00127   } e;  /* e for extra? ;-) */
00128 };
00129 
00130 /* Global vars for the client lib */
00131 extern int _pgsockfd;                  /* Socket fd to the pgserver */
00132 extern s16 _pgrequestid;             /* Request ID to detect errors */
00133 extern s16 _pgdefault_rship;         /* Default relationship and widget */
00134 extern pghandle _pgdefault_widget;        /*    when 0 is used */
00135 extern unsigned char _pgeventloop_on;  /* Boolean - is event loop running? */
00136 extern unsigned char _pgreqbuffer[PG_REQBUFSIZE];  /* Buffer of request packets */
00137 extern s16 _pgreqbuffer_size;        /* # of bytes in reqbuffer */
00138 extern s16 _pgreqbuffer_count;       /* # of packets in reqbuffer */
00139 extern s16 _pgreqbuffer_lasttype;    /* Type of last packet, indication of what return
00140                                         * packet should be sent */
00141 extern void (*_pgerrhandler)(u16 errortype,const char *msg); /* Error handler */
00142 extern struct _pghandlernode *_pghandlerlist;  /* List of pgBind event handlers */
00143 
00144 extern struct timeval _pgidle_period;  /* Period before calling idle handler */
00145 extern pgidlehandler _pgidle_handler;  /* Idle handler */
00146 extern unsigned char _pgidle_lock;     /* Already in idle handler? */
00147 extern char *_pg_appname;             /* Name of the app's binary */
00148 extern pgselecthandler _pgselect_handler;   /* Normally a pointer to select() */
00149 extern struct _pg_return_type _pg_return; /* Response from _pg_flushpackets */
00150 
00151 /* If this is nonzero, the application should be created in this container
00152  * instead of a new app in pgRegisterApp
00153  */
00154 extern pghandle _pg_appletbox;
00155 
00156 #define clienterr(msg)        (*_pgerrhandler)(PG_ERRT_CLIENT,msg)
00157 
00158 /**** Internal functions (netcore.c) */
00159 
00160 /* IO wrappers.  On error, they return nonzero and call clienterr() */
00161 int _pg_send(void *data,u32 datasize);
00162 int _pg_recv(void *data,u32 datasize);
00163 
00164 /* Wait for a new event, recieves the type code. This is used 
00165  * when an idle handler or other interruption is needed */
00166 int _pg_recvtimeout(s16 *rsptype);
00167 
00168 /* Malloc wrapper. Reports errors */
00169 void *_pg_malloc(size_t size);
00170 
00171 /* Default error handler (this should never be called directly) */
00172 void _pg_defaulterr(u16 errortype,const char *msg);
00173 
00174 /* Put a request into the queue */
00175 void _pg_add_request(s16 reqtype,void *data,u32 datasize);
00176 
00177 /* Receive a response packet and store its contents in _pg_return
00178  * (handling errors if necessary)
00179  *
00180  * If 'eventloop' is nonzero, this is waiting for a response from the
00181  * 'wait' packet and it's ok to use _pg_recvtimeout to process client-defined
00182  * things.
00183  */
00184 void _pg_getresponse(int eventwait);
00185 
00186 /* Get rid of a pgmemdata structure when done with it */
00187 void _pg_free_memdata(struct pgmemdata memdat);
00188 
00189 /* Format a message in a dynamically allocated buffer */
00190 char * _pg_dynformat(const char *fmt,va_list ap);
00191 
00192 /* Idle handler */
00193 void _pg_idle(void);
00194 
00195 /**** Platform-dependant functions (platform.c) */
00196 
00197 #ifdef UCLINUX
00198   int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
00199 #endif
00200 
00201 #endif /* _CLIENTLIB_H */
00202 
00203 /* The End */

Generated on Fri May 23 03:39:45 2003 for PicoGUI by doxygen1.3-rc3