| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- File List
- File Members

# DsoUtils.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006 //  note: This, I believe, should be part of Reflex::SharedLibrary
    00007
    00008 #ifndef GAUDIKERNEL_DSOUTILS_H
    00009 #define GAUDIKERNEL_DSOUTILS_H
    00010
    00011 // STL includes
    00012 #include <string>
    00013
    00014 // Reflex includes
    00015 #include "Reflex/Reflex.h"
    00016
    00017 namespace DsoUtils {
    00018
    00019 inline std::string libNativeName( const std::string& libName )
    00020 {
    00021 #if defined(_WIN32)
    00022   return libName+".dll";
    00023 #elif defined(__linux) || defined(__APPLE__)
    00024   return "lib"+libName+".so";
    00025 #else
    00026   // variant of the GIGO design pattern
    00027   return libName;
    00028 #endif
    00029 }
    00030
    00031 #ifdef _GNU_SOURCE
    00032 #include <dlfcn.h>
    00033 static std::string dsoName( const ROOT::Reflex::Member& mem )
    00034 {
    00035   Dl_info info;
    00036   if (dladdr ((void*)(mem.Stubfunction()), &info) == 0)
    00037     return "";
    00038
    00039   const char* pos = strrchr (info.dli_fname, '/');
    00040   if (pos)
    00041     ++pos;
    00042   else
    00043     pos = info.dli_fname;
    00044   return pos;
    00045 }
    00046 #elif defined(_WIN32)
    00047 #include <windows.h>
    00048
    00049 static std::string dsoName( const ROOT::Reflex::Member& mem )
    00050 {
    00051   void* addr = (void*)(mem.Stubfunction());
    00052   if (addr) {
    00053     MEMORY_BASIC_INFORMATION mbi;
    00054     if ( VirtualQuery(addr, &mbi, sizeof(mbi)) )    {
    00055       HMODULE h_module = (HMODULE)mbi.AllocationBase;
    00056       char mod[1024];
    00057       if( GetModuleFileName(h_module, mod, sizeof(mod)) ) {
    00058         const char* pos = strrchr (mod, '\\');
    00059         if (pos)
    00060           ++pos;
    00061         else
    00062           pos = mod;
    00063         return pos;
    00064       }
    00065     }
    00066   }
    00067   return "";
    00068 }
    00069
    00070 #else // dummy implementation for unknown platforms
    00071 static std::string dsoName( const ROOT::Reflex::Member& )
    00072 {
    00073   return "";
    00074 }
    00075
    00076 #endif
    00077
    00078 static bool inDso( const ROOT::Reflex::Member& mem,
    00079                     const std::string& dsoname )
    00080 {
    00081 #ifdef _WIN32
    00082   char sep = '\\';
    00083 #else
    00084   char sep = '/';
    00085 #endif
    00086
    00087   std::string srcname = dsoName(mem);
    00088   if (srcname.empty()) {
    00089     // we do not know the name of the library, let's guess it's OK
    00090     return true;
    00091   }
    00092
    00093   std::string::size_type pos = dsoname.find_last_of(sep);
    00094   std::string curname;
    00095   if (std::string::npos == pos) {
    00096     curname = dsoname;
    00097   } else {
    00098     curname = dsoname.substr(pos+1);
    00099   }
    00100
    00101   return srcname == curname;
    00102 }
    00103
    00104 } // end namespace DsoUtils
    00105
    00106 #endif // not GAUDIKERNEL_DSOUTILS_H
    00107