00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef UNIXSTL_INCL_UNIXSTL_DL_HPP_MODULE
00048 #define UNIXSTL_INCL_UNIXSTL_DL_HPP_MODULE
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define UNIXSTL_VER_UNIXSTL_DL_HPP_MODULE_MAJOR 6
00052 # define UNIXSTL_VER_UNIXSTL_DL_HPP_MODULE_MINOR 2
00053 # define UNIXSTL_VER_UNIXSTL_DL_HPP_MODULE_REVISION 5
00054 # define UNIXSTL_VER_UNIXSTL_DL_HPP_MODULE_EDIT 218
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #ifndef UNIXSTL_INCL_UNIXSTL_H_UNIXSTL
00069 # include <unixstl/unixstl.h>
00070 #endif
00071 #ifndef UNIXSTL_INCL_UNIXSTL_HPP_ERROR_UNIX_EXCEPTIONS
00072 # include <unixstl/error/exceptions.hpp>
00073 #endif
00074 #ifndef UNIXSTL_INCL_UNIXSTL_SHIMS_ACCESS_HPP_STRING
00075 # include <unixstl/shims/access/string.hpp>
00076 #endif
00077
00078 #ifndef STLSOFT_INCL_H_DLFCN
00079 # define STLSOFT_INCL_H_DLFCN
00080 # include <dlfcn.h>
00081 #endif
00082 #ifndef STLSOFT_INCL_H_ERRNO
00083 # define STLSOFT_INCL_H_ERRNO
00084 # include <errno.h>
00085 #endif
00086
00087
00088
00089
00090
00091 #ifndef _UNIXSTL_NO_NAMESPACE
00092 # if defined(_STLSOFT_NO_NAMESPACE) || \
00093 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00094
00095 namespace unixstl
00096 {
00097 # else
00098
00099
00100 namespace stlsoft
00101 {
00102
00103 namespace unixstl_project
00104 {
00105
00106 # endif
00107 #endif
00108
00109
00110
00111
00112
00117 class module
00118 {
00119 public:
00121 typedef void* module_handle_type;
00123 typedef module class_type;
00125 typedef void* proc_pointer_type;
00126
00129 public:
00138 ss_explicit_k module(us_char_a_t const* moduleName, int mode = RTLD_NOW);
00147 ss_explicit_k module(us_char_w_t const* moduleName, int mode = RTLD_NOW);
00159 template <ss_typename_param_k S>
00160 ss_explicit_k module(S const& moduleName, int mode = RTLD_NOW)
00161 : m_hmodule(load(moduleName, mode))
00162 {
00163 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00164 if(NULL == m_hmodule)
00165 {
00166 STLSOFT_THROW_X(unix_exception("Cannot load module", errno));
00167 }
00168 #endif
00169 }
00175 ss_explicit_k module(module_handle_type hmodule);
00177 ~module() stlsoft_throw_0();
00179
00182 public:
00190 static module_handle_type load(us_char_a_t const* moduleName, int mode = RTLD_NOW);
00198 static module_handle_type load(us_char_w_t const* moduleName, int mode = RTLD_NOW);
00209 template <ss_typename_param_k S>
00210 static module_handle_type load(S const& moduleName, int mode = RTLD_NOW)
00211 {
00212 return class_type::load(stlsoft_ns_qual(c_str_ptr)(moduleName), mode);
00213 }
00215 static void unload(module_handle_type hmodule);
00219 static proc_pointer_type get_symbol(module_handle_type hmodule, us_char_a_t const* symbolName);
00223 template <ss_typename_param_k F>
00224 static proc_pointer_type get_symbol(module_handle_type hmodule, us_char_a_t const* symbolName, F &f)
00225 {
00226 proc_pointer_type proc = class_type::get_symbol(hmodule, symbolName);
00227
00228 f = reinterpret_cast<F>(proc);
00229
00230 return proc;
00231 }
00233
00236 public:
00238 void unload();
00239
00241 module_handle_type detach();
00243
00246 public:
00250 proc_pointer_type get_symbol(us_char_a_t const* symbolName);
00254 template <ss_typename_param_k F>
00255 proc_pointer_type get_symbol(us_char_a_t const* symbolName, F &f)
00256 {
00257 return class_type::get_symbol(m_hmodule, symbolName, f);
00258 }
00260
00263 public:
00265 module_handle_type get_module_handle() const;
00267
00270 private:
00272
00275 private:
00276 module_handle_type m_hmodule;
00278
00281 private:
00282 module(class_type const&);
00283 class_type& operator =(class_type const&);
00285 };
00286
00287
00288
00289
00290
00295 inline void *get_module_handle(unixstl_ns_qual(module) const& m)
00296 {
00297 return m.get_module_handle();
00298 }
00299
00300
00301
00302
00303
00304 #ifdef STLSOFT_UNITTEST
00305 # include "./unittest/module_unittest_.h"
00306 #endif
00307
00308
00309
00310
00311
00312 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00313
00314 inline module::module(us_char_a_t const* moduleName, int mode)
00315 : m_hmodule(load(moduleName, mode))
00316 {
00317 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00318 if(NULL == m_hmodule)
00319 {
00320 STLSOFT_THROW_X(unix_exception("Cannot load module", errno));
00321 }
00322 #endif
00323 }
00324
00325 inline module::module(us_char_w_t const* moduleName, int mode)
00326 : m_hmodule(load(moduleName, mode))
00327 {
00328 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00329 if(NULL == m_hmodule)
00330 {
00331 STLSOFT_THROW_X(unix_exception("Cannot load module", errno));
00332 }
00333 #endif
00334 }
00335
00336 inline module::module(module::module_handle_type hmodule)
00337 : m_hmodule(hmodule)
00338 {
00339 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00340 if(NULL == m_hmodule)
00341 {
00342 STLSOFT_THROW_X(unix_exception("Cannot load module", errno));
00343 }
00344 #endif
00345 }
00346
00347 inline module::~module() stlsoft_throw_0()
00348 {
00349 unload(m_hmodule);
00350 }
00351
00352 inline void module::unload()
00353 {
00354 if(NULL != m_hmodule)
00355 {
00356 unload(m_hmodule);
00357 m_hmodule = NULL;
00358 }
00359 }
00360
00361 inline module::module_handle_type module::detach()
00362 {
00363 module_handle_type h;
00364
00365 h = m_hmodule;
00366 m_hmodule = NULL;
00367
00368 return h;
00369 }
00370
00371 inline module::module_handle_type module::load(us_char_a_t const* moduleName, int mode)
00372 {
00373 return ::dlopen(moduleName, mode);
00374 }
00375
00376 inline void module::unload(module::module_handle_type hmodule)
00377 {
00378 if(NULL != hmodule)
00379 {
00380 ::dlclose(hmodule);
00381 }
00382 }
00383
00384 inline module::proc_pointer_type module::get_symbol(module::module_handle_type hmodule, us_char_a_t const* symbolName)
00385 {
00386 return ::dlsym(hmodule, symbolName);
00387 }
00388
00389 inline module::proc_pointer_type module::get_symbol(us_char_a_t const* symbolName)
00390 {
00391 return get_symbol(m_hmodule, symbolName);
00392 }
00393
00394 inline module::module_handle_type module::get_module_handle() const
00395 {
00396 return m_hmodule;
00397 }
00398
00399 #endif
00400
00401
00402
00403 #ifndef _UNIXSTL_NO_NAMESPACE
00404 # if defined(_STLSOFT_NO_NAMESPACE) || \
00405 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00406 }
00407 # else
00408 }
00409 }
00410 # endif
00411 #endif
00412
00413
00414
00415 #endif
00416
00417