From: Kevron Rees Date: Mon, 9 Sep 2013 20:17:01 +0000 (-0700) Subject: rearranged bluemonkey's eval timeout X-Git-Tag: accepted/tizen/20131016.224205~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c57a54d51381814802ae10132c7bb76ccb346de;p=profile%2Fivi%2Fautomotive-message-broker.git rearranged bluemonkey's eval timeout --- diff --git a/examples/bluemonkey/bluemonkeyconfig b/examples/bluemonkey/bluemonkeyconfig index 0c15bef..e6db4f7 100644 --- a/examples/bluemonkey/bluemonkeyconfig +++ b/examples/bluemonkey/bluemonkeyconfig @@ -3,7 +3,7 @@ "sources" : [ { - "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so" + "path" : "/usr/lib/automotive-message-broker/murphysourceplugin.so" } ], "sinks": [ diff --git a/plugins/bluemonkey/agent.cpp b/plugins/bluemonkey/agent.cpp index 6d5252d..944478b 100644 --- a/plugins/bluemonkey/agent.cpp +++ b/plugins/bluemonkey/agent.cpp @@ -12,20 +12,27 @@ void BluemonkeyAgent::scriptLoad(qint64 id, const QString &program, const QStrin { DebugOut()<<"executing script"<setInterval(20000); + QTimer *timer = new QTimer(); timer->setSingleShot(true); - timer->start(); + timer->connect(timer, SIGNAL(timeout(QPrivateSignal)), this, SLOT(timeout(QPrivateSignal))); + timer->start(5000); + + timerIdMap[timer] = id; +} + +void BluemonkeyAgent::timeout(QPrivateSignal) +{ + quint64 id = timerIdMap[sender()]; + + if(idList.contains(id)) + { + DebugOut()<<"script aborted evaluation. timed out."<abortEvaluation(); + } - QScriptEngine* e = engine(); + timerIdMap.remove(sender()); - connect(timer, &QTimer::timeout, [id,&e,&timer,this](){ - if(idList.contains(id)) - { - e->abortEvaluation(); - } - }); + sender()->deleteLater(); } void BluemonkeyAgent::scriptUnload(qint64 id) diff --git a/plugins/bluemonkey/agent.h b/plugins/bluemonkey/agent.h index 3346401..f21fc92 100644 --- a/plugins/bluemonkey/agent.h +++ b/plugins/bluemonkey/agent.h @@ -12,8 +12,12 @@ public: void scriptLoad (qint64 id, const QString &program, const QString &fileName, int baseLineNumber ); void scriptUnload(qint64 id); +private Q_SLOTS: + void timeout(QPrivateSignal); + private: QList idList; + QMap timerIdMap; }; diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp index 73d2604..6ee363e 100644 --- a/plugins/bluemonkey/bluemonkey.cpp +++ b/plugins/bluemonkey/bluemonkey.cpp @@ -89,7 +89,7 @@ QVariant gvariantToQVariant(GVariant *value) } -BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map config): QObject(0), AbstractSink(e, config), agent(nullptr), engine(nullptr) +BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map config): QObject(0), AbstractSink(e, config), agent(nullptr), engine(nullptr), mSilentMode(false) { irc = new IrcCommunication(config, this); @@ -116,7 +116,8 @@ BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map con { if(!auth->isAuthorized(prefix)) { - irc->respond(sender, "denied"); + if(!mSilentMode) + irc->respond(sender, "denied"); return; } @@ -124,12 +125,13 @@ BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map con codes = codes.mid(bm.length()+1); - irc->respond(sender, engine->evaluate(codes).toString()); + QString response = engine->evaluate(codes).toString(); + + if(!mSilentMode || response != "undefined" ) + irc->respond(sender, response); } }); - - } diff --git a/plugins/bluemonkey/bluemonkey.h b/plugins/bluemonkey/bluemonkey.h index 97480e6..5c2b9a8 100644 --- a/plugins/bluemonkey/bluemonkey.h +++ b/plugins/bluemonkey/bluemonkey.h @@ -101,6 +101,11 @@ public Q_SLOTS: void getHistory(QStringList properties, QDateTime begin, QDateTime end, QScriptValue cbFunction); + void setSilentMode(bool m) + { + mSilentMode = m; + } + private Q_SLOTS: /// methods: void loadConfigPriv(); @@ -111,6 +116,7 @@ private: Authenticate* auth; BluemonkeyAgent* agent; + bool mSilentMode; }; class BluemonkeySinkManager: public AbstractSinkManager diff --git a/plugins/bluemonkey/irccoms.cpp b/plugins/bluemonkey/irccoms.cpp index 55b95e8..a6c99ef 100644 --- a/plugins/bluemonkey/irccoms.cpp +++ b/plugins/bluemonkey/irccoms.cpp @@ -164,7 +164,7 @@ void IrcCommunication::reconnect() QTimer::singleShot(5000,this,SLOT(open())); } -void IrcCommunication::sslError(QList &) +void IrcCommunication::sslError(QList ) { qDebug()<<"some ssl errors!! trying to ignore them"; QSslSocket* sock = qobject_cast(socket()); @@ -183,5 +183,5 @@ void IrcCommunication::socketError(QAbstractSocket::SocketError error) void IrcCommunication::setIgnoreInvalidCert(bool ignore) { if(ignore) - QObject::connect(socket(),SIGNAL(sslErrors(QList&)),this,SLOT(sslError(QList&))); + QObject::connect(socket(),SIGNAL(sslErrors(QList)),this,SLOT(sslError(QList))); } diff --git a/plugins/bluemonkey/irccoms.h b/plugins/bluemonkey/irccoms.h index 261d016..3ce016b 100644 --- a/plugins/bluemonkey/irccoms.h +++ b/plugins/bluemonkey/irccoms.h @@ -34,7 +34,7 @@ public Q_SLOTS: private Q_SLOTS: void onMessageReceived(IrcMessage*); - void sslError(QList &); + void sslError(QList); void socketError(QAbstractSocket::SocketError); Q_SIGNALS: diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp index c0141e2..bfb6bee 100644 --- a/plugins/dbus/abstractdbusinterface.cpp +++ b/plugins/dbus/abstractdbusinterface.cpp @@ -203,7 +203,8 @@ void AbstractDBusInterface::addProperty(AbstractProperty* property) "" " " " " - ""; + "" + ""; properties[property->name()] = property; @@ -304,6 +305,7 @@ void AbstractDBusInterface::updateValue(AbstractProperty *property) g_variant_builder_init(&builder, G_VARIANT_TYPE_DICTIONARY); g_variant_builder_add(&builder, "{sv}", property->name().c_str(), val); + g_variant_builder_add(&builder, "{sv}", std::string(property->name() + "Sequence").c_str(), g_variant_new("(i)", property->sequence())); g_variant_builder_add(&builder, "{sv}", "Time", g_variant_new("(d)", mTime) ); GError *error2 = NULL; @@ -383,6 +385,28 @@ GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const return value; } + if(boost::ends_with(pn, "Sequence")) + { + AbstractDBusInterface* t = static_cast(userData); + + int pos = pn.find("Sequence"); + + std::string p = pn.substr(0,pos); + + AbstractProperty* theProperty = t->property(p); + + if(!theProperty) + { + DebugOut(DebugOut::Error)<<"Invalid Sequence property: "<sequence(); + + GVariant* value = g_variant_new("(i)", sequence); + return value; + } + if(pn == "Zone") { if(objectMap.find(objectPath) == objectMap.end()) diff --git a/plugins/dbus/abstractdbusinterface.h b/plugins/dbus/abstractdbusinterface.h index 54906bd..68d74d9 100644 --- a/plugins/dbus/abstractdbusinterface.h +++ b/plugins/dbus/abstractdbusinterface.h @@ -66,6 +66,13 @@ public: double time() { return mTime; } + AbstractProperty* property(std::string propertyName) + { + if(properties.find(propertyName) != properties.end()) + return properties[propertyName]; + return nullptr; + } + AbstractRoutingEngine* re; void setObjectPath(std::string op) diff --git a/plugins/dbus/abstractproperty.h b/plugins/dbus/abstractproperty.h index f9e952c..4eb3f7f 100644 --- a/plugins/dbus/abstractproperty.h +++ b/plugins/dbus/abstractproperty.h @@ -84,6 +84,13 @@ public: return mTimestamp; } + int sequence() + { + if(mValue) + return mValue->sequence; + return 0; + } + virtual void setValue(AbstractPropertyType* val) { if(mValue) delete mValue;