~ci-train-bot/unity8/unity8-ubuntu-zesty-2373

« back to all changes in this revision

Viewing changes to tools/registry-tracker.cpp

  • Committer: Michal Hruby
  • Date: 2013-12-20 15:27:59 UTC
  • mto: This revision was merged to the branch mainline in revision 613.
  • Revision ID: michal.mhr@gmail.com-20131220152759-7o59l2oqwleinknu
Cherrypick the unity-scope-tool

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
19
 
 
20
// Qt
 
21
#include <QtGlobal>
 
22
#include <QDir>
 
23
 
 
24
// local
 
25
#include "registry-tracker.h"
 
26
 
 
27
 
 
28
RegistryTracker::RegistryTracker(QString const& scope_dir):
 
29
    m_scopeDir(scope_dir),
 
30
    m_registry(nullptr),
 
31
    m_endpoints_dir(QDir::temp().filePath("scope-dev-endpoints.XXXXXX"))
 
32
{
 
33
    runRegistry();
 
34
}
 
35
 
 
36
RegistryTracker::~RegistryTracker()
 
37
{
 
38
    if (m_registry.state() != QProcess::NotRunning) {
 
39
        m_registry.terminate();
 
40
        m_registry.waitForFinished(5000);
 
41
        m_registry.kill();
 
42
    }
 
43
}
 
44
 
 
45
#define RUNTIME_CONFIG \
 
46
"[Runtime]\n" \
 
47
"Registry.Identity = Registry\n" \
 
48
"Registry.ConfigFile = %1\n" \
 
49
"Default.Middleware = Zmq\n" \
 
50
"Zmq.ConfigFile = %2\n"
 
51
 
 
52
#define REGISTRY_CONFIG \
 
53
"[Registry]\n" \
 
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"
 
60
 
 
61
#define MW_CONFIG \
 
62
"[Zmq]\n" \
 
63
"EndpointDir.Public = %1\n" \
 
64
"EndpointDir.Private = %2\n"
 
65
 
 
66
void RegistryTracker::runRegistry()
 
67
{
 
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"));
 
72
 
 
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
    }
 
77
 
 
78
    QString scopesLibdir;
 
79
    {
 
80
        QProcess pkg_config;
 
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();
 
88
    }
 
89
 
 
90
    if (scopesLibdir.size() == 0) {
 
91
        qWarning("Unable to find libunity-scopes package config file");
 
92
        return;
 
93
    }
 
94
 
 
95
    QString scopeRunnerPath = QDir(scopesLibdir).filePath("scoperunner/scoperunner");
 
96
 
 
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());
 
100
 
 
101
    m_runtime_config.write(runtime_ini.toUtf8());
 
102
    m_registry_config.write(registry_ini.toUtf8());
 
103
    m_mw_config.write(mw_ini.toUtf8());
 
104
 
 
105
    m_runtime_config.flush();
 
106
    m_registry_config.flush();
 
107
    m_mw_config.flush();
 
108
 
 
109
    qputenv("UNITY_SCOPES_RUNTIME_PATH", m_runtime_config.fileName().toLocal8Bit());
 
110
 
 
111
    QString registryBin(QDir(scopesLibdir).filePath("scoperegistry/scoperegistry"));
 
112
    QStringList arguments;
 
113
    arguments << m_runtime_config.fileName();
 
114
 
 
115
    m_registry.start(registryBin, arguments);
 
116
}