changeset 8:c1669af82d6e

* Add external process action
author cannam
date Mon, 27 Nov 2006 11:32:40 +0000
parents b30fcffc5000
children 10715d2b3069
files host/ExternalProcessAction.cpp host/ExternalProcessAction.h host/ImageAction.cpp host/SimpleXMLRuleLoader.cpp test.xml vamp-live-host.pro
diffstat 6 files changed, 73 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/host/ExternalProcessAction.cpp	Mon Nov 27 11:32:40 2006 +0000
@@ -0,0 +1,33 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+#include "ExternalProcessAction.h"
+
+#include <QProcess>
+
+#include <iostream>
+
+ExternalProcessAction::ExternalProcessAction(QString processName,
+					     QStringList args) :
+    m_processName(processName),
+    m_args(args)
+{
+}
+
+ExternalProcessAction::~ExternalProcessAction()
+{
+}
+
+QString
+ExternalProcessAction::getName() const
+{
+    return QString("process: %1").arg(m_processName);
+}
+
+void
+ExternalProcessAction::fire()
+{
+    std::cerr << "ExternalProcessAction(\"" << getName().toStdString() << "\")::fire"
+              << std::endl;
+    QProcess::startDetached(m_processName, m_args);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/host/ExternalProcessAction.h	Mon Nov 27 11:32:40 2006 +0000
@@ -0,0 +1,26 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+#ifndef _EXTERNAL_PROCESS_ACTION_H_
+#define _EXTERNAL_PROCESS_ACTION_H_
+
+#include "Action.h"
+
+#include <QStringList>
+
+class ExternalProcessAction : public Action    
+{
+    Q_OBJECT
+
+public:
+    ExternalProcessAction(QString processName, QStringList args);
+    virtual ~ExternalProcessAction();
+
+    virtual QString getName() const;
+    virtual void fire();
+
+protected:
+    QString m_processName;
+    QStringList m_args;
+};
+
+#endif
--- a/host/ImageAction.cpp	Mon Nov 27 11:03:52 2006 +0000
+++ b/host/ImageAction.cpp	Mon Nov 27 11:32:40 2006 +0000
@@ -25,7 +25,7 @@
 void
 ImageAction::fire()
 {
-    std::cerr << "ImageAction(\"" << getName().toStdString() << "\"::fire"
+    std::cerr << "ImageAction(\"" << getName().toStdString() << "\")::fire"
               << std::endl;
     emit showImage(m_imageName);
 }
--- a/host/SimpleXMLRuleLoader.cpp	Mon Nov 27 11:03:52 2006 +0000
+++ b/host/SimpleXMLRuleLoader.cpp	Mon Nov 27 11:32:40 2006 +0000
@@ -3,6 +3,7 @@
 #include "SimpleXMLRuleLoader.h"
 #include "Rule.h"
 #include "ImageAction.h"
+#include "ExternalProcessAction.h"
 
 #include <QFile>
 #include <QIODevice>
@@ -164,6 +165,12 @@
             Action *action = new ImageAction(image);
             m_rule->setAction(action);
             std::cerr << "INFO: SimpleXMLRuleLoader: Added image action" << std::endl;
+        } else if (type == "process") {
+            QString process = atts.value("process").toLower();
+            QStringList args = atts.value("arguments").split(',');
+            Action *action = new ExternalProcessAction(process, args);
+            m_rule->setAction(action);
+            std::cerr << "INFO: SimpleXMLRuleLoader: Added external process action" << std::endl;
         } else {
             std::cerr << "WARNING: SimpleXMLRuleLoader: Unknown action type \""
                       << type.toStdString() << "\"" << std::endl;
--- a/test.xml	Mon Nov 27 11:03:52 2006 +0000
+++ b/test.xml	Mon Nov 27 11:32:40 2006 +0000
@@ -12,6 +12,10 @@
   <condition pluginIndex="1" condition="GapGreaterThan" argument="0.51"/>
   <action type="image" image="trees-mono.jpg"/>
 </outputRule>
+<outputRule>
+  <condition pluginIndex="1" condition="GapGreaterThan" argument="0.51"/>
+  <action type="process" process="/bin/echo" arguments="blah"/>
+</outputRule>
 <!-- <outputRule pluginIndex="1" outputNumber="0" condition="Present" action="image" image="ping"/> -->
 </rules>
 </vlh>
--- a/vamp-live-host.pro	Mon Nov 27 11:03:52 2006 +0000
+++ b/vamp-live-host.pro	Mon Nov 27 11:32:40 2006 +0000
@@ -24,6 +24,7 @@
            audioio/AudioRecordSourceFactory.h \
            audioio/BufferingAudioCallbackRecordTarget.h \
            host/Action.h \
+           host/ExternalProcessAction.h \
            host/ImageAction.h \
            host/ImageWindow.h \
            host/Processor.h \
@@ -35,6 +36,7 @@
            audioio/AudioRecordSourceFactory.cpp \
            audioio/BufferingAudioCallbackRecordTarget.cpp \
            host/host.cpp \
+           host/ExternalProcessAction.cpp \
            host/ImageAction.cpp \
            host/ImageWindow.cpp \
            host/Processor.cpp \