HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plugin.h
Go to the documentation of this file.
1 // Copyright 2008-present Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
4 
5 
6 /////////////////////////////////////////////////////////////////////////
7 /// \file
8 ///
9 /// Helper routines for managing runtime-loadable "plugins", implemented
10 /// variously as DSO's (traditional Unix/Linux), dynamic libraries (Mac
11 /// OS X), DLL's (Windows).
12 /////////////////////////////////////////////////////////////////////////
13 
14 
15 #pragma once
16 
17 #include <string>
18 
19 #include <OpenImageIO/export.h>
21 
22 
24 
25 namespace Plugin {
26 
27 typedef void* Handle;
28 
29 /// Return the platform-dependent suffix for plug-ins ("dll" on
30 /// Windows, "so" on Linux and Mac OS X.
31 OIIO_UTIL_API const char*
32 plugin_extension(void);
33 
34 /// Open the named plugin, return its handle. If it could not be
35 /// opened, return 0 and the next call to geterror() will contain
36 /// an explanatory message. If the 'global' parameter is true, all
37 /// symbols from the plugin will be available to the app (on Unix-like
38 /// platforms; this has no effect on Windows).
40 open(const char* plugin_filename, bool global = true);
41 
42 inline Handle
43 open(const std::string& plugin_filename, bool global = true)
44 {
45  return open(plugin_filename.c_str(), global);
46 }
47 
48 /// Close the open plugin with the given handle and return true upon
49 /// success. If some error occurred, return false and the next call to
50 /// geterror() will contain an explanatory message.
51 OIIO_UTIL_API bool
52 close(Handle plugin_handle);
53 
54 /// Get the address of the named symbol from the open plugin handle. If
55 /// some error occurred, return nullptr and the next call to
56 /// geterror() will contain an explanatory message (unless report_error
57 /// is false, in which case the error message will be suppressed).
58 OIIO_UTIL_API void*
59 getsym(Handle plugin_handle, const char* symbol_name, bool report_error = true);
60 
61 inline void*
62 getsym(Handle plugin_handle, const std::string& symbol_name,
63  bool report_error = true)
64 {
65  return getsym(plugin_handle, symbol_name.c_str(), report_error);
66 }
67 
68 /// Return any error messages associated with the last call to any of
69 /// open, close, or getsym from the same thread.
71 geterror(bool clear = true);
72 
73 
74 
75 } // namespace Plugin
76 
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
OIIO_UTIL_API std::string geterror(bool clear=true)
OIIO_UTIL_API bool close(Handle plugin_handle)
#define OIIO_UTIL_API
Definition: export.h:71
OIIO_UTIL_API const char * plugin_extension(void)
OIIO_UTIL_API Handle open(const char *plugin_filename, bool global=true)
OIIO_UTIL_API void * getsym(Handle plugin_handle, const char *symbol_name, bool report_error=true)
FMT_API void report_error(format_func func, int error_code, const char *message) FMT_NOEXCEPT
Definition: format-inl.h:79
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:94
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:93
void * Handle
Definition: plugin.h:27