added processMessage to network Object base class

Dieser Commit ist enthalten in:
Reinder Feenstra 2022-03-02 23:50:57 +01:00
Ursprung f37dbe194f
Commit c6be281ab1
8 geänderte Dateien mit 18 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020-2021 Reinder Feenstra
* Copyright (C) 2020-2022 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -143,7 +143,7 @@ void Board::processMessage(const Message& message)
break;
}
default:
Q_ASSERT(false);
Object::processMessage(message);
break;
}
}

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020-2021 Reinder Feenstra
* Copyright (C) 2020-2022 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -32,9 +32,6 @@
#include <traintastic/network/message.hpp>
#include "objectptr.hpp"
class Connection;
class Message;
class Board final : public Object
{
Q_OBJECT
@ -51,7 +48,7 @@ class Board final : public Object
int m_getTileDataRequestId;
void getTileDataResponse(const Message& response);
void processMessage(const Message& message);
void processMessage(const Message& message) final;
public:
inline static const QString classId = QStringLiteral("board");

Datei anzeigen

@ -374,7 +374,7 @@ int Connection::getInputMonitorInputInfo(InputMonitor& inputMonitor)
send(request,
[&inputMonitor](const std::shared_ptr<Message> message)
{
inputMonitor.processMessage(*message);
static_cast<Object&>(inputMonitor).processMessage(*message);
});
return request->requestId();
}
@ -386,16 +386,7 @@ int Connection::getOutputKeyboardOutputInfo(OutputKeyboard& object)
send(request,
[&object](const std::shared_ptr<Message> message)
{
uint32_t count = message->read<uint32_t>();
while(count > 0)
{
const uint32_t address = message->read<uint32_t>();
const QString id = QString::fromUtf8(message->read<QByteArray>());
const TriState value = message->read<TriState>();
emit object.outputIdChanged(address, id);
emit object.outputValueChanged(address, value);
count--;
}
static_cast<Object&>(object).processMessage(*message);
});
return request->requestId();
}
@ -973,36 +964,12 @@ void Connection::processMessage(const std::shared_ptr<Message> message)
case Message::Command::InputMonitorInputIdChanged:
case Message::Command::InputMonitorInputValueChanged:
if(auto inputMonitor = std::dynamic_pointer_cast<InputMonitor>(m_objects.value(message->read<Handle>()).lock()))
inputMonitor->processMessage(*message);
break;
case Message::Command::OutputKeyboardOutputIdChanged:
if(auto outputKeyboard = std::dynamic_pointer_cast<OutputKeyboard>(m_objects.value(message->read<Handle>()).lock()))
{
const uint32_t address = message->read<uint32_t>();
const QString id = QString::fromUtf8(message->read<QByteArray>());
emit outputKeyboard->outputIdChanged(address, id);
}
break;
case Message::Command::OutputKeyboardOutputValueChanged:
if(auto outputKeyboard = std::dynamic_pointer_cast<OutputKeyboard>(m_objects.value(message->read<Handle>()).lock()))
{
const uint32_t address = message->read<uint32_t>();
const TriState value = message->read<TriState>();
emit outputKeyboard->outputValueChanged(address, value);
}
break;
case Message::Command::BoardTileDataChanged:
if(auto board = std::dynamic_pointer_cast<Board>(m_objects.value(message->read<Handle>()).lock()))
board->processMessage(*message);
break;
case Message::Command::OutputMapOutputsChanged:
if(auto outputMap = std::dynamic_pointer_cast<OutputMap>(m_objects.value(message->read<Handle>()).lock()))
outputMap->processMessage(*message);
if(auto object = m_objects.value(message->read<Handle>()).lock())
object->processMessage(*message);
break;
default:

Datei anzeigen

@ -93,6 +93,7 @@ void InputMonitor::processMessage(const Message& message)
return;
}
default:
Object::processMessage(message);
break;
}
}

Datei anzeigen

@ -26,21 +26,17 @@
#include "object.hpp"
#include <traintastic/enum/tristate.hpp>
class Message;
class InputMonitor final : public Object
{
Q_OBJECT
friend class Connection;
private:
int m_requestId;
std::unordered_map<uint32_t, QString> m_inputIds;
std::unordered_map<uint32_t, TriState> m_inputValues;
protected:
void processMessage(const Message& message);
void processMessage(const Message& message) final;
public:
inline static const QString classId = QStringLiteral("input_monitor");

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2019-2021 Reinder Feenstra
* Copyright (C) 2019-2022 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -29,6 +29,7 @@
#include "interfaceitems.hpp"
class Connection;
class Message;
class AbstractProperty;
class AbstractVectorProperty;
class Method;
@ -45,6 +46,8 @@ class Object : public QObject
const QString m_classId;
InterfaceItems m_interfaceItems;
virtual void processMessage(const Message& /*message*/) {}
public:
explicit Object(std::shared_ptr<Connection> connection, Handle handle, const QString& classId);
Object(const Object&) = delete;

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2021 Reinder Feenstra
* Copyright (C) 2021-2022 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -93,7 +93,7 @@ void OutputMap::processMessage(const Message& message)
break;
default:
Q_ASSERT(false);
Object::processMessage(message);
break;
}
}

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2021 Reinder Feenstra
* Copyright (C) 2021-2022 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -26,15 +26,10 @@
#include "object.hpp"
#include "objectptr.hpp"
class Connection;
class Message;
class OutputMap final : public Object
{
Q_OBJECT
friend class Connection;
public:
using Items = std::vector<ObjectPtr>;
using Outputs = std::vector<ObjectPtr>;
@ -48,7 +43,7 @@ class OutputMap final : public Object
void readOutputs(const Message& message);
protected:
void processMessage(const Message& message);
void processMessage(const Message& message) final;
public:
inline static const QString classIdPrefix = QStringLiteral("output_map.");