| 1 | /* |
|---|---|
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org> |
| 4 | SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #include "connectionserver.h" |
| 10 | #include "connection_p.h" |
| 11 | #include "connectionbackend_p.h" |
| 12 | #include "kiocoredebug.h" |
| 13 | |
| 14 | using namespace KIO; |
| 15 | |
| 16 | ConnectionServer::ConnectionServer(QObject *parent) |
| 17 | : QObject(parent) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | ConnectionServer::~ConnectionServer() = default; |
| 22 | |
| 23 | void ConnectionServer::listenForRemote() |
| 24 | { |
| 25 | backend = new ConnectionBackend(this); |
| 26 | if (auto result = backend->listenForRemote(); !result.success) { |
| 27 | qCWarning(KIO_CORE) << "ConnectionServer::listenForRemote failed:"<< result.error; |
| 28 | delete backend; |
| 29 | backend = nullptr; |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | connect(sender: backend, signal: &ConnectionBackend::newConnection, context: this, slot: &ConnectionServer::newConnection); |
| 34 | // qDebug() << "Listening on" << d->backend->address; |
| 35 | } |
| 36 | |
| 37 | QUrl ConnectionServer::address() const |
| 38 | { |
| 39 | if (backend) { |
| 40 | return backend->address; |
| 41 | } |
| 42 | return QUrl(); |
| 43 | } |
| 44 | |
| 45 | bool ConnectionServer::isListening() const |
| 46 | { |
| 47 | return backend && backend->state == ConnectionBackend::Listening; |
| 48 | } |
| 49 | |
| 50 | void ConnectionServer::setNextPendingConnection(Connection *conn) |
| 51 | { |
| 52 | ConnectionBackend *newBackend = backend->nextPendingConnection(); |
| 53 | Q_ASSERT(newBackend); |
| 54 | |
| 55 | conn->d->setBackend(newBackend); |
| 56 | newBackend->setParent(conn); |
| 57 | |
| 58 | conn->d->dequeue(); |
| 59 | } |
| 60 | |
| 61 | #include "moc_connectionserver.cpp" |
| 62 |
