dynamic_library_lin.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "dynamic_library.h"
00012 
00013 #include <opc/common/addons_core/errors.h>
00014 
00015 #include <dlfcn.h>
00016 
00017 namespace
00018 {
00019 
00020   void* LoadLibrary(const char* path)
00021   {
00022     void* library = dlopen(path, RTLD_LAZY);
00023     if (!library)
00024     {
00025       std::string msg;
00026       if (const char* err = dlerror())
00027       {
00028         msg = err;
00029       }
00030       THROW_ERROR2(UnableToLoadDynamicLibrary, path, msg);
00031     }
00032     return library;
00033   }
00034 
00035 }
00036 
00037 namespace Common
00038 {
00039 
00040   DynamicLibrary::DynamicLibrary(const std::string& libraryPath)
00041     : Path(libraryPath)
00042     , Library(0)
00043   {
00044   }
00045 
00046   DynamicLibrary::~DynamicLibrary()
00047   {
00048     if (Library)
00049     {
00050       //dlclose(Library);
00051     }
00052   }
00053 
00054   void* DynamicLibrary::FindSymbol(const std::string& funcName)
00055   {
00056     if (!Library)
00057     {
00058       Library = LoadLibrary(Path.c_str());
00059     }
00060 
00061     void* func = dlsym(Library, funcName.c_str());
00062     if (!func)
00063     {
00064       std::string msg;
00065       if (const char* err =dlerror())
00066       {
00067         msg = err;
00068       }
00069       THROW_ERROR3(UnableToFundSymbolInTheLibrary, funcName, Path, msg);
00070     }
00071     return func;
00072   }
00073 
00074 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:40