1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtNfc module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qllcpserver_p.h"
41
42#if defined(QT_SIMULATOR)
43#include "qllcpserver_simulator_p.h"
44#elif defined(QT_ANDROID_NFC)
45#include "qllcpserver_android_p.h"
46#else
47#include "qllcpserver_p_p.h"
48#endif
49
50QT_BEGIN_NAMESPACE
51
52/*!
53 \class QLlcpServer
54 \brief The QLlcpServer class provides an NFC LLCP socket based server.
55 \internal
56
57 \ingroup connectivity-nfc
58 \inmodule QtNfc
59
60 This class makes it possible to accept incoming LLCP socket connections.
61
62 Call listen() to have the server start listening for incoming connections on a specified port.
63 The newConnection() signal is then emitted each time a client connects to the server.
64
65 Call nextPendingConnection() to accept the pending connection as a connected QLlcpSocket. The
66 function returns a pointer to a QLlcpSocket that can be used for communicating with the client.
67
68 If an error occurs, serverError() returns the type of error, and errorString() can be called to
69 get a human readable description of what happened.
70
71 When listening for connections, the port which the server is listening on is available through
72 serverPort().
73
74 Calling close() makes QLlcpServer stop listening for incoming connections.
75*/
76
77/*!
78 \fn QLlcpServer::newConnection()
79
80 This signal is emitted every time a new connection is available.
81
82 \sa hasPendingConnections(), nextPendingConnection()
83*/
84
85/*!
86 Constructs a new NFC LLCP server with \a parent.
87*/
88QLlcpServer::QLlcpServer(QObject *parent)
89: QObject(parent), d_ptr(new QLlcpServerPrivate(this))
90{
91}
92
93/*!
94 Destroys the NFC LLCP server.
95*/
96QLlcpServer::~QLlcpServer()
97{
98 delete d_ptr;
99}
100
101/*!
102 Tells the server to listen for incoming connections on \a serviceUri. If the server is
103 currently listening then it will return false. Returns true on success; otherwise returns
104 false.
105
106 serviceUri() will return the \a serviceUri that is passed into listen.
107
108 serverPort() will return the port that is assigned to the server.
109
110 \sa serverPort(), isListening(), close()
111*/
112bool QLlcpServer::listen(const QString &serviceUri)
113{
114 Q_D(QLlcpServer);
115
116 return d->listen(serviceUri);
117}
118
119/*!
120 Returns true if the server is listening for incoming connections; otherwise returns false.
121*/
122bool QLlcpServer::isListening() const
123{
124 Q_D(const QLlcpServer);
125
126 return d->isListening();
127}
128
129/*!
130 Stops listening for incoming connections.
131*/
132void QLlcpServer::close()
133{
134 Q_D(QLlcpServer);
135
136 d->close();
137}
138
139/*!
140 Returns the LLCP service URI that the server is listening on.
141*/
142QString QLlcpServer::serviceUri() const
143{
144 Q_D(const QLlcpServer);
145
146 return d->serviceUri();
147}
148
149/*!
150 Returns the LLCP port associated with the service URI that the server is listening on.
151 This call is not supported on all platforms and will return 0 on these platforms.
152*/
153quint8 QLlcpServer::serverPort() const
154{
155 Q_D(const QLlcpServer);
156
157 return d->serverPort();
158}
159
160/*!
161 Returns true if the server has a pending connection; otherwise returns false.
162
163 \sa nextPendingConnection()
164*/
165bool QLlcpServer::hasPendingConnections() const
166{
167 Q_D(const QLlcpServer);
168
169 return d->hasPendingConnections();
170}
171
172/*!
173 Returns the next pending connection as a connected QLlcpSocket object.
174
175 The socket is created as a child of the server, which means that it is automatically deleted
176 when the QLlcpServer object is destroyed. It is still a good idea to delete the object
177 explicitly when you are done with it, to avoid wasting memory.
178
179 0 is returned if this function is called when there are no pending connections.
180
181 \sa hasPendingConnections(), newConnection()
182*/
183QLlcpSocket *QLlcpServer::nextPendingConnection()
184{
185 Q_D(QLlcpServer);
186
187 return d->nextPendingConnection();
188}
189
190/*!
191 Returns the last error that occurred.
192*/
193QLlcpSocket::SocketError QLlcpServer::serverError() const
194{
195 Q_D(const QLlcpServer);
196
197 return d->serverError();
198}
199
200QT_END_NAMESPACE
201

source code of qtconnectivity/src/nfc/qllcpserver.cpp