Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/typehelper/typehelper.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001-2003 Peter Amstutz <tetron@interreality.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 */
00021 
00022 #ifndef _TYPEHELPER_HH_
00023 #define _TYPEHELPER_HH_
00024 
00025 #if defined(_WIN32) && defined(_MSC_VER)
00026 # ifdef TYPEHELPER_EXPORTS
00027 #  define TYPEHELPER_API __declspec(dllexport)
00028 # else
00029 #  define TYPEHELPER_API __declspec(dllimport)
00030 # endif
00031 #else
00032 # define TYPEHELPER_API
00033 #endif
00034 
00035 #include <list>
00036 #include <deque>
00037 #include <map>
00038 #include <set>
00039 #include <string>
00040 #include <stdexcept>
00041 
00042 using namespace std;
00043 
00044 /** Use a subclass of this class to specify action performed when a running
00045  * helper process ends by passing an instance to
00046  * TypeHeler::addProcessEndCallback().
00047  */
00048 class TYPEHELPER_API ProcessEndCallback
00049 {
00050 public:
00051     /// Override this method.
00052     virtual void notifyProcessTerminate(int pid) = 0;
00053 };
00054 
00055 /** A ProcessEndCallback that deletes a file when called. */
00056 class TYPEHELPER_API DeleteTempFile : public ProcessEndCallback
00057 {
00058 private:
00059     string file;
00060     set<int>* other_pids;
00061 public:
00062     /** Deletes a file when called back.
00063      * @param f     The name of the file to delete.
00064      */
00065     DeleteTempFile(const string& f);
00066 
00067     /** Removes the PID for the helper associated with this callback from
00068      * the given set of PIDs. If that set is then empty, then the file
00069      * is deleted and the PID set is freed from the heap.
00070      * Use a new instance of DeleteTempFile for each process, and pass each of
00071      * them a pointer to the PID set.
00072      * @param f         File to delete when the PID set becomes empty.
00073      * @param pidset    The PID set. If NULL, then behavior will be as described
00074      *                  in DeleteTempFile(const string&).
00075      */
00076     DeleteTempFile(const string& f, set<int>* pidset);
00077 
00078     virtual ~DeleteTempFile();
00079     virtual void notifyProcessTerminate(int pid);
00080 };
00081 
00082 class TYPEHELPER_API TypeHelper {
00083 private:
00084     string type;
00085     deque<string> parameters;
00086     string target;
00087     typedef enum { DATA, VOBJECT } RunFunc;
00088     RunFunc runFunc;
00089 
00090 public:
00091 
00092     TypeHelper() :
00093         runFunc(DATA)
00094     { }
00095 
00096     TypeHelper(string init_type) :
00097         type(init_type),
00098         runFunc(DATA)
00099     { }
00100 
00101     static void init(string filename);
00102     static deque<TypeHelper> findVobjectHelpers(const set<string>& s, const string& objpath);
00103     static deque<TypeHelper> findDataHelpers(const string& s, const string& tempfile);
00104     static void addHelper(const string& configline);
00105     static void addProcessEndCallback(int pid, ProcessEndCallback* pec);
00106     static void removeProcessEndCallback(int pid, ProcessEndCallback* pec);
00107     static void checkProcesses();
00108 
00109     string getType() { return type; }
00110     const deque<string>& getParameters() { return parameters; }
00111     string getCommand();
00112     int run();
00113 
00114     void setType(string t) { type = t; }
00115     void setParameters(deque<string> params) { parameters = params; }
00116     void setCommand(const string& cmd);
00117 };
00118 
00119 #endif

Generated on Tue Aug 12 03:55:39 2003 for Interreality Project - VOS by doxygen 1.3.2