Commit 1569acb4 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii Committed by Vlad Zahorodnii
Browse files

Allow creating global objects before Display is started

It can be especially useful if the compositor wants to ensure that all
globals have been created before starting to accept client connections.

Unfortunately, start() and terminate() stuff doesn't align well with it,
so the terminate() method was dropped to ensure that Display always
returns the same wl_display object.
parent 01ed2a3e
......@@ -28,7 +28,6 @@ private Q_SLOTS:
void testInitConnectionNoThread();
void testConnectionFailure();
void testConnectionDieing();
void testConnectionThread();
void testConnectFd();
void testConnectFdNoSocketName();
......@@ -167,33 +166,6 @@ void TestWaylandConnectionThread::testConnectionThread()
delete connectionThread;
}
void TestWaylandConnectionThread::testConnectionDieing()
{
QScopedPointer<KWayland::Client::ConnectionThread> connection(new KWayland::Client::ConnectionThread);
QSignalSpy connectedSpy(connection.data(), SIGNAL(connected()));
connection->setSocketName(s_socketName);
connection->initConnection();
QVERIFY(connectedSpy.wait());
QVERIFY(connection->display());
QSignalSpy diedSpy(connection.data(), SIGNAL(connectionDied()));
m_display->terminate();
QVERIFY(!m_display->isRunning());
QVERIFY(diedSpy.wait());
QCOMPARE(diedSpy.count(), 1);
QVERIFY(!connection->display());
connectedSpy.clear();
QVERIFY(connectedSpy.isEmpty());
// restarts the server
m_display->start();
QVERIFY(m_display->isRunning());
if (connectedSpy.count() == 0) {
QVERIFY(connectedSpy.wait());
}
QCOMPARE(connectedSpy.count(), 1);
}
void TestWaylandConnectionThread::testConnectFd()
{
using namespace KWayland::Client;
......
......@@ -56,23 +56,19 @@ void TestWaylandServerDisplay::testStartStop()
QVERIFY(runtimeDir.exists());
QVERIFY(!runtimeDir.exists(testSocketName));
Display display;
QSignalSpy runningSpy(&display, SIGNAL(runningChanged(bool)));
QScopedPointer<Display> display(new Display);
QSignalSpy runningSpy(display.data(), SIGNAL(runningChanged(bool)));
QVERIFY(runningSpy.isValid());
display.setSocketName(testSocketName);
QVERIFY(!display.isRunning());
display.start();
display->setSocketName(testSocketName);
QVERIFY(!display->isRunning());
display->start();
// QVERIFY(runningSpy.wait());
QCOMPARE(runningSpy.count(), 1);
QVERIFY(runningSpy.first().first().toBool());
QVERIFY(display.isRunning());
QVERIFY(display->isRunning());
QVERIFY(runtimeDir.exists(testSocketName));
display.terminate();
QVERIFY(!display.isRunning());
QCOMPARE(runningSpy.count(), 2);
QVERIFY(runningSpy.first().first().toBool());
QVERIFY(!runningSpy.last().first().toBool());
display.reset();
QVERIFY(!runtimeDir.exists(testSocketName));
}
......
......@@ -157,13 +157,13 @@ void TestWaylandServerSeat::testPointerPos()
void TestWaylandServerSeat::testDestroyThroughTerminate()
{
Display display;
display.setSocketName(s_socketName);
display.start();
SeatInterface *seat = display.createSeat();
QScopedPointer<Display> display(new Display());
display->setSocketName(s_socketName);
display->start();
SeatInterface *seat = display->createSeat();
QSignalSpy destroyedSpy(seat, SIGNAL(destroyed(QObject*)));
QVERIFY(destroyedSpy.isValid());
display.terminate();
display.reset();
QVERIFY(!destroyedSpy.isEmpty());
}
......
......@@ -108,14 +108,14 @@ Display::Display(QObject *parent)
: QObject(parent)
, d(new Private(this))
{
d->display = wl_display_create();
}
Display::~Display()
{
terminate();
if (d->display) {
wl_display_destroy(d->display);
}
emit aboutToTerminate();
wl_display_terminate(d->display);
wl_display_destroy(d->display);
}
void Display::Private::flush()
......@@ -164,17 +164,15 @@ bool Display::automaticSocketNaming() const
return d->automaticSocketNaming;
}
void Display::start(StartMode mode)
bool Display::start(StartMode mode)
{
Q_ASSERT(!d->running);
Q_ASSERT(!d->display);
d->display = wl_display_create();
if (mode == StartMode::ConnectToSocket) {
if (d->automaticSocketNaming) {
const char *socket = wl_display_add_socket_auto(d->display);
if (socket == nullptr) {
qCWarning(KWAYLAND_SERVER) << "Failed to create Wayland socket";
return;
return false;
}
const QString newEffectiveSocketName = QString::fromUtf8(socket);
......@@ -184,12 +182,14 @@ void Display::start(StartMode mode)
}
} else if (wl_display_add_socket(d->display, qPrintable(d->socketName)) != 0) {
qCWarning(KWAYLAND_SERVER) << "Failed to create Wayland socket";
return;
return false;
}
}
d->loop = wl_display_get_event_loop(d->display);
d->installSocketNotifier();
return d->running;
}
void Display::startLoop()
......@@ -210,19 +210,6 @@ void Display::dispatchEvents(int msecTimeout)
}
}
void Display::terminate()
{
if (!d->running) {
return;
}
emit aboutToTerminate();
wl_display_terminate(d->display);
wl_display_destroy(d->display);
d->display = nullptr;
d->loop = nullptr;
d->setRunning(false);
}
void Display::Private::setRunning(bool r)
{
Q_ASSERT(running != r);
......
......@@ -125,8 +125,11 @@ public:
ConnectToSocket,
ConnectClientsOnly
};
void start(StartMode mode = StartMode::ConnectToSocket);
void terminate();
/**
* Start accepting client connections. If the display has started successfully, this
* function returns @c true; otherwise @c false is returned.
*/
bool start(StartMode mode = StartMode::ConnectToSocket);
/**
* Starts the event loop for the server socket.
* This method should only be used if start() is used before creating the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment