-add_executable(ambd core.cpp main.cpp pluginloader.cpp)
+set(ambd_headers core.h imainloop.h pluginloader.h glibmainloop.h)
+set(ambd_sources core.cpp main.cpp pluginloader.cpp glibmainloop.cpp)
+
+if(use_qtcore)
+ set(qtmainloopplugin_headers qtmainloop.h)
+ set(qtmainloopplugin_sources qtmainloop.cpp)
+
+ add_library(qtmainloopplugin MODULE ${qtmainloopplugin_sources})
+ set_target_properties(qtmainloopplugin PROPERTIES PREFIX "")
+ target_link_libraries(qtmainloopplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
+
+ install(TARGETS qtmainloopplugin LIBRARY DESTINATION lib/automotive-message-broker)
+endif(use_qtcore)
+
+add_executable(ambd ${ambd_sources})
include_directories(${include_dirs} )
target_link_libraries(ambd ${link_libraries} amb)
--- /dev/null
+#include "glibmainloop.h"
+#include <glib.h>
+#include <stdlib.h>
+
+GlibMainLoop::GlibMainLoop(int argc, char **argv)
+ :IMainLoop(argc,argv)
+{
+ mainLoop = g_main_loop_new(NULL, false);
+}
+
+GlibMainLoop::~GlibMainLoop()
+{
+ g_main_loop_quit(mainLoop);
+ exit(0);
+}
+
+int GlibMainLoop::exec()
+{
+ g_main_loop_run(mainLoop);
+}
+
--- /dev/null
+#ifndef _GLIBMAINLOOP_H_
+#define _GLIBMAINLOOP_H_
+
+#include "imainloop.h"
+#include <glib.h>
+
+class GlibMainLoop: public IMainLoop
+{
+public:
+
+ GlibMainLoop(int argc, char** argv);
+ ~GlibMainLoop();
+
+ int exec();
+
+private:
+ GMainLoop* mainLoop;
+};
+
+
+#endif
--- /dev/null
+#ifndef IMAINLOOP_H_
+#define IMAINLOOP_H_
+
+
+
+class IMainLoop {
+public:
+
+ IMainLoop(int argc, char **argv)
+ :mArgc(argc),mArgv(argv)
+ {
+
+ }
+
+ virtual ~IMainLoop() { }
+
+ virtual int exec() = 0;
+
+private:
+ int mArgc;
+ char** mArgv;
+};
+
+
+#endif
using namespace std;
-#ifndef USE_QT_CORE
-
-GMainLoop* mainLoop = nullptr;
-
-#endif
+IMainLoop* mainloop = nullptr;
void interrupt(int sign)
{
signal(sign, SIG_IGN);
cout<<"Signal caught. Exiting gracefully.\n"<<endl;
-#ifdef USE_QT_CORE
- QCoreApplication::exit(0);
-#else
- g_main_loop_quit(mainLoop);
- exit(0);
-#endif
+ /// this will cause the application to terminate and clean up:
+ delete mainloop;
}
void daemonize();
DebugOut::setOutput(logfile);
}
-
-#ifdef USE_QT_CORE
-
- QCoreApplication app(argc,argv);
-
-#else
-
- mainLoop = g_main_loop_new(NULL, false);
-
-#endif
-
g_type_init();
VehicleProperty::factory();
-
- /* Register signal handler */
- signal(SIGINT, interrupt);
- signal(SIGTERM, interrupt);
- PluginLoader loader(config, new Core());
+ PluginLoader loader(config, new Core(), argc, argv);
if(!loader.sources().size())
{
throw std::runtime_error("No sources present. aborting");
}
-
-
-
-#ifdef USE_QT_CORE
-
- app.exec();
-
-#else
-
- g_main_loop_run(mainLoop);
-
-#endif
+
+ mainloop = loader.mainloop();
+
+ /* Register signal handler */
+ signal(SIGINT, interrupt);
+ signal(SIGTERM, interrupt);
+
+ mainloop->exec();
if(logfile.is_open())
logfile.close();
#include "pluginloader.h"
+#include "glibmainloop.h"
+
#include <iostream>
#include <stdexcept>
#include <json-glib/json-glib.h>
+
using namespace std;
/********************************************
*
**********************************************/
-PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re): f_create(NULL), routingEngine(re)
+PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re, int argc, char** argv): f_create(NULL), routingEngine(re), mMainLoop(nullptr)
{
DebugOut()<<"Loading config file: "<<configFile<<endl;
throw std::runtime_error("Unable to create JSON reader");
DebugOut()<<"Config members: "<<json_reader_count_members(reader)<<endl;
-
- json_reader_read_member(reader,"sources");
-
- const GError * srcReadError = json_reader_get_error(reader);
+
+ if(json_reader_read_member(reader,"mainloop"))
+ {
+ /// there is a mainloop entry. Load the plugin:
+
+ string mainloopstr = json_reader_get_string_value(reader);
+
+ mMainLoop = loadMainLoop(mainloopstr,argc, argv);
+
+ if(!mMainLoop)
+ {
+ DebugOut(0)<<"Failed to load main loop plugin."<<endl;
+ }
+ }
+ else if(!mMainLoop)
+ {
+ /// there is no mainloop entry, use default glib
+ DebugOut()<<"No mainloop specified in config. Using glib by default."<<endl;
+ mMainLoop = new GlibMainLoop(argc,argv);
+ }
- if(srcReadError != nullptr)
+ json_reader_end_member(reader);
+
+ if(!json_reader_read_member(reader,"sources"))
{
+
+ const GError * srcReadError = json_reader_get_error(reader);
+
DebugOut()<<"Error getting sources member: "<<srcReadError->message<<endl;
throw std::runtime_error("Error getting sources member");
}
return mSinks;
}
+IMainLoop *PluginLoader::mainloop()
+{
+ return mMainLoop;
+}
+
SourceList PluginLoader::sources()
{
return mSources;
#include "abstractsink.h"
#include "abstractroutingengine.h"
#include "debugout.h"
-
+#include "imainloop.h"
using namespace std;
typedef void* create_t(AbstractRoutingEngine*, map<string, string> );
-
+typedef void* create_mainloop_t(int argc, char** argv);
class PluginLoader
{
public:
- PluginLoader(string configFile, AbstractRoutingEngine* routingEngine);
+ PluginLoader(string configFile, AbstractRoutingEngine* routingEngine, int argc, char** argv);
~PluginLoader();
SourceList sources();
SinkList sinks();
+ IMainLoop* mainloop();
+
std::string errorString();
return nullptr;
}
+
+ IMainLoop* loadMainLoop(string pluginName, int argc, char** argv)
+ {
+ DebugOut()<<"Loading plugin: "<<pluginName<<endl;
+
+ if(lt_dlinit())
+ {
+ mErrorString = lt_dlerror();
+ cerr<<"error initializing libtool: "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
+ return nullptr;
+ }
+
+ lt_dlerror();
+
+ lt_dlhandle handle = lt_dlopenext(pluginName.c_str());
+
+ if(!handle)
+ {
+ mErrorString = lt_dlerror();
+ cerr<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
+ return nullptr;
+ }
+
+ m_create = (create_mainloop_t *)lt_dlsym(handle, "create");
+
+ if(m_create)
+ {
+ void* obj = m_create(argc, argv);
+ return static_cast<IMainLoop*>( obj );
+ }
+
+ return nullptr;
+ }
private:
SinkList mSinks;
create_t * f_create;
+ create_mainloop_t * m_create;
+
+
+ IMainLoop* mMainLoop;
};
#endif // PLUGINLOADER_H
--- /dev/null
+#include "qtmainloop.h"
+
+extern "C" IMainLoop * create(int argc, char** argv)
+{
+ return new QtMainLoop(argc, argv);
+}
+
+QtMainLoop::QtMainLoop(int argc, char** argv)
+ :IMainLoop(argc,argv)
+{
+ app = new QCoreApplication(argc,argv);
+}
+
+QtMainLoop::~QtMainLoop()
+{
+ app->exit(0);
+}
+
+int QtMainLoop::exec()
+{
+ app->exec();
+}
--- /dev/null
+#ifndef _QTMAINLOOP_H_
+#define _QTMAINLOOP_H_
+
+#include <QCoreApplication>
+#include "imainloop.h"
+
+class QtMainLoop: public IMainLoop
+{
+public:
+
+ QtMainLoop(int argc, char **argv);
+ ~QtMainLoop();
+
+ int exec();
+private:
+ QCoreApplication* app;
+};
+
+#endif
--- /dev/null
+{
+ "mainloop" : "/usr/lib/automotive-message-broker/qtmainloopplugin.so",
+ "sources" : [
+ {
+ "name" : "ExampleSouce",
+ "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so"
+ }
+ ],
+ "sinks": [
+ {
+ "name" : "Example sink",
+ "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so",
+ "interface" : "lo",
+ "port" : "23000"
+ }
+ ]
+}
+
REGISTERPROPERTY(TransmissionFluidLevel,0);
REGISTERPROPERTY(BrakeFluidLevel,0);
REGISTERPROPERTY(WasherFluidLevel,0);
- REGISTERPROPERTY(SecurityAlertStatus,0);
+ REGISTERPROPERTY(SecurityAlertStatus,Security::Idle);
REGISTERPROPERTY(ParkingBrakeStatus,false);
REGISTERPROPERTY(ParkingLightStatus,false);
REGISTERPROPERTY(HazardLightStatus,false);
add_subdirectory(websocketsourceplugin)
add_subdirectory(tpms)
add_subdirectory(database)
-add_subdirectory(opencvlux)
+#add_subdirectory(opencvlux)
* @type boolean
* @access readonly
**/
- wantProperty<bool>(VehicleProperty::SecurityAlertStatus,"SecurityAlert", "b", AbstractProperty::Read);
+ wantProperty<Security::Status>(VehicleProperty::SecurityAlertStatus,"SecurityAlert", "i", AbstractProperty::Read);
supportedChanged(re->supported());
}