00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects Software Inc. 00009 * 20 Maud St. 00010 * Toronto, Ontario, M5V 2M5 00011 * Canada 00012 * 416-366-4607 00013 * 00014 * NAME: UT library (C++) 00015 * 00016 * COMMENTS: Dynamic shared object management 00017 * 00018 */ 00019 00020 #ifndef __UT_DSO_H__ 00021 #define __UT_DSO_H__ 00022 00023 #include <UT/UT_PathSearch.h> 00024 00025 #include "FS_API.h" 00026 #if defined( WIN32 ) 00027 #define FS_DSO_EXTENSION ".dll" 00028 #elif defined( MBSD ) 00029 #define FS_DSO_EXTENSION ".dylib" 00030 #else 00031 #define FS_DSO_EXTENSION ".so" 00032 #endif 00033 00034 class dso_file; 00035 class UT_String; 00036 00037 // This abstract class is only used as a return value from UT_DSO::loadDSO() 00038 // and a parameter to UT_DSO::findSymbol(). 00039 class UT_DSOHandle; 00040 00041 class FS_API UT_DSO { 00042 public: 00043 // These static functions provide a much simplified and more generic 00044 // interface over UT_DSO objects. They also correspond more directly to 00045 // the underlying system's dlopen/LoadLibrary, dlsym/GetProcAddress, and 00046 // dlclose/FreeLibrary interface than do UT_DSO objects. 00047 00048 // loadDSO() will load one particular shared object, using the system's 00049 // standard search path. A pointer to an opaque UT_DSOHandle object is 00050 // returned on success, and you can use this handle to look up symbols. 00051 // on failure, this function returns null. 00052 // 00053 // Unlike UT_DSO objects, it will not load all the shared objects it can 00054 // find in Houdini's search paths. Also, a parameter controls whether or 00055 // not the symbols are available to shared objects that are loaded later. 00056 // UT_DSO objects instead look for a special function in the shared object 00057 // to determine if its symbols should be made available. 00058 static UT_DSOHandle *loadDSO( 00059 const char *file_name, bool available_to_later_loaded_libraries); 00060 00061 // Find a symbol (function or global variable) in a loaded shared object. 00062 // Unlike the findProcedure() method on UT_DSO objects, you pass in 00063 // a dso object that's already been loaded, instead of a file name. This 00064 // way you can quickly look up multiple symbols in the same shared library. 00065 // This function also doesn't for HoudiniDSOVersion symbols like UT_DSO 00066 // objects do. 00067 static void *findSymbol(UT_DSOHandle &handle, const char *symbol_name); 00068 00069 // Decrement the reference cound on the loaded library, unloading it if 00070 // it's no longer used. 00071 static int closeDSO(UT_DSOHandle &handle); 00072 00073 //------------------------------------------------------------------------ 00074 00075 // Load a dynamic object and run the function specified. 00076 bool run(const char *function_name, void *data = 0, 00077 int validate=1); 00078 bool run(const char *filename, const char *function_name, 00079 void *data = 0, int validate=1, 00080 UT_KnownPath path = UT_HOUDINI_DSO_PATH); 00081 00082 // This will go through the available DSOs in reverse order. 00083 // Normally, we run them from $HOME -> $HFS. However, if the 00084 // called procedure will override earlier on successive calls (rather 00085 // than ignore) the correct order should be $HFS -> $HOME. This is 00086 // the case with CMDextendLibrary. 00087 void runReverse(const char *function_name, void *data = 0, 00088 int validate=1); 00089 00090 // Rather than running the function, simply load the dynamic object and 00091 // return a pointer to the function. This returns a pointer to the 00092 // function (or NULL if no function was found). 00093 // The actual name of the dynamic object is returned in the fullpath string. 00094 void *findProcedure(const char *filename, const char *function_name, 00095 UT_String &fullpath, int validate=1); 00096 00097 // This will return the file which is currently being loaded (i.e. in the 00098 // run() command. If there is no file, then it will return a null ptr. 00099 static const char *getRunningFile(); 00100 00101 protected: 00102 // This is used to have a stack-based method of calling our linked 00103 // list in the inverted order... 00104 void processReverse(const char *fn_name, void *data, int validate, 00105 dso_file *cur, dso_file *prev); 00106 00107 private: 00108 static int theFirstTime; 00109 }; 00110 00111 #endif
1.5.9