initial bluemonkey irc plugin
authorKevron Rees <tripzero.kev@gmail.com>
Thu, 16 May 2013 05:14:47 +0000 (22:14 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Tue, 28 May 2013 01:26:52 +0000 (18:26 -0700)
CMakeLists.txt
plugins/CMakeLists.txt
plugins/bluemonkey/CMakeLists.txt [new file with mode: 0644]
plugins/bluemonkey/bluemonkey.cpp [new file with mode: 0644]
plugins/bluemonkey/bluemonkey.h [new file with mode: 0644]
plugins/bluemonkey/irccoms.cpp [new file with mode: 0644]
plugins/bluemonkey/irccoms.h [new file with mode: 0644]

index a44a695..1c4c8a0 100644 (file)
@@ -27,6 +27,7 @@ option(qt_bindings "AMB Qt DBus bindings" OFF)
 option(opencvlux_plugin "OpenCV Lux plugin" OFF)
 option(gpsd_plugin "gpsd location plugin" OFF)
 option(murphy_plugin "murphy policy framework plugin" OFF)
+option(bluemonkey_plugin "bluemonkey irc plugin" OFF)
 
 if(opencvlux_plugin)
    message(STATUS "OpenCV Lux plugin enabled")
index 4fd6cc1..a0f85ec 100644 (file)
@@ -30,3 +30,4 @@ add_subdirectory(database)
 add_subdirectory(opencvlux)
 add_subdirectory(gpsd)
 add_subdirectory(murphyplugin)
+add_subdirectory(bluemonkey)
diff --git a/plugins/bluemonkey/CMakeLists.txt b/plugins/bluemonkey/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b6d4770
--- /dev/null
@@ -0,0 +1,27 @@
+if(bluemonkey_plugin)
+
+
+FIND_PACKAGE(Qt4 COMPONENTS QtCore QtNetwork QtScript REQUIRED)
+include(${QT_USE_FILE})
+ADD_DEFINITIONS(${QT_DEFINITIONS})
+
+set(QT_USE_QSCRIPT TRUE)
+set(QT_USE_NETWORK TRUE)
+set(QT_DONT_USE_QTGUI TRUE)
+
+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})
+
+set(bluemonkeyplugin_headers bluemonkey.h irccoms.h)
+set(bluemonkeyplugin_sources bluemonkey.cpp irccoms.cpp)
+
+add_library(bluemonkeyplugin MODULE ${bluemonkeyplugin_sources})
+set_target_properties(bluemonkeyplugin PROPERTIES PREFIX "")
+target_link_libraries(bluemonkeyplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${QT_LIBRARIES} ${communi_LIBRARIES})
+
+install(TARGETS bluemonkeyplugin LIBRARY DESTINATION lib/automotive-message-broker)
+
+endif(bluemonkey_plugin)
diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp
new file mode 100644 (file)
index 0000000..b8a9375
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+    Copyright (C) 2012  Intel Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#include "bluemonkey.h"
+#include "abstractroutingengine.h"
+#include "debugout.h"
+
+#include <glib.h>
+
+
+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)
+{
+
+}
+
+
+PropertyList BluemonkeySink::subscriptions()
+{
+
+}
+
+void BluemonkeySink::supportedChanged(PropertyList supportedProperties)
+{
+
+}
+
+void BluemonkeySink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
+{
+
+}
+
+std::string BluemonkeySink::uuid()
+{
+       return "bluemonkey";
+}
diff --git a/plugins/bluemonkey/bluemonkey.h b/plugins/bluemonkey/bluemonkey.h
new file mode 100644 (file)
index 0000000..3839b9e
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+    Copyright (C) 2012  Intel Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#ifndef BluemonkeySink_H
+#define BluemonkeySink_H
+
+#include "abstractsink.h"
+#include <QObject>
+
+class BluemonkeySink : public QObject, public AbstractSink
+{
+Q_OBJECT
+public:
+       BluemonkeySink(AbstractRoutingEngine* engine, map<string, string> config);
+       virtual PropertyList subscriptions();
+       virtual void supportedChanged(PropertyList supportedProperties);
+       virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid);
+       virtual std::string uuid();
+};
+
+class BluemonkeySinkManager: public AbstractSinkManager
+{
+public:
+       BluemonkeySinkManager(AbstractRoutingEngine* engine, map<string, string> config)
+       :AbstractSinkManager(engine, config)
+       {
+               new BluemonkeySink(routingEngine, config);
+       }
+};
+
+#endif // BluemonkeySink_H
diff --git a/plugins/bluemonkey/irccoms.cpp b/plugins/bluemonkey/irccoms.cpp
new file mode 100644 (file)
index 0000000..cbe0c5f
--- /dev/null
@@ -0,0 +1,137 @@
+#include "irccoms.h"
+#include <QtDebug>
+#include <IrcCommand>
+#include <IrcMessage>
+#include <QSslSocket>
+#include <QScriptEngine>
+#include <QFile>
+#include <QNetworkProxy>
+#include <QTimer>
+
+
+IrcCommunication::IrcCommunication(QObject* parent)
+       :QObject(parent)
+{
+       session = new IrcSession(this);
+       mSsl=false;
+
+       QObject::connect(session,SIGNAL(connected()),this,SIGNAL(connected()));
+       QObject::connect(session,SIGNAL(disconnected()),this,SIGNAL(disconnected()));
+       QObject::connect(session,SIGNAL(disconnected()),this,SLOT(reconnect()));
+       QObject::connect(session,SIGNAL(socketError(QAbstractSocket::SocketError)),this,SLOT(socketError(QAbstractSocket::SocketError)));
+       QObject::connect(session,SIGNAL(connecting()),this,SIGNAL(connecting()));
+       QObject::connect(session,SIGNAL(messageReceived(IrcMessage*)),this,SLOT(messageReceived(IrcMessage*)));
+
+}
+
+void IrcCommunication::announce(QString s)
+{
+       qDebug()<<"channels: "<<mChannels;
+       foreach(QString channel, mChannels)
+       {
+               qDebug()<<"sending "<<s<<" to channel: "<<channel;
+               IrcCommand command;
+               command.setType(IrcCommand::Message);
+               command.setParameters(QStringList()<<channel<<s);
+               session->sendCommand(&command);
+       }
+}
+
+void IrcCommunication::respond(QString target, QString s)
+{
+       IrcCommand command;
+       command.setType(IrcCommand::Message);
+       command.setParameters(QStringList()<<target<<s);
+       session->sendCommand(&command);
+}
+
+void IrcCommunication::messageReceived(IrcMessage *msg)
+{
+       qDebug()<<"message received "<<msg->type()<<" prefix: "<<msg->sender().prefix()<<" params:"<<msg->parameters();
+
+       if(msg->type() == IrcMessage::Private)
+       {
+               if(msg->parameters().count() > 1)
+               {
+                       QString sender = msg->parameters().at(0);
+                       QString m = msg->parameters().at(1);
+
+                       message(sender,msg->sender().prefix(),m);
+               }
+
+       }
+}
+
+void IrcCommunication::connect(QString host, int port, QString proxy, QString user, QString nick, QString pass)
+{
+       session->setHost(host);
+       session->setPort(port);
+       session->setUserName(user);
+       session->setNickName(nick);
+       session->setRealName(nick);
+
+       if(!proxy.isEmpty())
+       {
+               if(!proxy.contains(":"))
+               {
+                       qDebug("proxy format must be 'address:port'");
+                       return;
+               }
+               QString host = proxy.split(":").at(0);
+               int port = proxy.split(":").at(1).toInt();
+
+               QNetworkProxy netproxy;
+               netproxy.setType(QNetworkProxy::Socks5Proxy);
+               netproxy.setHostName(host);
+               netproxy.setPort(port);
+
+               QNetworkProxy::setApplicationProxy(netproxy);
+       }
+
+       qDebug()<<"opening irc session";
+       session->open();
+}
+
+void IrcCommunication::setSsl(bool use)
+{
+       if(use)
+               session->setSocket(new QSslSocket(this));
+}
+
+void IrcCommunication::join(QString channel)
+{
+       if(!mChannels.contains(channel))
+               mChannels.append(channel);
+
+       IrcCommand command;
+       command.setType(IrcCommand::Join);
+       command.setParameters(QStringList()<<channel);
+       session->sendCommand(&command);
+}
+
+void IrcCommunication::reconnect()
+{
+       QTimer::singleShot(5000,session,SLOT(open()));
+}
+
+void IrcCommunication::sslError(QList<QSslError>)
+{
+       qDebug()<<"some ssl errors!! trying to ignore them";
+       QSslSocket* socket = qobject_cast<QSslSocket*>(session->socket());
+       if(socket)
+       {
+               socket->ignoreSslErrors();
+       }
+}
+
+void IrcCommunication::socketError(QAbstractSocket::SocketError error)
+{
+       qDebug()<<"Socket error.  attempting to reconnect..."<<error;
+       reconnect();
+}
+
+void IrcCommunication::setIgnoreInvalidCert(bool ignore)
+{
+       if(ignore)
+               QObject::connect(session->socket(),SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(sslError(QList<QSslError>)));
+}
diff --git a/plugins/bluemonkey/irccoms.h b/plugins/bluemonkey/irccoms.h
new file mode 100644 (file)
index 0000000..cb6d057
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef COMMUNICATION_H
+#define COMMUNICATION_H
+#include <QObject>
+#include <QVariant>
+#include <QStringList>
+
+#include <QSslError>
+
+#include <IrcSession>
+#include <IrcMessage>
+
+class IrcCommunication: public QObject
+{
+       Q_OBJECT
+       Q_PROPERTY(QStringList channels READ channels WRITE setChannels)
+       Q_PROPERTY(bool ssl WRITE setSsl)
+public:
+       IrcCommunication(QObject* parent=0);
+       QStringList channels() { return mChannels; }
+       void setChannels(QStringList c) { mChannels = c; }
+
+public 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 setSsl(bool use);
+       void setIgnoreInvalidCert(bool ignore);
+       void join(QString channel);
+
+       void reconnect();
+
+private slots:
+       void messageReceived(IrcMessage*);
+       void sslError(QList<QSslError>);
+       void socketError(QAbstractSocket::SocketError);
+
+signals:
+       void message(QString sender, QString prefix, QString codes);
+       void connecting();
+       void connected();
+       void disconnected();
+
+private:
+       bool mSsl;
+       QStringList mChannels;
+       IrcSession *session;
+};
+
+#endif // COMMUNICATION_H