bool clutl::Module::Load(clcpp::Database* host_db, const char* filename) { // Load the DLL m_Handle = LoadSharedLibrary(filename); if (m_Handle == 0) return false; // Keep this around for registering interface implementations clcpp::internal::Assert(host_db != 0); m_HostReflectionDB = host_db; // Get the module reflection database typedef clcpp::Database* (*GetReflectionDatabaseFunc)(); GetReflectionDatabaseFunc GetReflectionDatabase = (GetReflectionDatabaseFunc)GetSharedLibraryFunction(m_Handle, "GetReflectionDatabase"); if (GetReflectionDatabase) m_ReflectionDB = GetReflectionDatabase(); // Ask the DLL to register and interface implementations it has typedef void (*AddReflectionImplsFunc)(Module*); AddReflectionImplsFunc AddReflectionImpls = (AddReflectionImplsFunc)GetSharedLibraryFunction(m_Handle, "AddReflectionImpls"); if (AddReflectionImpls) AddReflectionImpls(this); return true; }
static inline void* CppRuntimeSpawnPlugin (CRuntimePtr crt, const pI_char* name) { SharedLibrary** injectptr = 0; CppRuntimeSpawnPluginFunc sfunc = 0; if (crt == 0) return 0; injectptr = (SharedLibrary**) crt->shared_library_data; sfunc = (CppRuntimeSpawnPluginFunc) GetSharedLibraryFunction (injectptr[1], "CppRuntimeSpawnPlugin"); if (sfunc == 0) return 0; return sfunc (crt, name); } // static inline void* CppRuntimeSpawnPlugin (CRuntimePtr crt, , const pI_char* name)
static inline CRuntimeError CppRuntimeRegisterPlugin (CRuntimePtr crt, void* ip) { SharedLibrary** injectptr = 0; CppRuntimeRegisterPluginFunc regfunc = 0; if (crt == 0) return pI_CRuntime_Error_InvalidInstance; injectptr = (SharedLibrary**) crt->shared_library_data; regfunc = (CppRuntimeRegisterPluginFunc) GetSharedLibraryFunction (injectptr[1], "CppRuntimeRegisterPlugin"); if (regfunc == 0) return pI_CRuntime_Error_InvalidInstance; return regfunc (crt, ip); } // static inline CRuntimeError CppRuntimeRegisterPlugin (CRuntimePtr runtime, void* ip)
static inline pI_int GetAPIVersion (struct _CRuntime* rt) { SharedLibrary** injectptr = 0; GetpIAPIVersionFunc vfunc = 0; if (rt == 0) return -1; injectptr = (SharedLibrary**) rt->shared_library_data; vfunc = (GetpIAPIVersionFunc) GetSharedLibraryFunction (injectptr[0], "GetpIAPIVersion"); if (vfunc == 0) return -1; return vfunc(); } // static inline void CleanUpCRuntime (struct _CRuntime* rt)
static inline CRuntimeError CppRuntimeErasePlugin (CRuntimePtr crt, void* ip) { SharedLibrary** injectptr = 0; CppRuntimeErasePluginFunc efunc = 0; if (crt == 0) return pI_CRuntime_Error_InvalidInstance; injectptr = (SharedLibrary**) crt->shared_library_data; efunc = (CppRuntimeErasePluginFunc) GetSharedLibraryFunction (injectptr[1], "CppRuntimeErasePlugin"); if (efunc == 0) return pI_CRuntime_Error_InvalidInstance; efunc (ip); return pI_CRuntime_Error_NoError; } // static inline CRuntimeError CppRuntimeErasePlugin (void* ip)
static inline void CleanUpCRuntimeWriteProperties (struct _CRuntime* rt) { SharedLibrary** injectptr = 0; DestroyCRuntimeFunc dfunc = 0; if (rt == 0) return; injectptr = (SharedLibrary**) rt->shared_library_data; dfunc = (DestroyCRuntimeFunc) GetSharedLibraryFunction (injectptr[0], "DestroyCRuntime"); if (dfunc == 0) return; dfunc (rt, pI_TRUE); UnloadSharedLibrary (injectptr[1]); UnloadSharedLibrary (injectptr[0]); } // static inline void CleanUpCRuntimeWriteProperties (struct _CRuntime* rt)
static inline CRuntimePtr CreateCRuntime (const pI_bool load_properties = pI_FALSE) { SharedLibrary* crtsl = 0; SharedLibrary* cppimplsl = 0; CreateCRuntimeFunc cfunc = 0; CRuntimePtr crt = 0; SharedLibrary** injectptr = 0; // load functionality from shared library crtsl = LoadSharedLibrary (pI_RUNTIME_MAKE_SHARED_LIB_NAME("pIRuntime")); if (crtsl == 0) return 0; cppimplsl = LoadSharedLibrary (pI_RUNTIME_MAKE_SHARED_LIB_NAME("pICppRuntimeImpl")); if (cppimplsl == 0) { UnloadSharedLibrary (crtsl); return 0; } // fetch runtime creation function from shared library cfunc = (CreateCRuntimeFunc) GetSharedLibraryFunction (crtsl, "CreateCRuntime"); if (cfunc == 0) { UnloadSharedLibrary (crtsl); UnloadSharedLibrary (cppimplsl); return 0; } // instantiate runtime crt = cfunc (load_properties); if (crt == 0) { UnloadSharedLibrary (crtsl); UnloadSharedLibrary (cppimplsl); return 0; } // inject shared libraries into runtime injectptr = (SharedLibrary**) crt->AllocateMemory (crt, sizeof(SharedLibrary*) * 2); injectptr[0] = crtsl; injectptr[1] = cppimplsl; crt->shared_library_data = injectptr; return crt; } // static inline CRuntimePtr CreateCRuntime (const pI_bool load_properties = pI_FALSE)