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() {}
12 
13  ClientResponse::ClientResponse(const QString &sender, const QString &receiver, ClientQueryType queryType,
14  const QStringList &responseData)
15  : MessageBase(sender, receiver), m_queryType(queryType), m_responseData(responseData)
16  {}
17 
18  QStringList ClientResponse::toTokens() const
19  {
20  QStringList tokens;
21  tokens.push_back(m_sender);
22  tokens.push_back(m_receiver);
23  tokens.push_back(toQString(m_queryType));
24  tokens.append(m_responseData);
25  return tokens;
26  }
27 
28  ClientResponse ClientResponse::fromTokens(const QStringList &tokens)
29  {
30  if (tokens.size() < 3)
31  {
32  swift::misc::CLogMessage(static_cast<ClientResponse *>(nullptr)).warning(u"Wrong number of arguments.");
33  return {};
34  }
35 
36  QStringList responseData;
37  if (tokens.size() > 3) { responseData = tokens.mid(3); }
38  return ClientResponse(tokens[0], tokens[1], fromQString<ClientQueryType>(tokens[2]), responseData);
39  }
40 } // 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