TSP: The Transport Sample Protocol



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

gdisp_hosts.c

Go to the documentation of this file.
00001 
00043 /*
00044  * System includes.
00045  */
00046 #include <stdio.h>
00047 #include <assert.h>
00048 #include <string.h>
00049 
00050 
00051 /*
00052  * GDISP+ includes.
00053  */
00054 #include "gdisp_kernel.h"
00055 #include "gdisp_prototypes.h"
00056 
00057 
00058 /*
00059  --------------------------------------------------------------------
00060                              STATIC ROUTINES
00061  --------------------------------------------------------------------
00062 */
00063 
00064 /*
00065  * Find a host by its name.
00066  */
00067 static Host_T*
00068 gdisp_findHostByName ( Kernel_T *kernel,
00069                        gchar    *hostName )
00070 {
00071 
00072   Host_T *host     = (Host_T*)NULL;
00073   GList  *hostItem =  (GList*)NULL;
00074 
00075   /*
00076    * Loop over the kernel host list.
00077    */
00078   hostItem = g_list_first(kernel->hostList);
00079   while (hostItem != (GList*)NULL) {
00080 
00081     host = (Host_T*)hostItem->data;
00082 
00083     if (strcmp(host->hName->str,hostName) == 0) {
00084       return host;
00085     }
00086 
00087     hostItem = g_list_next(hostItem);
00088 
00089   }
00090 
00091   return (Host_T*)NULL;
00092 
00093 }
00094 
00095 
00096 /*
00097  --------------------------------------------------------------------
00098                              PUBLIC ROUTINES
00099  --------------------------------------------------------------------
00100 */
00101 
00102 
00103 /*
00104  * Build the host list according to user specifications.
00105  */
00106 void
00107 gdisp_addHost ( Kernel_T *kernel,
00108                 gchar    *hostName )
00109 {
00110 
00111   Host_T *host = (Host_T*)NULL;
00112 
00113 
00114   /*
00115    * Add a new host into the host list, if this host does not already exist.
00116    */
00117   if (gdisp_findHostByName(kernel,hostName) == (Host_T*)NULL) {
00118 
00119     /*
00120      * Allocate a host structure.
00121      */
00122     host = g_malloc0(sizeof(Host_T));
00123     assert(host);
00124 
00125     host->hName = g_string_new(hostName);
00126 
00127     /*
00128      * Insert this new host into the host list.
00129      */
00130     kernel->hostList = g_list_append(kernel->hostList,
00131                                      (gpointer)host);
00132 
00133   }
00134 
00135 }
00136 
00137 
00138 /*
00139  * Build the URL list according to user specifications.
00140  */
00141 void
00142 gdisp_addUrl ( Kernel_T *kernel,
00143                gchar    *urlName )
00144 {
00145 
00146   gchar *url = (gchar*)NULL;
00147 
00148   /*
00149    * Duplicate URL name
00150    */
00151   url = strdup(urlName);
00152   assert(url);
00153 
00154   /*
00155    * Insert this new URL into the kernel URL list.
00156    */
00157   kernel->urlList = g_list_append(kernel->urlList,
00158                                   (gpointer)url);
00159 
00160 }
00161 
00162 
00163 /*
00164  * Destroy host list.
00165  */
00166 void
00167 gdisp_destroyHosts ( Kernel_T *kernel )
00168 {
00169 
00170   GList  *hostItem =  (GList*)NULL;
00171   Host_T *host     = (Host_T*)NULL;
00172 
00173 
00174   /*
00175    * Release all hosts.
00176    */
00177   hostItem = g_list_first(kernel->hostList);
00178   while (hostItem != (GList*)NULL) {
00179 
00180     host = (Host_T*)hostItem->data;
00181 
00182     g_string_free(host->hName,TRUE);
00183 
00184     g_free(host);
00185 
00186     hostItem = g_list_next(hostItem);
00187 
00188   }
00189 
00190   g_list_free(kernel->hostList);
00191   kernel->hostList = (GList*)NULL;
00192 
00193 }
00194 
00195 
00196 /*
00197  * Destroy URL list.
00198  */
00199 void
00200 gdisp_destroyUrls ( Kernel_T *kernel )
00201 {
00202 
00203   GList  *urlItem = (GList*)NULL;
00204   gchar  *url     = (gchar*)NULL;
00205 
00206 
00207   /*
00208    * Release all URLs.
00209    */
00210   urlItem = g_list_first(kernel->urlList);
00211   while (urlItem != (GList*)NULL) {
00212 
00213     url = (gchar*)urlItem->data;
00214 
00215     g_free(url);
00216 
00217     urlItem = g_list_next(urlItem);
00218 
00219   }
00220 
00221   g_list_free(kernel->urlList);
00222   kernel->urlList = (GList*)NULL;
00223 
00224 }
Framework Home Page.

Beware !! TSP wave is coming...