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.11 2003/07/10 14:02:12 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     return -1;
00066 
00067   yyparse();
00068 
00069   reduce_policies();
00070 
00071   return 0;
00072 }
00073 
00074 
00086 int getPluginNameAndArgs(lcmaps_db_entry_t** plugins)
00087 {
00088   const plugin_t* p_list, *tmp_p_list;
00089   int length, path_length;
00090   char* path;
00091 
00092   /*  Check if the plugins have been requested before.  */
00093   if (global_plugin_list) {
00094     *plugins = global_plugin_list;
00095     return 0;
00096   }
00097 
00098   /*  Set to a safe default value.  */
00099   *plugins = 0;
00100 
00101   path = strdup(pdl_path());
00102   path_length = strlen(path);
00103 
00104   if (path[path_length-1] != '/') {
00105     path = (char *)realloc(path, path_length+2);
00106     path[path_length] = '/';
00107     path[path_length+1] = '\0';
00108 
00109     path_length = strlen(path);
00110   }
00111 
00112   p_list = get_plugins();
00113 
00114   while (p_list) {
00115     lcmaps_db_entry_t* p;
00116 
00117     if (!*plugins) {
00118       *plugins = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00119       p = *plugins;
00120     } else {
00121       p->next = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00122       p = p->next;
00123     }
00124 
00125     /*  Copy the name and arguments while respecting max. lengths.  */
00126     strncpy(p->pluginname, path, LCMAPS_MAXPATHLEN);
00127     strncpy(p->pluginname+path_length, p_list->name, LCMAPS_MAXPATHLEN-path_length);
00128 
00129     if (p_list->args)
00130       strncpy(p->pluginargs, p_list->args, LCMAPS_MAXARGSTRING);
00131     else
00132       *p->pluginargs = '\0';
00133     p->next = 0;
00134 
00135     tmp_p_list = p_list->next;
00136 
00137     if (p_list->name)  free(p_list->name);
00138     if (p_list->args)  free(p_list->args);
00139     free(p_list);
00140 
00141     p_list = tmp_p_list;
00142 
00143     /*  Output some debug info.  */
00144     lcmaps_log_debug(1, "%s\n", p->pluginname);
00145     lcmaps_log_debug(1, "%s\n", p->pluginargs);
00146   }
00147 
00148   free(path);
00149 
00150   global_plugin_list = *plugins;
00151 
00152   return 0;
00153 }
00154 
00155 
00164 int runEvaluationManager(void)
00165 {
00166   const char* plugin_name;
00167   plugin_status_t result;
00168 
00169   lcmaps_log_debug(1, "runEvaluationManager called\n");
00170 
00171   result = EVALUATION_START;
00172   while (plugin_name=pdl_next_plugin(result)) {
00173     result = (runPlugin(plugin_name) ? EVALUATION_FAILURE : EVALUATION_SUCCESS);
00174 
00175     lcmaps_log_debug(1, "runEvaluationManager: running plugin: %s.\n", plugin_name);
00176     lcmaps_log_debug(1, "                    : result %s.\n", (result==EVALUATION_SUCCESS) ? "true" : "false");
00177 
00178     free(plugin_name);
00179   }
00180 
00181   return result==EVALUATION_SUCCESS ? 0 : 1;
00182 }
00183 
00184 
00195 int stopEvaluationManager(void)
00196 {
00197   lcmaps_log_debug(1, "stopEvaluationManager: cleaning up!\n");
00198 
00199   free_resources();
00200 
00201   free_lcmaps_db_entry();
00202 
00203   return 0;
00204 }
00205 
00206 
00216 int free_lcmaps_db_entry()
00217 {
00218   lcmaps_db_entry_t* plugin = global_plugin_list;
00219 
00220   while (plugin) {
00221     lcmaps_db_entry_t* tmp = plugin->next;
00222     free(plugin);
00223     plugin = tmp;
00224   }
00225 
00226   global_plugin_list = NULL;
00227 
00228   return 0;
00229 }

Generated at Fri Jul 11 18:37:43 2003 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001