TSP: The Transport Sample Protocol



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

gdispmain.c

Go to the documentation of this file.
00001 
00018 #include <unistd.h>
00019 #include <stdio.h>
00020 #include <assert.h>
00021 
00022 extern char *optarg;
00023 
00024 #include "interface.h"
00025 #include "page.h"
00026 
00027 
00031 TSP_provider_t tsp = 0;
00032 
00036 display_page* pages;
00037 
00043 variable*** index2vars;
00044 
00045 
00050 void init_tsp_index(void)
00051 {
00052   const TSP_consumer_symbol_requested_list_t* symbols;
00053   int i, j, k;
00054   variable* var;
00055   int maxid = 0;
00056 
00057   symbols = TSP_consumer_get_requested_sample(tsp);
00058   assert(symbols);
00059 
00060   for (i=0 ; i < symbols->len ; i++)
00061     {
00062       for (j=0; j < conf_data.nb_page; j++)
00063         {
00064           for (k=0; k < pages[j].variables->len; k++)
00065             {
00066               var =  g_ptr_array_index(pages[j].variables, k);        
00067               if(!strcmp(symbols->val[i].name, var->text) && (var->type != VAR_TITLE ) )
00068                 {
00069                   var->provider_global_index = symbols->val[i].index;
00070                 }
00071             }
00072         }      
00073     }
00074   
00075 }
00076 
00081 int get_nbvars_per_index(int index)
00082 {
00083  
00084   int j, k;
00085   variable* var;
00086   int nbvars = 0;
00087 
00088   for (j=0; j < conf_data.nb_page; j++)
00089     {
00090       for (k=0; k < pages[j].variables->len; k++)
00091         {
00092           var =  g_ptr_array_index(pages[j].variables, k);            
00093           if(var->provider_global_index == index)
00094             {
00095               nbvars++;
00096             }
00097         }
00098     }      
00099   
00100   return nbvars;
00101 
00102 }
00103 
00109 int get_index2vars_size(void)
00110 {
00111   const TSP_consumer_symbol_requested_list_t* symbols;
00112   int i;
00113   int maxid = 0;
00114 
00115   /* ask TSP the list of asked symbols */
00116   symbols = TSP_consumer_get_requested_sample(tsp);
00117   assert(symbols);
00118   
00119   /* find the max of all provider global index */
00120   for (i=0 ; i < symbols->len ; i++)
00121     {
00122       if (maxid < symbols->val[i].index )
00123         {
00124           maxid = symbols->val[i].index;
00125         }
00126     }
00127   
00128   return maxid+1;
00129 }
00130 
00131 
00132 
00137 void init_index2vars(void)
00138 {
00139   int size;
00140   int i, j, k;
00141   
00142 
00143   /* for each variable, when find the linked provider global id */
00144   init_tsp_index();
00145   
00146   size = get_index2vars_size();
00147                        
00148   index2vars = (variable***)calloc(size, sizeof(variable**));
00149   assert(index2vars);
00150 
00151   for( i = 0 ; i < size ; i++)
00152     {
00153       int nbvars = get_nbvars_per_index(i);
00154       int pos = 0;
00155       /* some index does not have any symbol */
00156       if(nbvars > 0)
00157         {
00158           /*Allocate room for all var with a trailing NULL */
00159           index2vars[i] = (variable**)calloc(nbvars + 1, sizeof(variable*));
00160           assert(index2vars[i]);
00161           
00162           /* fill the tab founding all var for the index i */
00163           for (j=0; j < conf_data.nb_page; j++)
00164             {
00165               for (k=0; k < pages[j].variables->len; k++)
00166                 {
00167                   variable* var =  g_ptr_array_index(pages[j].variables, k);          
00168                   if(var->provider_global_index == i)
00169                     {
00170                       index2vars[i][pos++] = var;
00171                     }
00172                 }                 
00173             }
00174         }
00175     }        
00176 }
00177 
00178 
00179 static int main_window_start(char* conf_file, char* tsp_prov_url)
00180 {
00181   int                   i, j, nitem, ts_ok;
00182   char                  *f, name[1024];
00183   GdkGCValues           gcvalues;
00184   /*Display                     dsp;*/
00185   GtkWidget       *widget;
00186 
00187   /*Scrollbar           v_scrollbar, h_scrollbar;*/
00188   int ret = FALSE;
00189 
00190   printf("Loading '%s' conf file\n", conf_file);
00191   /* Load configuration file  and initialise list of asked symbols */
00192   if (load_config(conf_file, &conf_data)) 
00193     {
00194       tsp = TSP_consumer_connect_url(tsp_prov_url);
00195       if(tsp)
00196         {
00197           if(TSP_consumer_request_open(tsp, 0, 0))
00198             {
00199               if(TSP_consumer_request_information(tsp))
00200                 {
00201                 
00202                   if(TSP_consumer_request_sample(tsp, &conf_data.tsp_requested))
00203                     {             
00204                     
00205                       /* Create the list of variable per provider global id */
00206                       init_index2vars();
00207                     
00208                       if(TSP_consumer_request_sample_init(tsp,0,0))
00209                         {
00210                           sprintf(name, "%s @ %s", conf_file, TSP_consumer_get_connected_name(tsp));
00211                           create_mainwin(&conf_data, name);
00212                         
00213                           ret = TRUE;
00214                         }
00215                       else
00216                         {
00217                           fprintf(stderr, "Error while initializing data stream '%s'\n", tsp_prov_url);
00218                         }
00219                     }
00220                   else
00221                     {
00222                       fprintf(stderr, "Error while asking for TSP symbols session on host '%s'\n", tsp_prov_url);
00223                     }
00224                 }
00225               else
00226                 {
00227                   fprintf(stderr, "Error while asking for TSP information on host '%s'\n", tsp_prov_url);
00228                 }
00229                 
00230             }
00231           else
00232             {
00233               fprintf(stderr, "Error while opening TSP session on host '%s'\n", tsp_prov_url);
00234             }         
00235         }
00236       else
00237         {
00238           fprintf(stderr, "unable to find any TSP provider on host '%s'\n", tsp_prov_url);
00239         }
00240     }
00241   
00242   return ret;
00243 }
00244 
00245 void usage(char *txt)
00246 {
00247   printf("\nUSAGE : %s -x fileconf.xml [-u tsp_serverURL]\n\n", txt);
00248   printf(TSP_URL_FORMAT_USAGE);
00249 }
00250 
00251 int
00252 main (int argc, char **argv) 
00253 {
00254   char myopt; /* Options */
00255   char* config_file = NULL;
00256   char* tsp_prov_url = "";
00257 
00258   gtk_init(&argc, &argv);
00259 
00260   if(!TSP_consumer_init(&argc, &argv))
00261     return -1;
00262                         
00263   while ((myopt = getopt(argc, argv, "u:x:h")) != -1)
00264     {
00265       switch(myopt)
00266         {
00267         case 'u': tsp_prov_url = optarg; break;
00268         case 'x': config_file = optarg; break;
00269         default: break;
00270         }
00271     }
00272  
00273   if(!config_file)
00274     {
00275       usage(argv[0]);
00276       return -1;
00277     }
00278 
00279   if(!main_window_start(config_file, tsp_prov_url))
00280     {
00281       usage(argv[0]);
00282       return -1;
00283     }
00284   
00285   gtk_main();
00286 }
Framework Home Page.

Beware !! TSP wave is coming...