Provide a MetaService convenience class to control jolie's metaservice.
svn path=/branches/work/~ervin/qtjolie/; revision=965146
This commit is contained in:
parent
e17822d5c2
commit
a9fe9d1c47
@ -2,6 +2,7 @@ install( FILES
|
||||
QtJolie/Client
|
||||
QtJolie/Fault
|
||||
QtJolie/Message
|
||||
QtJolie/MetaService
|
||||
QtJolie/PendingCall
|
||||
QtJolie/Value
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/QtJolie COMPONENT Devel)
|
||||
|
2
private/qtjolie-branch/includes/QtJolie/MetaService
Normal file
2
private/qtjolie-branch/includes/QtJolie/MetaService
Normal file
@ -0,0 +1,2 @@
|
||||
#include "../qtjolie/metaservice.h"
|
||||
|
@ -5,7 +5,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${QT_INCLUDE_DIR})
|
||||
|
||||
set(qtjolie_LIB_SRCS client.cpp clientthread.cpp value.cpp fault.cpp message.cpp pendingcall.cpp)
|
||||
set(qtjolie_LIB_SRCS client.cpp clientthread.cpp value.cpp fault.cpp message.cpp metaservice.cpp pendingcall.cpp)
|
||||
|
||||
kde4_add_library(QtJolie SHARED ${qtjolie_LIB_SRCS})
|
||||
|
||||
@ -21,5 +21,6 @@ install(FILES
|
||||
value.h
|
||||
fault.h
|
||||
message.h
|
||||
metaservice.h
|
||||
pendingcall.h
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/qtjolie)
|
||||
|
106
private/qtjolie-branch/qtjolie/metaservice.cpp
Normal file
106
private/qtjolie-branch/qtjolie/metaservice.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/**
|
||||
* This file is part of the KDE project
|
||||
* Copyright (C) 2009 Kevin Ottens <ervin@kde.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "metaservice.h"
|
||||
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
#include "client.h"
|
||||
#include "message.h"
|
||||
|
||||
namespace Jolie
|
||||
{
|
||||
|
||||
class MetaServicePrivate
|
||||
{
|
||||
public:
|
||||
QProcess metaserviceProcess;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
MetaService::MetaService()
|
||||
: d(new MetaServicePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
MetaService::~MetaService()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool MetaService::start()
|
||||
{
|
||||
d->metaserviceProcess.start("metaservice");
|
||||
return d->metaserviceProcess.waitForStarted();
|
||||
}
|
||||
|
||||
bool MetaService::stop()
|
||||
{
|
||||
Client client("localhost", 9000);
|
||||
Message message("/", "shutdown");
|
||||
client.callNoReply(message);
|
||||
return d->metaserviceProcess.waitForFinished(30000);
|
||||
}
|
||||
|
||||
bool MetaService::isRunning() const
|
||||
{
|
||||
return d->metaserviceProcess.state()==QProcess::Running;
|
||||
}
|
||||
|
||||
QString MetaService::loadService(const QString &name, const QString &fileName)
|
||||
{
|
||||
Client client("localhost", 9000);
|
||||
Message message("/", "loadEmbeddedJolieService");
|
||||
Value value;
|
||||
value.children("resourcePrefix") << Value(name);
|
||||
value.children("filepath") << Value(fileName);
|
||||
message.setData(value);
|
||||
|
||||
Message reply = client.call(message);
|
||||
return reply.data().toString();
|
||||
}
|
||||
|
||||
QStringList MetaService::loadedServices() const
|
||||
{
|
||||
Client client("localhost", 9000);
|
||||
Message message("/", "getServices");
|
||||
|
||||
Message reply = client.call(message);
|
||||
QList<Value> services = reply.data().children("service");
|
||||
|
||||
QStringList result;
|
||||
foreach (const Value &service, services) {
|
||||
result << service.children("resourceName").first().toString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void MetaService::unloadService(const QString &name)
|
||||
{
|
||||
Client client("localhost", 9000);
|
||||
Message message("/", "unloadEmbeddedService");
|
||||
message.setData(Value(name));
|
||||
|
||||
client.call(message);
|
||||
}
|
52
private/qtjolie-branch/qtjolie/metaservice.h
Normal file
52
private/qtjolie-branch/qtjolie/metaservice.h
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* This file is part of the KDE project
|
||||
* Copyright (C) 2009 Kevin Ottens <ervin@kde.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef QTJOLIE_METASERVICE_H
|
||||
#define QTJOLIE_METASERVICE_H
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QList>
|
||||
|
||||
namespace Jolie
|
||||
{
|
||||
class MetaServicePrivate;
|
||||
|
||||
class Q_DECL_EXPORT MetaService
|
||||
{
|
||||
public:
|
||||
MetaService();
|
||||
~MetaService();
|
||||
|
||||
bool start();
|
||||
bool stop();
|
||||
bool isRunning() const;
|
||||
|
||||
QString loadService(const QString &name, const QString &fileName);
|
||||
QStringList loadedServices() const;
|
||||
void unloadService(const QString &name);
|
||||
|
||||
private:
|
||||
MetaServicePrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <QtJolie/Client>
|
||||
#include <QtJolie/Message>
|
||||
#include <QtJolie/MetaService>
|
||||
#include <QtJolie/PendingCall>
|
||||
#include "testhelpers.h"
|
||||
|
||||
@ -66,7 +67,7 @@ class TestMetaService : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QProcess m_metaserviceProcess;
|
||||
MetaService m_metaService;
|
||||
Client *m_client;
|
||||
|
||||
public:
|
||||
@ -79,8 +80,7 @@ public:
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
m_metaserviceProcess.start("metaservice");
|
||||
QVERIFY2(m_metaserviceProcess.waitForStarted(), "Looks like you don't have Jolie's metaservice command");
|
||||
QVERIFY2(m_metaService.start(), "Looks like you don't have Jolie's metaservice command");
|
||||
QTest::qWait(1000);
|
||||
|
||||
m_client = new Client("localhost", 9000);
|
||||
@ -88,11 +88,8 @@ private slots:
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
Message message("/", "shutdown");
|
||||
m_client->callNoReply(message);
|
||||
delete m_client;
|
||||
|
||||
m_metaserviceProcess.waitForFinished();
|
||||
QVERIFY(m_metaService.stop());
|
||||
}
|
||||
|
||||
void shouldLoadService_data()
|
||||
@ -109,39 +106,15 @@ private slots:
|
||||
QFETCH(QString, resourcePrefix);
|
||||
QFETCH(QString, fileName);
|
||||
|
||||
Message message("/", "loadEmbeddedJolieService");
|
||||
Value value;
|
||||
value.children("resourcePrefix") << Value(resourcePrefix);
|
||||
value.children("filepath") << Value(QString(DATA_DIR"/")+fileName);
|
||||
message.setData(value);
|
||||
|
||||
Message reply = m_client->call(message);
|
||||
|
||||
Message expected("/", "loadEmbeddedJolieService");
|
||||
expected.setData(Value(resourcePrefix));
|
||||
|
||||
sodepCompare(reply, expected);
|
||||
QCOMPARE(m_metaService.loadService(resourcePrefix, QString(DATA_DIR"/")+fileName),
|
||||
resourcePrefix);
|
||||
}
|
||||
|
||||
void shouldListServices()
|
||||
{
|
||||
Message message("/", "getServices");
|
||||
|
||||
Message reply = m_client->call(message);
|
||||
Message expected("/", "getServices");
|
||||
Value value;
|
||||
|
||||
Value s1;
|
||||
s1.children("isEmbedded") << Value(1);
|
||||
s1.children("resourceName") << Value("Math");
|
||||
Value s2;
|
||||
s2.children("isEmbedded") << Value(1);
|
||||
s2.children("resourceName") << Value("Printer");
|
||||
|
||||
value.children("service") << s1 << s2;
|
||||
expected.setData(value);
|
||||
|
||||
sodepCompare(reply, expected);
|
||||
QStringList expected;
|
||||
expected << "Math" << "Printer";
|
||||
QCOMPARE(m_metaService.loadedServices(), expected);
|
||||
}
|
||||
|
||||
void shouldPlaceServiceCalls_data()
|
||||
@ -185,15 +158,7 @@ private slots:
|
||||
{
|
||||
QFETCH(QString, serviceName);
|
||||
|
||||
Message message("/", "unloadEmbeddedService");
|
||||
Value value(serviceName);
|
||||
message.setData(value);
|
||||
|
||||
Message reply = m_client->call(message);
|
||||
|
||||
Message expected("/", "unloadEmbeddedService");
|
||||
|
||||
sodepCompare(reply, expected);
|
||||
m_metaService.unloadService(serviceName);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user