00001
00002
00003
00004
00005
00006
00008 #ifndef JOBCMODULEREGISTRY_H
00009 #define JOBCMODULEREGISTRY_H
00010
00011 #include <cassert>
00012 #ifndef LIST
00013 #include <list>
00014 #define LIST
00015 #endif
00016 #ifndef MAP
00017 #include <map>
00018 #define MAP
00019 #endif
00020 #ifndef STRING
00021 #include <string>
00022 #define STRING
00023 #endif
00024 #ifndef JOBCMODULEPROXY_H
00025 #include "JobControl/JobCModuleProxy.h"
00026 #endif
00027 #ifndef __CINT__ // CINT can't possibly understand this. Its C++!
00028 # ifdef SITE_HAS_SIGC // temporary work around
00029 # ifndef SIGNAL_SYSTEM_H
00030 # include <sigc++/signal.h>
00031 # define SIGNAL_SYSTEM_H
00032 # endif
00033 # endif
00034 #endif
00035
00036 class JobCModule;
00037
00038 class JobCModuleRegistry
00039 {
00040 friend std::ostream& operator<<(std::ostream& os,
00041 const JobCModuleRegistry& jcr);
00042 public:
00043 ~JobCModuleRegistry();
00044
00045 static JobCModuleRegistry& Instance();
00046
00047 void Register(JobCModuleProxy *jobcModuleProxy);
00048 JobCModuleProxy* LookUp(const char *name, bool loadlibs=true);
00049
00050 private:
00051
00052 JobCModuleRegistry();
00053 JobCModuleRegistry(JobCModuleRegistry& ) { abort(); }
00054 JobCModuleRegistry& operator=(const JobCModuleRegistry& ) {
00055 abort(); return *this;
00056 }
00057 int BuildModToLibMap();
00058 int CheckLibMap(const std::string& mod);
00059 struct Cleaner {
00060 void ClassIsUsed() { }
00061 ~Cleaner() {
00062 if (JobCModuleRegistry::fInstance!=0) {
00063 delete JobCModuleRegistry::fInstance;
00064 JobCModuleRegistry::fInstance = 0;
00065 }
00066 }
00067 };
00068 friend struct Cleaner;
00069
00070 #ifdef SITE_HAS_SIGC // temporary
00071 # ifndef __CINT__
00072 public:
00073
00074
00075 SigC::Signal1<void,const char*> SigRegister;
00076 # endif
00077 #endif
00078
00079 private:
00080 static JobCModuleRegistry* fInstance;
00081 std::list<JobCModuleProxy*> fModuleTable;
00082 std::map<std::string,std::string> fModLibMap;
00083 };
00084
00085
00087
00088
00089
00091 #define JOBMODULE(CLASS, NAME, FUNC) \
00092 static class gs__Register__##CLASS##__ : public JobCModuleProxy { \
00093 public: \
00094 gs__Register__##CLASS##__() { \
00095 fName = NAME; \
00096 fFunc = FUNC; \
00097 JobCModuleRegistry::Instance().Register(this); \
00098 } \
00099 JobCModule *CreateModule() { \
00100 JobCModule* m = new CLASS(); \
00101 m->Init(NAME); \
00102 return m; \
00103 } \
00104 } gs__module__##CLASS##__proxy__
00105
00106 #endif // JOBCMODULEREGISTRY_H