36 #include <sys/param.h>
43 #if defined(__APPLE__)
46 #include <CoreFoundation/CoreFoundation.h>
47 #include <ApplicationServices/ApplicationServices.h>
63 return dlopen( dll_file_name, RTLD_NOW );
72 return dlsym( handle, function_name );
81 return dlclose( handle );
104 static string data_path;
107 if ( ! dir.empty() ) {
121 char *env = getenv(
"OM_DATA_DIR" );
125 string om_data_path = (
char const *)env;
127 if ( ! om_data_path.empty() ) {
152 vector<string> entries;
157 if ( ! default_dir.empty() ) {
161 entries.push_back( default_dir );
174 char *env = getenv(
"OM_ALGS_DIR" );
178 string envpath( (
char const *)env );
181 if ( ! envpath.empty() ) {
190 for ( string::size_type start = 0; start < envpath.length() ; ) {
193 string::size_type it = envpath.find(
':', start );
196 if ( it == string::npos ) {
199 entries.push_back( envpath.substr( start ) );
203 else if ( it > start ) {
205 string::size_type len = it - start;
206 entries.push_back( envpath.substr( start, len ) );
218 #if defined(__APPLE__)
219 CFURLRef myPluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
220 CFStringRef myMacPath = CFURLCopyFileSystemPath(myPluginRef, kCFURLPOSIXPathStyle);
221 const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding());
222 CFRelease(myPluginRef);
223 CFRelease(myMacPath);
224 std::string myFullPath(mypPathPtr);
225 string::size_type loc = myFullPath.find(
".app", 0 );
226 if( loc != string::npos )
228 myFullPath +=
"/Contents/MacOS/lib/openmodeller";
229 entries.push_back( myFullPath );
236 entries.push_back( OM_ALGS_DIR );
240 entries.push_back( OM_ALGS_DIR );
266 int filter(
const struct dirent *dir )
274 #if defined(__APPLE__)
278 std::string ext =
".so";
280 #elif defined(__CYGWIN__)
283 std::string ext =
".dll";
285 std::string ext =
".so";
288 const char *found = strstr( dir->d_name, (
const char *)ext.c_str() );
290 return found ? ! strcmp( found, ext.c_str() ) : 0;
299 vector<string> entries;
301 if ( dir.length() == 0 ) {
305 if ( dir[ dir.length() ] !=
'/' ) {
312 int nent = scandir( dir.c_str(), &namelist,
filter, alphasort );
318 for (
int i = 0; i < nent; i++ ) {
320 char *found = namelist[i]->d_name;
322 string name = dir + found;
323 entries.push_back( name );
341 #include <sys/time.h>
342 #include <sys/resource.h>
355 static unsigned int seed = 0;
357 if ( seed && !new_seed ) {
371 gettimeofday( &time, (
struct timezone *)NULL );
374 seed = (
unsigned int) time( NULL );
388 #ifdef _GLIBCPP_HAVE_DRAND48
400 char temp[MAXPATHLEN];
401 return ( getcwd(temp, MAXPATHLEN) ? std::string( temp ) : std::string(
"") );
410 if ( stat( path.c_str(), &status ) == 0 && S_ISDIR(status.st_mode) ) {
424 int nRC = ::mkdir( path.c_str(), 0775 );
432 if(
createPath( path.substr(0, path.find_last_of(
'/')) ) )
434 ok = 0 == ::mkdir( path.c_str(), 0775 );
vector< string > scanDirectory(string dir)
std::string omDataPath(std::string dir)
void * dllFunction(DLLHandle handle, char const *function_name)
bool createPath(const std::string path)
int initRandom(unsigned int new_seed)
static std::string getDefaultAlgDir()
int dllClose(DLLHandle handle)
static Log * instance()
Returns the instance pointer, creating the object on the first call.
int filter(const TDirent *dir)
static std::string get(const std::string &key)
std::string getWorkingPath()
void setupExternalResources()
bool pathExists(const std::string path)
vector< string > initialPluginPath()
static int count(const std::string &key)
DLLHandle dllOpen(char const *dll_file_name)
void debug(const char *format,...)
'Debug' level.
const char * dllError(DLLHandle)