Started implementing various things.
[aesalon.git] / monitor / src / module / Module.cpp
blob9fb32fe5bb3485da9f2df4c354ce2dc4db7d8852
1 /**
2 Aesalon, a tool to visualize a program's behaviour at run-time.
3 Copyright (C) 2010, Aesalon Development Team.
5 Aesalon is distributed under the terms of the GNU GPLv3. For more
6 licensing information, see the file LICENSE included with the distribution.
8 @file monitor/src/module/Module.cpp
12 #include <iostream>
14 #include <dlfcn.h>
16 #include "module/Module.h"
17 #include "monitor/Coordinator.h"
18 #include "common/Preprocessor.h"
19 #include "common/StringTo.h"
21 namespace Monitor {
22 namespace Module {
24 Module::Module(const std::string &moduleName) : m_moduleName(moduleName) {
25 m_instance = NULL;
26 loadPreprocessor();
27 loadMarshaller();
30 Module::~Module() {
31 dlclose(m_marshallerHandle);
34 void Module::loadMarshaller() {
35 std::string path =
36 Coordinator::instance()->vault()->get(m_moduleName + ":root")
37 + Coordinator::instance()->vault()->get(m_moduleName + ":marshallerPath");
39 std::cout << path << std::endl;
41 m_marshallerHandle = dlopen(path.c_str(), RTLD_LOCAL | RTLD_NOW);
42 if(m_marshallerHandle == NULL) {
43 return;
46 Common::MarshallerInterface *(*instantiate)() = NULL;
48 *(void **)(&instantiate) = dlsym(m_marshallerHandle, "AM_InstantiateMarshaller");
50 if(instantiate == NULL) {
51 /* This is an error. */
52 std::cout << "Module exists, but does not have exported AM_InstantiateMarshaller() . . ." << std::endl;
53 std::cout << "\tDid you forget to place it in an extern \"C\" block?" << std::endl;
55 else {
56 m_instance = instantiate();
60 void Module::loadPreprocessor() {
61 std::string ppPath = Coordinator::instance()->vault()->get(m_moduleName + ":preprocessorPath");
62 if(ppPath == "") return;
63 std::string path =
64 Coordinator::instance()->vault()->get(m_moduleName + ":root") + ppPath;
66 m_preprocessorHandle = dlopen(path.c_str(), RTLD_LOCAL | RTLD_NOW);
67 if(m_preprocessorHandle == NULL) return;
69 Common::Preprocessor preprocessor;
71 *(void **)(&preprocessor) = dlsym(m_marshallerHandle, "AM_Preprocess");
73 if(preprocessor == NULL) {
74 /* This is an error. */
75 std::cout << "Module exists, but does not have AM_Preprocess() . . ." << std::endl;
77 else {
78 preprocessor(Coordinator::instance()->vault());
82 } // namespace Module
83 } // namespace Monitor