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"
36 typedef void* create_t(AbstractRoutingEngine*, map<string, string> );
37 typedef void* create_mainloop_t(int argc, char** argv);
38 typedef void* createRoutingEngine(void);
44 PluginLoader(string configFile, int argc, char** argv);
49 IMainLoop* mainloop();
51 std::string errorString();
57 T loadPlugin(string pluginName, map<string, string> config)
59 DebugOut()<<"Loading plugin: "<<pluginName<<endl;
61 void* handle = dlopen(pluginName.c_str(), RTLD_LAZY);
65 mErrorString = dlerror();
66 DebugOut(DebugOut::Error)<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
70 openHandles.push_back(handle);
72 f_create = (create_t *)dlsym(handle, "create");
76 void* obj = f_create(routingEngine, config);
77 return static_cast<T>(obj);
83 IMainLoop* loadMainLoop(string pluginName, int argc, char** argv)
85 DebugOut()<<"Loading plugin: "<<pluginName<<endl;
87 void* handle = dlopen(pluginName.c_str(), RTLD_LAZY);
91 mErrorString = dlerror();
92 DebugOut(DebugOut::Error)<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
96 openHandles.push_back(handle);
98 m_create = (create_mainloop_t *)dlsym(handle, "create");
102 void* obj = m_create(argc, argv);
103 return static_cast<IMainLoop*>( obj );
108 AbstractRoutingEngine* loadRoutingEngine(string pluginName)
110 DebugOut()<<"Loading plugin: "<<pluginName<<endl;
112 void* handle = dlopen(pluginName.c_str(), RTLD_LAZY);
116 mErrorString = dlerror();
117 cerr<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
121 openHandles.push_back(handle);
123 r_create = (createRoutingEngine *)dlsym(handle, "create");
127 void* obj = r_create();
128 return static_cast<AbstractRoutingEngine*>( obj );
136 std::string mPluginPath;
137 std::string mErrorString;
139 AbstractRoutingEngine* routingEngine;
142 list<AbstractSinkManager*> mSinkManagers;
145 create_mainloop_t * m_create;
146 createRoutingEngine * r_create;
149 IMainLoop* mMainLoop;
151 std::vector<void*> openHandles;
154 #endif // PLUGINLOADER_H