Skip to content

Commit

Permalink
Rename to BridgedDevice and BridgedDeviceManager (project-chip#34776)
Browse files Browse the repository at this point in the history
* Rename to BridgedDevice and BridgedDeviceManager

* Restyled by clang-format

* Restyled by gn

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
tehampson and restyled-commits authored Aug 6, 2024
1 parent 545b034 commit 7d9a332
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
8 changes: 4 additions & 4 deletions examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ source_set("fabric-bridge-lib") {
public_configs = [ ":config" ]

sources = [
"include/BridgedDevice.h",
"include/BridgedDeviceManager.h",
"include/CHIPProjectAppConfig.h",
"include/Device.h",
"include/DeviceManager.h",
"src/Device.cpp",
"src/DeviceManager.cpp",
"src/BridgedDevice.cpp",
"src/BridgedDeviceManager.cpp",
"src/ZCLCallbacks.cpp",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#include <string>
#include <vector>

class Device
class BridgedDevice
{
public:
static const int kDeviceNameSize = 32;

Device(chip::NodeId nodeId);
virtual ~Device() {}
BridgedDevice(chip::NodeId nodeId);
virtual ~BridgedDevice() {}

bool IsReachable();
void SetReachable(bool reachable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@

#include <platform/CHIPDeviceLayer.h>

#include "Device.h"
#include "BridgedDevice.h"

class DeviceManager
class BridgedDeviceManager
{
public:
DeviceManager() = default;
BridgedDeviceManager() = default;

/**
* @brief Initializes the DeviceManager.
* @brief Initializes the BridgedDeviceManager.
*
* This function sets up the initial state of the DeviceManager, clearing
* This function sets up the initial state of the BridgedDeviceManager, clearing
* any existing devices and setting the starting dynamic endpoint ID.
*/
void Init();
Expand All @@ -47,7 +47,7 @@ class DeviceManager
* @param parentEndpointId The parent endpoint ID. Defaults to an invalid endpoint ID.
* @return int The index of the dynamic endpoint if successful, -1 otherwise.
*/
int AddDeviceEndpoint(Device * dev, chip::EndpointId parentEndpointId = chip::kInvalidEndpointId);
int AddDeviceEndpoint(BridgedDevice * dev, chip::EndpointId parentEndpointId = chip::kInvalidEndpointId);

/**
* @brief Removes a device from a dynamic endpoint.
Expand All @@ -60,7 +60,7 @@ class DeviceManager
* @param dev A pointer to the device to be removed.
* @return int The index of the removed dynamic endpoint if successful, -1 otherwise.
*/
int RemoveDeviceEndpoint(Device * dev);
int RemoveDeviceEndpoint(BridgedDevice * dev);

/**
* @brief Gets a device from its endpoint ID.
Expand All @@ -69,9 +69,9 @@ class DeviceManager
* specified endpoint ID. If no device matches the endpoint ID, it returns nullptr.
*
* @param endpointId The endpoint ID of the device to be retrieved.
* @return Device* A pointer to the device if found, nullptr otherwise.
* @return BridgedDevice* A pointer to the device if found, nullptr otherwise.
*/
Device * GetDevice(chip::EndpointId endpointId) const;
BridgedDevice * GetDevice(chip::EndpointId endpointId) const;

/**
* @brief Gets a device from its NodeId.
Expand All @@ -80,9 +80,9 @@ class DeviceManager
* specified NodeId. If no device matches the NodeId, it returns nullptr.
*
* @param nodeId The NodeId of the device to be retrieved.
* @return Device* A pointer to the device if found, nullptr otherwise.
* @return BridgedDevice* A pointer to the device if found, nullptr otherwise.
*/
Device * GetDeviceByNodeId(chip::NodeId nodeId) const;
BridgedDevice * GetDeviceByNodeId(chip::NodeId nodeId) const;

/**
* @brief Removes a device from a dynamic endpoint by its NodeId.
Expand All @@ -98,22 +98,22 @@ class DeviceManager
int RemoveDeviceByNodeId(chip::NodeId nodeId);

private:
friend DeviceManager & DeviceMgr();
friend BridgedDeviceManager & BridgeDeviceMgr();

static DeviceManager sInstance;
static BridgedDeviceManager sInstance;

chip::EndpointId mCurrentEndpointId;
chip::EndpointId mFirstDynamicEndpointId;
Device * mDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
BridgedDevice * mDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
};

/**
* Returns the public interface of the DeviceManager singleton object.
* Returns the public interface of the BridgedDeviceManager singleton object.
*
* Applications should use this to access features of the DeviceManager
* Applications should use this to access features of the BridgedDeviceManager
* object.
*/
inline DeviceManager & DeviceMgr()
inline BridgedDeviceManager & BridgeDeviceMgr()
{
return DeviceManager::sInstance;
return BridgedDeviceManager::sInstance;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

#include "Device.h"
#include "BridgedDevice.h"

#include <cstdio>
#include <platform/CHIPDeviceLayer.h>
Expand All @@ -25,35 +25,35 @@

using namespace chip::app::Clusters::Actions;

Device::Device(chip::NodeId nodeId)
BridgedDevice::BridgedDevice(chip::NodeId nodeId)
{
mReachable = false;
mNodeId = nodeId;
mEndpointId = chip::kInvalidEndpointId;
}

bool Device::IsReachable()
bool BridgedDevice::IsReachable()
{
return mReachable;
}

void Device::SetReachable(bool reachable)
void BridgedDevice::SetReachable(bool reachable)
{
mReachable = reachable;

if (reachable)
{
ChipLogProgress(NotSpecified, "Device[%s]: ONLINE", mName);
ChipLogProgress(NotSpecified, "BridgedDevice[%s]: ONLINE", mName);
}
else
{
ChipLogProgress(NotSpecified, "Device[%s]: OFFLINE", mName);
ChipLogProgress(NotSpecified, "BridgedDevice[%s]: OFFLINE", mName);
}
}

void Device::SetName(const char * name)
void BridgedDevice::SetName(const char * name)
{
ChipLogProgress(NotSpecified, "Device[%s]: New Name=\"%s\"", mName, name);
ChipLogProgress(NotSpecified, "BridgedDevice[%s]: New Name=\"%s\"", mName, name);

chip::Platform::CopyString(mName, name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

#include "DeviceManager.h"
#include "BridgedDeviceManager.h"

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
Expand Down Expand Up @@ -121,17 +121,17 @@ const EmberAfDeviceType sBridgedDeviceTypes[] = { { DEVICE_TYPE_BRIDGED_NODE, DE
} // namespace

// Define the static member
DeviceManager DeviceManager::sInstance;
BridgedDeviceManager BridgedDeviceManager::sInstance;

void DeviceManager::Init()
void BridgedDeviceManager::Init()
{
memset(mDevices, 0, sizeof(mDevices));
mFirstDynamicEndpointId = static_cast<chip::EndpointId>(
static_cast<int>(emberAfEndpointFromIndex(static_cast<uint16_t>(emberAfFixedEndpointCount() - 1))) + 1);
mCurrentEndpointId = mFirstDynamicEndpointId;
}

int DeviceManager::AddDeviceEndpoint(Device * dev, chip::EndpointId parentEndpointId)
int BridgedDeviceManager::AddDeviceEndpoint(BridgedDevice * dev, chip::EndpointId parentEndpointId)
{
uint8_t index = 0;
EmberAfEndpointType * ep = &sBridgedNodeEndpoint;
Expand Down Expand Up @@ -181,7 +181,7 @@ int DeviceManager::AddDeviceEndpoint(Device * dev, chip::EndpointId parentEndpoi
return -1;
}

int DeviceManager::RemoveDeviceEndpoint(Device * dev)
int BridgedDeviceManager::RemoveDeviceEndpoint(BridgedDevice * dev)
{
uint8_t index = 0;
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
Expand All @@ -201,7 +201,7 @@ int DeviceManager::RemoveDeviceEndpoint(Device * dev)
return -1;
}

Device * DeviceManager::GetDevice(chip::EndpointId endpointId) const
BridgedDevice * BridgedDeviceManager::GetDevice(chip::EndpointId endpointId) const
{
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; ++index)
{
Expand All @@ -213,7 +213,7 @@ Device * DeviceManager::GetDevice(chip::EndpointId endpointId) const
return nullptr;
}

Device * DeviceManager::GetDeviceByNodeId(chip::NodeId nodeId) const
BridgedDevice * BridgedDeviceManager::GetDeviceByNodeId(chip::NodeId nodeId) const
{
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; ++index)
{
Expand All @@ -225,7 +225,7 @@ Device * DeviceManager::GetDeviceByNodeId(chip::NodeId nodeId) const
return nullptr;
}

int DeviceManager::RemoveDeviceByNodeId(chip::NodeId nodeId)
int BridgedDeviceManager::RemoveDeviceByNodeId(chip::NodeId nodeId)
{
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; ++index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "DeviceManager.h"
#include "BridgedDeviceManager.h"

#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
Expand All @@ -36,7 +36,7 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
{
AttributeId attributeId = attributeMetadata->attributeId;

Device * dev = DeviceMgr().GetDevice(endpoint);
BridgedDevice * dev = BridgeDeviceMgr().GetDevice(endpoint);
if (dev != nullptr && clusterId == app::Clusters::BridgedDeviceBasicInformation::Id)
{
using namespace app::Clusters::BridgedDeviceBasicInformation::Attributes;
Expand Down Expand Up @@ -80,7 +80,7 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
uint16_t endpointIndex = emberAfGetDynamicIndexFromEndpoint(endpoint);
Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Failure;

Device * dev = DeviceMgr().GetDevice(endpointIndex);
BridgedDevice * dev = BridgeDeviceMgr().GetDevice(endpointIndex);
if (dev != nullptr && dev->IsReachable())
{
ChipLogProgress(NotSpecified, "emberAfExternalAttributeWriteCallback: ep=%d, clusterId=%d", endpoint, clusterId);
Expand Down
10 changes: 5 additions & 5 deletions examples/fabric-bridge-app/linux/RpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include "pigweed/rpc_services/FabricBridge.h"
#endif

#include "Device.h"
#include "DeviceManager.h"
#include "BridgedDevice.h"
#include "BridgedDeviceManager.h"

using namespace chip;
using namespace chip::app;
Expand All @@ -51,10 +51,10 @@ pw::Status FabricBridge::AddSynchronizedDevice(const chip_rpc_SynchronizedDevice
NodeId nodeId = request.node_id;
ChipLogProgress(NotSpecified, "Received AddSynchronizedDevice: " ChipLogFormatX64, ChipLogValueX64(nodeId));

Device * device = new Device(nodeId);
BridgedDevice * device = new BridgedDevice(nodeId);
device->SetReachable(true);

int result = DeviceMgr().AddDeviceEndpoint(device, 1);
int result = BridgeDeviceMgr().AddDeviceEndpoint(device, 1);
if (result == -1)
{
delete device;
Expand All @@ -70,7 +70,7 @@ pw::Status FabricBridge::RemoveSynchronizedDevice(const chip_rpc_SynchronizedDev
NodeId nodeId = request.node_id;
ChipLogProgress(NotSpecified, "Received RemoveSynchronizedDevice: " ChipLogFormatX64, ChipLogValueX64(nodeId));

int removed_idx = DeviceMgr().RemoveDeviceByNodeId(nodeId);
int removed_idx = BridgeDeviceMgr().RemoveDeviceByNodeId(nodeId);
if (removed_idx < 0)
{
ChipLogError(NotSpecified, "Failed to remove device with nodeId=0x" ChipLogFormatX64, ChipLogValueX64(nodeId));
Expand Down
8 changes: 4 additions & 4 deletions examples/fabric-bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#include <AppMain.h>

#include "BridgedDevice.h"
#include "BridgedDeviceManager.h"
#include "CommissionableInit.h"
#include "Device.h"
#include "DeviceManager.h"

#include <app/AttributeAccessInterfaceRegistry.h>
#include <app/CommandHandlerInterfaceRegistry.h>
Expand Down Expand Up @@ -140,7 +140,7 @@ void AdministratorCommissioningCommandHandler::InvokeCommand(HandlerContext & ha
Status status = Status::Failure;

#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
Device * device = DeviceMgr().GetDevice(endpointId);
BridgedDevice * device = BridgeDeviceMgr().GetDevice(endpointId);

// TODO: issues:#33784, need to make OpenCommissioningWindow synchronous
if (device != nullptr &&
Expand Down Expand Up @@ -185,7 +185,7 @@ void ApplicationInit()
std::thread pollingThread(BridgePollingThread);
pollingThread.detach();

DeviceMgr().Init();
BridgeDeviceMgr().Init();
}

void ApplicationShutdown()
Expand Down

0 comments on commit 7d9a332

Please sign in to comment.