Skip to content

Commit

Permalink
Supporting custom protocol options.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Nov 16, 2024
1 parent c7b52f2 commit 5a7905c
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 45 deletions.
8 changes: 7 additions & 1 deletion demo/cc_plugin/DemoFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ namespace demo
namespace cc_plugin
{

using DemoFrame = cc_tools_qt::ToolsFrameBase<DemoMessage, demo::Frame, DemoMsgFactory, DemoTransportMessage>;
using DemoFrame =
cc_tools_qt::ToolsFrameBase<
DemoMessage,
demo::Frame<DemoMessage::ProtInterface>,
DemoMsgFactory,
DemoTransportMessage
>;

} // namespace cc_plugin

Expand Down
7 changes: 5 additions & 2 deletions demo/cc_plugin/DemoMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#pragma once

#include "demo/DemoMessage.h"
#include "demo/DefaultOptions.h"

#include "cc_tools_qt/ToolsMessage.h"
#include "cc_tools_qt/ToolsProtMsgInterface.h"

namespace demo
{
Expand All @@ -31,8 +33,9 @@ namespace cc_plugin
class DemoMessage : public cc_tools_qt::ToolsMessage
{
public:
template <typename... TOptions>
using ProtMsgBase = demo::DemoMessage<TOptions...>;
using ProtInterface = cc_tools_qt::ToolsProtMsgInterface<demo::DemoMessage>;

using ProtOptions = demo::DefaultOptions;

DemoMessage();
virtual ~DemoMessage() noexcept;
Expand Down
22 changes: 11 additions & 11 deletions demo/protocol/include/demo/AllMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
namespace demo
{

template <typename TMsgBase>
template <typename TMsgBase, typename TOpt>
using AllMessages = std::tuple<
demo::message::IntValues<TMsgBase>,
demo::message::EnumValues<TMsgBase>,
demo::message::BitmaskValues<TMsgBase>,
demo::message::Bitfields<TMsgBase>,
demo::message::Strings<TMsgBase>,
demo::message::Lists<TMsgBase>,
demo::message::Optionals<TMsgBase>,
demo::message::FloatValues<TMsgBase>,
demo::message::Variants<TMsgBase>,
demo::message::Bundles<TMsgBase>
demo::message::IntValues<TMsgBase, TOpt>,
demo::message::EnumValues<TMsgBase, TOpt>,
demo::message::BitmaskValues<TMsgBase, TOpt>,
demo::message::Bitfields<TMsgBase, TOpt>,
demo::message::Strings<TMsgBase, TOpt>,
demo::message::Lists<TMsgBase, TOpt>,
demo::message::Optionals<TMsgBase, TOpt>,
demo::message::FloatValues<TMsgBase, TOpt>,
demo::message::Variants<TMsgBase, TOpt>,
demo::message::Bundles<TMsgBase, TOpt>
>;

} // namespace demo
Expand Down
2 changes: 1 addition & 1 deletion demo/protocol/include/demo/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ using StackBase =
/// type of the payload field for "caching" read/write operations.
template <
typename TMsgBase,
typename TMessages = demo::AllMessages<TMsgBase>,
typename TMessages = demo::AllMessages<TMsgBase, demo::DefaultOptions>,
typename TMsgAllocOptions = comms::option::EmptyOption,
typename TDataFieldStorageOptions = comms::option::EmptyOption >
class Frame : public StackBase<TMsgBase, TMessages, TMsgAllocOptions, TDataFieldStorageOptions>
Expand Down
10 changes: 5 additions & 5 deletions lib/include/cc_tools_qt/ToolsFrameBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
namespace cc_tools_qt
{

template <typename TMsgBase, template<typename...> class TProtFrame, typename TMsgFactory, typename TTransportMsg>
template <typename TMsgBase, class TProtFrame, typename TMsgFactory, typename TTransportMsg>
class ToolsFrameBase : public ToolsFrameCommon<TMsgBase>
{
using Base = ToolsFrameCommon<TMsgBase>;
public:
using ProtMsgBase = typename Base::ProtMsgBase;
using ProtInterface = typename Base::ProtInterface;
using DataSeq = typename Base::DataSeq;

using TransportMsg = TTransportMsg;
Expand All @@ -53,7 +53,7 @@ class ToolsFrameBase : public ToolsFrameCommon<TMsgBase>
/// @brief Type of "Extra Info ToolsMessage"
using ExtraInfoMsg = ToolsExtraInfoMessage<TMsgBase>;

using ProtFrame = TProtFrame<ProtMsgBase>;
using ProtFrame = TProtFrame;

ToolsFrameBase() = default;

Expand Down Expand Up @@ -81,7 +81,7 @@ class ToolsFrameBase : public ToolsFrameCommon<TMsgBase>


using ProtMsgPtr = typename ProtFrame::MsgPtr;
using ReadIter = typename ProtMsgBase::ReadIterator;
using ReadIter = typename ProtInterface::ReadIterator;
while (consumed < m_inData.size()) {
ProtMsgPtr msgPtr;

Expand Down Expand Up @@ -223,7 +223,7 @@ class ToolsFrameBase : public ToolsFrameCommon<TMsgBase>
return m_factory.createMessage(idAsString, idx);
}

virtual DataSeq writeProtMsgImpl(const ProtMsgBase& msg) override
virtual DataSeq writeProtMsgImpl(const ProtInterface& msg) override
{
DataSeq data;
data.reserve(m_frame.length(msg));
Expand Down
7 changes: 3 additions & 4 deletions lib/include/cc_tools_qt/ToolsFrameCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#pragma once

#include "cc_tools_qt/ToolsFrame.h"
#include "cc_tools_qt/ToolsProtMsgInterface.h"

namespace cc_tools_qt
{
Expand All @@ -28,18 +27,18 @@ template <typename TMsgBase>
class ToolsFrameCommon : public ToolsFrame
{
public:
using ProtMsgBase = ToolsProtMsgInterface<TMsgBase::template ProtMsgBase>;
using ProtInterface = typename TMsgBase::ProtInterface;
using DataSeq = typename TMsgBase::DataSeq;

DataSeq writeProtMsg(const ProtMsgBase& msg)
DataSeq writeProtMsg(const ProtInterface& msg)
{
return writeProtMsgImpl(msg);
}

protected:
ToolsFrameCommon() = default;

virtual DataSeq writeProtMsgImpl(const ProtMsgBase& msg) = 0;
virtual DataSeq writeProtMsgImpl(const ProtInterface& msg) = 0;
};

} // namespace cc_tools_qt
Expand Down
8 changes: 5 additions & 3 deletions lib/include/cc_tools_qt/ToolsMessageBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class ToolsMessageBase : public TBase
/// @brief Data sequence type
using DataSeq = typename TBase::DataSeq;

using ProtMsgBase = ToolsProtMsgInterface<TBase::template ProtMsgBase>;
using ProtInterface = typename TBase::ProtInterface;

using ProtOptions = typename TBase::ProtOptions;

/// @brief Protocol definition message type
using ProtMsg = TProtMsg<ProtMsgBase>;
using ProtMsg = TProtMsg<ProtInterface, ProtOptions>;

using FieldsList = typename Base::FieldsList;

Expand Down Expand Up @@ -207,7 +209,7 @@ class ToolsMessageBase : public TBase

virtual void assignProtMessageImpl(void* protMsg) override
{
auto* protMsgBase = reinterpret_cast<ProtMsgBase*>(protMsg);
auto* protMsgBase = reinterpret_cast<ProtInterface*>(protMsg);
auto* actProtMsg = static_cast<ProtMsg*>(protMsgBase);
m_msg = std::move(*actProtMsg);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/include/cc_tools_qt/ToolsMsgFactoryBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class TupleMsgFactoryHelper
template <typename TAllMessages>
class ToolsMsgFactoryBase : public ToolsMsgFactory
{
public:
using AllMessages = TAllMessages;

protected:
virtual MessagesListInternal createAllMessagesImpl() override
{
Expand Down
2 changes: 1 addition & 1 deletion plugin/raw_data_protocol/cc_plugin/RawDataProtocolFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace cc_plugin
class RawDataProtocolFrame : public
cc_tools_qt::ToolsFrameBase<
RawDataProtocolMessage,
raw_data_protocol::Frame,
raw_data_protocol::Frame<RawDataProtocolMessage::ProtInterface>,
RawDataProtocolMsgFactory,
RawDataProtocolTransportMessage
>
Expand Down
7 changes: 5 additions & 2 deletions plugin/raw_data_protocol/cc_plugin/RawDataProtocolMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#pragma once

#include "raw_data_protocol/Message.h"
#include "raw_data_protocol/DefaultOptions.h"

#include "cc_tools_qt/ToolsMessage.h"
#include "cc_tools_qt/ToolsProtMsgInterface.h"

namespace cc_tools_qt
{
Expand All @@ -37,8 +39,9 @@ namespace cc_plugin
class RawDataProtocolMessage : public cc_tools_qt::ToolsMessage
{
public:
template <typename... TOptions>
using ProtMsgBase = raw_data_protocol::Message<TOptions...>;
using ProtInterface = cc_tools_qt::ToolsProtMsgInterface<raw_data_protocol::Message>;

using ProtOptions = raw_data_protocol::DefaultOptions;

protected:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ using RawDataProtocolTransportMessageFields =
raw_data_protocol::DataField<>
>;

template <typename TProtMsgBase, typename... TOptions>
template <typename TProtMsgBase, typename TOpt>
class RawDataProtocolPortTransportMessage : public
cc_tools_qt::ToolsTransportProtMessageBase<
TProtMsgBase,
RawDataProtocolTransportMessageFields<TProtMsgBase>,
RawDataProtocolPortTransportMessage<TProtMsgBase, TOptions...>,
TOptions...
RawDataProtocolPortTransportMessage<TProtMsgBase, TOpt>
>
{
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ namespace plugin
namespace raw_data_protocol
{

template <typename TMsgBase>
template <typename TMsgBase, typename TOpt>
using AllMessages =
std::tuple<
DataMessage<TMsgBase>
DataMessage<TMsgBase, TOpt>
>;

} // namespace raw_data_protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ struct DataMessageFields
>;
};

template <typename TMsgBase, typename... TOptions>
template <typename TMsgBase, typename TOpt>
class DataMessage : public
comms::MessageBase<
TMsgBase,
comms::option::StaticNumIdImpl<0>,
comms::option::FieldsImpl<typename DataMessageFields<typename TMsgBase::Field>::All>,
comms::option::MsgType<DataMessage<TMsgBase, TOptions...>>,
comms::option::MsgType<DataMessage<TMsgBase, TOpt>>,
comms::option::HasName
>
{
Expand All @@ -66,7 +66,7 @@ class DataMessage : public
TMsgBase,
comms::option::StaticNumIdImpl<0>,
comms::option::FieldsImpl<typename DataMessageFields<typename TMsgBase::Field>::All>,
comms::option::MsgType<DataMessage<TMsgBase, TOptions...>>,
comms::option::MsgType<DataMessage<TMsgBase, TOpt>>,
comms::option::HasName
>;
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright 2016 - 2024 (C). Alex Robenko. All rights reserved.
//

// This file is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#pragma once

namespace cc_tools_qt
{

namespace plugin
{

namespace raw_data_protocol
{

struct DefaultOptions {};

} // namespace raw_data_protocol

} // namespace plugin

} // namespace cc_tools_qt


11 changes: 4 additions & 7 deletions plugin/raw_data_protocol/include/raw_data_protocol/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "raw_data_protocol/AllMessages.h"
#include "raw_data_protocol/Message.h"
#include "raw_data_protocol/DefaultOptions.h"

#include "comms/field/IntValue.h"
#include "comms/protocol/MsgDataLayer.h"
Expand Down Expand Up @@ -65,18 +66,14 @@ class DataField : public comms::protocol::MsgDataLayer<TOptions...>::Field

template <
typename TMsgBase,
typename TAllMessages = raw_data_protocol::AllMessages<TMsgBase>,
typename TMsgAllocOptions = comms::option::EmptyOption,
typename TDataFieldStorageOptions = comms::option::EmptyOption>
typename TAllMessages = raw_data_protocol::AllMessages<TMsgBase, raw_data_protocol::DefaultOptions>
>
using Frame =
comms::protocol::MsgIdLayer<
IdField<typename TMsgBase::Field>,
TMsgBase,
TAllMessages,
comms::protocol::MsgDataLayer<
TDataFieldStorageOptions
>,
TMsgAllocOptions
comms::protocol::MsgDataLayer<>
>;

} // namespace raw_data_protocol
Expand Down

0 comments on commit 5a7905c

Please sign in to comment.