41 DECLARE_EXPORT const MetaCategory* MetaCategory::firstCategory = NULL;
72 static bool init =
false;
75 logger <<
"Warning: Calling frepple::LibraryUtils::initialize() more "
76 <<
"than once." << endl;
90 #if defined(HAVE_SETLOCALE) || defined(_MSC_VER)
91 setlocale(LC_ALL,
"" );
95 xercesc::XMLPlatformUtils::Initialize();
103 "Dynamically load a module in memory.");
110 static char pathseperator =
'\\';
112 static char pathseperator =
'/';
117 int result = stat(filename.c_str(), &stat_p);
118 if (!result && (stat_p.st_mode & S_IREAD))
123 char * envvar = getenv(
"FREPPLE_HOME");
127 if (*fullname.rbegin() != pathseperator)
128 fullname += pathseperator;
129 fullname += filename;
130 result = stat(fullname.c_str(), &stat_p);
131 if (!result && (stat_p.st_mode & S_IREAD))
137 fullname = DATADIRECTORY;
138 if (*fullname.rbegin() != pathseperator)
139 fullname += pathseperator;
140 fullname.append(filename);
141 result = stat(fullname.c_str(), &stat_p);
142 if (!result && (stat_p.st_mode & S_IREAD))
148 fullname = LIBDIRECTORY;
149 if (*fullname.rbegin() != pathseperator)
150 fullname += pathseperator;
151 fullname +=
"frepple";
152 fullname += pathseperator;
153 fullname += filename;
154 result = stat(fullname.c_str(), &stat_p);
155 if (!result && (stat_p.st_mode & S_IREAD))
159 #ifdef SYSCONFDIRECTORY
161 fullname = SYSCONFDIRECTORY;
162 if (*fullname.rbegin() != pathseperator)
163 fullname += pathseperator;
164 fullname += filename;
165 result = stat(fullname.c_str(), &stat_p);
166 if (!result && (stat_p.st_mode & S_IREAD))
178 if (processorcores >= 1)
return processorcores;
184 GetSystemInfo(&sysinfo);
185 processorcores = sysinfo.dwNumberOfProcessors;
189 processorcores = sysconf(_SC_NPROCESSORS_ONLN);
192 if (processorcores<1) processorcores = 1;
193 return processorcores;
200 if (!logfilename.empty())
204 if (logfile.is_open()) logfile.close();
207 if (x.empty() || x ==
"+")
210 logger.rdbuf(cout.rdbuf());
215 if (x[0] !=
'+') logfile.open(x.c_str(), ios::out);
216 else logfile.open(x.c_str()+1, ios::app);
220 if (logfile.is_open()) logfile.close();
221 logfile.open(logfilename.c_str(), ios::app);
222 logger.rdbuf(logfile.is_open() ? logfile.rdbuf() : cout.rdbuf());
231 logger.rdbuf(logfile.rdbuf());
235 << __DATE__ <<
") at " <<
Date::now() << endl;
246 throw DataException(
"Error: No library name specified for loading");
252 UINT em = SetErrorMode(SEM_FAILCRITICALERRORS);
253 HINSTANCE handle = LoadLibraryEx(lib.c_str(),NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
254 if (!handle) handle = LoadLibraryEx(lib.c_str(), NULL, 0);
260 FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
273 reinterpret_cast<func
>(GetProcAddress(HMODULE(handle),
"initialize"));
279 FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
294 if (fullpath.empty())
297 void *handle = dlopen(fullpath.c_str(), RTLD_NOW | RTLD_GLOBAL);
298 const char *err = dlerror();
303 handle = dlopen(lib.c_str(), RTLD_NOW | RTLD_GLOBAL);
309 func inithandle = (func)(dlsym(handle,
"initialize"));
315 string x = (inithandle)(parameters);
319 moduleRegistry.insert(x);
324 bool def, creatorDefault f)
333 +
" not found when registering class " + b);
336 type = b.empty() ?
"unspecified" : b;
352 readController f, writeController w)
356 if (!gr.empty()) categoriesByGroupTag[
Keyword::hash(gr)] =
this;
361 type = a.empty() ?
"unspecified" : a;
363 group = gr.empty() ?
"unspecified" : gr;
369 firstCategory =
this;
373 while (i->nextCategory) i = i->nextCategory;
382 CategoryMap::const_iterator i = categoriesByTag.find(
Keyword::hash(c));
383 return (i!=categoriesByTag.end()) ? i->second : NULL;
390 CategoryMap::const_iterator i = categoriesByTag.find(h);
391 return (i!=categoriesByTag.end()) ? i->second : NULL;
398 CategoryMap::const_iterator i = categoriesByGroupTag.find(
Keyword::hash(c));
399 return (i!=categoriesByGroupTag.end()) ? i->second : NULL;
406 CategoryMap::const_iterator i = categoriesByGroupTag.find(h);
407 return (i!=categoriesByGroupTag.end()) ? i->second : NULL;
414 MetaCategory::ClassMap::const_iterator j = classes.find(
Keyword::hash(c));
415 return (j == classes.end()) ? NULL : j->second;
422 MetaCategory::ClassMap::const_iterator j = classes.find(h);
423 return (j == classes.end()) ? NULL : j->second;
429 for (
const MetaCategory *i = firstCategory; i; i = i->nextCategory)
430 if (i->writeFunction) i->writeFunction(i, o);
437 for (MetaCategory::CategoryMap::const_iterator i = MetaCategory::categoriesByTag.begin();
438 i != MetaCategory::categoriesByTag.end(); ++i)
441 MetaCategory::ClassMap::const_iterator j
443 if (j != i->second->classes.end())
return j->second;
452 logger <<
"Registered classes:" << endl;
454 for (MetaCategory::CategoryMap::const_iterator i = MetaCategory::categoriesByTag.begin();
455 i != MetaCategory::categoriesByTag.end(); ++i)
457 logger <<
" " << i->second->type << endl;
459 for (MetaCategory::ClassMap::const_iterator
460 j = i->second->classes.begin();
461 j != i->second->classes.end();
464 logger <<
" default ( = " << j->second->type <<
" )" << j->second << endl;
466 logger <<
" " << j->second->type << j->second << endl;
476 else if (!strcmp(x,
"A"))
return ADD;
477 else if (!strcmp(x,
"C"))
return CHANGE;
478 else if (!strcmp(x,
"R"))
return REMOVE;
494 for (list<Functor*>::const_iterator i = subscribers[a].begin();
495 i != subscribers[a].end(); ++i)
499 if (!(*i)->callback(v,a)) result =
false;
515 (
"Entity " + cat->
type +
" doesn't support REMOVE action");
518 (
"Entity " + cat->
type +
" doesn't support CHANGE action");
532 string t(*type ? type->
getString() :
"default");
581 if (!wild || !str)
return 1;
583 const char *cp = NULL, *mp = NULL;
585 while ((*str) && *wild !=
'*')
587 if (*wild != *str && *wild !=
'?')
598 if (!*++wild)
return 1;
602 else if (*wild == *str || *wild ==
'?')
614 while (*wild ==
'*') wild++;