forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary_loading.cpp
More file actions
89 lines (77 loc) · 2.13 KB
/
Copy pathlibrary_loading.cpp
File metadata and controls
89 lines (77 loc) · 2.13 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
#include "build_environment.h"
#ifdef BUILD_ON_UNIX
#include <dlfcn.h>
#include "imehandler.h"
#endif
#include "library_loading.h"
#include "logging.h"
#ifdef BUILD_ON_UNIX
IMELIB_TYPE tryToOpenImeLib() {
void* lib = dlopen("libibushandler.so", RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE);
if (!lib) {
LOG(DEBUG) << "Cannot load the shared library: " << dlerror();
return NULL;
}
// Reset error.
dlerror();
return lib;
}
destroy_h* getDestroyHandler(IMELIB_TYPE lib) {
destroy_h* destroy_handler = (destroy_h*) dlsym(lib, "destroy");
const char* dlsym_error = dlerror();
if (dlsym_error) {
LOG(DEBUG) <<"Cannot load symbol destroy: " << dlsym_error;
return NULL;
}
return destroy_handler;
}
create_h* getCreateHandler(IMELIB_TYPE lib) {
create_h* create_handler = (create_h*) dlsym(lib, "create");
const char* dlsym_error = dlerror();
if (dlsym_error) {
LOG(DEBUG) <<"Cannot load symbol create: " << dlsym_error;
return NULL;
}
return create_handler;
}
void tryToCloseImeLib(ImeHandler* handler, IMELIB_TYPE lib) {
destroy_h* destroy_handler = getDestroyHandler(lib);
destroy_handler(handler);
if(dlclose(lib) != 0) {
LOG(ERROR) << dlerror();
}
}
#else
IMELIB_TYPE tryToOpenImeLib() {
IMELIB_TYPE lib = LoadLibrary(L"imehandler.dll");
if (!lib) {
LOG(DEBUG) << "Cannot load the shared library: " << GetLastError();
return NULL;
}
return lib;
}
destroy_h* getDestroyHandler(IMELIB_TYPE lib) {
FARPROC initializer = GetProcAddress(lib, "destroy");
if(initializer == NULL)
{
LOG(DEBUG) <<"Cannot load symbol destroy: " << GetLastError();
return NULL;
}
destroy_h* destroy_handler = (destroy_h*)initializer;
return destroy_handler;
}
create_h* getCreateHandler(IMELIB_TYPE lib) {
FARPROC initializer = GetProcAddress(lib, "create");
if(initializer == NULL) {
LOG(DEBUG) <<"Cannot load symbol create: " << GetLastError();
return NULL;
}
create_h* create_handler = (create_h*)initializer;
return create_handler;
}
void tryToCloseImeLib(ImeHandler* handler, IMELIB_TYPE lib) {
if( FreeLibrary(lib) == 0) {
LOG(ERROR) << GetLastError();
}
}
#endif