~unity-team/qtmir/qtmir-gles

« back to all changes in this revision

Viewing changes to src/platforms/mirserver/qmirserver.cpp

  • Committer: Gerry Boland
  • Date: 2014-07-10 14:12:59 UTC
  • Revision ID: gerry.boland@canonical.com-20140710141259-8kt847ji6g6funki
Import lp:qtmir version 0.4.0 and modify for GLES-only mirserver plugin build

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it under
 
5
 * the terms of the GNU Lesser General Public License version 3, as published by
 
6
 * the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
9
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 
10
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
// Qt
 
18
#include <QObject>
 
19
#include <QCoreApplication>
 
20
#include <QDebug>
 
21
 
 
22
// local
 
23
#include "qmirserver.h"
 
24
 
 
25
 
 
26
QMirServer::QMirServer(const QSharedPointer<MirServerConfiguration> &config, QObject *parent)
 
27
    : QObject(parent)
 
28
    , m_mirServer(new MirServerWorker(config))
 
29
{
 
30
    m_mirServer->moveToThread(&m_mirThread);
 
31
 
 
32
    connect(this, &QMirServer::run, m_mirServer, &MirServerWorker::run);
 
33
    connect(this, &QMirServer::stop, m_mirServer, &MirServerWorker::stop);
 
34
 
 
35
    connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &QMirServer::shutDownMirServer);
 
36
    connect(m_mirServer, &MirServerWorker::stopped, this, &QMirServer::shutDownQApplication, Qt::DirectConnection); // since no event loop
 
37
 
 
38
    m_mirThread.start(QThread::TimeCriticalPriority);
 
39
    Q_EMIT run();
 
40
}
 
41
 
 
42
QMirServer::~QMirServer()
 
43
{
 
44
    shutDownMirServer();
 
45
}
 
46
 
 
47
void QMirServer::shutDownMirServer()
 
48
{
 
49
    if (m_mirThread.isRunning()) {
 
50
        m_mirServer->stop();
 
51
        m_mirThread.wait();
 
52
    }
 
53
}
 
54
 
 
55
void QMirServer::shutDownQApplication()
 
56
{
 
57
    if (m_mirThread.isRunning())
 
58
        m_mirThread.quit();
 
59
 
 
60
    // if unexpected mir server stop, better quit the QApplication
 
61
    if (!QCoreApplication::closingDown()) {
 
62
        QCoreApplication::quit();
 
63
    }
 
64
}