on 7.86+14.10.20140507.3-0ubuntu1 help sign in
unity8/tools/registry-tracker.cpp
131 lines 4.5 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"
54#define REGISTRY_CONFIG \
55"[Registry]\n" \
56"Middleware = Zmq\n" \
57"Zmq.Endpoint = ipc://%1/Registry\n" \
58"Zmq.EndpointDir = %2\n" \
59"Zmq.ConfigFile = %3\n" \
60"Scope.InstallDir = %4\n" \
61"Scoperunner.Path = %5\n" \
62"%6"
64#define MW_CONFIG \
65"[Zmq]\n" \
66"EndpointDir.Public = %1\n" \
67"EndpointDir.Private = %2\n"
69void RegistryTracker::runRegistry()
71 QDir tmp(QDir::temp());
72 m_runtime_config.setFileTemplate(tmp.filePath("Runtime.ini.XXXXXX"));
73 m_registry_config.setFileTemplate(tmp.filePath("Registry.ini.XXXXXX"));
74 m_mw_config.setFileTemplate(tmp.filePath("Zmq.ini.XXXXXX"));
76 if (!m_runtime_config.open() || !m_registry_config.open() || !m_mw_config.open() || !m_endpoints_dir.isValid()) {
77 qWarning("Unable to open temporary files!");
78 return;
79 }
81 QString scopesLibdir;
82 {
83 QProcess pkg_config;
84 QStringList arguments;
85 arguments << "--variable=libdir";
86 arguments << "libunity-scopes";
87 pkg_config.start("pkg-config", arguments);
88 pkg_config.waitForFinished();
89 QByteArray libdir = pkg_config.readAllStandardOutput();
90 scopesLibdir = QDir(QString::fromLocal8Bit(libdir)).path().trimmed();
91 }
93 if (scopesLibdir.size() == 0) {
94 qWarning("Unable to find libunity-scopes package config file");
95 return;
96 }
98 QString scopeRunnerPath = QDir(scopesLibdir).filePath("scoperunner/scoperunner");
100 QString runtime_ini = QString(RUNTIME_CONFIG).arg(m_registry_config.fileName()).arg(m_mw_config.fileName());
101 // FIXME: keep in sync with the SSRegistry config
102 QString serverRegistryConfig(m_serverScopes ? "SS.Registry.Identity = SSRegistry\nSS.Registry.Endpoint = ipc:///tmp/SSRegistry" : "");
103 QString scopeInstallDir(scopesLibdir + "/unity-scopes");
104 if (!m_systemScopes) {
105 m_scopeInstallDir.reset(new QTemporaryDir(tmp.filePath("scopes.XXXXXX")));
106 if (!m_scopeInstallDir->isValid()) {
107 qWarning("Unable to create temporary scopes directory!");
108 }
109 scopeInstallDir = m_scopeInstallDir->path();
110 }
111 QString registry_ini = QString(REGISTRY_CONFIG).arg(m_endpoints_dir.path()).arg(m_endpoints_dir.path()).arg(m_mw_config.fileName()).arg(scopeInstallDir).arg(scopeRunnerPath).arg(serverRegistryConfig);
112 QString mw_ini = QString(MW_CONFIG).arg(m_endpoints_dir.path()).arg(m_endpoints_dir.path());
114 m_runtime_config.write(runtime_ini.toUtf8());
115 m_registry_config.write(registry_ini.toUtf8());
116 m_mw_config.write(mw_ini.toUtf8());
118 m_runtime_config.flush();
119 m_registry_config.flush();
120 m_mw_config.flush();
122 qputenv("UNITY_SCOPES_RUNTIME_PATH", m_runtime_config.fileName().toLocal8Bit());
124 QString registryBin(QDir(scopesLibdir).filePath("scoperegistry/scoperegistry"));
125 QStringList arguments;
126 arguments << m_runtime_config.fileName();
127 arguments << m_scopes;
129 m_registry.setProcessChannelMode(QProcess::ForwardedChannels);
130 m_registry.start(registryBin, arguments);