Skip to content

Commit

Permalink
Refactored mDNS Browse Interface (project-chip#32866)
Browse files Browse the repository at this point in the history
* Refactored mDNS Browse Interface and necessary renaming done

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and kurvaSai committed May 29, 2024
1 parent 9ce9b24 commit d1ba7d9
Show file tree
Hide file tree
Showing 44 changed files with 276 additions and 287 deletions.
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/common/DeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ CHIP_ERROR DeviceScanner::Stop()

void DeviceScanner::OnNodeDiscovered(const DiscoveredNodeData & nodeData)
{
auto & commissionData = nodeData.commissionData;
auto & commissionData = nodeData.nodeData;

auto discriminator = commissionData.longDiscriminator;
auto vendorId = static_cast<VendorId>(commissionData.vendorId);
Expand Down
4 changes: 2 additions & 2 deletions examples/chip-tool/commands/common/DeviceScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct DeviceScannerResult
chip::Optional<chip::Dnssd::CommonResolutionData> mResolutionData;
};

class DeviceScanner : public chip::Dnssd::CommissioningResolveDelegate,
class DeviceScanner : public chip::Dnssd::DiscoverNodeDelegate,
public chip::Dnssd::DnssdBrowseDelegate
#if CONFIG_NETWORK_LAYER_BLE
,
Expand All @@ -55,7 +55,7 @@ class DeviceScanner : public chip::Dnssd::CommissioningResolveDelegate,
CHIP_ERROR Get(uint16_t index, chip::Dnssd::CommonResolutionData & resolutionData);
void Log() const;

/////////// CommissioningResolveDelegate Interface /////////
/////////// DiscoverNodeDelegate Interface /////////
void OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) override;

/////////// DnssdBrowseDelegate Interface /////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::DiscoveredNodeData & nodeDat
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);

auto & resolutionData = nodeData.resolutionData;
auto & commissionData = nodeData.commissionData;
auto & commissionData = nodeData.nodeData;

if (!chip::CanCastTo<uint8_t>(resolutionData.numIPs))
{
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void PairingCommand::OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedA
void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::DiscoveredNodeData & nodeData)
{
// Ignore nodes with closed commissioning window
VerifyOrReturn(nodeData.commissionData.commissioningMode != 0);
VerifyOrReturn(nodeData.nodeData.commissioningMode != 0);

auto & resolutionData = nodeData.resolutionData;

Expand Down
4 changes: 2 additions & 2 deletions examples/platform/linux/ControllerShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ static CHIP_ERROR display(bool printHeader)
else
{
streamer_printf(sout, " Entry %d instanceName=%s host=%s longDiscriminator=%d vendorId=%d productId=%d\r\n", i,
next->commissionData.instanceName, next->resolutionData.hostName,
next->commissionData.longDiscriminator, next->commissionData.vendorId, next->commissionData.productId);
next->nodeData.instanceName, next->resolutionData.hostName, next->nodeData.longDiscriminator,
next->nodeData.vendorId, next->nodeData.productId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,53 +324,50 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered
jstring jInstanceName = static_cast<jstring>(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField));
if (jInstanceName != nullptr)
{
chip::Platform::CopyString(outCppDiscoveredNodeData.commissionData.instanceName,
chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.instanceName,
chip::Dnssd::Commission::kInstanceNameMaxLength + 1, env->GetStringUTFChars(jInstanceName, 0));
}

jfieldID jLongDiscriminatorField = env->GetFieldID(jDiscoveredNodeDataClass, "longDiscriminator", "J");
outCppDiscoveredNodeData.commissionData.vendorId =
outCppDiscoveredNodeData.nodeData.vendorId =
static_cast<uint16_t>(env->GetLongField(jDiscoveredNodeData, jLongDiscriminatorField));

jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J");
outCppDiscoveredNodeData.commissionData.vendorId =
static_cast<uint16_t>(env->GetLongField(jDiscoveredNodeData, jVendorIdField));
jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J");
outCppDiscoveredNodeData.nodeData.vendorId = static_cast<uint16_t>(env->GetLongField(jDiscoveredNodeData, jVendorIdField));

jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J");
outCppDiscoveredNodeData.commissionData.productId =
static_cast<uint16_t>(env->GetLongField(jDiscoveredNodeData, jProductIdField));
jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J");
outCppDiscoveredNodeData.nodeData.productId = static_cast<uint16_t>(env->GetLongField(jDiscoveredNodeData, jProductIdField));

jfieldID jCommissioningModeField = env->GetFieldID(jDiscoveredNodeDataClass, "commissioningMode", "B");
outCppDiscoveredNodeData.commissionData.commissioningMode =
outCppDiscoveredNodeData.nodeData.commissioningMode =
static_cast<uint8_t>(env->GetByteField(jDiscoveredNodeData, jCommissioningModeField));

jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J");
outCppDiscoveredNodeData.commissionData.deviceType =
static_cast<uint16_t>(env->GetLongField(jDiscoveredNodeData, jDeviceTypeField));
jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J");
outCppDiscoveredNodeData.nodeData.deviceType = static_cast<uint16_t>(env->GetLongField(jDiscoveredNodeData, jDeviceTypeField));

jfieldID getDeviceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceName", "Ljava/lang/String;");
jstring jDeviceName = static_cast<jstring>(env->GetObjectField(jDiscoveredNodeData, getDeviceNameField));
if (jDeviceName != nullptr)
{
chip::Platform::CopyString(outCppDiscoveredNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1,
chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1,
env->GetStringUTFChars(jDeviceName, 0));
}

// TODO: map rotating ID
jfieldID jRotatingIdLenField = env->GetFieldID(jDiscoveredNodeDataClass, "rotatingIdLen", "I");
outCppDiscoveredNodeData.commissionData.rotatingIdLen =
outCppDiscoveredNodeData.nodeData.rotatingIdLen =
static_cast<size_t>(env->GetIntField(jDiscoveredNodeData, jRotatingIdLenField));

jfieldID jPairingHintField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingHint", "S");
outCppDiscoveredNodeData.commissionData.pairingHint =
outCppDiscoveredNodeData.nodeData.pairingHint =
static_cast<uint16_t>(env->GetShortField(jDiscoveredNodeData, jPairingHintField));

jfieldID getPairingInstructionField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingInstruction", "Ljava/lang/String;");
jstring jPairingInstruction = static_cast<jstring>(env->GetObjectField(jDiscoveredNodeData, getPairingInstructionField));
if (jPairingInstruction != nullptr)
{
chip::Platform::CopyString(outCppDiscoveredNodeData.commissionData.pairingInstruction,
chip::Dnssd::kMaxPairingInstructionLen + 1, env->GetStringUTFChars(jPairingInstruction, 0));
chip::Platform::CopyString(outCppDiscoveredNodeData.nodeData.pairingInstruction, chip::Dnssd::kMaxPairingInstructionLen + 1,
env->GetStringUTFChars(jPairingInstruction, 0));
}

jfieldID jPortField = env->GetFieldID(jDiscoveredNodeDataClass, "port", "I");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ + (CHIP_ERROR)convertToCppDiscoveredNodeDataFrom:(DiscoveredNodeData * _Nonnull)
outDiscoveredNodeData:(chip::Dnssd::DiscoveredNodeData &)outDiscoveredNodeData
{
// setting CommissionNodeData
outDiscoveredNodeData.commissionData.deviceType = objCDiscoveredNodeData.deviceType;
outDiscoveredNodeData.commissionData.vendorId = objCDiscoveredNodeData.vendorId;
outDiscoveredNodeData.commissionData.productId = objCDiscoveredNodeData.productId;
outDiscoveredNodeData.commissionData.longDiscriminator = objCDiscoveredNodeData.longDiscriminator;
outDiscoveredNodeData.commissionData.commissioningMode = objCDiscoveredNodeData.commissioningMode;
outDiscoveredNodeData.commissionData.pairingHint = objCDiscoveredNodeData.pairingHint;
memset(outDiscoveredNodeData.commissionData.deviceName, '\0', sizeof(outDiscoveredNodeData.commissionData.deviceName));
outDiscoveredNodeData.nodeData.deviceType = objCDiscoveredNodeData.deviceType;
outDiscoveredNodeData.nodeData.vendorId = objCDiscoveredNodeData.vendorId;
outDiscoveredNodeData.nodeData.productId = objCDiscoveredNodeData.productId;
outDiscoveredNodeData.nodeData.longDiscriminator = objCDiscoveredNodeData.longDiscriminator;
outDiscoveredNodeData.nodeData.commissioningMode = objCDiscoveredNodeData.commissioningMode;
outDiscoveredNodeData.nodeData.pairingHint = objCDiscoveredNodeData.pairingHint;
memset(outDiscoveredNodeData.nodeData.deviceName, '\0', sizeof(outDiscoveredNodeData.nodeData.deviceName));
if (objCDiscoveredNodeData.deviceName != nullptr) {
chip::Platform::CopyString(outDiscoveredNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1,
chip::Platform::CopyString(outDiscoveredNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1,
[objCDiscoveredNodeData.deviceName UTF8String]);
}
outDiscoveredNodeData.commissionData.rotatingIdLen = objCDiscoveredNodeData.rotatingIdLen;
outDiscoveredNodeData.nodeData.rotatingIdLen = objCDiscoveredNodeData.rotatingIdLen;
memcpy(
outDiscoveredNodeData.commissionData.rotatingId, objCDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingIdLen);
outDiscoveredNodeData.nodeData.rotatingId, objCDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingIdLen);

// setting CommonResolutionData
outDiscoveredNodeData.resolutionData.port = objCDiscoveredNodeData.port;
Expand Down Expand Up @@ -121,17 +121,17 @@ + (DiscoveredNodeData *)convertToObjCDiscoveredNodeDataFrom:(const chip::Dnssd::
DiscoveredNodeData * objCDiscoveredNodeData = [DiscoveredNodeData new];

// from CommissionNodeData
objCDiscoveredNodeData.deviceType = cppDiscoveredNodedata->commissionData.deviceType;
objCDiscoveredNodeData.vendorId = cppDiscoveredNodedata->commissionData.vendorId;
objCDiscoveredNodeData.productId = cppDiscoveredNodedata->commissionData.productId;
objCDiscoveredNodeData.longDiscriminator = cppDiscoveredNodedata->commissionData.longDiscriminator;
objCDiscoveredNodeData.commissioningMode = cppDiscoveredNodedata->commissionData.commissioningMode;
objCDiscoveredNodeData.pairingHint = cppDiscoveredNodedata->commissionData.pairingHint;
objCDiscoveredNodeData.deviceName = [NSString stringWithCString:cppDiscoveredNodedata->commissionData.deviceName
objCDiscoveredNodeData.deviceType = cppDiscoveredNodedata->nodeData.deviceType;
objCDiscoveredNodeData.vendorId = cppDiscoveredNodedata->nodeData.vendorId;
objCDiscoveredNodeData.productId = cppDiscoveredNodedata->nodeData.productId;
objCDiscoveredNodeData.longDiscriminator = cppDiscoveredNodedata->nodeData.longDiscriminator;
objCDiscoveredNodeData.commissioningMode = cppDiscoveredNodedata->nodeData.commissioningMode;
objCDiscoveredNodeData.pairingHint = cppDiscoveredNodedata->nodeData.pairingHint;
objCDiscoveredNodeData.deviceName = [NSString stringWithCString:cppDiscoveredNodedata->nodeData.deviceName
encoding:NSUTF8StringEncoding];
objCDiscoveredNodeData.rotatingIdLen = cppDiscoveredNodedata->commissionData.rotatingIdLen;
objCDiscoveredNodeData.rotatingId = cppDiscoveredNodedata->commissionData.rotatingId;
objCDiscoveredNodeData.instanceName = [NSString stringWithCString:cppDiscoveredNodedata->commissionData.instanceName
objCDiscoveredNodeData.rotatingIdLen = cppDiscoveredNodedata->nodeData.rotatingIdLen;
objCDiscoveredNodeData.rotatingId = cppDiscoveredNodedata->nodeData.rotatingId;
objCDiscoveredNodeData.instanceName = [NSString stringWithCString:cppDiscoveredNodedata->nodeData.instanceName
encoding:NSUTF8StringEncoding];

// from CommonResolutionData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover
CastingPlayerAttributes attributes;
snprintf(attributes.id, kIdMaxLength + 1, "%s%u", nodeData.resolutionData.hostName, nodeData.resolutionData.port);

chip::Platform::CopyString(attributes.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, nodeData.commissionData.deviceName);
chip::Platform::CopyString(attributes.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, nodeData.nodeData.deviceName);
chip::Platform::CopyString(attributes.hostName, chip::Dnssd::kHostNameMaxLength + 1, nodeData.resolutionData.hostName);
chip::Platform::CopyString(attributes.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1,
nodeData.commissionData.instanceName);
nodeData.nodeData.instanceName);

attributes.numIPs = (unsigned int) nodeData.resolutionData.numIPs;
for (unsigned j = 0; j < attributes.numIPs; j++)
Expand All @@ -95,9 +95,9 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover
}
attributes.interfaceId = nodeData.resolutionData.interfaceId;
attributes.port = nodeData.resolutionData.port;
attributes.productId = nodeData.commissionData.productId;
attributes.vendorId = nodeData.commissionData.vendorId;
attributes.deviceType = nodeData.commissionData.deviceType;
attributes.productId = nodeData.nodeData.productId;
attributes.vendorId = nodeData.nodeData.vendorId;
attributes.deviceType = nodeData.nodeData.deviceType;

memory::Strong<CastingPlayer> player = std::make_shared<CastingPlayer>(attributes);

Expand Down
10 changes: 5 additions & 5 deletions examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,20 @@ CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::Discovered
getIpAddressForUDCRequest(selectedCommissioner->resolutionData.ipAddress, selectedCommissioner->resolutionData.numIPs);
ReturnErrorOnFailure(SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP(
*ipAddressToUse, selectedCommissioner->resolutionData.port, selectedCommissioner->resolutionData.interfaceId)));
mTargetVideoPlayerVendorId = selectedCommissioner->commissionData.vendorId;
mTargetVideoPlayerProductId = selectedCommissioner->commissionData.productId;
mTargetVideoPlayerDeviceType = selectedCommissioner->commissionData.deviceType;
mTargetVideoPlayerVendorId = selectedCommissioner->nodeData.vendorId;
mTargetVideoPlayerProductId = selectedCommissioner->nodeData.productId;
mTargetVideoPlayerDeviceType = selectedCommissioner->nodeData.deviceType;
mTargetVideoPlayerNumIPs = selectedCommissioner->resolutionData.numIPs;
for (size_t i = 0; i < mTargetVideoPlayerNumIPs && i < chip::Dnssd::CommonResolutionData::kMaxIPAddresses; i++)
{
mTargetVideoPlayerIpAddress[i] = selectedCommissioner->resolutionData.ipAddress[i];
}
chip::Platform::CopyString(mTargetVideoPlayerDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1,
selectedCommissioner->commissionData.deviceName);
selectedCommissioner->nodeData.deviceName);
chip::Platform::CopyString(mTargetVideoPlayerHostName, chip::Dnssd::kHostNameMaxLength + 1,
selectedCommissioner->resolutionData.hostName);
chip::Platform::CopyString(mTargetVideoPlayerInstanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1,
selectedCommissioner->commissionData.instanceName);
selectedCommissioner->nodeData.instanceName);
mTargetVideoPlayerPort = selectedCommissioner->resolutionData.port;
return CHIP_NO_ERROR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::D
if (inPlayer == nullptr)
return CHIP_ERROR_INVALID_ARGUMENT;

outNodeData.commissionData.vendorId = inPlayer->GetVendorId();
outNodeData.commissionData.productId = static_cast<uint16_t>(inPlayer->GetProductId());
outNodeData.commissionData.deviceType = inPlayer->GetDeviceType();
outNodeData.resolutionData.numIPs = inPlayer->GetNumIPs();
outNodeData.nodeData.vendorId = inPlayer->GetVendorId();
outNodeData.nodeData.productId = static_cast<uint16_t>(inPlayer->GetProductId());
outNodeData.nodeData.deviceType = inPlayer->GetDeviceType();
outNodeData.resolutionData.numIPs = inPlayer->GetNumIPs();

const chip::Inet::IPAddress * ipAddresses = inPlayer->GetIpAddresses();
if (ipAddresses != nullptr)
Expand All @@ -37,8 +37,7 @@ CHIP_ERROR ConvertToDiscoveredNodeData(TargetVideoPlayerInfo * inPlayer, chip::D
}
}

chip::Platform::CopyString(outNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1,
inPlayer->GetDeviceName());
chip::Platform::CopyString(outNodeData.nodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, inPlayer->GetDeviceName());
chip::Platform::CopyString(outNodeData.resolutionData.hostName, chip::Dnssd::kHostNameMaxLength + 1, inPlayer->GetHostName());

return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,6 @@ bool TargetVideoPlayerInfo::IsSameAs(const chip::Dnssd::DiscoveredNodeData * dis
return false;
}

return IsSameAs(discoveredNodeData->resolutionData.hostName, discoveredNodeData->commissionData.deviceName,
return IsSameAs(discoveredNodeData->resolutionData.hostName, discoveredNodeData->nodeData.deviceName,
discoveredNodeData->resolutionData.numIPs, discoveredNodeData->resolutionData.ipAddress);
}
2 changes: 1 addition & 1 deletion src/controller/AbstractDnssdDiscoveryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Controller {
* to maintain a list of DiscoveredNodes and providing the implementation
* of the template GetDiscoveredNodes() function.
*/
class DLL_EXPORT AbstractDnssdDiscoveryController : public Dnssd::CommissioningResolveDelegate
class DLL_EXPORT AbstractDnssdDiscoveryController : public Dnssd::DiscoverNodeDelegate
{
public:
explicit AbstractDnssdDiscoveryController(Dnssd::Resolver * resolver = nullptr) : mDNSResolver(resolver) {}
Expand Down
4 changes: 2 additions & 2 deletions src/controller/CHIPCommissionableNodeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ CHIP_ERROR CommissionableNodeController::DiscoverCommissioners(Dnssd::DiscoveryF
mDNSResolver.Shutdown(); // reset if already inited
ReturnErrorOnFailure(mDNSResolver.Init(DeviceLayer::UDPEndPointManager()));
#endif
mDNSResolver.SetCommissioningDelegate(this);
mDNSResolver.SetDiscoveryDelegate(this);
return mDNSResolver.DiscoverCommissioners(discoveryFilter);
}

CommissionableNodeController::~CommissionableNodeController()
{
mDNSResolver.SetCommissioningDelegate(nullptr);
mDNSResolver.SetDiscoveryDelegate(nullptr);
}

const Dnssd::DiscoveredNodeData * CommissionableNodeController::GetDiscoveredCommissioner(int idx)
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params)
VerifyOrReturnError(params.systemState->TransportMgr() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

ReturnErrorOnFailure(mDNSResolver.Init(params.systemState->UDPEndPointManager()));
mDNSResolver.SetCommissioningDelegate(this);
mDNSResolver.SetDiscoveryDelegate(this);
RegisterDeviceDiscoveryDelegate(params.deviceDiscoveryDelegate);

VerifyOrReturnError(params.operationalCredentialsDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
Expand Down
Loading

0 comments on commit d1ba7d9

Please sign in to comment.