HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plugin.h
Go to the documentation of this file.
1 /*
2  Copyright 2008 Larry Gritz and the other authors and contributors.
3  All Rights Reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 
32 /////////////////////////////////////////////////////////////////////////
33 /// \file
34 ///
35 /// Helper routines for managing runtime-loadable "plugins", implemented
36 /// variously as DSO's (traditional Unix/Linux), dynamic libraries (Mac
37 /// OS X), DLL's (Windows).
38 /////////////////////////////////////////////////////////////////////////
39 
40 
41 #pragma once
42 
43 #include <string>
44 
45 #include <OpenImageIO/export.h>
47 
48 
50 
51 namespace Plugin {
52 
53 typedef void* Handle;
54 
55 /// Return the platform-dependent suffix for plug-ins ("dll" on
56 /// Windows, "so" on Linux, "dylib" on Mac OS X.
57 OIIO_API const char*
58 plugin_extension(void);
59 
60 /// Open the named plugin, return its handle. If it could not be
61 /// opened, return 0 and the next call to geterror() will contain
62 /// an explanatory message. If the 'global' parameter is true, all
63 /// symbols from the plugin will be available to the app (on Unix-like
64 /// platforms; this has no effect on Windows).
66 open(const char* plugin_filename, bool global = true);
67 
68 inline Handle
69 open(const std::string& plugin_filename, bool global = true)
70 {
71  return open(plugin_filename.c_str(), global);
72 }
73 
74 /// Close the open plugin with the given handle and return true upon
75 /// success. If some error occurred, return false and the next call to
76 /// geterror() will contain an explanatory message.
77 OIIO_API bool
78 close(Handle plugin_handle);
79 
80 /// Get the address of the named symbol from the open plugin handle. If
81 /// some error occurred, return nullptr and the next call to
82 /// geterror() will contain an explanatory message (unless report_error
83 /// is false, in which case the error message will be suppressed).
84 OIIO_API void*
85 getsym(Handle plugin_handle, const char* symbol_name, bool report_error = true);
86 
87 inline void*
88 getsym(Handle plugin_handle, const std::string& symbol_name,
89  bool report_error = true)
90 {
91  return getsym(plugin_handle, symbol_name.c_str());
92 }
93 
94 /// Return any error messages associated with the last call to any of
95 /// open, close, or getsym. Note that in a multithreaded environment,
96 /// it's up to the caller to properly mutex to ensure that no other
97 /// thread has called open, close, or getsym (all of which clear or
98 /// overwrite the error message) between the error-generating call and
99 /// geterror.
101 geterror(void);
102 
103 
104 
105 } // namespace Plugin
106 
OIIO_API const char * plugin_extension(void)
OIIO_API void * getsym(Handle plugin_handle, const char *symbol_name, bool report_error=true)
OIIO_API Handle open(const char *plugin_filename, bool global=true)
void report_error(FormatFunc func, int error_code, string_view message) FMT_NOEXCEPT
Definition: format-inl.h:184
OIIO_API bool close(Handle plugin_handle)
GLsizei const GLchar *const * string
Definition: glew.h:1844
OIIO_API std::string geterror(void)
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:66
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:65
void * Handle
Definition: plugin.h:53
#define OIIO_API
Definition: export.h:91