Back to index

nordugrid-arc-nox  1.1.0~rc6
run_plugin.h
Go to the documentation of this file.
00001 #ifndef GRID_MANAGER_RUN_PLUGIN_H
00002 #define GRID_MANAGER_RUN_PLUGIN_H
00003 
00004 //@ #include "../std.h"
00005 #include <sys/resource.h>
00006 #include <sys/wait.h>
00007 #include <string>
00008 #include <list>
00009 #include <pthread.h>
00010 
00011 extern char** environ;
00012 
00013 
00014 class RunPlugin {
00015  private:
00016   std::list<std::string> args_;
00017   std::string lib;
00018   std::string stdin_;
00019   std::string stdout_;
00020   std::string stderr_;
00021   int timeout_;
00022   int result_;
00023   void set(const std::string& cmd);
00024   void set(char const * const * args);
00025  public:
00026   typedef void (*substitute_t)(std::string& str,void* arg);
00027   union lib_plugin_t {
00028     int (*f)(...);
00029     void* v;
00030   };
00031   RunPlugin(void):timeout_(10),result_(0) { };
00032   RunPlugin(const std::string& cmd):timeout_(10),result_(0) { set(cmd); };
00033   RunPlugin(char const * const * args):timeout_(10),result_(0) { set(args); };
00034   void operator=(const std::string& cmd) { set(cmd); };
00035   void operator=(char const * const * args) { set(args); };
00036   bool run(void);
00037   bool run(substitute_t subst,void* arg);
00038   int result(void) const { return result_; };
00039   void timeout(int t) { timeout_=t; };
00040   void stdin_channel(const std::string& s) { stdin_=s; };
00041   const std::string& stdout_channel(void) const { return stdout_; };
00042   const std::string& stderr_channel(void) const { return stderr_; };
00043   operator bool(void) const { return (args_.size() > 0); };
00044 };
00045 
00046 class RunPlugins {
00047  private:
00048   std::list<RunPlugin*> plugins_;
00049   int result_;
00050  public:
00051   RunPlugins(void):result_(0) { };
00052   void add(const std::string& cmd);
00053   bool run(void);
00054   bool run(RunPlugin::substitute_t subst,void* arg);
00055   int result(void) { return result_; };
00056 };
00057 
00058 void free_args(char** args);
00059 char** string_to_args(const std::string& command);
00060 
00061 #endif // GRID_MANAGER_RUN_PLUGIN_H