set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in")
set (DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/packages/${PROJECT_NAME}" CACHE PATH "The directory the docs will be installed to")
-option(use_qtcore "Use QCoreApplication mainloop " OFF)
+option(qtmainloop "Use QCoreApplication mainloop " OFF)
option(websocket_plugin "websocket source and sink plugins" OFF)
option(tpms_plugin "TPMS plugin " OFF)
option(obd_plugin "OBD-II plugin" OFF)
set(include_dirs ${libtool_INCLUDE_DIR} ${glib_INCLUDE_DIRS} ${gio_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${json_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(link_libraries -lamb ${libtool_LIBRARY} ${glib_LIBRARIES} ${json_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib)
-if(use_qtcore)
+if(qtmainloop)
message(STATUS "using Qt mainloop")
- find_package( Qt4 REQUIRED )
+ find_package(Qt5Core)
+ if(Qt5Core_FOUND)
+ message(STATUS "using Qt5")
+ set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS})
+ set(QT_LIBRARIES ${Qt5Core_LIBRARIES})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} -mcmodel=large")
+ add_definitions(${Qt5Core_DEFINITIONS})
+ else(Qt5Core_FOUND)
+ message(STATUS "using Qt4")
+ find_package( Qt4 REQUIRED )
+ include(${QT_USE_FILE})
+
+ endif(Qt5Core_FOUND)
- include(${QT_USE_FILE})
set(include_dirs ${include_dirs} ${QT_INCLUDE_DIRS})
set(link_libraries ${link_libraries} ${QT_LIBRARIES})
- add_definitions(-DUSE_QT_CORE)
add_definitions(-DQT_NO_KEYWORDS)
-
-endif(use_qtcore)
+ add_definitions(-DUSE_QT_CORE)
+endif(qtmainloop)
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${PROJECT_VERSION})
add_custom_target(dist COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD | bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
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)
+if(qtmainloop)
set(qtmainloopplugin_headers qtmainloop.h)
set(qtmainloopplugin_sources qtmainloop.cpp)
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)
+endif(qtmainloop)
add_executable(ambd ${ambd_sources})
if(bluemonkey_plugin)
-FIND_PACKAGE(Qt4 COMPONENTS QtCore QtNetwork QtScript REQUIRED)
-include(${QT_USE_FILE})
-ADD_DEFINITIONS(${QT_DEFINITIONS})
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Network REQUIRED)
+find_package(Qt5Script REQUIRED)
+if(Qt5Core_FOUND)
+ message(STATUS "using Qt5")
-set(QT_USE_QSCRIPT TRUE)
-set(QT_USE_NETWORK TRUE)
-set(QT_DONT_USE_QTGUI TRUE)
+ set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Script_INCLUDE_DIRS})
+ set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Script_LIBRARIES})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} -mcmodel=large")
+ add_definitions(${Qt5Core_DEFINITIONS})
+endif(Qt5Core_FOUND)
+
+set(CMAKE_AUTOMOC ON)
set(communi_INCLUDE_DIRS /usr/include/qt4/Communi)
set(communi_LIBRARIES -lCommuni)
add_definitions(-DCOMMUNI_SHARED)
-include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${communi_INCLUDE_DIRS})
+include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${communi_INCLUDE_DIRS} ${QT_INCLUDE_DIRS})
set(bluemonkeyplugin_headers bluemonkey.h irccoms.h)
set(bluemonkeyplugin_sources bluemonkey.cpp irccoms.cpp)
#include "bluemonkey.h"
#include "abstractroutingengine.h"
#include "debugout.h"
+#include "irccoms.h"
-#include <glib.h>
+#include <QJsonDocument>
extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
return new BluemonkeySinkManager(routingengine, config);
}
-BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
+BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* engine, map<string, string> config): QObject(0),AbstractSink(engine, config)
{
+ irc = new IrcCommunication(this);
+ irc->connect("chat.freenode.com",8001,"","tripzero","bluemoney","");
+ connect(irc,&IrcCommunication::connected, [&]() {
+ irc->join("#linuxice");
+ });
}
{
return "bluemonkey";
}
+
+QObject *BluemonkeySink::subscribeTo(QString str)
+{
+ return new Property(str.toStdString(), routingEngine, this);
+}
+
+
+QVariant Property::value()
+{
+ QJsonDocument doc;
+
+ doc.fromJson(mValue->toString().c_str());
+
+ return doc.toVariant();
+}
+
+void Property::setValue(QVariant v)
+{
+ QJsonDocument doc;
+ doc.fromVariant(v);
+
+ mValue->fromString(doc.toJson().data());
+
+ AsyncSetPropertyRequest request;
+ request.property = mValue->name;
+ request.value = mValue;
+ request.completed = [](AsyncPropertyReply* reply) { delete reply; };
+ routingEngine->setProperty(request);
+}
+
+Property::Property(VehicleProperty::Property prop, AbstractRoutingEngine* re, QObject *parent)
+ :QObject(parent), AbstractSink(re, std::map<std::string,std::string>())
+{
+ setType(prop.c_str());
+}
+
+QString Property::type()
+{
+ return mValue->name.c_str();
+}
+
+void Property::setType(QString t)
+{
+ mValue = VehicleProperty::getPropertyTypeForPropertyNameValue(t.toStdString());
+
+ AsyncPropertyRequest request;
+ request.property = mValue->name;
+ request.completed = [this](AsyncPropertyReply* reply)
+ {
+ propertyChanged(reply->property, reply->value,uuid());
+ delete reply;
+ };
+}
#include "abstractsink.h"
#include <QObject>
+#include <QVariant>
+
+class IrcCommunication;
+
+class Property: public QObject, public AbstractSink
+{
+ Q_OBJECT
+ Q_PROPERTY(QString type READ type)
+ Q_PROPERTY(QVariant value READ value WRITE setValue)
+
+public:
+ Property(VehicleProperty::Property, AbstractRoutingEngine* re, QObject *parent = 0);
+
+ QString type();
+ void setType(QString t);
+
+ virtual PropertyList subscriptions();
+ virtual void supportedChanged(PropertyList supportedProperties);
+
+ virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
+ {
+ mValue = value->copy();
+ }
+
+ virtual std::string uuid();
+
+ QVariant value();
+ void setValue(QVariant v);
+
+Q_SIGNALS:
+ void changed(QVariant val);
+
+private:
+ AbstractPropertyType* mValue;
+
+};
class BluemonkeySink : public QObject, public AbstractSink
{
virtual void supportedChanged(PropertyList supportedProperties);
virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid);
virtual std::string uuid();
+
+public Q_SLOTS:
+
+ QObject* subscribeTo(QString str);
+
+Q_SIGNALS:
+
+
+private:
+ IrcCommunication* irc;
};
class BluemonkeySinkManager: public AbstractSinkManager
#include <IrcCommand>
#include <IrcMessage>
#include <QSslSocket>
-#include <QScriptEngine>
#include <QFile>
#include <QNetworkProxy>
#include <QTimer>
+#define foreach Q_FOREACH
IrcCommunication::IrcCommunication(QObject* parent)
:QObject(parent)
QTimer::singleShot(5000,session,SLOT(open()));
}
-void IrcCommunication::sslError(QList<QSslError>)
+/*void IrcCommunication::sslError(QList<QSslError>)
{
qDebug()<<"some ssl errors!! trying to ignore them";
QSslSocket* socket = qobject_cast<QSslSocket*>(session->socket());
{
socket->ignoreSslErrors();
}
-}
+}*/
void IrcCommunication::socketError(QAbstractSocket::SocketError error)
{
void IrcCommunication::setIgnoreInvalidCert(bool ignore)
{
if(ignore)
- QObject::connect(session->socket(),SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(sslError(QList<QSslError>)));
+ QObject::connect(session->socket(),SIGNAL(),this,SLOT(sslError(QList<QSslError>)));
}
#include <QVariant>
#include <QStringList>
-#include <QSslError>
-
#include <IrcSession>
#include <IrcMessage>
QStringList channels() { return mChannels; }
void setChannels(QStringList c) { mChannels = c; }
-public slots:
+public Q_SLOTS:
void respond(QString target, QString msg);
void announce(QString);
void connect(QString host,int port, QString proxy, QString user, QString nick, QString pass);
void reconnect();
-private slots:
+private Q_SLOTS:
void messageReceived(IrcMessage*);
- void sslError(QList<QSslError>);
+// void sslError(QList<QSslError>);
void socketError(QAbstractSocket::SocketError);
-signals:
+Q_SIGNALS:
void message(QString sender, QString prefix, QString codes);
void connecting();
void connected();