diff --git a/include/examples/PacketExample.h b/include/examples/PacketExample.h new file mode 100644 index 0000000..da9fbec --- /dev/null +++ b/include/examples/PacketExample.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +enum PacketId { + KeepAlive = 0, +}; + +using KeepAliveFields = std::tuple>; + +class KeepAlivePacket : public sp::MessageBase, // provide idImpl() if needed + sp::option::DispatchImpl, // provide dispatchImpl() if needed + sp::option::FieldsImpl // provide access to fields + > {}; + +using AllPackets = std::tuple; + +#include \ No newline at end of file diff --git a/include/sp/Types.h b/include/sp/Types.h deleted file mode 100644 index ddb6c3f..0000000 --- a/include/sp/Types.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -namespace sp { - -using PeerID = std::uint16_t; - -} // namespace sp diff --git a/include/sp/default/DefaultPacket.h b/include/sp/default/DefaultPacket.h new file mode 100644 index 0000000..bf2beb0 --- /dev/null +++ b/include/sp/default/DefaultPacket.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +namespace sp { +class PacketHandler; + +using PacketMessage = Message< + option::MsgIdType, // add id() operation + option::ReadOperations, // add read() operation + option::WriteOperations, // add write() operation + option::Handler // add dispatch() operation + >; + +} // namespace sp diff --git a/include/sp/default/DefaultPacketHandler.h b/include/sp/default/DefaultPacketHandler.h new file mode 100644 index 0000000..6be435d --- /dev/null +++ b/include/sp/default/DefaultPacketHandler.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +// the tuple AllPackets must be defined ! + +namespace sp { +class PacketHandler : public sp::GenericHandler {}; +} // namespace sp diff --git a/include/sp/Field.h b/include/sp/protocol/Field.h similarity index 100% rename from include/sp/Field.h rename to include/sp/protocol/Field.h diff --git a/include/sp/GenericHandler.h b/include/sp/protocol/GenericHandler.h similarity index 100% rename from include/sp/GenericHandler.h rename to include/sp/protocol/GenericHandler.h diff --git a/include/sp/Message.h b/include/sp/protocol/Message.h similarity index 84% rename from include/sp/Message.h rename to include/sp/protocol/Message.h index 2dddd70..9b5bdf4 100644 --- a/include/sp/Message.h +++ b/include/sp/protocol/Message.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace sp { diff --git a/include/sp/MessageBase.h b/include/sp/protocol/MessageBase.h similarity index 97% rename from include/sp/MessageBase.h rename to include/sp/protocol/MessageBase.h index e39c7e8..b29bd8a 100644 --- a/include/sp/MessageBase.h +++ b/include/sp/protocol/MessageBase.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include namespace sp { namespace option { @@ -261,7 +261,7 @@ struct MessageImplBuilder { using Base5 = typename MessageImplProcessWriteFields::Type; // Provide ValidImpl() if possible - static const bool HasValidImpl = InterfaceOptions::HasWriteOperations && ImplOptions::HasFieldsImpl; + static const bool HasValidImpl = InterfaceOptions::HasValid && ImplOptions::HasFieldsImpl; using Base6 = typename MessageImplProcessValidFields::Type; // The last BaseN must be taken as final type. diff --git a/include/sp/MessageInterfaceBuilder.h b/include/sp/protocol/MessageInterfaceBuilder.h similarity index 96% rename from include/sp/MessageInterfaceBuilder.h rename to include/sp/protocol/MessageInterfaceBuilder.h index 2dd5dfa..a52fedc 100644 --- a/include/sp/MessageInterfaceBuilder.h +++ b/include/sp/protocol/MessageInterfaceBuilder.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace sp { namespace option { diff --git a/include/sp/MessageInterfaces.h b/include/sp/protocol/MessageInterfaces.h similarity index 99% rename from include/sp/MessageInterfaces.h rename to include/sp/protocol/MessageInterfaces.h index 6ab39b1..bfaa896 100644 --- a/include/sp/MessageInterfaces.h +++ b/include/sp/protocol/MessageInterfaces.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace sp { namespace option { diff --git a/include/sp/Options.h b/include/sp/protocol/Options.h similarity index 100% rename from include/sp/Options.h rename to include/sp/protocol/Options.h diff --git a/include/sp/Templates.h b/include/sp/protocol/Templates.h similarity index 100% rename from include/sp/Templates.h rename to include/sp/protocol/Templates.h diff --git a/src/main.cpp b/src/main.cpp index 7686ec7..7f2a44a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,70 +1,17 @@ #include -#include -#include -#include - #include +#include -enum MyMsgId { - MyMsgId_Msg1, - MyMsgId_Msg2, -}; - -class MyHandler; // forward declaration of the handler class. - -using MyMessage = sp::Message, // add id() operation - sp::option::ReadOperations, // add read() operation - sp::option::WriteOperations, // add write() operation - sp::option::Handler, // add dispatch() operation - sp::option::ValidCheckInterface, // add valid() operation - sp::option::LittleEndian // use little endian for serialisation - >; - - - -using ActualMessage1Fields = std::tuple, sp::Field>; - - - -template -class ActualMessage1 : public sp::MessageBase, // provide idImpl() if needed - sp::option::DispatchImpl>, // provide dispatchImpl() if needed - sp::option::FieldsImpl // provide access to fields and - // readImpl(), writeImpl(), - // lengthImpl(), validImpl() - // functions if needed - > {}; - -using MyActualMessage1 = ActualMessage1; - -using AllMessages = std::tuple; - -class MyHandler : public sp::GenericHandler { - public: - void Handle(MyActualMessage1& msg) { - std::cout << "Got message 1 !\n"; +class KeepAliveHandler : public sp::PacketHandler { + void Handle(KeepAlivePacket& packet) { + std::cout << "KeepAlive handled !\n"; } }; - int main() { - MyMessage::MsgIdType test; - auto yes = std::make_unique>(); - auto& fields = yes->GetFields(); - - std::get<0>(fields) = 69; - std::get<1>(fields) = 42; - - MyHandler handlerTest; - yes->Dispatch(handlerTest); - sp::DataBuffer buffer; - yes->Write(buffer); - - auto yesyes = std::make_unique>(); - yesyes->Read(buffer); - std::cout << "Field 1 : " << yesyes->GetField<0>() << std::endl; - std::cout << "Field 2 : " << (unsigned) yesyes->GetField<1>() << std::endl; + std::unique_ptr msg = std::make_unique(); + KeepAliveHandler handler; + msg->Dispatch(handler); return 0; } \ No newline at end of file