TSP: The Transport Sample Protocol



Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

gdisp_main.c

Go to the documentation of this file.
00001 
00043 /*
00044  * System includes.
00045  */
00046 #include <stdio.h>
00047 #include <assert.h>
00048 #include <unistd.h>
00049 #include <libgen.h> /* basename function */
00050 
00051 
00052 /*
00053  * GDISP+ includes.
00054  */
00055 #include "gdisp_kernel.h"
00056 #include "gdisp_prototypes.h"
00057 
00058 
00059 /*
00060  --------------------------------------------------------------------
00061                              STATIC ROUTINES
00062  --------------------------------------------------------------------
00063 */
00064 
00065 /*
00066  * Usage.
00067  */
00068 static void
00069 gdisp_usage ( Kernel_T *kernel,
00070               gchar    *applicationName )
00071 {
00072 
00073   /*
00074    * Print application usage.
00075    */
00076   fprintf(stdout,
00077           "------------------------------------------------------------\n");
00078 
00079   fprintf(stdout,
00080           "Usage : %s [ -u url1 [ -u url2 ... ] ] [ -h host1 [ -h host2 ... ] ]\n",
00081           basename(applicationName));
00082 
00083   fprintf(stdout,
00084           "  -u : insert one or several specific URLs.\n");
00085   fprintf(stdout,
00086           "  -h : insert one or several additional hosts.\n");
00087 
00088   fprintf(stdout,
00089           "       'localhost' is always taken into account if no URL specified.\n");
00090 
00091   fprintf(stdout,
00092           "------------------------------------------------------------\n");
00093 
00094   fflush (stdout);
00095 
00096 }
00097 
00098 
00099 /*
00100  * Analyse all arguments given by the user.
00101  * Returns TRUE in case of error.
00102  */
00103 static gboolean
00104 gdisp_analyseUserArguments ( Kernel_T *kernel )
00105 {
00106 
00107   gint     opt      = 0;
00108   gboolean mustStop = FALSE;
00109 
00110   /*
00111    * The user can specify several host to be looked at, with the '-h' option.
00112    */
00113   while ((opt = getopt(kernel->argCounter,
00114                        kernel->argTable,
00115                        "h:u:")) != EOF) {
00116 
00117     switch (opt) {
00118 
00119     case 'h' :
00120       gdisp_addHost(kernel,optarg);
00121       break;
00122 
00123     case 'u' :
00124       gdisp_addUrl(kernel,optarg);
00125       break;
00126 
00127     default :
00128       mustStop = TRUE;
00129       break;
00130 
00131     } /* end switch */
00132 
00133   } /* end while */
00134 
00135   return mustStop;
00136 
00137 }
00138 
00139 
00140 /*
00141  --------------------------------------------------------------------
00142                              PUBLIC ROUTINES
00143  --------------------------------------------------------------------
00144 */
00145 
00146 
00147 /*
00148  * GDISP+ main part.
00149  */
00150 gint
00151 main (int argc, char **argv) 
00152 {
00153 
00154   Kernel_T *gdispKernel = (Kernel_T*)NULL;
00155   gboolean  mustStop    = FALSE;
00156 
00157 
00158   /*
00159    * Set up GTK+ things, such as the default visual and color map.
00160    * Initialize the library for use, sets up default signal handlers, and
00161    * checks the arguments passed to the application on the command line.
00162    */
00163   gtk_init(&argc, &argv);
00164 
00165 
00166   /*
00167    * Allocate memory for managing GDISP+ kernel.
00168    * Take into account user defined arguments passed to the application
00169    * on the command line.
00170    */
00171   gdispKernel = gdisp_createKernel(argc,argv);
00172 
00173 
00174   /*
00175    * Discover all options given by the user.
00176    */
00177   mustStop = gdisp_analyseUserArguments(gdispKernel);
00178   if (mustStop == TRUE) {
00179 
00180     /*
00181      * Write the usage.
00182      */
00183     gdisp_usage(gdispKernel,argv[0]);
00184 
00185     /*
00186      * Destroy kernel, and exit.
00187      */
00188     gdisp_destroyKernel(gdispKernel);
00189     return -1;
00190 
00191   }
00192 
00193 
00194   /*
00195    * Create GDISP+ main board.
00196    * The main board is a little window that offers all GDISP+ functions.
00197    */
00198   gdisp_createMainBoard(gdispKernel);
00199 
00200 
00201   /*
00202    * Write few information into the output window before starting.
00203    */
00204   gdisp_writeInitialInformation(gdispKernel);
00205 
00206 
00207   /*
00208    * Create our colormap.
00209    */
00210   gdisp_createColormap(gdispKernel);
00211 
00212 
00213   /*
00214    * Initialize consuming environment.
00215    */
00216   gdisp_consumingInit(gdispKernel);
00217 
00218 
00219   /*
00220    * Enter GTK main processing loop.
00221    * Sleep waiting for X events (such as button or key presses), timeouts,
00222    * file IO notifications to occur.
00223    */
00224   gtk_main();
00225 
00226 
00227   /*
00228    * Close consuming environment.
00229    */
00230   gdisp_consumingEnd(gdispKernel);
00231 
00232 
00233   /*
00234    * Destroy our colormap.
00235    */
00236   gdisp_destroyColormap(gdispKernel);
00237 
00238 
00239   /*
00240    * End of GDISP+ main part, by destroying kernel.
00241    */
00242   gdisp_destroyKernel(gdispKernel);
00243 
00244   return 0;
00245 
00246 }
Framework Home Page.

Beware !! TSP wave is coming...