HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_DSO.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT library (C++)
7  *
8  * COMMENTS: Dynamic shared object management
9  *
10  */
11 
12 #ifndef __UT_DSO_H__
13 #define __UT_DSO_H__
14 
15 #include "FS_API.h"
16 
17 #include <UT/UT_PathSearch.h>
18 #include <SYS/SYS_Types.h>
19 
20 #if defined( WIN32 )
21  #define FS_DSO_EXTENSION ".dll"
22 #elif defined( MBSD )
23  #define FS_DSO_EXTENSION ".dylib"
24 #else
25  #define FS_DSO_EXTENSION ".so"
26 #endif
27 
28 class dso_file;
29 class UT_String;
30 class UT_StringRef;
31 
32 // This abstract class is only used as a return value from UT_DSO::loadDSO()
33 // and a parameter to UT_DSO::findSymbol().
34 class UT_DSOHandle;
35 
36 class FS_API UT_DSO {
37 public:
38  // These static functions provide a much simplified and more generic
39  // interface over UT_DSO objects. They also correspond more directly to
40  // the underlying system's dlopen/LoadLibrary, dlsym/GetProcAddress, and
41  // dlclose/FreeLibrary interface than do UT_DSO objects.
42 
43  // loadDSO() will load one particular shared object, using the system's
44  // standard search path. A pointer to an opaque UT_DSOHandle object is
45  // returned on success, and you can use this handle to look up symbols.
46  // on failure, this function returns null.
47  //
48  // Unlike UT_DSO objects, it will not load all the shared objects it can
49  // find in Houdini's search paths. Also, a parameter controls whether or
50  // not the symbols are available to shared objects that are loaded later.
51  // UT_DSO objects instead look for a special function in the shared object
52  // to determine if its symbols should be made available.
53  static UT_DSOHandle *loadDSO(
54  const char *file_name, bool available_to_later_loaded_libraries,
55  UT_String *error = NULL);
56 
57  // Find a symbol (function or global variable) in a loaded shared object.
58  // Unlike the findProcedure() method on UT_DSO objects, you pass in
59  // a dso object that's already been loaded, instead of a file name. This
60  // way you can quickly look up multiple symbols in the same shared library.
61  // This function also doesn't for HoudiniDSOVersion symbols like UT_DSO
62  // objects do.
63  static void *findSymbol(UT_DSOHandle &handle, const char *symbol_name);
64 
65  // Decrement the reference cound on the loaded library, unloading it if
66  // it's no longer used.
67  static int closeDSO(UT_DSOHandle &handle);
68 
69  // Return the UT_DSOHandle for the main program. This lets you look up
70  // symbols in the main program from a shared library that was loaded.
71  static UT_DSOHandle *getExecutable();
72 
73  // Return the UT_DSOHandle for a given loaded library.
74  // Return NULL if the library is not loaded.
75  // Use this function to check whether a particular library has been loaded
76  // or to look up symbols in a library.
77  static UT_DSOHandle *getLoadedLibrary(const char *lib_name);
78 
79  //------------------------------------------------------------------------
80 
81  // Given the name of a shared object, search for the file on disk using the
82  // system's library path resolution mechanism and try to load it. Returns
83  // null if the file could not be found or couldn't be loaded for some
84  // reason.
85  static UT_DSOHandle *loadLibraryInPath(
86  const char *shared_object_name,
87  bool available_to_later_loaded_libraries);
88 
89  //------------------------------------------------------------------------
90 
91  // Load a dynamic object and run the function specified.
92  bool run(const char *function_name, void *data = NULL,
93  bool validate_version = true);
94  bool run(const char *filename, const char *function_name,
95  void *data = NULL, bool validate_version = true,
97 
98  // This will go through the available DSOs in reverse order.
99  // Normally, we run them from $HOME -> $HFS. However, if the
100  // called procedure will override earlier on successive calls (rather
101  // than ignore) the correct order should be $HFS -> $HOME. This is
102  // the case with CMDextendLibrary.
103  bool runReverse(const char *function_name, void *data = NULL,
104  bool validate_version = true);
105 
106  // Rather than running the function, simply load the dynamic object and
107  // return a pointer to the function. This returns a pointer to the
108  // function (or NULL if no function was found).
109  // The actual name of the dynamic object is returned in the fullpath string.
110  void *findProcedure(const char *filename, const char *function_name,
111  UT_String &fullpath,
112  bool validate_version = true);
113 
114  // This will return the file which is currently being loaded (i.e. in the
115  // run() command. If there is no file, then it will return a null ptr.
116  static const char *getRunningFile();
117 
118 private:
119  bool dsoListRun(exint data_i,
120  const UT_StringRef& func_name,
121  void* func_data,
122  bool validate_version,
123  bool* skip_func);
124 
125  static bool checkDSOVersion(UT_DSOHandle *handle,
126  const char *filename);
127 
128  typedef void (*DSOCallback)(void *);
129  static DSOCallback loadDSOAndFindFunction(UT_DSOHandle *&handle,
130  const char *file_name,
131  const char *func_name,
132  bool validate_version,
133  bool err_on_missing_func);
134  static UT_DSOHandle *openLibrary(const char *filename);
135 private:
136  static const char *theRunningFile;
137 };
138 
139 #endif
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
Definition: UT_DSO.h:36
int64 exint
Definition: SYS_Types.h:109
UT_KnownPath
Definition: UT_PathSearch.h:52
GLboolean * data
Definition: glcorearb.h:130
#define FS_API
Definition: FS_API.h:10