some work on the bluemonkey
authorKevron Rees <tripzero.kev@gmail.com>
Wed, 22 May 2013 14:32:54 +0000 (07:32 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Tue, 28 May 2013 01:26:52 +0000 (18:26 -0700)
CMakeLists.txt
ambd/CMakeLists.txt
plugins/bluemonkey/CMakeLists.txt
plugins/bluemonkey/bluemonkey.cpp
plugins/bluemonkey/bluemonkey.h
plugins/bluemonkey/irccoms.cpp
plugins/bluemonkey/irccoms.h

index 1c4c8a0..c1762ae 100644 (file)
@@ -18,7 +18,7 @@ set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_LIBRARY_A
 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)
@@ -69,19 +69,29 @@ add_definitions(-DDBusServiceName="org.automotive.message.broker")
 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})
index 08ee300..6ea67e4 100644 (file)
@@ -1,7 +1,7 @@
 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)
 
@@ -10,7 +10,7 @@ if(use_qtcore)
     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})
 
index b6d4770..2024828 100644 (file)
@@ -1,19 +1,25 @@
 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)
index b8a9375..c28d267 100644 (file)
@@ -20,8 +20,9 @@
 #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)
@@ -29,8 +30,13 @@ extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, ma
        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");
+       });
 
 }
 
@@ -54,3 +60,56 @@ std::string BluemonkeySink::uuid()
 {
        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;
+       };
+}
index 3839b9e..1803de7 100644 (file)
 
 #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
 {
@@ -32,6 +68,16 @@ public:
        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
index cbe0c5f..1cdb12e 100644 (file)
@@ -3,11 +3,11 @@
 #include <IrcCommand>
 #include <IrcMessage>
 #include <QSslSocket>
-#include <QScriptEngine>
 #include <QFile>
 #include <QNetworkProxy>
 #include <QTimer>
 
+#define foreach Q_FOREACH
 
 IrcCommunication::IrcCommunication(QObject* parent)
        :QObject(parent)
@@ -114,7 +114,7 @@ void IrcCommunication::reconnect()
        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());
@@ -122,7 +122,7 @@ void IrcCommunication::sslError(QList<QSslError>)
        {
                socket->ignoreSslErrors();
        }
-}
+}*/
 
 void IrcCommunication::socketError(QAbstractSocket::SocketError error)
 {
@@ -133,5 +133,5 @@ 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>)));
 }
index cb6d057..8c4a61e 100644 (file)
@@ -4,8 +4,6 @@
 #include <QVariant>
 #include <QStringList>
 
-#include <QSslError>
-
 #include <IrcSession>
 #include <IrcMessage>
 
@@ -19,7 +17,7 @@ public:
        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);
@@ -29,12 +27,12 @@ public slots:
 
        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();