diff options
author | Andrew Christian <andrew.christian@nokia.com> | 2012-03-22 12:09:27 -0400 |
---|---|---|
committer | Chris Craig <ext-chris.craig@nokia.com> | 2012-03-22 21:56:07 +0100 |
commit | 34f27402a2b09e70d74a2e9caad860e17b9bd505 (patch) | |
tree | 947a27423c6d4e321f789f06afc52c40c5e98054 | |
parent | 1a45397265d17753225c2ca3134fd0793f70cfc8 (diff) |
Updated declarative interfaces
* Fixed up PipeProcessBackendFactory to support being instantiated
by declarative.
* Added a DeclarativeProcessManager::registerTypes() function to
call qmlRegisterType() for all usable classes.
* Updated registered QML class names for items in declarative to
follow the "PmNAME" convention (because the QML type name can't
be the same as the C++ type name)
* Updated documentation for declarative types
Change-Id: I587689752cb69c7280db67bbc20c1a91b0c6722a
Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r-- | doc/src/qmlpm.qdoc | 2 | ||||
-rw-r--r-- | examples/plugin/plugin.cpp | 35 | ||||
-rw-r--r-- | src/core/pipeprocessbackendfactory.cpp | 146 | ||||
-rw-r--r-- | src/core/pipeprocessbackendfactory.h | 20 | ||||
-rw-r--r-- | src/declarative/declarativematchdelegate.cpp | 56 | ||||
-rw-r--r-- | src/declarative/declarativeprocessmanager.cpp | 111 | ||||
-rw-r--r-- | src/declarative/declarativeprocessmanager.h | 2 | ||||
-rw-r--r-- | src/declarative/declarativerewritedelegate.cpp | 49 | ||||
-rw-r--r-- | src/declarative/declarativesocketlauncher.cpp | 49 | ||||
-rw-r--r-- | tests/auto/declarative/data/testfrontend.qml | 2 | ||||
-rw-r--r-- | tests/auto/declarative/data/testmatch.qml | 4 | ||||
-rw-r--r-- | tests/auto/declarative/data/testprelaunch.qml | 2 | ||||
-rw-r--r-- | tests/auto/declarative/data/testrangesocket.qml | 2 | ||||
-rw-r--r-- | tests/auto/declarative/data/testsocket.qml | 2 | ||||
-rw-r--r-- | tests/auto/declarative/data/testsocketfrontend.qml | 2 | ||||
-rw-r--r-- | tests/auto/declarative/testSocketLauncher/main.cpp | 12 | ||||
-rw-r--r-- | tests/auto/declarative/tst_declarative.cpp | 28 | ||||
-rw-r--r-- | tests/auto/processmanager/tst_processmanager.cpp | 8 |
18 files changed, 396 insertions, 136 deletions
diff --git a/doc/src/qmlpm.qdoc b/doc/src/qmlpm.qdoc index dff3e78..1b28ad0 100644 --- a/doc/src/qmlpm.qdoc +++ b/doc/src/qmlpm.qdoc @@ -41,7 +41,7 @@ use: import QtQuick 2.0 import ProcessManager 1.0 - DeclarativeProcessManager { + PmManager { id: myManager factories: [ diff --git a/examples/plugin/plugin.cpp b/examples/plugin/plugin.cpp index f405298..bc1f9d2 100644 --- a/examples/plugin/plugin.cpp +++ b/examples/plugin/plugin.cpp @@ -7,45 +7,12 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER -/*! - \qmlclass Manager DeclarativeProcessManager - \inqmlmodule ProcessManager 1 - \brief The Manager element controls running processes. - - Only a single DeclarativeProcessManager class should be loaded at one time. - - Typical use of the ProcessManager class is as follows: - - \code - import QtQuick 2.0 - import ProcessManager 1.0 - - Manager { - id: myProcessManager - - factories: [ - GdbProcessBackendFactory {}, - StandardProcessBackendFactory {} - ] - } - \endcode -*/ - -/*! - \qmlproperty list ProcessManager::Manager::factories - \brief The factories assigned to this process manager - - The factories property is an ordered list of ProcessBackendFactory objects. -*/ - - class ProcessManagerPlugin : public QQmlExtensionPlugin { Q_OBJECT public: void registerTypes(const char *uri) { - qmlRegisterType<ProcessInfoTemplate>(uri, 1, 0, "ProcessInfoTemplate"); - qmlRegisterType<DeclarativeProcessManager>(uri, 1, 0, "Manager"); + DeclarativeProcessManager::registerTypes(uri); } void initializeEngine(QQmlEngine *engine, const char *uri) { diff --git a/src/core/pipeprocessbackendfactory.cpp b/src/core/pipeprocessbackendfactory.cpp index d69fd46..c9a3435 100644 --- a/src/core/pipeprocessbackendfactory.cpp +++ b/src/core/pipeprocessbackendfactory.cpp @@ -40,6 +40,7 @@ #include "pipeprocessbackendfactory.h" #include "remoteprocessbackend.h" #include "remoteprotocol.h" +#include "processinfo.h" #include <QDebug> #include <QJsonDocument> @@ -60,38 +61,20 @@ const int kPipeTimerInterval = 1000; */ /*! + \property PipeProcessBackendFactory::processInfo + \brief ProcessInfo record used to create the pipe process + */ + +/*! Construct a PipeProcessBackendFactory with optional \a parent. - The \a info ProcessInfo is used to start the pipe process. + You must set a ProcessInfo object before this factory will be activated. */ -PipeProcessBackendFactory::PipeProcessBackendFactory(const ProcessInfo& info, - QObject *parent) +PipeProcessBackendFactory::PipeProcessBackendFactory(QObject *parent) : RemoteProcessBackendFactory(parent) , m_process(NULL) + , m_info(NULL) { - m_process = new QProcess; // Note that we do NOT own the pipe process - m_process->setReadChannel(QProcess::StandardOutput); - connect(m_process, SIGNAL(readyReadStandardOutput()), - this, SLOT(pipeReadyReadStandardOutput())); - connect(m_process, SIGNAL(readyReadStandardError()), - this, SLOT(pipeReadyReadStandardError())); - connect(m_process, SIGNAL(started()), this, SLOT(pipeStarted())); - connect(m_process,SIGNAL(error(QProcess::ProcessError)), - this,SLOT(pipeError(QProcess::ProcessError))); - connect(m_process,SIGNAL(finished(int, QProcess::ExitStatus)), - this,SLOT(pipeFinished(int, QProcess::ExitStatus))); - connect(m_process, SIGNAL(stateChanged(QProcess::ProcessState)), - this,SLOT(pipeStateChanged(QProcess::ProcessState))); - - QProcessEnvironment env; - QMapIterator<QString, QVariant> it(info.environment()); - while (it.hasNext()) { - it.next(); - env.insert(it.key(), it.value().toString()); - } - m_process->setProcessEnvironment(env); - m_process->setWorkingDirectory(info.workingDirectory()); - m_process->start(info.program(), info.arguments()); } /*! @@ -100,10 +83,21 @@ PipeProcessBackendFactory::PipeProcessBackendFactory(const ProcessInfo& info, PipeProcessBackendFactory::~PipeProcessBackendFactory() { - // ### Note: The m_process process is NOT a child of the - // factory to avoid stranding grandchildren - // However, we do send it a "stop" message before we exit - if (m_process) { + stopRemoteProcess(); +} + +/*! + \internal + + The m_process process is NOT a child of the factory to avoid + stranding grandchildren (which would happen if we summarily + kill it). Instead, we send it a "stop" message and count on + the remote process to kill itself. + */ + +void PipeProcessBackendFactory::stopRemoteProcess() +{ + if (m_process && m_process->state() == QProcess::Running) { QJsonObject object; object.insert(RemoteProtocol::remote(), RemoteProtocol::stop()); m_process->write(QJsonDocument(object).toBinaryData()); @@ -113,6 +107,22 @@ PipeProcessBackendFactory::~PipeProcessBackendFactory() } /*! + Return true if the PipeProcessBackendFactory can create a process + that matches \a info. The default implementation only checks that a + valid info object has been previously set in the factory, and then + passes the decision on to the default implementation, which should + probably have some kind of MatchDelegate installed. +*/ + +bool PipeProcessBackendFactory::canCreate(const ProcessInfo &info) const +{ + if (!m_info || !m_process || m_process->state() != QProcess::Running) + return false; + + return RemoteProcessBackendFactory::canCreate(info); +} + +/*! If there is a pipe process running, it will be returned here. */ @@ -125,6 +135,75 @@ QList<Q_PID> PipeProcessBackendFactory::internalProcesses() } /*! + Sets the ProcessInfo that is used to create the pipe process to \a processInfo. + An internal copy is made of the \a processInfo object. + This routine will start the pipe process. + + TODO: If you set the process info twice, you may end up with local + process backend objects that are invalid and refer to children that + don't exist. + */ + +void PipeProcessBackendFactory::setProcessInfo(ProcessInfo *processInfo) +{ + if (m_info != processInfo) { + if (m_info) { + delete m_info; + m_info = NULL; + } + + stopRemoteProcess(); + + if (processInfo) { + m_info = new ProcessInfo(*processInfo); + m_info->setParent(this); + + m_process = new QProcess; // Note that we do NOT own the pipe process + m_process->setReadChannel(QProcess::StandardOutput); + connect(m_process, SIGNAL(readyReadStandardOutput()), + this, SLOT(pipeReadyReadStandardOutput())); + connect(m_process, SIGNAL(readyReadStandardError()), + this, SLOT(pipeReadyReadStandardError())); + connect(m_process, SIGNAL(started()), this, SLOT(pipeStarted())); + connect(m_process,SIGNAL(error(QProcess::ProcessError)), + this,SLOT(pipeError(QProcess::ProcessError))); + connect(m_process,SIGNAL(finished(int, QProcess::ExitStatus)), + this,SLOT(pipeFinished(int, QProcess::ExitStatus))); + connect(m_process, SIGNAL(stateChanged(QProcess::ProcessState)), + this,SLOT(pipeStateChanged(QProcess::ProcessState))); + + QProcessEnvironment env; + QMapIterator<QString, QVariant> it(m_info->environment()); + while (it.hasNext()) { + it.next(); + env.insert(it.key(), it.value().toString()); + } + m_process->setProcessEnvironment(env); + m_process->setWorkingDirectory(m_info->workingDirectory()); + m_process->start(m_info->program(), m_info->arguments()); + } + emit processInfoChanged(); + } +} + +/*! + Sets the ProcessInfo that is used to determine the prelaunched runtime to \a processInfo. + */ +void PipeProcessBackendFactory::setProcessInfo(ProcessInfo& processInfo) +{ + setProcessInfo(&processInfo); +} + +/*! + Return the pipe process information + */ + +ProcessInfo *PipeProcessBackendFactory::processInfo() const +{ + return m_info; +} + +/*! Send \a message to a pipe process. */ bool PipeProcessBackendFactory::send(const QJsonObject& message) @@ -187,6 +266,13 @@ void PipeProcessBackendFactory::pipeStateChanged(QProcess::ProcessState state) Q_UNUSED(state); } + +/*! + \fn void PipeProcessBackendFactory::processInfoChanged() + This signal is emitted when the internal ProcessInfo record is + changed. + */ + #include "moc_pipeprocessbackendfactory.cpp" QT_END_NAMESPACE_PROCESSMANAGER diff --git a/src/core/pipeprocessbackendfactory.h b/src/core/pipeprocessbackendfactory.h index 8023919..7dbee9e 100644 --- a/src/core/pipeprocessbackendfactory.h +++ b/src/core/pipeprocessbackendfactory.h @@ -47,12 +47,22 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER class Q_ADDON_PROCESSMANAGER_EXPORT PipeProcessBackendFactory : public RemoteProcessBackendFactory { Q_OBJECT + Q_PROPERTY(ProcessInfo* processInfo READ processInfo WRITE setProcessInfo NOTIFY processInfoChanged) + public: - PipeProcessBackendFactory(const ProcessInfo& info, QObject *parent = 0); + PipeProcessBackendFactory(QObject *parent = 0); virtual ~PipeProcessBackendFactory(); + virtual bool canCreate(const ProcessInfo &info) const; virtual QList<Q_PID> internalProcesses(); + ProcessInfo *processInfo() const; + void setProcessInfo(ProcessInfo *processInfo); + void setProcessInfo(ProcessInfo& processInfo); + +signals: + void processInfoChanged(); + protected: virtual bool send(const QJsonObject&); @@ -65,8 +75,12 @@ private slots: void pipeStateChanged(QProcess::ProcessState state); private: - QProcess *m_process; - QByteArray m_buffer; + void stopRemoteProcess(); + +private: + QProcess *m_process; + ProcessInfo *m_info; + QByteArray m_buffer; }; QT_END_NAMESPACE_PROCESSMANAGER diff --git a/src/declarative/declarativematchdelegate.cpp b/src/declarative/declarativematchdelegate.cpp index 58c5c53..419162d 100644 --- a/src/declarative/declarativematchdelegate.cpp +++ b/src/declarative/declarativematchdelegate.cpp @@ -43,17 +43,17 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER /*! - \qmlclass ScriptMatch DeclarativeMatchDelegate - \brief The ScriptMatch class allows a factory to use a Javascript function for matching + \qmlclass PmScriptMatch DeclarativeMatchDelegate + \brief The PmScriptMatch class allows a factory to use a Javascript function for matching - The ScriptMatch element can be used in factory - objects to specify match conditions. + The PmScriptMatch object can be used in factory objects + to specify match conditions. \qml - DeclarativeProcessManager { + PmManager { factories: [ StandardProcessBackendFactory { - matchDelegate: ScriptMatch { + matchDelegate: PmScriptMatch { script: { return (model.program == "ls"); } } } @@ -63,27 +63,54 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER */ /*! - \qmlproperty script ScriptMatch::script + \qmlproperty QQmlScriptString PmScriptMatch::script + \brief Script to execute to see if there is a match This property holds the script to run. The ProcessInfo object will be passed in as a global "model" variable. The script should return "true" if the factory can create this object. */ +/*! + \class DeclarativeMatchDelegate + \brief The DeclarativeMatchDelegate class allows a factory to use Javascript functions for matching. + + The DeclarativeMatchDelegate class can be used in factory objects to + specify match conditions. +*/ + +/*! + Construct a DeclarativeMatchDelegate with optional \a parent. + */ + DeclarativeMatchDelegate::DeclarativeMatchDelegate(QObject *parent) : MatchDelegate(parent) , m_modelContext(0) { } +/*! + \internal + */ + void DeclarativeMatchDelegate::classBegin() { } +/*! + \internal + */ + void DeclarativeMatchDelegate::componentComplete() { } +/*! + Return true if the script object evaluates to \c{true} for this + ProcessInfo object \a info. The ProcessInfo object is internally + bound to the \c{model} object property. + */ + bool DeclarativeMatchDelegate::matches(const ProcessInfo& info) { if (m_script.script().isEmpty()) @@ -96,17 +123,32 @@ bool DeclarativeMatchDelegate::matches(const ProcessInfo& info) return expr.evaluate().toBool(); } +/*! + Return the script object. + */ + QQmlScriptString DeclarativeMatchDelegate::script() const { return m_script; } +/*! + Set the script object to \a script + */ + void DeclarativeMatchDelegate::setScript(const QQmlScriptString& script) { m_script = script; emit scriptChanged(); } +/*! + \fn void DeclarativeMatchDelegate::scriptChanged() + This signal is emitted when the script object is changed. + + \sa setScript() + */ + #include "moc_declarativematchdelegate.cpp" QT_END_NAMESPACE_PROCESSMANAGER diff --git a/src/declarative/declarativeprocessmanager.cpp b/src/declarative/declarativeprocessmanager.cpp index d070873..ec1fe35 100644 --- a/src/declarative/declarativeprocessmanager.cpp +++ b/src/declarative/declarativeprocessmanager.cpp @@ -41,17 +41,124 @@ #include "processbackendfactory.h" #include "processfrontend.h" +#include "prelaunchprocessbackend.h" +#include "remoteprocessbackend.h" +#include "standardprocessbackend.h" + +#include "cpuidledelegate.h" +#include "timeoutidledelegate.h" +#include "gdbrewritedelegate.h" +#include "infomatchdelegate.h" +#include "keymatchdelegate.h" +#include "pipelauncher.h" +#include "pipeprocessbackendfactory.h" +#include "preforkprocessbackendfactory.h" +#include "prelaunchprocessbackendfactory.h" +#include "processinfotemplate.h" +#include "socketlauncher.h" +#include "standardprocessbackendfactory.h" +#include "socketprocessbackendfactory.h" + +#include "declarativematchdelegate.h" +#include "declarativesocketlauncher.h" +#include "declarativerewritedelegate.h" + #include <QDebug> QT_BEGIN_NAMESPACE_PROCESSMANAGER /*! - \class DeclarativeProcessManager DeclarativeProcessManager - \brief The DeclarativeProcessManager class encapsulates ways of creating and tracking processes + \qmlclass PmManager DeclarativeProcessManager + \brief The PmManager class encapsulates ways of creating and tracking processes suitable for QtQml programs. + + Only a single PmManager object should be loaded at one time. + + Typical use of the PmManager class is as follows: + + \code + import QtQuick 2.0 + import ProcessManager 1.0 + + PmManager { + id: myProcessManager + + factories: [ + GdbProcessBackendFactory {}, + StandardProcessBackendFactory {} + ] + } + \endcode */ /*! + \qmlproperty list<ProcessBackendFactory> PmManager::factories + List of ProcessBackendFactory objects. + + The order of the list is important. When launching a new + process, each factory will be consulted in order to select + the factory that will launch the process. + */ + +/*! + \class DeclarativeProcessManager + \brief The DeclarativeProcessManager class is a ProcessManager designed to be embedded + in a QML context. + */ + +/*! + \fn DeclarativeProcessManager::registerTypes(const char *uri) + \brief Register all QML data types for the process manager + + Register all types with the QML object system. Pass the name the + library to register as \a uri. + */ + +void DeclarativeProcessManager::registerTypes(const char *uri) +{ + // Non-creatable types + qmlRegisterType<IdleDelegate>(); + qmlRegisterType<MatchDelegate>(); + qmlRegisterType<PrelaunchProcessBackend>(); + qmlRegisterType<ProcessBackend>(); + qmlRegisterType<ProcessFrontend>(); + qmlRegisterType<ProcessBackendFactory>(); + qmlRegisterType<RemoteProcessBackend>(); + qmlRegisterType<RemoteProcessBackendFactory>(); + qmlRegisterType<RewriteDelegate>(); + qmlRegisterType<StandardProcessBackend>(); + qmlRegisterType<UnixProcessBackend>(); + + // Non-creatable, with enum values + qmlRegisterUncreatableType<Process>(uri, 1, 0, "Process", "Don't try to make this"); + + // Types registered from the Core library + qmlRegisterType<CpuIdleDelegate>(uri, 1, 0, "CpuIdleDelegate"); + qmlRegisterType<GdbRewriteDelegate>(uri, 1, 0, "GdbRewriteDelegate"); + qmlRegisterType<InfoMatchDelegate>(uri, 1, 0, "InfoMatchDelegate"); + qmlRegisterType<KeyMatchDelegate>(uri, 1, 0, "KeyMatchDelegate"); + qmlRegisterType<PipeLauncher>(uri, 1, 0, "PipeLauncher"); + qmlRegisterType<PipeProcessBackendFactory>(uri, 1, 0, "PipeProcessBackendFactory"); + qmlRegisterType<PreforkProcessBackendFactory>(uri, 1, 0, "PreforkProcessBackendFactory"); + qmlRegisterType<PrelaunchProcessBackendFactory>(uri, 1, 0, "PrelaunchProcessBackendFactory"); + qmlRegisterType<ProcessBackendManager>(uri, 1, 0, "ProcessBackendManager"); + qmlRegisterType<ProcessInfo>(uri, 1, 0, "ProcessInfo"); + qmlRegisterType<ProcessInfoTemplate>(uri, 1, 0, "ProcessInfoTemplate"); + qmlRegisterType<ProcessManager>(uri, 1, 0, "ProcessManager"); + qmlRegisterType<SocketLauncher>(uri, 1, 0, "SocketLauncher"); + qmlRegisterType<SocketProcessBackendFactory>(uri, 1, 0, "SocketProcessBackendFactory"); + qmlRegisterType<StandardProcessBackendFactory>(uri, 1, 0, "StandardProcessBackendFactory"); + qmlRegisterType<TimeoutIdleDelegate>(uri, 1, 0, "TimeoutIdleDelegate"); + + // Types registered from the Declarative library + qmlRegisterType<DeclarativeMatchDelegate>(uri, 1, 0, "PmScriptMatch"); + qmlRegisterType<DeclarativeProcessManager>(uri, 1, 0, "PmManager"); + qmlRegisterType<DeclarativeSocketLauncher>(uri, 1, 0, "PmLauncher"); + qmlRegisterType<DeclarativeRewriteDelegate>(uri, 1, 0, "PmScriptRewrite"); + qmlRegisterType<ProcessInfoTemplate>(uri, 1, 0, "ProcessInfoTemplate"); +} + +/*! Construct a DeclarativeProcessManager with an optional \a parent */ diff --git a/src/declarative/declarativeprocessmanager.h b/src/declarative/declarativeprocessmanager.h index 695ff68..4661b0f 100644 --- a/src/declarative/declarativeprocessmanager.h +++ b/src/declarative/declarativeprocessmanager.h @@ -57,6 +57,8 @@ class Q_ADDON_PROCESSMANAGER_EXPORT DeclarativeProcessManager : public ProcessMa Q_PROPERTY(QQmlListProperty<ProcessBackendFactory> factories READ factories) public: + static void registerTypes(const char *uri); + DeclarativeProcessManager(QObject *parent=0); QQmlListProperty<ProcessBackendFactory> factories(); diff --git a/src/declarative/declarativerewritedelegate.cpp b/src/declarative/declarativerewritedelegate.cpp index 9f35399..b0e1959 100644 --- a/src/declarative/declarativerewritedelegate.cpp +++ b/src/declarative/declarativerewritedelegate.cpp @@ -44,15 +44,15 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER /*! - \qmlclass ScriptRewrite DeclarativeRewriteDelegate - \brief The ScriptRewrite class allows a factory to use a Javascript function for rewriting + \qmlclass PmScriptRewrite DeclarativeRewriteDelegate + \brief The PmScriptRewrite class allows a factory to use a Javascript function for rewriting ProcessInfo objects. \qml - DeclarativeProcessManager { + PmManager { factories: [ StandardProcessBackendFactory { - rewriteDelegate: ScriptRewrite { + rewriteDelegate: PmScriptRewrite { script: { var oldprog = model.program; model.program = "gdb"; @@ -69,26 +69,52 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER */ /*! - \qmlproperty script ScriptRewrite::script + \qmlproperty script PmScriptRewrite::script This property holds the script to run. The ProcessInfo object will be passed in as a global "model" variable. */ +/*! + \class DeclarativeRewriteDelegate + \brief The DeclarativeRewriteDelegate class is a lightweight wrapper around a RewriteDelegate. + + The DeclarativeRewriteDelegate class rewrites ProcessInfo objects by + passing them to a script object containing Javascript code. + */ + +/*! + Construct a DeclarativeRewriteDelegate object with optional \a parent. + */ + DeclarativeRewriteDelegate::DeclarativeRewriteDelegate(QObject *parent) : RewriteDelegate(parent) , m_modelContext(0) { } +/*! + \internal +*/ + void DeclarativeRewriteDelegate::classBegin() { } +/*! + \internal +*/ + void DeclarativeRewriteDelegate::componentComplete() { } +/*! + Rewrite the \a info object by passing it to the stored Javascript. + The \a info object is bound to the \c{model} property in the + stored Javascript. +*/ + void DeclarativeRewriteDelegate::rewrite(ProcessInfo& info) { if (!m_script.script().isEmpty()) { @@ -100,17 +126,30 @@ void DeclarativeRewriteDelegate::rewrite(ProcessInfo& info) } } +/*! + Return a copy of the Javascript. +*/ + QQmlScriptString DeclarativeRewriteDelegate::script() const { return m_script; } +/*! + Set the Javascript object to \a script. +*/ + void DeclarativeRewriteDelegate::setScript(const QQmlScriptString& script) { m_script = script; emit scriptChanged(); } +/*! + \fn void DeclarativeRewriteDelegate::scriptChanged() + This signal is emitted when the internal script object is changed. +*/ + #include "moc_declarativerewritedelegate.cpp" QT_END_NAMESPACE_PROCESSMANAGER diff --git a/src/declarative/declarativesocketlauncher.cpp b/src/declarative/declarativesocketlauncher.cpp index 8308a24..f6dad60 100644 --- a/src/declarative/declarativesocketlauncher.cpp +++ b/src/declarative/declarativesocketlauncher.cpp @@ -42,12 +42,12 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER /*! - \qmlclass Launcher DeclarativeSocketLauncher - \brief The Launcher class encapsulates ways of creating and tracking processes + \qmlclass PmLauncher DeclarativeSocketLauncher + \brief The PmLauncher class encapsulates ways of creating and tracking processes suitable for QtQml programs. - The Launcher class is used to create a standalone program for launching - and tracking child processes. Other programs can connect to the Launcher using + The PmLauncher class is used to create a standalone program for launching + and tracking child processes. Other programs can connect to the PmLauncher using a JsonStream-formatted socket connection. Here is an example of a simple launcher instantiation: @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER import QtQuick 2.0 import Test 1.0 - Launcher { + PmLauncher { id: socket_launcher factories: [ @@ -82,14 +82,14 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER } \endqml - Note that the Launcher object has been configured with two factories, the first + Note that the PmLauncher object has been configured with two factories, the first of which rewrites any ProcessInfo objects containing a "gdb" attribute to - use the gdb server. The Launcher object also has a JsonUIDRangeAuthority object + use the gdb server. The PmLauncher object also has a JsonUIDRangeAuthority object which is assigned to the internal JsonServer. */ /*! - \qmlproperty list<ProcessBackendFactory> Launcher::factories + \qmlproperty list<ProcessBackendFactory> PmLauncher::factories List of ProcessBackendFactory objects. The order of the list is important - when launching a new @@ -97,24 +97,45 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER */ /*! - \qmlproperty list<Object> Launcher::children - Generic child objects of this Launcher - allows extra objects like Authorities + \qmlproperty list<Object> PmLauncher::children + Generic child objects of this PmLauncher - allows extra objects like Authorities to be instantiated under this class. */ +/*! + \class DeclarativeSocketLauncher + \brief The DeclarativeSocketLauncher class is a lightweight wrapper around a SocketLauncher object. +*/ + +/*! + Create a DeclarativeSocketLauncher object with optional parent \a parent. + */ + DeclarativeSocketLauncher::DeclarativeSocketLauncher(QObject *parent) : SocketLauncher(parent) { } +/*! + \internal +*/ + void DeclarativeSocketLauncher::classBegin() { } +/*! + \internal +*/ + void DeclarativeSocketLauncher::componentComplete() { } +/*! + \internal +*/ + void DeclarativeSocketLauncher::append_factory(QQmlListProperty<ProcessBackendFactory> *list, ProcessBackendFactory *factory) { @@ -123,11 +144,19 @@ void DeclarativeSocketLauncher::append_factory(QQmlListProperty<ProcessBackendFa launcher->addFactory(factory); } +/*! + \internal +*/ + QQmlListProperty<ProcessBackendFactory> DeclarativeSocketLauncher::factories() { return QQmlListProperty<ProcessBackendFactory>(this, NULL, append_factory); } +/*! + \internal +*/ + QQmlListProperty<QObject> DeclarativeSocketLauncher::children() { return QQmlListProperty<QObject>(this, m_children); diff --git a/tests/auto/declarative/data/testfrontend.qml b/tests/auto/declarative/data/testfrontend.qml index ec6a07d..9a90f37 100644 --- a/tests/auto/declarative/data/testfrontend.qml +++ b/tests/auto/declarative/data/testfrontend.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import Test 1.0 -DeclarativeProcessManager { +PmManager { id: foo factories: [ diff --git a/tests/auto/declarative/data/testmatch.qml b/tests/auto/declarative/data/testmatch.qml index 27fefd2..eb5ab5f 100644 --- a/tests/auto/declarative/data/testmatch.qml +++ b/tests/auto/declarative/data/testmatch.qml @@ -1,12 +1,12 @@ import QtQuick 2.0 import Test 1.0 -DeclarativeProcessManager { +PmManager { id: foo factories: [ StandardProcessBackendFactory { - matchDelegate: DeclarativeMatchDelegate { + matchDelegate: PmScriptMatch { script: { console.log("Model "+model); console.log("Model type "+typeof(model)); diff --git a/tests/auto/declarative/data/testprelaunch.qml b/tests/auto/declarative/data/testprelaunch.qml index a06cbbf..2083418 100644 --- a/tests/auto/declarative/data/testprelaunch.qml +++ b/tests/auto/declarative/data/testprelaunch.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import Test 1.0 -DeclarativeProcessManager { +PmManager { id: foo factories: [ diff --git a/tests/auto/declarative/data/testrangesocket.qml b/tests/auto/declarative/data/testrangesocket.qml index b055af8..fcf98dc 100644 --- a/tests/auto/declarative/data/testrangesocket.qml +++ b/tests/auto/declarative/data/testrangesocket.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import Test 1.0 -DeclarativeSocketLauncher { +PmLauncher { id: socket_launcher factories: [ diff --git a/tests/auto/declarative/data/testsocket.qml b/tests/auto/declarative/data/testsocket.qml index d44dae9..e7befc5 100644 --- a/tests/auto/declarative/data/testsocket.qml +++ b/tests/auto/declarative/data/testsocket.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import Test 1.0 -DeclarativeSocketLauncher { +PmLauncher { id: socket_launcher factories: [ diff --git a/tests/auto/declarative/data/testsocketfrontend.qml b/tests/auto/declarative/data/testsocketfrontend.qml index d25e925..27fb097 100644 --- a/tests/auto/declarative/data/testsocketfrontend.qml +++ b/tests/auto/declarative/data/testsocketfrontend.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 import Test 1.0 -DeclarativeProcessManager { +PmManager { id: foo factories: [ diff --git a/tests/auto/declarative/testSocketLauncher/main.cpp b/tests/auto/declarative/testSocketLauncher/main.cpp index dadd456..638b0db 100644 --- a/tests/auto/declarative/testSocketLauncher/main.cpp +++ b/tests/auto/declarative/testSocketLauncher/main.cpp @@ -47,6 +47,7 @@ #include <jsonuidrangeauthority.h> #include "declarativesocketlauncher.h" +#include "declarativeprocessmanager.h" #include "standardprocessbackendfactory.h" #include "keymatchdelegate.h" #include "gdbrewritedelegate.h" @@ -67,16 +68,7 @@ static void usage() static void registerQmlTypes() { const char *uri = "Test"; - qmlRegisterType<ProcessBackendFactory>(); - qmlRegisterType<MatchDelegate>(); - qmlRegisterType<RewriteDelegate>(); - qmlRegisterType<SocketLauncher>(); - - qmlRegisterType<DeclarativeSocketLauncher>(uri, 1, 0, "DeclarativeSocketLauncher"); - qmlRegisterType<StandardProcessBackendFactory>(uri, 1, 0, "StandardProcessBackendFactory"); - qmlRegisterType<KeyMatchDelegate>(uri, 1, 0, "KeyMatchDelegate"); - qmlRegisterType<GdbRewriteDelegate>(uri, 1, 0, "GdbRewriteDelegate"); - + DeclarativeProcessManager::registerTypes(uri); qmlRegisterUncreatableType<QtAddOn::JsonStream::JsonAuthority>(uri, 1, 0, "JsonAuthority", "Abstract class"); qmlRegisterType<QtAddOn::JsonStream::JsonUIDRangeAuthority>(uri, 1, 0, "JsonUIDRangeAuthority"); qmlRegisterType<QtAddOn::JsonStream::JsonUIDAuthority>(uri, 1, 0, "JsonUIDAuthority"); diff --git a/tests/auto/declarative/tst_declarative.cpp b/tests/auto/declarative/tst_declarative.cpp index a01a9e8..dcf9f5a 100644 --- a/tests/auto/declarative/tst_declarative.cpp +++ b/tests/auto/declarative/tst_declarative.cpp @@ -87,34 +87,12 @@ private slots: void tst_DeclarativeProcessManager::initTestCase() { - qDebug() << "Registering types"; const char *uri = "Test"; - - qmlRegisterType<MatchDelegate>(); - qmlRegisterType<RewriteDelegate>(); - qmlRegisterType<ProcessBackendFactory>(); - qmlRegisterType<ProcessFrontend>(); - - qmlRegisterType<StandardProcessBackendFactory>(uri, 1, 0, "StandardProcessBackendFactory"); - qmlRegisterType<PrelaunchProcessBackendFactory>(uri, 1, 0, "PrelaunchProcessBackendFactory"); - qmlRegisterType<ProcessInfo>(uri, 1, 0, "ProcessInfo"); - qmlRegisterType<SocketProcessBackendFactory>(uri, 1, 0, "SocketProcessBackendFactory"); - qmlRegisterType<DeclarativeProcessManager>(uri, 1, 0, "DeclarativeProcessManager"); - qmlRegisterType<DeclarativeMatchDelegate>(uri, 1, 0, "DeclarativeMatchDelegate"); - qmlRegisterType<DeclarativeRewriteDelegate>(uri, 1, 0, "DeclarativeRewriteDelegate"); - qmlRegisterUncreatableType<Process>(uri, 1, 0, "Process", "Don't try to make this"); - - qmlRegisterUncreatableType<IdleDelegate>(uri, 1, 0, "IdleDelegate", "Don't try to make this"); - qmlRegisterType<TimeoutIdleDelegate>(uri, 1, 0, "TimeoutIdleDelegate"); + DeclarativeProcessManager::registerTypes(uri); qRegisterMetaType<QProcess::ProcessState>(); qRegisterMetaType<QProcess::ExitStatus>(); qRegisterMetaType<QProcess::ProcessError>(); - - qRegisterMetaType<ProcessFrontend*>("ProcessFrontend*"); - qRegisterMetaType<const ProcessFrontend*>("const ProcessFrontend*"); - qRegisterMetaType<ProcessBackend*>("ProcessBackend*"); - qRegisterMetaType<ProcessInfo*>("ProcessInfo*"); } @@ -312,7 +290,7 @@ void tst_DeclarativeProcessManager::socketRangeLauncher() } const char *kMatchTest = "import QtQuick 2.0; import Test 1.0; \n" -"DeclarativeMatchDelegate { \n" +"PmScriptMatch { \n" " script: { \n" " if ( model.program == \"goodprogram\" ) return true; \n" " if ( model.program == \"badprogram\" ) return false; \n" @@ -353,7 +331,7 @@ void tst_DeclarativeProcessManager::match() } const char *kRewriteTest = "import QtQuick 2.0; import Test 1.0; \n" -"DeclarativeRewriteDelegate { \n" +"PmScriptRewrite { \n" " script: { \n" " model.program = \"foo-\"+model.program; \n" " var oldargs = model.arguments; \n" diff --git a/tests/auto/processmanager/tst_processmanager.cpp b/tests/auto/processmanager/tst_processmanager.cpp index fba8def..01686d4 100644 --- a/tests/auto/processmanager/tst_processmanager.cpp +++ b/tests/auto/processmanager/tst_processmanager.cpp @@ -767,7 +767,9 @@ static void pipeLauncherTest( clientFunc func, infoFunc infoFixup=0 ) ProcessBackendManager *manager = new ProcessBackendManager; ProcessInfo info; info.setValue("program", "testPipeLauncher/testPipeLauncher"); - manager->addFactory(new PipeProcessBackendFactory(info)); + PipeProcessBackendFactory *factory = new PipeProcessBackendFactory; + factory->setProcessInfo(info); + manager->addFactory(factory); // Wait for the factory to have launched a pipe waitForInternalProcess(manager); @@ -825,7 +827,9 @@ static void forkLauncherTest( clientFunc func, infoFunc infoFixup=0 ) ProcessBackendManager *manager = new ProcessBackendManager; ProcessInfo info; info.setValue("program", "testForkLauncher/testForkLauncher"); - manager->addFactory(new PipeProcessBackendFactory(info)); + PipeProcessBackendFactory *factory = new PipeProcessBackendFactory; + factory->setProcessInfo(info); + manager->addFactory(factory); // Wait for the factory to have launched a pipe waitForInternalProcess(manager); |