Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Inet::EndPoint into per-implementation files #11539

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ buildconfig_header("inet_buildconfig") {
defines +=
[ "INET_PLATFORM_CONFIG_INCLUDE=${chip_inet_platform_config_include}" ]
}

defines += [ "CHIP_INET_END_POINT_IMPL_CONFIG_FILE=<inet/EndPointBasisImpl${chip_system_config_inet}.h>" ]
}

source_set("inet_config_header") {
Expand All @@ -66,8 +68,8 @@ static_library("inet") {
output_name = "libInetLayer"

sources = [
"EndPointBasis.cpp",
"EndPointBasis.h",
"EndPointBasisImpl${chip_system_config_inet}.h",
"IANAConstants.h",
"IPAddress-StringFuncts.cpp",
"IPAddress.cpp",
Expand Down
66 changes: 0 additions & 66 deletions src/inet/EndPointBasis.cpp

This file was deleted.

64 changes: 15 additions & 49 deletions src/inet/EndPointBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,14 @@
/**
* @file
* This file contains the basis class for all the various transport
* endpoint classes in the Inet layer, i.e. TCP, UDP, Raw and Tun.
* endpoint classes in the Inet layer, i.e. TCP and UDP.
*/

#pragma once

#include <inet/InetConfig.h>

#include <inet/IPAddress.h>
#include <lib/support/DLLUtil.h>

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
#include <system/SocketEvents.h>
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
#include <Network/Network.h>
#endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

#if CHIP_SYSTEM_CONFIG_USE_LWIP
struct udp_pcb;
struct tcp_pcb;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

namespace chip {
namespace Inet {

Expand All @@ -50,7 +35,7 @@ class InetLayer;
/**
* Basis of internet transport endpoint classes.
*/
class DLL_EXPORT EndPointBasis
class DLL_EXPORT EndPointBase
{
public:
/**
Expand All @@ -73,42 +58,23 @@ class DLL_EXPORT EndPointBasis
InetLayer * mInetLayer; /**< Pointer to the InetLayer object that owns this object. */

protected:
void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr);
virtual ~EndPointBase() = default;

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
nw_parameters_t mParameters;
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
#endif

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
static constexpr int kInvalidSocketFd = -1;
int mSocket; /**< Encapsulated socket descriptor. */
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
System::SocketWatchToken mWatch; /**< Socket event watcher */
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

#if CHIP_SYSTEM_CONFIG_USE_LWIP
/** Encapsulated LwIP protocol control block */
union
void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr)
{
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
udp_pcb * mUDP; /**< User datagram protocol (UDP) control */
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
tcp_pcb * mTCP; /**< Transmission control protocol (TCP) control */
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
};
AppState = aAppState;
mInetLayer = &aInetLayer;
InitEndPointBasisImpl();
}

enum class LwIPEndPointType : uint8_t
{
Unknown = 0,
Raw = 1,
UDP = 2,
UCP = 3,
TCP = 4
} mLwIPEndPointType;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
virtual void InitEndPointBasisImpl() = 0;
};

} // namespace Inet
} // namespace chip

#ifdef CHIP_INET_END_POINT_IMPL_CONFIG_FILE
#include CHIP_INET_END_POINT_IMPL_CONFIG_FILE
#else // CHIP_INET_END_POINT_IMPL_CONFIG_FILE
#include <inet/EndPointBasisImplSockets.h>
#endif // CHIP_INET_END_POINT_IMPL_CONFIG_FILE
64 changes: 64 additions & 0 deletions src/inet/EndPointBasisImplLwIP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2015-2017 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* LwIP implementation of EndPointBase.
*/

#pragma once

#include <inet/EndPointBasis.h>

#include <inet/IPAddress.h>

struct udp_pcb;
struct tcp_pcb;

namespace chip {
namespace Inet {

class DLL_EXPORT EndPointImplLwIP : public EndPointBase
{
protected:
// EndPointBase overrides
void InitEndPointBasisImpl() override { mLwIPEndPointType = LwIPEndPointType::Unknown; }

/** Encapsulated LwIP protocol control block */
union
{
const void * mVoid; /**< An untyped protocol control buffer reference */
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
udp_pcb * mUDP; /**< User datagram protocol (UDP) control */
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
tcp_pcb * mTCP; /**< Transmission control protocol (TCP) control */
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
};

enum class LwIPEndPointType : uint8_t
{
Unknown = 0,
UDP = 1,
TCP = 2
} mLwIPEndPointType;
};

using EndPointBasis = EndPointImplLwIP;

} // namespace Inet
} // namespace chip
46 changes: 46 additions & 0 deletions src/inet/EndPointBasisImplNetworkFramework.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2015-2017 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Network Framework implementation of EndPointBase.
*/

#pragma once

#include <inet/EndPointBasis.h>

#include <inet/IPAddress.h>

#include <Network/Network.h>

namespace chip {
namespace Inet {

class DLL_EXPORT EndPointImplNetworkFramework : public EndPointBase
{
protected:
void InitEndPointBasisImpl() override {}

nw_parameters_t mParameters;
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
};

using EndPointBasis = EndPointImplNetworkFramework;

} // namespace Inet
} // namespace chip
47 changes: 47 additions & 0 deletions src/inet/EndPointBasisImplSockets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2015-2017 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Sockets implementation of EndPointBase.
*/

#pragma once

#include <inet/EndPointBasis.h>

#include <inet/IPAddress.h>
#include <system/SocketEvents.h>

namespace chip {
namespace Inet {

class DLL_EXPORT EndPointImplSockets : public EndPointBase
{
protected:
void InitEndPointBasisImpl() override { mSocket = kInvalidSocketFd; }

static constexpr int kInvalidSocketFd = -1;
int mSocket; /**< Encapsulated socket descriptor. */
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
System::SocketWatchToken mWatch; /**< Socket event watcher */
};

using EndPointBasis = EndPointImplSockets;

} // namespace Inet
} // namespace chip
7 changes: 7 additions & 0 deletions src/inet/inet.gni
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ declare_args() {

# Enable TCP endpoint.
chip_inet_config_enable_tcp_endpoint = true

# Inet implementation type.
if (chip_system_config_use_lwip) {
chip_system_config_inet = "LwIP"
} else {
chip_system_config_inet = "Sockets"
}
}