on 8.02+15.04.20141216.1-0ubuntu1 help sign in
unity8/tools/registry-tracker.cpp
144 lines 4.8 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Michal Hruby <michal.hruby@canonical.com>
6 *
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.
10 *
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.
15 *
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/>.
18 */
20// Qt
21#include <QtGlobal>
22#include <QDir>
24// local
25#include "registry-tracker.h"
28RegistryTracker::RegistryTracker(QStringList const& scopes, bool systemScopes, bool serverScopes):
29 m_scopes(scopes),
30 m_systemScopes(systemScopes),
31 m_serverScopes(serverScopes),
32 m_registry(nullptr),
33 m_endpoints_dir(QDir::temp().filePath("scope-dev-endpoints.XXXXXX"))
35 runRegistry();
38RegistryTracker::~RegistryTracker()
40 if (m_registry.state() != QProcess::NotRunning) {
41 m_registry.terminate();
42 m_registry.waitForFinished(5000);
43 m_registry.kill();
44 }
47#define RUNTIME_CONFIG \
48"[Runtime]\n" \
49"Registry.Identity = Registry\n" \
50"Registry.ConfigFile = %1\n" \
51"Default.Middleware = Zmq\n" \
52"Zmq.ConfigFile = %2\n" \
53"Smartscopes.Registry.Identity = %3\n"
55#define REGISTRY_CONFIG \
56"[Registry]\n" \
57"Middleware = Zmq\n" \
58"Zmq.ConfigFile = %1\n" \
59"Scope.InstallDir = %2\n" \
60"Scoperunner.Path = %3\n"
62#define MW_CONFIG \
63"[Zmq]\n" \
64"EndpointDir = %1\n"
66void RegistryTracker::runRegistry()
68 QDir tmp(QDir::temp());
69 m_runtime_config.setFileTemplate(tmp.filePath("Runtime.XXXXXX.ini"));
70 m_registry_config.setFileTemplate(tmp.filePath("Registry.XXXXXX.ini"));
71 m_mw_config.setFileTemplate(tmp.filePath("Zmq.XXXXXX.ini"));
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!");
75 return;
76 }
78 QString scopeInstallDir;
79 QString scopeRegistryBin;
80 QString scopeRunnerBin;
81 {
82 QProcess pkg_config;
83 QByteArray output;
84 QStringList arguments;
85 arguments << "--variable=scopesdir";
86 arguments << "libunity-scopes";
87 pkg_config.start("pkg-config", arguments);
88 pkg_config.waitForFinished();
89 output = pkg_config.readAllStandardOutput();
90 scopeInstallDir = QDir(QString::fromLocal8Bit(output)).path().trimmed();
92 arguments[0] = "--variable=scoperegistry_bin";
93 pkg_config.start("pkg-config", arguments);
94 pkg_config.waitForFinished();
95 output = pkg_config.readAllStandardOutput();
96 scopeRegistryBin = QString::fromLocal8Bit(output).trimmed();
98 arguments[0] = "--variable=scoperunner_bin";
99 pkg_config.start("pkg-config", arguments);
100 pkg_config.waitForFinished();
101 output = pkg_config.readAllStandardOutput();
102 scopeRunnerBin = QString::fromLocal8Bit(output).trimmed();
103 }
105 if (scopeInstallDir.isEmpty() || scopeRegistryBin.isEmpty() || scopeRunnerBin.isEmpty()) {
106 qWarning("Unable to find libunity-scopes package config file");
107 return;
108 }
110 // FIXME: keep in sync with the SSRegistry config
111 QString runtime_ini = QString(RUNTIME_CONFIG).arg(m_registry_config.fileName()).arg(m_mw_config.fileName()).arg(m_serverScopes ? "SSRegistry" : "");
112 if (!m_systemScopes) {
113 m_scopeInstallDir.reset(new QTemporaryDir(tmp.filePath("scopes.XXXXXX")));
114 if (!m_scopeInstallDir->isValid()) {
115 qWarning("Unable to create temporary scopes directory!");
116 }
117 scopeInstallDir = m_scopeInstallDir->path();
118 }
119 QString registry_ini = QString(REGISTRY_CONFIG).arg(m_mw_config.fileName()).arg(scopeInstallDir).arg(scopeRunnerBin);
120 QString mw_ini = QString(MW_CONFIG).arg(m_endpoints_dir.path());
122 if (!m_systemScopes) {
123 // Disable OEM and Click scopes when system scopes are disabled
124 registry_ini += "OEM.InstallDir = /unused\n";
125 registry_ini += "Click.InstallDir = /unused\n";
126 }
128 m_runtime_config.write(runtime_ini.toUtf8());
129 m_registry_config.write(registry_ini.toUtf8());
130 m_mw_config.write(mw_ini.toUtf8());
132 m_runtime_config.flush();
133 m_registry_config.flush();
134 m_mw_config.flush();
136 qputenv("UNITY_SCOPES_RUNTIME_PATH", m_runtime_config.fileName().toLocal8Bit());
138 QStringList arguments;
139 arguments << m_runtime_config.fileName();
140 arguments << m_scopes;
142 m_registry.setProcessChannelMode(QProcess::ForwardedChannels);
143 m_registry.start(scopeRegistryBin, arguments);