Skip to content

[Network.framework] Move UDPEndPointImplNetworkFramework files under src/platform/Darwin/inet #39148

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ if (chip_system_config_use_lwip) {
import("//build_overrides/lwip.gni")
}

if (chip_device_platform == "darwin") {
import("${chip_root}/src/platform/Darwin/inet/darwin_sources.gni")
}

declare_args() {
# Extra header to include in SystemConfig.h for project.
chip_inet_project_config_include = ""
Expand Down Expand Up @@ -94,7 +98,6 @@ static_library("inet") {
# - src/inet/EndPointStateSockets.h
sources = [
"EndPointBasis.h",
"EndPointState${chip_system_config_inet}.h",
"IANAConstants.h",
"IPAddress-StringFuncts.cpp",
"IPAddress.cpp",
Expand All @@ -114,6 +117,10 @@ static_library("inet") {
"arpa-inet-compatibility.h",
]

if (!chip_system_config_use_network_framework) {
sources += [ "EndPointState${chip_system_config_inet}.h" ]
}

public_deps = [
":impl_header",
":inet_config_header",
Expand Down Expand Up @@ -168,9 +175,7 @@ static_library("inet") {
"UDPEndPointImpl.h",
]

if (chip_system_config_use_network_framework) {
sources += [ "UDPEndPointImpl${chip_system_config_inet}.mm" ]
} else {
if (!chip_system_config_use_network_framework) {
sources += [ "UDPEndPointImpl${chip_system_config_inet}.cpp" ]
}
}
Expand All @@ -197,6 +202,7 @@ static_library("inet") {
if (current_os == "nuttx") {
cflags -= [ "-Wconversion" ]
} else if (chip_system_config_use_network_framework) {
sources += darwin_sources
cflags += [ "-fobjc-arc" ]
}
}
61 changes: 2 additions & 59 deletions src/inet/UDPEndPointImplNetworkFramework.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2018 Google LLC
* Copyright (c) 2013-2017 Nest Labs, Inc.
* Copyright (c) 2025 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,59 +19,4 @@
* This file declares an implementation of Inet::UDPEndPoint using Network Framework.
*/

#pragma once

#include <inet/EndPointStateNetworkFramework.h>

namespace chip {
namespace Inet {

class UDPEndPointImplNetworkFramework : public UDPEndPoint, public EndPointStateNetworkFramework
{
public:
UDPEndPointImplNetworkFramework(EndPointManager<UDPEndPoint> & endPointManager) : UDPEndPoint(endPointManager) {}

// UDPEndPoint overrides.
CHIP_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) override;
InterfaceId GetBoundInterface() const override;
uint16_t GetBoundPort() const override;
void Free() override;

private:
// UDPEndPoint overrides.
#if INET_CONFIG_ENABLE_IPV4
CHIP_ERROR IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override;
#endif // INET_CONFIG_ENABLE_IPV4
CHIP_ERROR IPv6JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override;
CHIP_ERROR BindImpl(IPAddressType addressType, const IPAddress & address, uint16_t port, InterfaceId interfaceId) override;
CHIP_ERROR BindInterfaceImpl(IPAddressType addressType, InterfaceId interfaceId) override;
CHIP_ERROR ListenImpl() override;
CHIP_ERROR SendMsgImpl(const IPPacketInfo * pktInfo, chip::System::PacketBufferHandle && msg) override;
void CloseImpl() override;

nw_listener_t mListener;
dispatch_semaphore_t mListenerSemaphore;
dispatch_queue_t mListenerQueue;
nw_connection_t mConnection;
dispatch_semaphore_t mConnectionSemaphore;
dispatch_queue_t mConnectionQueue;
dispatch_semaphore_t mSendSemaphore;
dispatch_queue_t mSystemQueue;

CHIP_ERROR ConfigureProtocol(IPAddressType aAddressType, const nw_parameters_t & aParameters);
CHIP_ERROR StartListener();
CHIP_ERROR GetConnection(const IPPacketInfo * aPktInfo);
nw_endpoint_t GetEndPoint(const IPAddressType aAddressType, const IPAddress & aAddress, uint16_t aPort,
InterfaceId interfaceIndex = InterfaceId::Null());
CHIP_ERROR StartConnection(nw_connection_t aConnection);
void GetPacketInfo(const nw_connection_t & aConnection, IPPacketInfo & aPacketInfo);
void HandleDataReceived(const nw_connection_t & aConnection);
CHIP_ERROR ReleaseListener();
CHIP_ERROR ReleaseConnection();
void ReleaseAll();
};

using UDPEndPointImpl = UDPEndPointImplNetworkFramework;

} // namespace Inet
} // namespace chip
#include <platform/Darwin/inet/UDPEndPointImplNetworkFramework.h>
79 changes: 79 additions & 0 deletions src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2018 Google LLC
* Copyright (c) 2013-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.
*/

/**
* This file declares an implementation of Inet::UDPEndPoint using Network Framework.
*/

#pragma once

#include <inet/EndPointStateNetworkFramework.h>

namespace chip {
namespace Inet {

class UDPEndPointImplNetworkFramework : public UDPEndPoint, public EndPointStateNetworkFramework
{
public:
UDPEndPointImplNetworkFramework(EndPointManager<UDPEndPoint> & endPointManager) : UDPEndPoint(endPointManager) {}

// UDPEndPoint overrides.
CHIP_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) override;
InterfaceId GetBoundInterface() const override;
uint16_t GetBoundPort() const override;
void Free() override;

private:
// UDPEndPoint overrides.
#if INET_CONFIG_ENABLE_IPV4
CHIP_ERROR IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override;
#endif // INET_CONFIG_ENABLE_IPV4
CHIP_ERROR IPv6JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) override;
CHIP_ERROR BindImpl(IPAddressType addressType, const IPAddress & address, uint16_t port, InterfaceId interfaceId) override;
CHIP_ERROR BindInterfaceImpl(IPAddressType addressType, InterfaceId interfaceId) override;
CHIP_ERROR ListenImpl() override;
CHIP_ERROR SendMsgImpl(const IPPacketInfo * pktInfo, chip::System::PacketBufferHandle && msg) override;
void CloseImpl() override;

nw_listener_t mListener;
dispatch_semaphore_t mListenerSemaphore;
dispatch_queue_t mListenerQueue;
nw_connection_t mConnection;
dispatch_semaphore_t mConnectionSemaphore;
dispatch_queue_t mConnectionQueue;
dispatch_semaphore_t mSendSemaphore;
dispatch_queue_t mSystemQueue;

CHIP_ERROR ConfigureProtocol(IPAddressType aAddressType, const nw_parameters_t & aParameters);
CHIP_ERROR StartListener();
CHIP_ERROR GetConnection(const IPPacketInfo * aPktInfo);
nw_endpoint_t GetEndPoint(const IPAddressType aAddressType, const IPAddress & aAddress, uint16_t aPort,
InterfaceId interfaceIndex = InterfaceId::Null());
CHIP_ERROR StartConnection(nw_connection_t aConnection);
void GetPacketInfo(const nw_connection_t & aConnection, IPPacketInfo & aPacketInfo);
void HandleDataReceived(const nw_connection_t & aConnection);
CHIP_ERROR ReleaseListener();
CHIP_ERROR ReleaseConnection();
void ReleaseAll();
};

using UDPEndPointImpl = UDPEndPointImplNetworkFramework;

} // namespace Inet
} // namespace chip
30 changes: 30 additions & 0 deletions src/platform/Darwin/inet/darwin_sources.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2025 Project CHIP Authors
#
# 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.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${chip_root}/src/inet/inet.gni")

# These files are physically located under src/platform/Darwin/inet/,
# but are considered part of the inet logical layer.

darwin_sources = []

if (chip_inet_config_enable_udp_endpoint) {
darwin_sources += [
"${chip_root}/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.h",
"${chip_root}/src/platform/Darwin/inet/UDPEndPointImplNetworkFramework.mm",
]
}
Loading