Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVS-154700, Implement LoadLibrary for windows with GetProcAddress #2874

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
66 changes: 64 additions & 2 deletions src/dags/custom_node_library_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,73 @@ Status CustomNodeLibraryManager::loadLibrary(const std::string& name, const std:
SPDLOG_LOGGER_INFO(modelmanager_logger, "Successfully loaded custom node library name: {}; base_path: {}", name, basePath);
#elif _WIN32
// TODO: implement LoadLibrary for windows with GetProcAddress
void* handle = NULL;
if (handle == NULL) {
HMODULE handle = LoadLibraryA(basePath.c_str());
DWORD error = GetLastError();
// void* handle = NULL;
if (!handle) {
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Library name: {} failed to open base_path: {} with error: {}", name, basePath, "e");
return StatusCode::NODE_LIBRARY_LOAD_FAILED_OPEN;
}

initialize_fn initialize = reinterpret_cast<initialize_fn>(GetProcAddress(handle, "initialize"));
if (!initialize) {
error = GetLastError();
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error);
FreeLibrary(handle);
return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM;
}

deinitialize_fn deinitialize = reinterpret_cast<deinitialize_fn>(GetProcAddress(handle, "deinitialize"));
if (!deinitialize) {
error = GetLastError();
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error);
FreeLibrary(handle);
return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM;
}

execute_fn execute = reinterpret_cast<execute_fn>(GetProcAddress(handle, "execute"));
if (!execute) {
error = GetLastError();
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error);
FreeLibrary(handle);
return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM;
}

metadata_fn getInputsInfo = reinterpret_cast<metadata_fn>(GetProcAddress(handle, "getInputsInfo"));
if (!getInputsInfo) {
error = GetLastError();
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error);
FreeLibrary(handle);
return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM;
}

metadata_fn getOutputsInfo = reinterpret_cast<metadata_fn>(GetProcAddress(handle, "getOutputsInfo"));
if (!getOutputsInfo) {
error = GetLastError();
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error);
FreeLibrary(handle);
return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM;
}

release_fn release = reinterpret_cast<release_fn>(GetProcAddress(handle, "release"));
if (!release) {
error = GetLastError();
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error);
FreeLibrary(handle);
return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM;
}

libraries[name] = NodeLibrary{
initialize,
deinitialize,
execute,
getInputsInfo,
getOutputsInfo,
release,
basePath};

SPDLOG_LOGGER_INFO(modelmanager_logger, "Successfully loaded custom node library name: {}; base_path: {}", name, basePath);

#endif

return StatusCode::OK;
Expand Down