-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
33 lines (26 loc) · 951 Bytes
/
main.cpp
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
#include "api.hpp"
#include <cassert>
#include <iostream>
#include <dlfcn.h>
typedef Job* (*JobCreateFn)();
typedef JobExecutor* (*JobExecutorCreateFn)();
int main(int argn, char* argv[]) {
if (argn != 2 || (strcmp(argv[1], "local") && strcmp(argv[1], "global"))) {
std::cerr << "usage: main <local | global>" << std::endl;
return 1;
}
int flag = (strcmp(argv[1], "local") ? RTLD_GLOBAL : RTLD_LOCAL) | RTLD_NOW;
void *h1 = dlopen("./libjob_impl.so", flag);
assert(h1);
JobCreateFn job_create_fn = (JobCreateFn)dlsym(h1, "create_job");
assert(job_create_fn);
Job* job = job_create_fn();
assert(job);
void *h2 = dlopen("./libjob_executor_impl.so", flag);
assert(h2);
JobExecutorCreateFn job_executor_create_fn = (JobExecutorCreateFn)dlsym(h2, "create_job_executor");
assert(job_executor_create_fn);
JobExecutor* job_executor = job_executor_create_fn();
assert(job_executor);
job_executor->execute(job);
}