2
* Copyright (C) 2013 Canonical, Ltd.
5
* Michal Hruby <michal.hruby@canonical.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
#include "registry-tracker.h"
28
RegistryTracker::RegistryTracker(QString const& scope_dir):
29
m_scopeDir(scope_dir),
31
m_endpoints_dir(QDir::temp().filePath("scope-dev-endpoints.XXXXXX"))
36
RegistryTracker::~RegistryTracker()
38
if (m_registry.state() != QProcess::NotRunning) {
39
m_registry.terminate();
40
m_registry.waitForFinished(5000);
45
#define RUNTIME_CONFIG \
47
"Registry.Identity = Registry\n" \
48
"Registry.ConfigFile = %1\n" \
49
"Default.Middleware = Zmq\n" \
50
"Zmq.ConfigFile = %2\n"
52
#define REGISTRY_CONFIG \
54
"Middleware = Zmq\n" \
55
"Zmq.Endpoint = ipc://%1/Registry\n" \
56
"Zmq.EndpointDir = %2\n" \
57
"Zmq.ConfigFile = %3\n" \
58
"Scope.InstallDir = %4\n" \
59
"Scoperunner.Path = %5\n"
63
"EndpointDir.Public = %1\n" \
64
"EndpointDir.Private = %2\n"
66
void RegistryTracker::runRegistry()
68
QDir tmp(QDir::temp());
69
m_runtime_config.setFileTemplate(tmp.filePath("Runtime.ini.XXXXXX"));
70
m_registry_config.setFileTemplate(tmp.filePath("Registry.ini.XXXXXX"));
71
m_mw_config.setFileTemplate(tmp.filePath("Zmq.ini.XXXXXX"));
73
if (!m_runtime_config.open() || !m_registry_config.open() || !m_mw_config.open() || !m_endpoints_dir.isValid()) {
74
qWarning("Unable to open temporary files!");
81
QStringList arguments;
82
arguments << "--variable=libdir";
83
arguments << "libunity-scopes";
84
pkg_config.start("pkg-config", arguments);
85
pkg_config.waitForFinished();
86
QByteArray libdir = pkg_config.readAllStandardOutput();
87
scopesLibdir = QDir(QString::fromLocal8Bit(libdir)).path().trimmed();
90
if (scopesLibdir.size() == 0) {
91
qWarning("Unable to find libunity-scopes package config file");
95
QString scopeRunnerPath = QDir(scopesLibdir).filePath("scoperunner/scoperunner");
97
QString runtime_ini = QString(RUNTIME_CONFIG).arg(m_registry_config.fileName()).arg(m_mw_config.fileName());
98
QString registry_ini = QString(REGISTRY_CONFIG).arg(m_endpoints_dir.path()).arg(m_endpoints_dir.path()).arg(m_mw_config.fileName()).arg(m_scopeDir).arg(scopeRunnerPath);
99
QString mw_ini = QString(MW_CONFIG).arg(m_endpoints_dir.path()).arg(m_endpoints_dir.path());
101
m_runtime_config.write(runtime_ini.toUtf8());
102
m_registry_config.write(registry_ini.toUtf8());
103
m_mw_config.write(mw_ini.toUtf8());
105
m_runtime_config.flush();
106
m_registry_config.flush();
109
qputenv("UNITY_SCOPES_RUNTIME_PATH", m_runtime_config.fileName().toLocal8Bit());
111
QString registryBin(QDir(scopesLibdir).filePath("scoperegistry/scoperegistry"));
112
QStringList arguments;
113
arguments << m_runtime_config.fileName();
115
m_registry.start(registryBin, arguments);