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.14 2003/07/16 09:30:57 venekamp 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 
00036 #include <string.h>
00037 
00038 #include "lcmaps_log.h"
00039 #include "evaluationmanager.h"
00040 
00049 static lcmaps_db_entry_t* global_plugin_list = NULL;
00050 
00051 int free_lcmaps_db_entry();
00052 
00053 
00062 int startEvaluationManager(const char* name)
00063 {
00064   if (pdl_init(name) < 0) {
00065     stopEvaluationManager();
00066     return -1;
00067   }
00068 
00069   /*  Let's see if the config file makes sence.  */
00070   yyparse();
00071 
00072   /*
00073    *  Check if there were any errors. Ifo so, there is not much point
00074    *  on continuing.
00075    */
00076   if (yyparse_errors()) {
00077     stopEvaluationManager();
00078     return -1;
00079   }
00080 
00081   /*
00082    *  We need to replace the variables found in the policy rules by
00083    *  their respective values.
00084    */
00085   reduce_policies();
00086 
00087   return 0;
00088 }
00089 
00090 
00102 int getPluginNameAndArgs(lcmaps_db_entry_t** plugins)
00103 {
00104   const plugin_t* p_list, *tmp_p_list;
00105   int length, path_length;
00106   char* path;
00107 
00108   /*  Check if the plugins have been requested before.  */
00109   if (global_plugin_list) {
00110     *plugins = global_plugin_list;
00111     return 0;
00112   }
00113 
00114   /*  Set to a safe default value.  */
00115   *plugins = 0;
00116 
00117   if (!pdl_path()) {
00118     lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00119     return -1; 
00120   }
00121 
00122   path = strdup(pdl_path());
00123   path_length = strlen(path);
00124 
00125   if (path[path_length-1] != '/') {
00126     path = (char *)realloc(path, path_length+2);
00127     path[path_length] = '/';
00128     path[path_length+1] = '\0';
00129 
00130     path_length = strlen(path);
00131   }
00132 
00133   p_list = get_plugins();
00134 
00135   while (p_list) {
00136     lcmaps_db_entry_t* p;
00137 
00138     if (!*plugins) {
00139       *plugins = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00140       p = *plugins;
00141     } else {
00142       p->next = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00143       p = p->next;
00144     }
00145 
00146     /*  Copy the name and arguments while respecting max. lengths.  */
00147     strncpy(p->pluginname, path, LCMAPS_MAXPATHLEN);
00148     strncpy(p->pluginname+path_length, p_list->name, LCMAPS_MAXPATHLEN-path_length);
00149 
00150     if (p_list->args)
00151       strncpy(p->pluginargs, p_list->args, LCMAPS_MAXARGSTRING);
00152     else
00153       *p->pluginargs = '\0';
00154     p->next = 0;
00155 
00156     tmp_p_list = p_list->next;
00157 
00158     if (p_list->name)  free(p_list->name);
00159     if (p_list->args)  free(p_list->args);
00160     free(p_list);
00161 
00162     p_list = tmp_p_list;
00163 
00164     /*  Output some debug info.  */
00165     lcmaps_log_debug(1, "%s\n", p->pluginname);
00166     lcmaps_log_debug(1, "%s\n", p->pluginargs);
00167   }
00168 
00169   free(path);
00170 
00171   global_plugin_list = *plugins;
00172 
00173   return 0;
00174 }
00175 
00176 
00185 int runEvaluationManager(void)
00186 {
00187   const char* plugin_name;
00188   plugin_status_t result;
00189 
00190   lcmaps_log_debug(1, "runEvaluationManager called\n");
00191 
00192   result = EVALUATION_START;
00193   while (plugin_name=pdl_next_plugin(result)) {
00194     result = (runPlugin(plugin_name) ? EVALUATION_FAILURE : EVALUATION_SUCCESS);
00195 
00196     lcmaps_log_debug(1, "runEvaluationManager: running plugin: %s.\n", plugin_name);
00197     lcmaps_log_debug(1, "                    : result %s.\n", (result==EVALUATION_SUCCESS) ? "true" : "false");
00198 
00199     free(plugin_name);
00200   }
00201 
00202   if (result==EVALUATION_START)
00203     lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00204 
00205   return result==EVALUATION_SUCCESS ? 0 : 1;
00206 }
00207 
00208 
00219 int stopEvaluationManager(void)
00220 {
00221   lcmaps_log_debug(1, "stopEvaluationManager: cleaning up!\n");
00222 
00223   free_resources();
00224 
00225   free_lcmaps_db_entry();
00226 
00227   return 0;
00228 }
00229 
00230 
00240 int free_lcmaps_db_entry()
00241 {
00242   lcmaps_db_entry_t* plugin = global_plugin_list;
00243 
00244   while (plugin) {
00245     lcmaps_db_entry_t* tmp = plugin->next;
00246     free(plugin);
00247     plugin = tmp;
00248   }
00249 
00250   global_plugin_list = NULL;
00251 
00252   return 0;
00253 }

Generated at Wed Jul 16 16:33:34 2003 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001