Skip to content

Commit

Permalink
Merge pull request #4 from nvidianz/processor-windows-support
Browse files Browse the repository at this point in the history
Processor windows support
  • Loading branch information
ZiyueXu77 authored Apr 25, 2024
2 parents 5b2dfe6 + 80d3b89 commit 184b67f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/processing/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ class Processor {
class ProcessorLoader {
private:
std::map<std::string, std::string> params;
void *handle = NULL;

#if defined(_WIN32)
HMODULE handle_ = NULL;
#else
void *handle_ = NULL;
#endif

public:
ProcessorLoader(): params{} {}
Expand Down
40 changes: 32 additions & 8 deletions src/processing/processor_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

#include <iostream>

#include "dlfcn.h"
#if defined(_WIN32)
#include <windows.h>
#else
#include <dlfcn.h>
#endif

#include "./processor.h"
#include "plugins/dummy_processor.h"
Expand All @@ -21,7 +25,9 @@ namespace processing {
auto lib_name = "libproc_" + plugin_name;

auto extension =
#if defined(__APPLE__) || defined(__MACH__)
#if defined(_WIN32)
".dll";
#elif defined(__APPLE__) || defined(__MACH__)
".dylib";
#else
".so";
Expand All @@ -34,31 +40,49 @@ namespace processing {
lib_path = lib_file_name;
} else {
auto p = params[kLibraryPath];
if (p.back() != '/') {
if (p.back() != '/' && p.back() != '\\') {
p += '/';
}
lib_path = p + lib_file_name;
}

handle = dlopen(lib_path.c_str(), RTLD_LAZY);
if (!handle) {
std::cerr << "Failed to load the dynamic library: " << dlerror() << std::endl;
#if defined(_WIN32)
HMODULE handle_ = LoadLibrary(lib_path.c_str());
if (!handle_) {
std::cerr << "Failed to load the dynamic library" << std::endl;
return NULL;
}

void* func_ptr = dlsym(handle, kLoadFunc);
void* func_ptr = GetProcAddress(handle_, kLoadFunc);
if (!func_ptr) {
std::cerr << "Failed to find loader function." << std::endl;
return NULL;
}

#else
handle_ = dlopen(lib_path.c_str(), RTLD_LAZY);
if (!handle_) {
std::cerr << "Failed to load the dynamic library: " << dlerror() << std::endl;
return NULL;
}
void* func_ptr = dlsym(handle_, kLoadFunc);
if (!func_ptr) {
std::cerr << "Failed to find loader function: " << dlerror() << std::endl;
return NULL;
}

#endif

auto func = reinterpret_cast<LoadFunc *>(func_ptr);

return (*func)(plugin_name.c_str());
}

void ProcessorLoader::unload() {
dlclose(handle);
#if defined(_WIN32)
FreeLibrary(handle_);
#else
dlclose(handle_);
#endif
}
} // namespace processing

0 comments on commit 184b67f

Please sign in to comment.