1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
/*
* Copyright (C) 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: James Henstridge <james.henstridge@canonical.com>
*/
#include "dbusserver.h"
#include <service/dbus_names.h>
#include <testsetup.h>
#include <libqtdbustest/DBusTestRunner.h>
#include <libqtdbustest/QProcessDBusService.h>
DBusServer::DBusServer()
{
using namespace lomiri::thumbnailer::service;
runner_.reset(new QtDBusTest::DBusTestRunner());
service_.reset(new QtDBusTest::QProcessDBusService(
BUS_NAME, QDBusConnection::SessionBus,
THUMBNAILER_SERVICE, {}));
runner_->registerService(service_);
runner_->startServices();
thumbnailer_.reset(
new ThumbnailerInterface(BUS_NAME, THUMBNAILER_BUS_PATH,
runner_->sessionConnection()));
admin_.reset(
new AdminInterface(BUS_NAME, ADMIN_BUS_PATH,
runner_->sessionConnection()));
}
DBusServer::~DBusServer()
{
// If the service is running, give it a chance to shut down.
// Without this, it won't update the coverage stats.
if (service_process().state() == QProcess::Running)
{
admin_->Shutdown().waitForFinished();
service_process().waitForFinished();
}
admin_.reset();
thumbnailer_.reset();
runner_.reset();
}
QProcess& DBusServer::service_process()
{
// Ugly, but we need access to some of the non-const methods
return const_cast<QProcess&>(service_->underlyingProcess());
}
QDBusConnection const& DBusServer::connection()
{
return runner_->sessionConnection();
}
|