~mir-team/qtmir/compatibility-with-mir-API-changes

« back to all changes in this revision

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

Wait for ApplicationManager to be there

Fixes some autopilot tests in which the signal comes before the object is there and therefore the ApplicationManager never thinks there's a dash running 
Approved by: Daniel d'Andrada, Gerry Boland

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "logging.h"
19
19
#include "tracepoints.h" // generated from tracepoints.tp
20
20
 
 
21
#include <QMetaMethod>
 
22
#include <QThread>
 
23
 
21
24
// mir
22
25
#include <mir/frontend/session_credentials.h>
23
26
 
25
28
 
26
29
SessionAuthorizer::SessionAuthorizer(QObject *parent)
27
30
    : QObject(parent)
 
31
    , m_connectionChecked(false)
28
32
{
29
33
}
30
34
 
38
42
    qCDebug(QTMIR_MIR_MESSAGES) << "SessionAuthorizer::connection_is_allowed - this=" << this << "pid=" << creds.pid();
39
43
    bool authorized = true;
40
44
 
 
45
    if (!m_connectionChecked) {
 
46
        // Wait until the ApplicationManager is ready to receive requestAuthorizationForSession signals
 
47
        const QMetaObject *mo = metaObject();
 
48
        QMetaMethod mm = mo->method(mo->indexOfSignal("requestAuthorizationForSession(quint64,bool&)"));
 
49
        for (int i = 0; i < 100 && !isSignalConnected(mm); ++i) {
 
50
            QThread::usleep(10000);
 
51
        }
 
52
        if (!isSignalConnected(mm)) {
 
53
            qCDebug(QTMIR_MIR_MESSAGES) <<
 
54
                "SessionAuthorizer::connection_is_allowed - Gave up waiting for signal listeners";
 
55
        }
 
56
        m_connectionChecked = true;
 
57
    }
 
58
 
41
59
    Q_EMIT requestAuthorizationForSession(creds.pid(), authorized); // needs to block until authorized value returned
42
60
    tracepoint(qtmirserver, sessionAuthorizeEnd);
43
61