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

evaluationmanager.c

Go to the documentation of this file.
00001 /*
00002  *   Copyright (c) 2003 EU DataGrid        http://www.eu-datagrid.org/
00003  *
00004  *   $Id: evaluationmanager.c,v 1.21 2003/08/15 12:55:40 martijn Exp $
00005  *
00006  *   Copyright (c) 2003 by
00007  *      G.M. Venekamp <venekamp@nikhef.nl>
00008  *      NIKHEF Amsterdam, the Netherlands
00009  *
00010  *   This software is distributed under a BSD-style open source
00011  *   licence. For a complete description of the licence take a look
00012  *   at: http://eu-datagrid.web.cern.ch/eu-datagrid/license.html
00013  *
00014  */
00015 
00016 
00035 #include <stdlib.h>
00036 #include <string.h>
00037 
00038 #include "_lcmaps_pluginmanager.h"
00039 #include "lcmaps_log.h"
00040 #include "evaluationmanager.h"
00041 
00050 static lcmaps_db_entry_t* global_plugin_list = NULL;
00051 
00052 int free_lcmaps_db_entry();
00053 
00054 
00063 int startEvaluationManager(const char* name)
00064 {
00065   if (pdl_init(name) < 0) {
00066     stopEvaluationManager();
00067     return -1;
00068   }
00069 
00070   /*  Let's see if the config file makes sence.  */
00071   yyparse();
00072 
00073   /*
00074    *  Check if there were any errors. Ifo so, there is not much point
00075    *  on continuing.
00076    */
00077   if (yyparse_errors()) {
00078     stopEvaluationManager();
00079     return -1;
00080   }
00081 
00082   /*
00083    *  Check to see if there are any recustions in the config file.
00084    *  If so, continuing might/will cause an infinite loop.
00085    */
00086   if (check_policies_for_recursion())
00087     return -1;
00088 
00089   /*
00090    *  We need to replace the variables found in the policy rules by
00091    *  their respective values.
00092    */
00093   reduce_policies();
00094 
00095   return 0;
00096 }
00097 
00098 
00110 int getPluginNameAndArgs(lcmaps_db_entry_t** plugins)
00111 {
00112   const plugin_t* p_list, *tmp_p_list;
00113   lcmaps_db_entry_t* p=0;
00114   int path_length;
00115   char* path;
00116   BOOL string_too_long;
00117 
00118   string_too_long = FALSE;
00119 
00120   /*  Check if the plugins have been requested before.  */
00121   if (global_plugin_list) {
00122     *plugins = global_plugin_list;
00123     return 0;
00124   }
00125 
00126   /*  Set to a safe default value.  */
00127   *plugins = 0;
00128 
00129   if (!pdl_path()) {
00130     lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00131     return -1; 
00132   }
00133 
00134   path = strdup(pdl_path());
00135   path_length = strlen(path);
00136 
00137   if (path[path_length-1] != '/') {
00138     path = (char *)realloc(path, path_length+2);
00139     path[path_length] = '/';
00140     path[path_length+1] = '\0';
00141 
00142     path_length = strlen(path);
00143   }
00144 
00145   p_list = get_plugins();
00146 
00147   while (p_list) {
00148     if (!*plugins) {
00149       *plugins = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00150       p = *plugins;
00151     } else {
00152       p->next = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00153       p = p->next;
00154     }
00155 
00156     /*  Copy the name and arguments while respecting max. lengths.  */
00157     strncpy(p->pluginname, path, LCMAPS_MAXPATHLEN);
00158     strncpy(p->pluginname+path_length, p_list->name, LCMAPS_MAXPATHLEN-path_length);
00159 
00160     if ((strlen(path) + strlen(p_list->name))>=LCMAPS_MAXPATHLEN) {
00161       lcmaps_log(1, "String too long to copy. Max length = %d\n", LCMAPS_MAXPATHLEN);
00162       string_too_long = TRUE;
00163     }
00164 
00165     if (p_list->args) {
00166       strncpy(p->pluginargs, p_list->args, LCMAPS_MAXARGSTRING);
00167       if (strlen(p_list->args)>LCMAPS_MAXARGSTRING) {
00168         lcmaps_log(1, "String too long to copy. Max length = %d\n", LCMAPS_MAXARGSTRING);
00169         string_too_long = TRUE;
00170       }
00171     }
00172     else
00173       *p->pluginargs = '\0';
00174     p->next = 0;
00175 
00176     tmp_p_list = p_list->next;
00177 
00178     if (p_list->name)  free(p_list->name);
00179     if (p_list->args)  free(p_list->args);
00180     free((plugin_t*)p_list);
00181 
00182     p_list = tmp_p_list;
00183 
00184     /*  Output some debug info.  */
00185     lcmaps_log_debug(1, "%s\n", p->pluginname);
00186     lcmaps_log_debug(1, "%s\n", p->pluginargs);
00187   }
00188 
00189   free(path);
00190 
00191   global_plugin_list = *plugins;
00192 
00193   return string_too_long ? -1 : 0;
00194 }
00195 
00196 
00205 int runEvaluationManager(void)
00206 {
00207   const char* plugin_name;
00208   plugin_status_t result;
00209   policy_t* policy;
00210 
00211   lcmaps_log_debug(1, "runEvaluationManager called\n");
00212 
00213   result = EVALUATION_START;
00214   while ((plugin_name=pdl_next_plugin(result))) {
00215     result = (runPlugin(plugin_name) ? EVALUATION_FAILURE : EVALUATION_SUCCESS);
00216     
00217     lcmaps_log_debug(1, "runEvaluationManager: running plugin: %s.\n", plugin_name);
00218     lcmaps_log_debug(1, "                    : result %s.\n", (result==EVALUATION_SUCCESS) ? "true" : "false");
00219     
00220     free((char *)plugin_name);
00221   }
00222 
00223   if (result==EVALUATION_START)
00224     lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00225 
00226   return result==EVALUATION_SUCCESS ? 0 : 1;
00227 }
00228 
00229 
00240 int stopEvaluationManager(void)
00241 {
00242   lcmaps_log_debug(1, "stopEvaluationManager: cleaning up!\n");
00243 
00244   free_resources();
00245 
00246   free_lcmaps_db_entry();
00247 
00248   return 0;
00249 }
00250 
00251 
00261 int free_lcmaps_db_entry()
00262 {
00263   lcmaps_db_entry_t* plugin = global_plugin_list;
00264 
00265   while (plugin) {
00266     lcmaps_db_entry_t* tmp = plugin->next;
00267     free(plugin);
00268     plugin = tmp;
00269   }
00270 
00271   global_plugin_list = NULL;
00272 
00273   return 0;
00274 }

Generated at Tue Sep 23 15:48:08 2003 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001