swift
clientresponse.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "core/fsd/serializer.h"
7 #include "misc/logmessage.h"
8 
9 namespace swift::core::fsd
10 {
11  ClientResponse::ClientResponse(const QString &sender, const QString &receiver, ClientQueryType queryType,
12  const QStringList &responseData)
13  : MessageBase(sender, receiver), m_queryType(queryType), m_responseData(responseData)
14  {}
15 
17  {
18  QStringList tokens;
19  tokens.push_back(m_sender);
20  tokens.push_back(m_receiver);
21  tokens.push_back(toQString(m_queryType));
22  tokens.append(m_responseData);
23  return tokens;
24  }
25 
27  {
28  if (tokens.size() < 3)
29  {
30  swift::misc::CLogMessage(static_cast<ClientResponse *>(nullptr)).warning(u"Wrong number of arguments.");
31  return {};
32  }
33 
34  QStringList responseData;
35  if (tokens.size() > 3) { responseData = tokens.mid(3); }
36  return { tokens[0], tokens[1], fromQString<ClientQueryType>(tokens[2]), responseData };
37  }
38 } // namespace swift::core::fsd
This packet is used to respond to a client data request.
QStringList toTokens() const
Message converted to tokens.
static ClientResponse fromTokens(const QStringList &tokens)
Construct from tokens.
ClientQueryType m_queryType
Properties.
QStringList m_responseData
Properties.
FSD message base class.
Definition: messagebase.h:58
QString m_receiver
message receiver
Definition: messagebase.h:89
QString m_sender
message sender
Definition: messagebase.h:88
Class for emitting a log message.
Definition: logmessage.h:27
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
ClientQueryType
Client query types.
Definition: enums.h:72
void append(QList< T > &&value)
QList< T > mid(qsizetype pos, qsizetype length) const const
void push_back(QList< T >::parameter_type value)
qsizetype size() const const