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

Move UDPEndPointManager out of Globals.cpp #19784

Merged
merged 1 commit into from
Jun 21, 2022
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
12 changes: 9 additions & 3 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState()
if (mSystemState != nullptr)
{
params.systemLayer = mSystemState->SystemLayer();
params.tcpEndPointManager = mSystemState->TCPEndPointManager();
params.udpEndPointManager = mSystemState->UDPEndPointManager();
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
params.tcpEndPointManager = mSystemState->TCPEndPointManager();
#endif
#if CONFIG_NETWORK_LAYER_BLE
params.bleLayer = mSystemState->BleLayer();
#endif
Expand Down Expand Up @@ -109,8 +111,10 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
ReturnErrorOnFailure(DeviceLayer::PlatformMgr().InitChipStack());

stateParams.systemLayer = &DeviceLayer::SystemLayer();
stateParams.tcpEndPointManager = DeviceLayer::TCPEndPointManager();
stateParams.udpEndPointManager = DeviceLayer::UDPEndPointManager();
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
stateParams.tcpEndPointManager = DeviceLayer::TCPEndPointManager();
#endif
#else
stateParams.systemLayer = params.systemLayer;
stateParams.tcpEndPointManager = params.tcpEndPointManager;
Expand Down Expand Up @@ -408,8 +412,10 @@ CHIP_ERROR DeviceControllerSystemState::Shutdown()
}

mSystemLayer = nullptr;
mTCPEndPointManager = nullptr;
mUDPEndPointManager = nullptr;
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
mTCPEndPointManager = nullptr;
#endif
#if CONFIG_NETWORK_LAYER_BLE
mBleLayer = nullptr;
#endif // CONFIG_NETWORK_LAYER_BLE
Expand Down
14 changes: 12 additions & 2 deletions src/include/platform/CHIPDeviceLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,24 @@ namespace DeviceLayer {
void SetSystemLayerForTesting(System::LayerImpl * layer);

// These functions are defined in src/platform/Globals.cpp
chip::Inet::EndPointManager<Inet::UDPEndPoint> * UDPEndPointManager();
chip::Inet::EndPointManager<Inet::TCPEndPoint> * TCPEndPointManager();
chip::System::Layer & SystemLayer();

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
chip::System::LayerSockets & SystemLayerSockets();
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

inline chip::Inet::EndPointManager<Inet::UDPEndPoint> * UDPEndPointManager()
{
return &ConnectivityMgr().UDPEndPointManager();
}

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
inline chip::Inet::EndPointManager<Inet::TCPEndPoint> * TCPEndPointManager()
{
return &ConnectivityMgr().TCPEndPointManager();
}
#endif

} // namespace DeviceLayer
} // namespace chip

Expand Down
23 changes: 23 additions & 0 deletions src/include/platform/ConnectivityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <memory>

#include <app/AttributeAccessInterface.h>
#include <inet/UDPEndPoint.h>
#include <lib/support/CodeUtils.h>
#include <platform/CHIPDeviceBuildConfig.h>
#include <platform/CHIPDeviceConfig.h>
Expand All @@ -33,6 +34,10 @@
#include <app-common/zap-generated/cluster-objects.h>
#include <app/util/basic-types.h>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <inet/TCPEndPoint.h>
#endif

namespace chip {

namespace Ble {
Expand Down Expand Up @@ -158,6 +163,12 @@ class ConnectivityManager
void SetDelegate(ConnectivityManagerDelegate * delegate) { mDelegate = delegate; }
ConnectivityManagerDelegate * GetDelegate() const { return mDelegate; }

chip::Inet::EndPointManager<Inet::UDPEndPoint> & UDPEndPointManager();

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
chip::Inet::EndPointManager<Inet::TCPEndPoint> & TCPEndPointManager();
#endif

// WiFi station methods
WiFiStationMode GetWiFiStationMode();
CHIP_ERROR SetWiFiStationMode(WiFiStationMode val);
Expand Down Expand Up @@ -323,6 +334,18 @@ extern ConnectivityManagerImpl & ConnectivityMgrImpl();
namespace chip {
namespace DeviceLayer {

inline chip::Inet::EndPointManager<Inet::UDPEndPoint> & ConnectivityManager::UDPEndPointManager()
{
return static_cast<ImplClass *>(this)->_UDPEndPointManager();
}

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
inline chip::Inet::EndPointManager<Inet::TCPEndPoint> & ConnectivityManager::TCPEndPointManager()
{
return static_cast<ImplClass *>(this)->_TCPEndPointManager();
}
#endif

inline ConnectivityManager::WiFiStationMode ConnectivityManager::GetWiFiStationMode()
{
return static_cast<ImplClass *>(this)->_GetWiFiStationMode();
Expand Down
42 changes: 42 additions & 0 deletions src/include/platform/internal/GenericConnectivityManagerImpl_TCP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* Copyright (c) 2022 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.
*/

/**
* @file
* Provides a generic implementation of ConnectivityManager features
* for use on platforms that use TCP.
*/

#pragma once

#include <inet/TCPEndPointImpl.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

template <class ImplClass>
class GenericConnectivityManagerImpl_TCP
{
public:
// ConnectivityManager:
static chip::Inet::EndPointManager<Inet::TCPEndPoint> & _TCPEndPointManager();
};

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* Copyright (c) 2022 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.
*/

/**
* @file
* Provides a generic implementation of ConnectivityManager features
* for use on platforms that use TCP.
*/

#ifndef GENERIC_CONNECTIVITY_MANAGER_IMPL_TCP_CPP
#define GENERIC_CONNECTIVITY_MANAGER_IMPL_TCP_CPP

#include <platform/internal/CHIPDeviceLayerInternal.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

template <class ImplClass>
chip::Inet::EndPointManager<Inet::TCPEndPoint> & GenericConnectivityManagerImpl_TCP<ImplClass>::_TCPEndPointManager()
{
static chip::Inet::TCPEndPointManagerImpl sTCPEndPointManagerImpl;
return sTCPEndPointManagerImpl;
}

// Fully instantiate the generic implementation class in whatever compilation unit includes this file.
// NB: This must come after all templated class members are defined.
template class GenericConnectivityManagerImpl_TCP<ConnectivityManagerImpl>;

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip

#endif // GENERIC_CONNECTIVITY_MANAGER_IMPL_TCP_CPP
42 changes: 42 additions & 0 deletions src/include/platform/internal/GenericConnectivityManagerImpl_UDP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* Copyright (c) 2022 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.
*/

/**
* @file
* Provides a generic implementation of ConnectivityManager features
* for use on platforms that use UDP.
*/

#pragma once

#include <inet/UDPEndPointImpl.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

template <class ImplClass>
class GenericConnectivityManagerImpl_UDP
{
public:
// ConnectivityManager:
static chip::Inet::EndPointManager<Inet::UDPEndPoint> & _UDPEndPointManager();
};

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* Copyright (c) 2022 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.
*/

/**
* @file
* Provides a generic implementation of ConnectivityManager features
* for use on platforms that use UDP.
*/

#ifndef GENERIC_CONNECTIVITY_MANAGER_IMPL_UDP_CPP
#define GENERIC_CONNECTIVITY_MANAGER_IMPL_UDP_CPP

#include <platform/internal/CHIPDeviceLayerInternal.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

template <class ImplClass>
chip::Inet::EndPointManager<Inet::UDPEndPoint> & GenericConnectivityManagerImpl_UDP<ImplClass>::_UDPEndPointManager()
{
static chip::Inet::UDPEndPointManagerImpl sUDPEndPointManagerImpl;
return sUDPEndPointManagerImpl;
}

// Fully instantiate the generic implementation class in whatever compilation unit includes this file.
// NB: This must come after all templated class members are defined.
template class GenericConnectivityManagerImpl_UDP<ConnectivityManagerImpl>;

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip

#endif // GENERIC_CONNECTIVITY_MANAGER_IMPL_UDP_CPP
6 changes: 6 additions & 0 deletions src/platform/Ameba/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

#include <platform/ConnectivityManager.h>

#include <platform/internal/GenericConnectivityManagerImpl_UDP.ipp>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <platform/internal/GenericConnectivityManagerImpl_TCP.ipp>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <platform/internal/GenericConnectivityManagerImpl_BLE.ipp>
#endif
Expand Down
9 changes: 9 additions & 0 deletions src/platform/Ameba/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

#include <platform/ConnectivityManager.h>
#include <platform/internal/GenericConnectivityManagerImpl.h>
#include <platform/internal/GenericConnectivityManagerImpl_UDP.h>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <platform/internal/GenericConnectivityManagerImpl_TCP.h>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.h>
Expand Down Expand Up @@ -55,6 +60,10 @@ class PlatformManagerImpl;

class ConnectivityManagerImpl final : public ConnectivityManager,
public Internal::GenericConnectivityManagerImpl<ConnectivityManagerImpl>,
public Internal::GenericConnectivityManagerImpl_UDP<ConnectivityManagerImpl>,
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
public Internal::GenericConnectivityManagerImpl_TCP<ConnectivityManagerImpl>,
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
public Internal::GenericConnectivityManagerImpl_WiFi<ConnectivityManagerImpl>,
#else
Expand Down
4 changes: 4 additions & 0 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ if (chip_device_platform != "none") {
"../include/platform/internal/GenericConnectivityManagerImpl_NoBLE.h",
"../include/platform/internal/GenericConnectivityManagerImpl_NoThread.h",
"../include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h",
"../include/platform/internal/GenericConnectivityManagerImpl_TCP.h",
"../include/platform/internal/GenericConnectivityManagerImpl_TCP.ipp",
"../include/platform/internal/GenericConnectivityManagerImpl_Thread.h",
"../include/platform/internal/GenericConnectivityManagerImpl_Thread.ipp",
"../include/platform/internal/GenericConnectivityManagerImpl_UDP.h",
"../include/platform/internal/GenericConnectivityManagerImpl_UDP.ipp",
"../include/platform/internal/GenericConnectivityManagerImpl_WiFi.h",
"../include/platform/internal/GenericConnectivityManagerImpl_WiFi.ipp",
"../include/platform/internal/GenericDeviceInstanceInfoProvider.h",
Expand Down
6 changes: 6 additions & 0 deletions src/platform/CYW30739/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

#include <platform/ConnectivityManager.h>

#include <platform/internal/GenericConnectivityManagerImpl_UDP.ipp>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <platform/internal/GenericConnectivityManagerImpl_TCP.ipp>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <platform/internal/GenericConnectivityManagerImpl_Thread.ipp>
#endif
Expand Down
9 changes: 9 additions & 0 deletions src/platform/CYW30739/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

#include <platform/ConnectivityManager.h>
#include <platform/internal/GenericConnectivityManagerImpl.h>
#include <platform/internal/GenericConnectivityManagerImpl_UDP.h>
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <platform/internal/GenericConnectivityManagerImpl_TCP.h>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <platform/internal/GenericConnectivityManagerImpl_BLE.h>
#else
Expand All @@ -40,6 +45,10 @@ namespace DeviceLayer {
*/
class ConnectivityManagerImpl final : public ConnectivityManager,
public Internal::GenericConnectivityManagerImpl<ConnectivityManagerImpl>,
public Internal::GenericConnectivityManagerImpl_UDP<ConnectivityManagerImpl>,
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
public Internal::GenericConnectivityManagerImpl_TCP<ConnectivityManagerImpl>,
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
public Internal::GenericConnectivityManagerImpl_BLE<ConnectivityManagerImpl>,
#else
Expand Down
6 changes: 6 additions & 0 deletions src/platform/Darwin/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

#include <platform/internal/GenericConnectivityManagerImpl_UDP.ipp>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <platform/internal/GenericConnectivityManagerImpl_TCP.ipp>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <platform/internal/GenericConnectivityManagerImpl_BLE.ipp>
#endif
Expand Down
Loading