From: Kevron Rees Date: Thu, 16 May 2013 05:14:47 +0000 (-0700) Subject: initial bluemonkey irc plugin X-Git-Tag: submit/tizen/20130618.181635~24^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2eaa168f1618927c2b3d66ffa61d66a350c721d5;p=profile%2Fivi%2Fautomotive-message-broker.git initial bluemonkey irc plugin --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a44a695..1c4c8a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4fd6cc1..a0f85ec 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -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 index 0000000..b6d4770 --- /dev/null +++ b/plugins/bluemonkey/CMakeLists.txt @@ -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 index 0000000..b8a9375 --- /dev/null +++ b/plugins/bluemonkey/bluemonkey.cpp @@ -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 + + +extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map config) +{ + return new BluemonkeySinkManager(routingengine, config); +} + +BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* engine, map 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 index 0000000..3839b9e --- /dev/null +++ b/plugins/bluemonkey/bluemonkey.h @@ -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 + +class BluemonkeySink : public QObject, public AbstractSink +{ +Q_OBJECT +public: + BluemonkeySink(AbstractRoutingEngine* engine, map 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 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 index 0000000..cbe0c5f --- /dev/null +++ b/plugins/bluemonkey/irccoms.cpp @@ -0,0 +1,137 @@ +#include "irccoms.h" +#include +#include +#include +#include +#include +#include +#include +#include + + +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: "<sendCommand(&command); + } +} + +void IrcCommunication::respond(QString target, QString s) +{ + IrcCommand command; + command.setType(IrcCommand::Message); + command.setParameters(QStringList()<sendCommand(&command); +} + +void IrcCommunication::messageReceived(IrcMessage *msg) +{ + qDebug()<<"message received "<type()<<" prefix: "<sender().prefix()<<" params:"<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()<sendCommand(&command); +} + +void IrcCommunication::reconnect() +{ + QTimer::singleShot(5000,session,SLOT(open())); +} + +void IrcCommunication::sslError(QList) +{ + qDebug()<<"some ssl errors!! trying to ignore them"; + QSslSocket* socket = qobject_cast(session->socket()); + if(socket) + { + socket->ignoreSslErrors(); + } +} + +void IrcCommunication::socketError(QAbstractSocket::SocketError error) +{ + qDebug()<<"Socket error. attempting to reconnect..."<socket(),SIGNAL(sslErrors(QList)),this,SLOT(sslError(QList))); +} diff --git a/plugins/bluemonkey/irccoms.h b/plugins/bluemonkey/irccoms.h new file mode 100644 index 0000000..cb6d057 --- /dev/null +++ b/plugins/bluemonkey/irccoms.h @@ -0,0 +1,49 @@ +#ifndef COMMUNICATION_H +#define COMMUNICATION_H +#include +#include +#include + +#include + +#include +#include + +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); + 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