rearranged bluemonkey's eval timeout
authorKevron Rees <kevron.m.rees@intel.com>
Mon, 9 Sep 2013 20:17:01 +0000 (13:17 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Mon, 9 Sep 2013 21:26:09 +0000 (14:26 -0700)
examples/bluemonkey/bluemonkeyconfig
plugins/bluemonkey/agent.cpp
plugins/bluemonkey/agent.h
plugins/bluemonkey/bluemonkey.cpp
plugins/bluemonkey/bluemonkey.h
plugins/bluemonkey/irccoms.cpp
plugins/bluemonkey/irccoms.h
plugins/dbus/abstractdbusinterface.cpp
plugins/dbus/abstractdbusinterface.h
plugins/dbus/abstractproperty.h

index 0c15bef..e6db4f7 100644 (file)
@@ -3,7 +3,7 @@
 
        "sources" : [ 
                {
-                       "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so"
+                       "path" : "/usr/lib/automotive-message-broker/murphysourceplugin.so"
                }
        ],
        "sinks": [
index 6d5252d..944478b 100644 (file)
@@ -12,20 +12,27 @@ void BluemonkeyAgent::scriptLoad(qint64 id, const QString &program, const QStrin
 {
        DebugOut()<<"executing script"<<endl;
 
-       QTimer* timer = new QTimer(this);
-
-       timer->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."<<endl;
+               engine()->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)
index 3346401..f21fc92 100644 (file)
@@ -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<quint64> idList;
+       QMap<QObject*,quint64> timerIdMap;
 };
 
 
index 73d2604..6ee363e 100644 (file)
@@ -89,7 +89,7 @@ QVariant gvariantToQVariant(GVariant *value)
 
 }
 
-BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config): QObject(0), AbstractSink(e, config), agent(nullptr), engine(nullptr)
+BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map<string, string> 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<string, string> 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<string, string> 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);
                }
        });
 
-
-
 }
 
 
index 97480e6..5c2b9a8 100644 (file)
@@ -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
index 55b95e8..a6c99ef 100644 (file)
@@ -164,7 +164,7 @@ void IrcCommunication::reconnect()
                QTimer::singleShot(5000,this,SLOT(open()));
 }
 
-void IrcCommunication::sslError(QList<QSslError> &)
+void IrcCommunication::sslError(QList<QSslError> )
 {
        qDebug()<<"some ssl errors!! trying to ignore them";
        QSslSocket* sock = qobject_cast<QSslSocket*>(socket());
@@ -183,5 +183,5 @@ void IrcCommunication::socketError(QAbstractSocket::SocketError error)
 void IrcCommunication::setIgnoreInvalidCert(bool ignore)
 {
        if(ignore)
-               QObject::connect(socket(),SIGNAL(sslErrors(QList<QSslError>&)),this,SLOT(sslError(QList<QSslError>&)));
+               QObject::connect(socket(),SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(sslError(QList<QSslError>)));
 }
index 261d016..3ce016b 100644 (file)
@@ -34,7 +34,7 @@ public Q_SLOTS:
 
 private Q_SLOTS:
        void onMessageReceived(IrcMessage*);
-       void sslError(QList<QSslError> &);
+       void sslError(QList<QSslError>);
        void socketError(QAbstractSocket::SocketError);
 
 Q_SIGNALS:
index c0141e2..bfb6bee 100644 (file)
@@ -203,7 +203,8 @@ void AbstractDBusInterface::addProperty(AbstractProperty* property)
                        "<signal name='" + pn + "Changed' >"
                        "       <arg type='v' name='" + nameToLower + "' direction='out' />"
                        "       <arg type='d' name='timestamp' direction='out' />"
-                       "</signal>";
+                       "</signal>"
+                       "<property type='i' name='" + property->name() + "Sequence' access='read' />";
        
        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<AbstractDBusInterface*>(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: "<<p<<endl;
+                       return nullptr;
+               }
+
+               int sequence = theProperty->sequence();
+
+               GVariant* value = g_variant_new("(i)", sequence);
+               return value;
+       }
+
        if(pn == "Zone")
        {
                if(objectMap.find(objectPath) == objectMap.end())
index 54906bd..68d74d9 100644 (file)
@@ -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)
index f9e952c..4eb3f7f 100644 (file)
@@ -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;