2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef PLUGINLOADER_H
20 #define PLUGINLOADER_H
27 #include "abstractsource.h"
28 #include "abstractsink.h"
29 #include "abstractroutingengine.h"
31 #include "imainloop.h"
33 typedef void create_t(AbstractRoutingEngine*, map<string, string> );
34 typedef void* create_mainloop_t(int argc, char** argv);
35 typedef void* createRoutingEngine(void);
41 PluginLoader(std::string configFile, int argc, char** argv);
44 IMainLoop* mainloop();
46 std::string errorString();
48 void scanPluginDir(const std::string &);
50 bool readPluginConfig(const std::string & configData);
55 bool loadPlugin(string pluginName, std::map<std::string, std::string> config)
57 DebugOut()<<"Loading plugin: "<<pluginName<<endl;
59 void* handle = dlopen(pluginName.c_str(), RTLD_LAZY);
63 mErrorString = dlerror();
64 DebugOut(DebugOut::Error)<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
68 openHandles.push_back(handle);
70 f_create = (create_t *)dlsym(handle, "create");
74 f_create(routingEngine, config);
81 IMainLoop* loadMainLoop(string pluginName, int argc, char** argv)
83 DebugOut()<<"Loading plugin: "<<pluginName<<endl;
85 void* handle = dlopen(pluginName.c_str(), RTLD_LAZY);
89 mErrorString = dlerror();
90 DebugOut(DebugOut::Error)<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
94 openHandles.push_back(handle);
96 m_create = (create_mainloop_t *)dlsym(handle, "create");
100 void* obj = m_create(argc, argv);
101 return static_cast<IMainLoop*>( obj );
106 AbstractRoutingEngine* loadRoutingEngine(string pluginName)
108 DebugOut()<<"Loading plugin: "<<pluginName<<endl;
110 void* handle = dlopen(pluginName.c_str(), RTLD_LAZY);
114 mErrorString = dlerror();
115 cerr<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
119 openHandles.push_back(handle);
121 r_create = (createRoutingEngine *)dlsym(handle, "create");
125 void* obj = r_create();
126 return static_cast<AbstractRoutingEngine*>( obj );
134 std::string mPluginPath;
135 std::string mErrorString;
137 AbstractRoutingEngine* routingEngine;
140 create_mainloop_t * m_create;
141 createRoutingEngine * r_create;
143 IMainLoop* mMainLoop;
145 std::vector<void*> openHandles;
148 #endif // PLUGINLOADER_H