1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCloudMessaging module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3-COMM$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qcloudmessagingclient.h"
#include "qcloudmessagingclient_p.h"
/*!
\class QCloudMessagingClient
\inmodule QtCloudMessaging
\since 5.11
\brief The QCloudMessagingClient class is a single IoT/embedded or mobile device
providing way to received and send messages either by broadcasting or
by direct connect to other client with known token.
Implementing specific cloud messaging service client needs inherit this
QCloudMessagingClient class and implement the virtual functions defined in the
header.
*/
QT_BEGIN_NAMESPACE
/*!
* \brief QCloudMessagingClient::QCloudMessagingClient
* QCloudMessagingClient constructor
*
* \param parent
* Parent is QObject
*/
QCloudMessagingClient::QCloudMessagingClient(QObject *parent) :
QObject(parent),
d(new QCloudMessagingClientPrivate)
{
}
/*!
* \brief QCloudMessagingClient::~QCloudMessagingClient
* Desctructor
*/
QCloudMessagingClient::~QCloudMessagingClient()
{
disconnectClient();
}
/*!
* \brief QCloudMessagingClient::connectClient
* Attaches the client into the provider. This is virtual function
* and should be re-implemented in the inheritance for connecting
* the client to real service.
*
* \param clientId
* Mobile or IoT client identification string (defined by user) added for the
* provider
*
* \param parameters
* Client specific parameters in a variant map.
*
* \return
* return given ClientId when successful, empty string if not.
*
*/
QString QCloudMessagingClient::connectClient(const QString &clientId,
const QVariantMap ¶meters)
{
d->m_clientId = clientId;
d->m_clientState = QtCloudMessagingClientConnecting;
d->m_client_parameters = parameters;
return QString();
}
/*!
* \brief QCloudMessagingClient::disconnectClient
* Virtual function to disconnect the client from the service.
*
* \return
* returns the client specific state as integer
*/
void QCloudMessagingClient::disconnectClient()
{
d->m_clientState = QtCloudMessagingClientDisconnecting;
}
/*!
* \brief QCloudMessagingClient::setClientState
* Sets the client state. This is virtual function and can be
* re-implemented in the inheritance
*
* \param state
* Setting client specific state as integer.
*/
void QCloudMessagingClient::setClientState(int state)
{
d->m_clientState = state;
}
/*!
* \brief QCloudMessagingClient::clientState
* Gets the client specific state
*
* \return
* Returns clients specific state value as integer.
*/
int QCloudMessagingClient::clientState()
{
return (CloudMessagingClientState) d->m_clientState;
}
/*!
* \brief QCloudMessagingClient::clientId
* Gets the client id.
*
* \return
* Returns client id as QString
*/
QString QCloudMessagingClient::clientId()
{
return d->m_clientId;
}
/*!
* \brief QCloudMessagingClient::providerId
* Gets the client's service provider id.
*
* \return
* Returns the provider id as QString.
*/
QString QCloudMessagingClient::providerId()
{
return d->m_providerId;
}
/*!
* \brief QCloudMessagingClient::setClientId
* Sets the client id
*
* \param clientid
* Client id as QString
*
* \return
* Returns new client id as QString
*/
void QCloudMessagingClient::setClientId(const QString &clientid)
{
d->m_clientId = clientid;
}
/*!
* \brief QCloudMessagingClient::setProviderId
* Gets the client's service provider id.
*
* \return
* Returns new provider id as QString.
*/
void QCloudMessagingClient::setProviderId(const QString &providerId)
{
d->m_providerId = providerId;
}
/*!
* \brief QCloudMessagingClient::clientParameters
* Gets the client parameters
*
* \return
* Returns client parameters as QVariantMap
*/
QVariantMap QCloudMessagingClient::clientParameters()
{
return d->m_client_parameters;
}
// Pure Virtual functions documentation
/*!
\fn QCloudMessagingClient::flushMessageQueue()
When receiving push messages they can be stored by clients internally.
This function gives developers possibility to do flush commnand for them.
This is pure virtual function and needs to be implemented in the
inheritance.
\return
return true when successful, false otherwise.
*/
/*!
\fn QCloudMessagingClient::sendMessage(
const QByteArray &msg,
const QString &clientToken = QString(),
const QString &channel = QString())
Sends a message to one single client or to subscribed channel.
This is pure virtual function and needs to be implemented in the inheritance.
\param msg
Message as string which is interpreted to the service specific message
type e.g. json
\param clientToken
By providing client token, message is targeted straight to client
\param channel
Channel name if broadcasting the message to channel
\return
return true when successful, false otherwise.
*/
/*!
\fn QCloudMessagingClient::setClientToken(const QString &token)
Sets the client token for the client.
This can be used in case of client
token is received otherwise or defined by
API user separately.
\param token
Token value as string
*/
/*!
\fn QCloudMessagingClient::clientToken()
Gets client token (uuid / rid received from the provider services)
\return
If found returns client token as QString. Returns empty QString otherwise.
*/
/*!
\fn QCloudMessagingClient::subscribeToChannel(
const QString &channel)
Subscribes client to broadcast channel of the provider service.
This is pure virtual function and needs to be implemented in the
inheritance.
\param channnel
Channel name as QString
\return
return true when successful, false otherwise.
*/
/*!
\fn QCloudMessagingClient::unsubscribeFromChannel(
const QString &channel)
Unsubscribes client from the broadcast channel of the provider service.
This is pure virtual function and needs to be implemented in the
inheritance.
\param channnel
Channel name as QString
\return
return true when successful, false otherwise.
*/
// Signals documentation
/*!
\fn QCloudMessagingClient::clientStateChanged(
const QString &clientId,
int state)
This signal is triggered when the client state has changed
\param clientId
Client idenfitication string
\param state
Client State can be either enum from QCloudMessagingClient::CloudMessagingClientState
or it can be client backend specific state.
*/
/*!
\fn QCloudMessagingClient::messageReceived(const QString &clientId,
const QByteArray &message)
This signal is triggered when a message is received from the network to client.
\param clientId
Receiving clientId string
\param message
Received message as QByteArray. Message content is service specific.
*/
/*!
\fn QCloudMessagingClient::clientTokenReceived(const QString &token)
This signal is triggered when connected gets the client
token from the service provider.
\param token
Received token as a QString.
Token is unique identification value used for straight communication
and identification with the client.
*/
// Enums
/*!
\enum QCloudMessagingClient::CloudMessagingClientState
This enum type describes types of QCloudMessagingClient connection states.
\value QtCloudMessgingClientDisconnected Client is disconnected.
\value QtCloudMessagingClientConnecting Client connection started.
\value QtCloudMessagingClientDisconnecting Client disconnection started.
\value QtCloudMessagingClientOffline Client is connected but offline.
\value QtCloudMessagingClientOnline Client is connected and online.
*/
QT_END_NAMESPACE
|