-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAddonLoaders.hpp
More file actions
109 lines (93 loc) · 2.54 KB
/
AddonLoaders.hpp
File metadata and controls
109 lines (93 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include "Logger.hpp"
#include <assert.h>
#if defined(__APPLE__) || defined(__ANDROID__)
#include <dlfcn.h>
#include <stdio.h>
using callstack::react_native_node_api::log_debug;
struct PosixLoader {
using Module = void *;
using Symbol = void *;
static Module loadLibrary(const char *filePath) {
assert(NULL != filePath);
Module result = dlopen(filePath, RTLD_NOW | RTLD_LOCAL);
if (NULL == result) {
log_debug("NapiHost: Failed to load library '%s': %s", filePath,
dlerror());
}
return result;
}
static Symbol getSymbol(Module library, const char *name) {
assert(NULL != library);
assert(NULL != name);
Symbol result = dlsym(library, name);
// if (NULL == result) {
// NSLog(@"NapiHost: Cannot find '%s' symbol!", name);
// }
return result;
}
static void unloadLibrary(Module library) {
if (NULL != library) {
dlclose(library);
}
}
};
#endif
#if defined(_WIN32)
struct Win32Loader {
using Module = HMODULE;
using Symbol = void *;
static Module loadLibrary(const char *filePath) {
assert(NULL != filePath);
Module result = LoadLibrary(filePath);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;
}
static Symbol getSymbol(Module library, const char *name) {
assert(NULL != library);
assert(NULL != name);
Symbol result = GetProcAddress(library, name);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;
}
static void unloadLibrary(Module library) {
if (NULL != library) {
FreeLibrary(library);
}
}
};
struct WinRTLoader {
using Module = HMODULE;
using Symbol = void *;
static Module loadLibrary(const char *filePath) {
assert(NULL != filePath);
Module result = LoadPackagedLibrary(filePath);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;
}
static Symbol getSymbol(Module library, const char *name) {
assert(NULL != library);
assert(NULL != name);
Symbol result = GetProcAddress(library, name);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;
}
static void unloadLibrary(Module library) {
if (NULL != library) {
FreeLibrary(library);
}
}
};
#endif