Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,23 @@
#pragma once
#include <AzCore/Console/ILogger.h>
#include <AzNetworking/Serialization/ISerializer.h>
#include <AzNetworking/PacketLayer/IPacketHeader.h>
#include <AzNetworking/ConnectionLayer/IConnection.h>
#include "{{ (outputFile|basename).replace(".AutoPacketDispatcher.h", ".AutoPackets.h") }}"
{% for xml in dataFiles %}
namespace {{ xml.attrib['Name'] }}
{
//! Request dispatcher for incoming packets.
//! @param connection pointer to the connection that sent this request
//! @param packetHeader the header of the received packet
//! @param serializer serializer containing the raw packet payload
//! @param handler the handler used to handle the received packet
//! @return boolean true on successful dispatch, false if the request was not handled
template <typename HANDLER>
bool DispatchPacket(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, AzNetworking::ISerializer& serializer, HANDLER& handler);
}
{% endfor %}
#include "{{ (outputFile|basename).replace(".AutoPacketDispatcher.h", ".AutoPacketDispatcher.inl") }}"
@@ -0,0 +1,25 @@
{% for xml in dataFiles %}
namespace {{ xml.attrib['Name'] }}
{
template <typename HANDLER>
inline bool DispatchPacket(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, AzNetworking::ISerializer& serializer, HANDLER& handler)
{
switch (aznumeric_cast<int32_t>(packetHeader.GetPacketType()))
{
{% for Packet in xml.iter('Packet') %}
case aznumeric_cast<int32_t>({{ Packet.attrib['Name'] }}::Type):
{
AZLOG(Debug_DispatchPackets, "Received packet %s", "{{ Packet.attrib['Name'] }}");
{{ Packet.attrib['Name'] }} packet;
if (!serializer.Serialize(packet, "Packet"))
{
return false;
}
return handler.HandleRequest(connection, packetHeader, packet);
}
{% endfor %}
}
return false;
}
}
{% endfor %}
@@ -0,0 +1,111 @@
{#
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#}
{% macro ElementType(element) -%}
{% if ('Container' not in element.attrib) or (element.attrib['Container'] == 'None') %}
{{ element.attrib['Type'] }}{% elif element.attrib['Container'] == 'Array' %}
AZStd::array<{{ element.attrib['Type'] }}, {{ element.attrib['Count'] }}>{% elif element.attrib['Container'] == 'Vector' %}
AZStd::fixed_vector<{{ element.attrib['Type'] }}, {{ element.attrib['Count'] }}>{% endif %}
{%- endmacro %}
{% macro CamelCase(text) %}{{ text[0] | upper}}{{ text[1:] }}{% endmacro %}
{% macro DeclarePacket(name, packetNode, type) %}
//! @class {{ name }}
//! @brief {{ packetNode.attrib['Desc'] }}.
class {{ name }} final
: public AzNetworking::IPacket
{
public:
static constexpr AzNetworking::PacketType Type = aznumeric_cast<AzNetworking::PacketType>({{ type }});
{{ name }}() = default;
{% if (packetNode.getchildren()) | len > 0 %}
explicit {{ name }}
(
{% for Member in packetNode %}
{% if loop.first %} {% else %}, {% endif %}{{ ElementType(Member) }} {{ Member.attrib['Name'] }}
{% endfor %}
);
{% endif %}
~{{ name }}() override = default;
//! Equality operator, returns true if the current instance is equal to rhs.
//! @param rhs the {{ name }} instance to test for equality against
//! @return boolean true if equal, false if not
bool operator ==(const {{ name }}& rhs) const;
//! Inequality operator, returns true if the current instance is not equal to rhs.
//! @param rhs the {{ name }} instance to test for inequality against
//! @return boolean false if equal, true if not equal
bool operator !=(const {{ name }}& rhs) const;
{% for Member in packetNode.iter('Member') %}
//! Sets the value of {{ Member.attrib['Name'] }}.
//! @param value the value to set {{ Member.attrib['Name'] }} to
void Set{{ CamelCase(Member.attrib['Name']) }}(const {{ ElementType(Member) }}& value);
//! Gets the value of {{ Member.attrib['Name'] }}.
//! @return the value of {{ Member.attrib['Name'] }}
const {{ ElementType(Member) }}& Get{{ CamelCase(Member.attrib['Name']) }}() const;
//! Retrieves a non-const reference to the value of {{ Member.attrib['Name'] }}
//! @return a non-const reference to the value of {{ Member.attrib['Name'] }}
{{ ElementType(Member) }}& Modify{{ CamelCase(Member.attrib['Name']) }}();
{% endfor %}
//! IPacket interface
//! @{
AzNetworking::PacketType GetPacketType() const override;
AZStd::unique_ptr<AzNetworking::IPacket> Clone() const override;
bool Serialize(AzNetworking::ISerializer& serializer) override;
//! @}
{% if (packetNode.getchildren()) | len > 0 %}
private:
{% for Member in packetNode.iter('Member') %}
{{ ElementType(Member) }} m_{{ Member.attrib['Name'] }}{% if Member.attrib['Init'] %} = {{ Member.attrib['Init'] }}{% endif %};
{% endfor %}
{% endif %}
};
{% endmacro %}
#pragma once
#include <AzCore/RTTI/TypeInfo.h>
#include <AzNetworking/PacketLayer/IPacket.h>
#include <AzNetworking/Serialization/ISerializer.h>
#include <AzNetworking/ConnectionLayer/IConnection.h>
#include <AzNetworking/DataStructures/ByteBuffer.h>
{% for xml in dataFiles %}
{% for Include in xml.iter('Include') %}
#include <{{ Include.attrib['File'] }}>
{% endfor %}
{% endfor %}
{% for xml in dataFiles %}
namespace {{ xml.attrib['Name'] }}
{
enum class PacketType
{
START = aznumeric_cast<int32_t>({{ xml.attrib['PacketStart'] }})
{% for Packet in xml.iter('Packet') %}
, {{ Packet.attrib['Name'] }}
{% endfor %}
, MAX
};
{% for Packet in xml.iter('Packet') %}
{{ DeclarePacket(Packet.attrib['Name'], Packet, "PacketType::" + Packet.attrib['Name']) -}}
{% endfor %}
}
{% endfor %}
{% set inlineFile = "{0}.inl".format(((outputFile|basename)|splitext)[0]) %}
#include "{{ inlineFile }}"
@@ -0,0 +1,51 @@
{#
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#}
{% macro ElementType(element) -%}
{% if ('Container' not in element.attrib) or (element.attrib['Container'] == 'None') %}
{{ element.attrib['Type'] }}{% elif element.attrib['Container'] == 'Array' %}
AZStd::array<{{ element.attrib['Type'] }}, {{ element.attrib['Count'] }}>{% elif element.attrib['Container'] == 'Vector' %}
AZStd::fixed_vector<{{ element.attrib['Type'] }}, {{ element.attrib['Count'] }}>{% endif %}
{%- endmacro %}
{% macro CamelCase(text) %}{{ text[0] | upper}}{{ text[1:] }}{% endmacro %}
{% macro DeclareInlineMethods(packetNode, name) %}
inline bool {{ name }}::operator !=(const {{ name }} &rhs) const
{
return !(*this == rhs);
}
{% for Member in packetNode.iter('Member') %}
inline void {{ name }}::Set{{ CamelCase(Member.attrib['Name']) }}(const {{ ElementType(Member) }}& value)
{
m_{{ Member.attrib['Name'] }} = value;
}
inline const {{ ElementType(Member) }}& {{ name }}::Get{{ CamelCase(Member.attrib['Name']) }}() const
{
return m_{{ Member.attrib['Name'] }};
}
inline {{ ElementType(Member) }}& {{ name }}::Modify{{ CamelCase(Member.attrib['Name']) }}()
{
return m_{{ Member.attrib['Name'] }};
}
{% endfor %}
{% endmacro %}
#pragma once
{% for xml in dataFiles %}
namespace {{ xml.attrib['Name'] }}
{
{% for Packet in xml.iter('Packet') %}
{{ DeclareInlineMethods(Packet, Packet.attrib['Name']) -}}
{% endfor %}
}
{% endfor %}
@@ -0,0 +1,78 @@
{#
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#}
{% macro ElementType(element) -%}
{% if ('Container' not in element.attrib) or (element.attrib['Container'] == 'None') %}
{{ element.attrib['Type'] }}{% elif element.attrib['Container'] == 'Array' %}
AZStd::array<{{ element.attrib['Type'] }}, {{ element.attrib['Count'] }}>{% elif element.attrib['Container'] == 'Vector' %}
AZStd::fixed_vector<{{ element.attrib['Type'] }}, {{ element.attrib['Count'] }}>{% endif %}
{%- endmacro %}
{% macro DefinePacketMethods(packetNode, name) %}
{% if (packetNode.getchildren()) | len > 0 %}
{{ name }}::{{ name }}
(
{% for Member in packetNode.iter('Member') %}
{{ ElementType(Member) }} {{ Member.attrib['Name'] }}{% if not loop.last %},{% endif %}
{% endfor %}
)
{% for Member in packetNode.iter('Member') %}
{% if loop.first %}: {% else %}, {% endif %}m_{{ Member.attrib['Name'] }}({{ Member.attrib['Name'] }})
{% endfor %}
{
;
}
{% endif %}
AzNetworking::PacketType {{ name }}::GetPacketType() const
{
return Type;
}
bool {{ name }}::operator ==([[maybe_unused]] const {{ name }}& rhs) const
{
{% for Member in packetNode.iter('Member') %}
if (m_{{ Member.attrib['Name'] }} != rhs.m_{{ Member.attrib['Name'] }})
{
return false;
}
{% endfor %}
return true;
}
AZStd::unique_ptr<AzNetworking::IPacket> {{ name }}::Clone() const
{
AZStd::unique_ptr<{{ name }}> result = AZStd::make_unique<{{ name }}>();
{% for Member in packetNode.iter('Member') %}
result->m_{{ Member.attrib['Name'] }} = m_{{ Member.attrib['Name'] }};
{% endfor %}
return result;
}
bool {{ name }}::Serialize(AzNetworking::ISerializer& serializer)
{
{% for Member in packetNode.iter('Member') %}
serializer.Serialize(m_{{ Member.attrib['Name'] }}, "{{ Member.attrib['Name'] }}");
{% endfor %}
return serializer.IsValid();
}
{% endmacro %}
{% set includeFile = "{0}.h".format(((outputFile|basename)|splitext)[0]) %}
#include "{{ includeFile }}"
{% for xml in dataFiles %}
namespace {{ xml.attrib['Name'] }}
{
{% for Packet in xml.iter('Packet') %}
{{ DefinePacketMethods(Packet, Packet.attrib['Name']) -}}
{% endfor %}
}
{% endfor %}
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<PacketGroup Name="CorePackets" PacketStart="0">
<Packet Name="InitiateConnectionPacket" Desc="This packet is used to initiate a new connection" />
<Packet Name="TerminateConnectionPacket" Desc="This packet is used to gracefully terminate an existing connection">
<Member Type="AzNetworking::DisconnectReason" Name="disconnectReason" Init="AzNetworking::DisconnectReason::None" />
</Packet>
<Packet Name="HeartbeatPacket" Desc="This packet is used to keep an established connection alive" />
<Packet Name="FragmentedPacket" Desc="This packet is used to segment a packet that exceeds a connections MTU">
<Member Type="AzNetworking::SequenceId" Name="unfragmentedSequence" Init="AzNetworking::InvalidSequenceId" />
<Member Type="AzNetworking::SequenceId" Name="fragmentSequence" Init="AzNetworking::InvalidSequenceId" />
<Member Type="uint8_t" Name="chunkIndex" Init="0" />
<Member Type="uint8_t" Name="chunkCount" Init="0" />
<Member Type="AzNetworking::ChunkBuffer" Name="chunkBuffer" />
</Packet>
</PacketGroup>