Skip to content

Commit

Permalink
[Tizen] Use Thread implementation of mDNS functions (#22550)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq authored and pull[bot] committed Nov 7, 2023
1 parent 100e478 commit df2d6c2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
44 changes: 37 additions & 7 deletions src/platform/Tizen/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,23 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service, DnssdPublishCal
VerifyOrReturnError(callback != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
if (chip::DeviceLayer::ThreadStackMgr().IsThreadEnabled())
if (DeviceLayer::ThreadStackMgr().IsThreadEnabled())
{
std::string regtype = GetFullType(service->mType, service->mProtocol);
Span<const char * const> subTypes(service->mSubTypes, service->mSubTypeSize);
Span<const TextEntry> textEntries(service->mTextEntries, service->mTextEntrySize);
CHIP_ERROR err;

if (strcmp(service->mHostName, "") != 0)
{
chip::DeviceLayer::ThreadStackMgr().SetupSrpHost(service->mHostName);
err = DeviceLayer::ThreadStackMgr().SetupSrpHost(service->mHostName);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
}

std::string regtype = GetFullType(service->mType, service->mProtocol);
Span<const char * const> subTypes(service->mSubTypes, service->mSubTypeSize);
Span<const TextEntry> textEntries(service->mTextEntries, service->mTextEntrySize);
return chip::DeviceLayer::ThreadStackMgr().AddSrpService(service->mName, regtype.c_str(), service->mPort, subTypes,
textEntries);
err = DeviceLayer::ThreadStackMgr().AddSrpService(service->mName, regtype.c_str(), service->mPort, subTypes, textEntries);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);

return CHIP_NO_ERROR;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT

Expand All @@ -743,6 +748,15 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service, DnssdPublishCal

CHIP_ERROR ChipDnssdRemoveServices()
{

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
if (DeviceLayer::ThreadStackMgr().IsThreadEnabled())
{
DeviceLayer::ThreadStackMgr().InvalidateAllSrpServices();
return DeviceLayer::ThreadStackMgr().RemoveInvalidSrpServices();
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT

return DnssdTizen::GetInstance().UnregisterAllServices();
}

Expand All @@ -758,6 +772,14 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi
VerifyOrReturnError(IsSupportedProtocol(protocol), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(callback != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
if (DeviceLayer::ThreadStackMgr().IsThreadEnabled())
{
std::string fullType = GetFullType(type, protocol);
return DeviceLayer::ThreadStackMgr().DnsBrowse(fullType.c_str(), callback, context);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT

return DnssdTizen::GetInstance().Browse(type, protocol, addressType, interface, callback, context);
}

Expand All @@ -768,6 +790,14 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId
VerifyOrReturnError(IsSupportedProtocol(browseResult->mProtocol), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(callback != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
if (DeviceLayer::ThreadStackMgr().IsThreadEnabled())
{
std::string fullType = GetFullType(browseResult->mType, browseResult->mProtocol);
return DeviceLayer::ThreadStackMgr().DnsResolve(fullType.c_str(), browseResult->mName, callback, context);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT

return DnssdTizen::GetInstance().Resolve(*browseResult, interface, callback, context);
}

Expand Down
3 changes: 2 additions & 1 deletion src/platform/Tizen/DnssdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

#pragma once

#include <lib/dnssd/platform/Dnssd.h>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <sys/param.h>
#include <vector>

#include <lib/dnssd/platform/Dnssd.h>

#include <dns-sd.h>
#include <glib.h>

Expand Down
11 changes: 11 additions & 0 deletions src/platform/Tizen/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,17 @@ CHIP_ERROR ThreadStackManagerImpl::_ClearSrpHost(const char * aHostName)
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR ThreadStackManagerImpl::_DnsBrowse(const char * aServiceName, DnsBrowseCallback aCallback, void * aContext)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR ThreadStackManagerImpl::_DnsResolve(const char * aServiceName, const char * aInstanceName, DnsResolveCallback aCallback,
void * aContext)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
} // namespace DeviceLayer
} // namespace chip

0 comments on commit df2d6c2

Please sign in to comment.