diff options
author | Giuseppe Gorgoglione <gorgogsp@gmail.com> | 2016-05-28 04:14:15 +0200 |
---|---|---|
committer | Giuseppe Gorgoglione <gorgogsp@gmail.com> | 2016-06-11 20:14:09 +0200 |
commit | 58dc78b6eba373d88fe7ef68f9ce3c2c43e635d6 (patch) | |
tree | 90af8c2c2323070c2c336153de8376d83a3f1f44 /src/osd/modules/lib/osdlib.h | |
parent | ea1b66f146e4c6663e06b124f8665f878c43ce0c (diff) |
Introduce dynamic_module
This is a central cross-platform facility to dynamically bind functions from shared libraries.
Updated all OSD modules to use it.
Diffstat (limited to 'src/osd/modules/lib/osdlib.h')
-rw-r--r-- | src/osd/modules/lib/osdlib.h | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/osd/modules/lib/osdlib.h b/src/osd/modules/lib/osdlib.h index f4a632dbbd1..64bd556cd3c 100644 --- a/src/osd/modules/lib/osdlib.h +++ b/src/osd/modules/lib/osdlib.h @@ -19,6 +19,10 @@ #ifndef __OSDLIB__ #define __OSDLIB__ +#include <string> +#include <type_traits> +#include <vector> + /*----------------------------------------------------------------------------- osd_process_kill: kill the current process @@ -30,8 +34,10 @@ None. -----------------------------------------------------------------------------*/ + void osd_process_kill(void); + /*----------------------------------------------------------------------------- osd_setenv: set environment variable @@ -48,14 +54,52 @@ void osd_process_kill(void); int osd_setenv(const char *name, const char *value, int overwrite); + /*----------------------------------------------------------------------------- osd_get_clipboard_text: retrieves text from the clipboard Return value: the returned string needs to be osd_free()-ed! - -----------------------------------------------------------------------------*/ + char *osd_get_clipboard_text(void); + +/*----------------------------------------------------------------------------- + dynamic_module: load functions from optional shared libraries + + Notes: + + - Supports Mac OS X, Unix and Windows (both desktop and Windows + Store universal applications) + - A symbol can be searched in a list of libraries (e.g. more + revisions of a same library) +-----------------------------------------------------------------------------*/ + +namespace osd { + +class dynamic_module +{ +public: + typedef std::unique_ptr<dynamic_module> ptr; + + static ptr open(std::vector<std::string> &&libraries); + + virtual ~dynamic_module() { }; + + template <typename T> + typename std::enable_if<std::is_pointer<T>::value, T>::type bind(char const *symbol) + { + return reinterpret_cast<T>(get_symbol_address(symbol)); + } + +protected: + typedef void (*generic_fptr_t)(); + + virtual generic_fptr_t get_symbol_address(char const *symbol) = 0; +}; + +} // namespace osd + #endif /* __OSDLIB__ */ |