00001
00002
00003
00004
00005
00006
00008 #include "JobControl/JobCPathRegistry.h"
00009 #include "MessageService/MsgService.h"
00010 #include "JobControl/JobCPath.h"
00011
00012 #include <cassert>
00013 #include <cstring>
00014
00015 using namespace std;
00016
00017 CVSID("$Id: JobCPathRegistry.cxx,v 1.9 2009/02/28 21:46:13 gmieg Exp $");
00018
00019
00020
00021 JobCPathRegistry::JobCPathRegistry()
00022 {
00023
00024 fPathList.reserve(10);
00025 }
00026
00027
00028
00029 JobCPathRegistry::~JobCPathRegistry()
00030 {
00031
00032
00033
00034 std::vector<JobCPath*>::iterator itrPath(fPathList.begin());
00035 std::vector<JobCPath*>::iterator itrEnd(fPathList.end());
00036 for (; itrPath != itrEnd; ++itrPath) {
00037 delete (*itrPath);
00038 }
00039 }
00040
00041
00042
00043 JobCModule* JobCPathRegistry::LookUpModule(const char* module) const
00044 {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 int nmatch = 0;
00057 JobCModule* jmtry;
00058 JobCModule* jm;
00059
00060
00061 jmtry = 0;
00062 jm = 0;
00063 vector<JobCPath*>::const_iterator itrPath(fPathList.begin());
00064 vector<JobCPath*>::const_iterator itrEnd(fPathList.end());
00065 for (; itrPath != itrEnd; ++itrPath) {
00066 jmtry = (*itrPath)->GetModule(module);
00067 if (jmtry!=0) {
00068 jm = jmtry;
00069 MSG("JobC",Msg::kVerbose) <<
00070 "Found " << module << " in path " << (*itrPath)->GetName() << "\n";
00071 ++nmatch;
00072 }
00073 }
00074
00075
00076
00077
00078 if (nmatch == 1) {
00079
00080 return jm;
00081 }
00082 else if (nmatch > 1) {
00083
00084 MSG("JobC",Msg::kWarning) <<
00085 "Module specification not unique!\n" <<
00086 " '" << module << "' matches " << nmatch << " possible modules.\n" <<
00087 " Please specify the path name for the module you want, eg:\n" <<
00088 " /[path_name]/[module_name]" << endl;
00089 return 0;
00090 }
00091
00092
00093 return 0;
00094 }
00095
00096
00097
00098 JobCPath* JobCPathRegistry::LookUpPath(const char* path) const
00099 {
00100
00101
00102
00103
00104
00105
00106
00107
00108 std::vector<JobCPath*>::const_iterator itrPath(fPathList.begin());
00109 std::vector<JobCPath*>::const_iterator itrEnd(fPathList.end());
00110 for (; itrPath != itrEnd; ++itrPath) {
00111 if (strcmp(path,(*itrPath)->GetName())==0) {
00112 return (*itrPath);
00113 }
00114 }
00115 return 0;
00116 }
00117
00118
00119
00120 JobCPath* JobCPathRegistry::MakePath(const char* name,
00121 MomNavigator* mom,
00122 JobCInputModule* inp)
00123 {
00124
00125
00126
00127
00128 JobCPath* path(this->LookUpPath(name));
00129 if (path != 0) {
00130 MSG("JobC",Msg::kWarning) <<
00131 " Path '" << name << "' already exists!\n";
00132 return 0;
00133 }
00134
00135
00136
00137 path = new JobCPath(name,mom,inp);
00138 assert(path);
00139 fPathList.push_back(path);
00140 #ifdef SITE_HAS_SIGC
00141 this->NewPath(path);
00142 #endif
00143 return path;
00144 }
00145
00146
00147
00148 void JobCPathRegistry::DeletePath(const char* path)
00149 {
00150
00151
00152
00153
00154 vector<JobCPath*>::iterator itrPath(fPathList.begin());
00155 vector<JobCPath*>::iterator itrEnd(fPathList.end());
00156 for (; itrPath != itrEnd; ++itrPath) {
00157 if (strcmp(path,(*itrPath)->GetName())==0) {
00158 delete (*itrPath);
00159 (*itrPath) = 0;
00160 fPathList.erase(itrPath);
00161 }
00162 }
00163 }
00164
00165
00166
00167 void JobCPathRegistry::Reset()
00168 {
00169
00170
00171
00172 std::vector<JobCPath*>::iterator itrPath(fPathList.begin());
00173 std::vector<JobCPath*>::iterator itrEnd(fPathList.end());
00174 for (; itrPath != itrEnd; ++itrPath) {
00175 delete (*itrPath);
00176 (*itrPath) = 0;
00177 }
00178 fPathList.erase(fPathList.begin(),itrEnd);
00179 }
00180