JobCModuleRegistry Class Reference

#include <JobCModuleRegistry.h>

List of all members.

Public Member Functions

 ~JobCModuleRegistry ()
void Register (JobCModuleProxy *jobcModuleProxy)
JobCModuleProxyLookUp (const char *name, bool loadlibs=true)

Static Public Member Functions

static JobCModuleRegistryInstance ()

Private Member Functions

 JobCModuleRegistry ()
 JobCModuleRegistry (JobCModuleRegistry &)
JobCModuleRegistryoperator= (const JobCModuleRegistry &)
int BuildModToLibMap ()
int CheckLibMap (const std::string &mod)

Private Attributes

std::list< JobCModuleProxy * > fModuleTable
std::map< std::string, std::string > fModLibMap

Static Private Attributes

static JobCModuleRegistryfInstance = 0

Friends

struct Cleaner
std::ostream & operator<< (std::ostream &os, const JobCModuleRegistry &jcr)

Classes

struct  Cleaner


Detailed Description

Definition at line 39 of file JobCModuleRegistry.h.


Constructor & Destructor Documentation

JobCModuleRegistry::~JobCModuleRegistry (  ) 

Definition at line 37 of file JobCModuleRegistry.cxx.

00037 {}

JobCModuleRegistry::JobCModuleRegistry (  )  [private]

Definition at line 93 of file JobCModuleRegistry.cxx.

References BuildModToLibMap(), MsgService::GetStream(), MsgService::Instance(), Msg::kVerbose, and MsgStream::SetLogLevel().

00094 {
00095 #ifdef DEBUG_JOBC
00096 #include <MessageService/MsgStream.h>
00097   // Setting this debug level at run time is too late in this case...
00098   MsgService::Instance()->GetStream("JobC")->SetLogLevel(Msg::kVerbose);
00099 #endif
00100   this->BuildModToLibMap();
00101 }

JobCModuleRegistry::JobCModuleRegistry ( JobCModuleRegistry  )  [inline, private]

Definition at line 54 of file JobCModuleRegistry.h.

00054 { abort(); }


Member Function Documentation

int JobCModuleRegistry::BuildModToLibMap (  )  [private]

Definition at line 117 of file JobCModuleRegistry.cxx.

References fModLibMap, Msg::kWarning, len, and MSG.

Referenced by JobCModuleRegistry().

00118 {
00119 //======================================================================
00120 // Poke around looking for a "jobmodules.txt" file and use it to build
00121 // the map of which libraries provide which modules
00122 //======================================================================
00123 
00124   // Try to find a jobmodules file which lists which libraries provide
00125   // which modules
00126   FILE* fp = 0;
00127   // First try in the private release
00128   const char* tmp = getenv("SRT_PRIVATE_CONTEXT");
00129   if (!tmp) return 0;
00130   std::string modfile = tmp;
00131   modfile += "/tmp/jobmodules.txt";
00132   if ( (fp=fopen(modfile.c_str(),"r"))==0 ) {
00133     // Next, try the public release
00134     tmp = getenv("SRT_PUBLIC_CONTEXT");
00135     if (!tmp) return 0;
00136     std::string modfile = tmp;
00137     modfile += "/tmp/jobmodules.txt";
00138     if ( (fp=fopen(modfile.c_str(),"r"))==0 ) {
00139       // Finally try in /tmp
00140       modfile = "/tmp/jobmodules.txt";
00141       if ( (fp=fopen(modfile.c_str(),"r"))==0 ) {
00142         // Give up...
00143         return 0;
00144       }
00145     }
00146   }
00147   
00148   // To get here fp must be valid
00149   std::string lib = "";
00150   char buff[256];
00151   while (fgets(buff,255,fp)) {
00152     if (buff[0]=='#') continue;
00153 
00154     // Get rid of leading and training white space
00155     const char* b = buff;
00156     for (; *b==' ' && *b!='\0'; ++b);
00157     int len = strlen(buff)-1;
00158     for (; len>0 && (buff[len]==' '||buff[len]=='\n'); --len);
00159     buff[len+1] = '\0';
00160     
00161     // Figure out if entry is library or module
00162     len = strlen(b);
00163     if (len<2) continue;
00164     const char* tag = b + len - 3;
00165     if (strncmp(b,"lib",3)==0 && strncmp(tag, ".so",3)==0) {
00166       lib = b;
00167     }
00168     else {
00169       std::string module = b;
00170       if (fModLibMap[module]=="") {
00171         fModLibMap[module] = lib;
00172       }
00173       else {
00174         if (!(fModLibMap[module] == lib)) {
00175           MSG("JobC",Msg::kWarning) << 
00176             "Duplicate entry: " << 
00177             module << "->" << fModLibMap[module] << "," <<
00178             module << "->" << lib                << "." << 
00179             std::endl;
00180         }
00181       }
00182     }
00183   }
00184   fclose(fp);
00185   return 1;
00186 }

int JobCModuleRegistry::CheckLibMap ( const std::string &  mod  )  [private]

Definition at line 190 of file JobCModuleRegistry.cxx.

References fModLibMap, gSystem(), Msg::kWarning, and MSG.

00191 {
00192   std::string lib = fModLibMap[module];
00193   if (lib=="") {
00194     MSG("JobC",Msg::kWarning) << 
00195       "\n" <<
00196       "Unable to find module '"<<module<<"' in job module list.\n" <<
00197       "Consider regenerating list with 'makemodulemap' command or\n" <<
00198       "edit the $SRT_PRIVATE_CONTEXT/tmp/jobmodules.txt file by hand.\n";
00199     return 0;
00200   }
00201   if (gSystem) {
00202     if (gSystem->Load(lib.c_str())==0) {
00203       // Loaded OK, we can remove entries pointing at this library
00204       std::map<std::string,std::string>::iterator itr(fModLibMap.begin());
00205       std::map<std::string,std::string>::iterator itrEnd(fModLibMap.end());
00206       for (;itr!=itrEnd;++itr) {
00207         if (itr->first == lib) fModLibMap.erase(itr);
00208       }
00209       return 1;
00210     }
00211   }
00212   return 0;
00213 }

JobCModuleRegistry & JobCModuleRegistry::Instance (  )  [static]

Definition at line 105 of file JobCModuleRegistry.cxx.

References JobCModuleRegistry::Cleaner::ClassIsUsed(), and fInstance.

Referenced by JobCPath::GetModule(), JobController::Help(), JobCDisplayModule::Start(), and JobCInput::Use().

00106 {
00107   static JobCModuleRegistry::Cleaner c; // end-of-run clean up
00108   if (fInstance==0) {
00109     c.ClassIsUsed(); // Keeps compiler's quite if I "use" this object
00110     fInstance = new JobCModuleRegistry;
00111   }
00112   return *fInstance;
00113 }

JobCModuleProxy * JobCModuleRegistry::LookUp ( const char *  name,
bool  loadlibs = true 
)

Definition at line 73 of file JobCModuleRegistry.cxx.

References fModuleTable.

Referenced by JobCPath::GetModule(), JobController::Help(), JobCDisplayModule::Start(), and JobCInput::Use().

00074 {
00075   // Check if its in table
00076   list<JobCModuleProxy*>::iterator itrModuleTable;
00077   for (itrModuleTable  = fModuleTable.begin();
00078        itrModuleTable != fModuleTable.end();
00079        ++itrModuleTable) {
00080     if (strcmp(name,(*itrModuleTable)->GetName())==0) {
00081       return (*itrModuleTable);
00082     }
00083   }
00084   
00085   // Not in table... try loading libraries
00086   if (loadlib && this->CheckLibMap(name)) return this->LookUp(name);
00087 
00088   return 0;
00089 }

JobCModuleRegistry& JobCModuleRegistry::operator= ( const JobCModuleRegistry  )  [inline, private]

Definition at line 55 of file JobCModuleRegistry.h.

00055                                                                        { 
00056     abort(); return *this;
00057   }

void JobCModuleRegistry::Register ( JobCModuleProxy jobcModuleProxy  ) 

Definition at line 41 of file JobCModuleRegistry.cxx.

References fModuleTable, JobCModuleProxy::GetName(), Msg::kDebug, and MSG.

00042 {
00043   const char* modName = proxy->GetName();
00044   // Add the module to the table
00045   if (this->LookUp(modName,false)) {
00046     // MSG("JobC", Msg::kWarning)
00047     // << "A job module named " << modName << " is already registered!\n"
00048     // << "Duplicate module names are not allowed!\n";
00049     return;
00050   }
00051   else {
00052     // Do insertions in alphabetical order
00053     list<JobCModuleProxy*>::iterator itrModuleTable;
00054     for (itrModuleTable  = fModuleTable.begin();
00055          itrModuleTable != fModuleTable.end();
00056          ++itrModuleTable) {
00057       if (strcmp(modName,(*itrModuleTable)->GetName())<0) {
00058         break;
00059       }
00060     }
00061     fModuleTable.insert(itrModuleTable,proxy);
00062 #ifdef SITE_HAS_SIGC // temporary
00063     this->SigRegister(modName);
00064 #endif
00065     MSG("JobC", Msg::kDebug) 
00066       << "Registered job module " << modName << " " 
00067       << proxy << ".\n";
00068   }
00069 }


Friends And Related Function Documentation

friend struct Cleaner [friend]

Definition at line 69 of file JobCModuleRegistry.h.

std::ostream& operator<< ( std::ostream &  os,
const JobCModuleRegistry jcr 
) [friend]


Member Data Documentation

JobCModuleRegistry * JobCModuleRegistry::fInstance = 0 [static, private]

Definition at line 81 of file JobCModuleRegistry.h.

Referenced by Instance(), and JobCModuleRegistry::Cleaner::~Cleaner().

std::map<std::string,std::string> JobCModuleRegistry::fModLibMap [private]

Definition at line 83 of file JobCModuleRegistry.h.

Referenced by BuildModToLibMap(), and CheckLibMap().

std::list<JobCModuleProxy*> JobCModuleRegistry::fModuleTable [private]

Definition at line 82 of file JobCModuleRegistry.h.

Referenced by LookUp(), operator<<(), and Register().


The documentation for this class was generated from the following files:
Generated on Wed Dec 10 22:49:41 2014 for loon by  doxygen 1.4.7