-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.cpp
More file actions
51 lines (39 loc) · 1013 Bytes
/
Loader.cpp
File metadata and controls
51 lines (39 loc) · 1013 Bytes
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
#include <memory>
#include <vector>
#include <string>
#include <dlfcn.h>
#include "Agent.h"
#include "HubAPI.h"
#include "configure.h"
#include "Loader.h"
typedef shared_ptr<Agent> (*externCreate)(void);
typedef void (*externDestroy)(shared_ptr<Agent>);
Loader::Loader(){
}
Loader::~Loader(){
}
shared_ptr<Agent> Loader::CreateInitAgent(shared_ptr<Configuration> _configInfo, HubAPI* _hub){
void* handle;
const char* error;
externCreate createSo;
shared_ptr<Agent> newAgent;
handle = dlopen(_configInfo->GetType().c_str(), RTLD_LAZY);
if (!handle) {
fprintf(stderr, "Couldn't open libctest: %s\n", dlerror());
exit(1);
}
l_handles.push_back(handle);
createSo = (externCreate) dlsym(handle, "create");
if ((error = dlerror())) {
cout << "Couldn't find create" << endl;
exit(1);
}
newAgent = createSo();
newAgent->Initialize(_configInfo, _hub);
return newAgent;
}
void Loader::DestroyAllAgents(){
for(unsigned int i = 0; i < l_handles.size(); ++i){
dlclose(l_handles[i]);
}
}