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

Convert operator new and delete to use CHIPMem.h #3260

Merged
merged 2 commits into from
Oct 16, 2020
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
30 changes: 19 additions & 11 deletions examples/chip-tool/commands/common/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,29 @@ int Commands::Run(NodeId localId, NodeId remoteId, int argc, char ** argv)
{
ConfigureChipLogging();

CHIP_ERROR err = CHIP_NO_ERROR;
ChipDeviceController dc;
CHIP_ERROR err = chip::Platform::MemoryInit();
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Init Memory failure: %s", chip::ErrorStr(err));
}
else
{

err = dc.Init(localId);
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure: %s", chip::ErrorStr(err)));
ChipDeviceController dc;

err = dc.ServiceEvents();
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init Run Loop failure: %s", chip::ErrorStr(err)));
err = dc.Init(localId);
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure: %s", chip::ErrorStr(err)));

err = RunCommand(dc, remoteId, argc, argv);
SuccessOrExit(err);
err = dc.ServiceEvents();
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init Run Loop failure: %s", chip::ErrorStr(err)));

exit:
dc.ServiceEventSignal();
dc.Shutdown();
err = RunCommand(dc, remoteId, argc, argv);
SuccessOrExit(err);

exit:
dc.ServiceEventSignal();
dc.Shutdown();
}
return (err == CHIP_NO_ERROR) ? EXIT_SUCCESS : EXIT_FAILURE;
}

Expand Down
4 changes: 3 additions & 1 deletion examples/common/screen-framework/ScreenManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#if CONFIG_HAVE_DISPLAY

#include <support/CHIPMem.h>

#include <cassert>
#include <vector>

Expand Down Expand Up @@ -260,7 +262,7 @@ void ScreenManager::PopScreen()
Screen * screen = screens.back();
screens.pop_back(); // screen is popped immediately before last exit
screen->Exit(true); // screen is not top when exit/popped
delete screen;
chip::Platform::Delete(screen);

focusBack = false;

Expand Down
4 changes: 3 additions & 1 deletion examples/common/screen-framework/include/ListScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#if CONFIG_HAVE_DISPLAY

#include <support/CHIPMem.h>

#include <functional>
#include <string>
#include <tuple>
Expand All @@ -56,7 +58,7 @@ class ListScreen : public Screen
public:
ListScreen(Model * model) : model(model) {}

virtual ~ListScreen() { delete model; }
virtual ~ListScreen() { chip::Platform::Delete(model); }

virtual std::string GetTitle() { return model->GetTitle(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "RendezvousMessageHandler.h"
#include "esp_log.h"
#include <platform/ConfigurationManager.h>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
Expand All @@ -46,7 +47,7 @@ RendezvousDeviceDelegate::RendezvousDeviceDelegate()

params.SetSetupPINCode(setupPINCode).SetLocalNodeId(kLocalNodeId).SetBleLayer(DeviceLayer::ConnectivityMgr().GetBleLayer());

mRendezvousSession = new RendezvousSession(this, &mDeviceNetworkProvisioningDelegate);
mRendezvousSession = chip::Platform::New<RendezvousSession>(this, &mDeviceNetworkProvisioningDelegate);
err = mRendezvousSession->Init(params);

exit:
Expand Down
66 changes: 34 additions & 32 deletions examples/wifi-echo/server/esp32/main/wifi-echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <crypto/CHIPCryptoPAL.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <support/CHIPMem.h>
#include <support/ErrorStr.h>
#include <transport/SecureSessionMgr.h>

Expand Down Expand Up @@ -203,7 +204,7 @@ class AttributeListModel : public ListScreen::Model
virtual void ItemAction(int i)
{
ESP_LOGI(TAG, "Opening attribute %d", i);
ScreenManager::PushScreen(new ListScreen(new EditAttributeListModel(d, e, c, i)));
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(chip::Platform::New<EditAttributeListModel>(d, e, c, i)));
}
};

Expand All @@ -220,7 +221,7 @@ class ClusterListModel : public ListScreen::Model
virtual void ItemAction(int i)
{
ESP_LOGI(TAG, "Opening cluster %d", i);
ScreenManager::PushScreen(new ListScreen(new AttributeListModel(d, e, i)));
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(chip::Platform::New<AttributeListModel>(d, e, i)));
}
};

Expand All @@ -236,7 +237,7 @@ class EndpointListModel : public ListScreen::Model
virtual void ItemAction(int i)
{
ESP_LOGI(TAG, "Opening endpoint %d", i);
ScreenManager::PushScreen(new ListScreen(new ClusterListModel(d, i)));
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(chip::Platform::New<ClusterListModel>(d, i)));
}
};

Expand All @@ -249,7 +250,7 @@ class DeviceListModel : public ListScreen::Model
virtual void ItemAction(int i)
{
ESP_LOGI(TAG, "Opening device %d", i);
ScreenManager::PushScreen(new ListScreen(new EndpointListModel(i)));
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(chip::Platform::New<EndpointListModel>(i)));
}
};

Expand Down Expand Up @@ -480,7 +481,7 @@ extern "C" void app_main()

if (isRendezvousBLE())
{
rendezvousDelegate = new RendezvousDeviceDelegate();
rendezvousDelegate = chip::Platform::New<RendezvousDeviceDelegate>();
}
else if (isRendezvousBypassed())
{
Expand Down Expand Up @@ -513,33 +514,34 @@ extern "C" void app_main()

// Initialize the screen manager and push a rudimentary user interface.
ScreenManager::Init();
ScreenManager::PushScreen(new ListScreen((new SimpleListModel())
->Title("CHIP")
->Action([](int i) { ESP_LOGI(TAG, "action on item %d", i); })
->Item("Devices",
[]() {
ESP_LOGI(TAG, "Opening device list");
ScreenManager::PushScreen(new ListScreen(new DeviceListModel()));
})
->Item("Custom",
[]() {
ESP_LOGI(TAG, "Opening custom screen");
ScreenManager::PushScreen(new CustomScreen());
})
->Item("QR Code",
[=]() {
ESP_LOGI(TAG, "Opening QR code screen");
ScreenManager::PushScreen(new QRCodeScreen(qrCodeText));
})
->Item("Setup",
[=]() {
ESP_LOGI(TAG, "Opening Setup list");
ScreenManager::PushScreen(new ListScreen(new SetupListModel()));
})
->Item("More")
->Item("Items")
->Item("For")
->Item("Demo")));
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(
(chip::Platform::New<SimpleListModel>())
->Title("CHIP")
->Action([](int i) { ESP_LOGI(TAG, "action on item %d", i); })
->Item("Devices",
[]() {
ESP_LOGI(TAG, "Opening device list");
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(chip::Platform::New<DeviceListModel>()));
})
->Item("Custom",
[]() {
ESP_LOGI(TAG, "Opening custom screen");
ScreenManager::PushScreen(chip::Platform::New<CustomScreen>());
})
->Item("QR Code",
[=]() {
ESP_LOGI(TAG, "Opening QR code screen");
ScreenManager::PushScreen(chip::Platform::New<QRCodeScreen>(qrCodeText));
})
->Item("Setup",
[=]() {
ESP_LOGI(TAG, "Opening Setup list");
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(chip::Platform::New<SetupListModel>()));
})
->Item("More")
->Item("Items")
->Item("For")
->Item("Demo")));

// Connect the status LED to VLEDs.
{
Expand Down
34 changes: 18 additions & 16 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <core/CHIPEncoding.h>
#include <core/CHIPSafeCasts.h>
#include <support/Base64.h>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/TimeUtils.h>
Expand Down Expand Up @@ -79,7 +80,7 @@ ChipDeviceController::~ChipDeviceController()
{
if (mTestSecurePairingSecret != nullptr)
{
delete mTestSecurePairingSecret;
chip::Platform::Delete(mTestSecurePairingSecret);
}
}

Expand Down Expand Up @@ -143,22 +144,22 @@ CHIP_ERROR ChipDeviceController::Shutdown()
#else
mSystemLayer->Shutdown();
mInetLayer->Shutdown();
delete mSystemLayer;
delete mInetLayer;
chip::Platform::Delete(mSystemLayer);
chip::Platform::Delete(mInetLayer);
#endif // CONFIG_DEVICE_LAYER

mSystemLayer = nullptr;
mInetLayer = nullptr;

if (mSessionManager != nullptr)
{
delete mSessionManager;
chip::Platform::Delete(mSessionManager);
mSessionManager = nullptr;
}

if (mRendezvousSession != nullptr)
{
delete mRendezvousSession;
chip::Platform::Delete(mRendezvousSession);
mRendezvousSession = nullptr;
}

Expand Down Expand Up @@ -189,7 +190,7 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(NodeId remoteDeviceId, Rendezvous
}
#endif // CONFIG_DEVICE_LAYER && CONFIG_NETWORK_LAYER_BLE

mRendezvousSession = new RendezvousSession(this);
mRendezvousSession = chip::Platform::New<RendezvousSession>(this);
err = mRendezvousSession->Init(params.SetLocalNodeId(mLocalDeviceId));
SuccessOrExit(err);

Expand All @@ -208,7 +209,7 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(NodeId remoteDeviceId, Rendezvous
exit:
if (err != CHIP_NO_ERROR && mRendezvousSession != nullptr)
{
delete mRendezvousSession;
chip::Platform::Delete(mRendezvousSession);
mRendezvousSession = nullptr;
}

Expand All @@ -222,10 +223,11 @@ CHIP_ERROR ChipDeviceController::ConnectDeviceWithoutSecurePairing(NodeId remote
{
if (mTestSecurePairingSecret != nullptr)
{
delete mTestSecurePairingSecret;
chip::Platform::Delete(mTestSecurePairingSecret);
}

mTestSecurePairingSecret = new SecurePairingUsingTestSecret(Optional<NodeId>::Value(remoteDeviceId), 0, 0);
mTestSecurePairingSecret = chip::Platform::New<SecurePairingUsingTestSecret>(
Optional<NodeId>::Value(remoteDeviceId), static_cast<uint16_t>(0), static_cast<uint16_t>(0));

mSecurePairingSession = mTestSecurePairingSecret;

Expand Down Expand Up @@ -258,7 +260,7 @@ CHIP_ERROR ChipDeviceController::EstablishSecureSession()
ExitNow(err = CHIP_ERROR_INCORRECT_STATE);
}

mSessionManager = new SecureSessionMgr<Transport::UDP>();
mSessionManager = chip::Platform::New<SecureSessionMgr<Transport::UDP>>();

err = mSessionManager->Init(mLocalDeviceId, mSystemLayer,
Transport::UdpListenParameters(mInetLayer).SetAddressType(mDeviceAddr.Type()));
Expand All @@ -281,7 +283,7 @@ CHIP_ERROR ChipDeviceController::EstablishSecureSession()
{
if (mSessionManager != nullptr)
{
delete mSessionManager;
chip::Platform::Delete(mSessionManager);
mSessionManager = nullptr;
}
mConState = kConnectionState_NotConnected;
Expand All @@ -298,7 +300,7 @@ CHIP_ERROR ChipDeviceController::ResumeSecureSession()

if (mSessionManager != nullptr)
{
delete mSessionManager;
chip::Platform::Delete(mSessionManager);
mSessionManager = nullptr;
}

Expand Down Expand Up @@ -340,13 +342,13 @@ CHIP_ERROR ChipDeviceController::DisconnectDevice()

if (mSessionManager != nullptr)
{
delete mSessionManager;
chip::Platform::Delete(mSessionManager);
mSessionManager = nullptr;
}

if (mRendezvousSession != nullptr)
{
delete mRendezvousSession;
chip::Platform::Delete(mRendezvousSession);
mRendezvousSession = nullptr;
}

Expand Down Expand Up @@ -478,7 +480,7 @@ void ChipDeviceController::OnRendezvousComplete()
{
if (mRendezvousSession != nullptr)
{
delete mRendezvousSession;
chip::Platform::Delete(mRendezvousSession);
mRendezvousSession = nullptr;
}
}
Expand All @@ -491,7 +493,7 @@ void ChipDeviceController::OnRendezvousMessageReceived(PacketBuffer * buffer)
// to clean up the session
if (mRendezvousSession != nullptr)
{
delete mRendezvousSession;
chip::Platform::Delete(mRendezvousSession);
mRendezvousSession = nullptr;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/inet/tests/TapAddrAutoconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* from the corresponding configuration on the tap interface.
*/

#include <new>
#include <vector>

int CollectTapAddresses(std::vector<char *> & addresses, const char * ifName);
1 change: 0 additions & 1 deletion src/inet/tests/TestInetCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include "TestInetCommon.h"

#include <new>
#include <vector>

#include <inttypes.h>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/core/ReferenceCounted.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <limits>
#include <stdlib.h>

#include <support/CHIPMem.h>

namespace chip {

/**
Expand Down Expand Up @@ -62,7 +64,7 @@ class ReferenceCounted

if (--mRefCount == 0)
{
delete this;
chip::Platform::Delete(this);
}
}

Expand Down
Loading