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

[genio] Correct dnssd api usage #23848

Merged
merged 6 commits into from
Dec 6, 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
8 changes: 8 additions & 0 deletions examples/platform/mt793x/link_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ void __assert_func(const char * file, int line, const char * func, const char *
#include <assert.h>
#include <stdlib.h>

void * __wrap__calloc_r(size_t nmemb, size_t size)
{
void * p = pvPortCalloc(nmemb, size);
while (!p)
;
return p;
}

void * __wrap__malloc_r(void * REENT, size_t size)
{
void * p = pvPortMalloc(size);
Expand Down
48 changes: 45 additions & 3 deletions src/platform/mt793x/DnssdContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ DNSServiceProtocol GetProtocol(const chip::Inet::IPAddressType & addressType)
return kDNSServiceProtocol_IPv6;
#endif
}

} // namespace

namespace chip {
namespace Dnssd {

CHIP_ERROR GenericContext::Finalize(DNSServiceErrorType err)
{
if (MdnsContexts::GetInstance().Has(this) == CHIP_NO_ERROR)
Expand All @@ -139,6 +137,51 @@ CHIP_ERROR GenericContext::Finalize(DNSServiceErrorType err)
return Error::ToChipError(err);
}

RegisterContext::RegisterContext(const char * sType, const char * instanceName, DnssdPublishCallback cb, void * cbContext)
{
type = ContextType::Register;
context = cbContext;
callback = cb;

mType = sType;
mInstanceName = instanceName;
}

void RegisterContext::DispatchFailure(DNSServiceErrorType err)
{
ChipLogError(Discovery, "Mdns: Register failure (%s)", Error::ToString(err));
callback(context, nullptr, nullptr, Error::ToChipError(err));
MdnsContexts::GetInstance().Remove(this);
}

void RegisterContext::DispatchSuccess()
{
std::string typeWithoutSubTypes = GetFullTypeWithoutSubTypes(mType);
callback(context, typeWithoutSubTypes.c_str(), mInstanceName.c_str(), CHIP_NO_ERROR);

// Once a service has been properly published it is normally unreachable because the hostname has not yet been
// registered against the dns daemon. Register the records mapping the hostname to our IP.
// mHostNameRegistrar.Register();
}

CHIP_ERROR MdnsContexts::GetRegisterContextOfType(const char * type, RegisterContext ** context)
{
bool found = false;
std::vector<GenericContext *>::iterator iter;

for (iter = mContexts.begin(); iter != mContexts.end(); iter++)
{
if ((*iter)->type == ContextType::Register && (static_cast<RegisterContext *>(*iter))->matches(type))
{
*context = static_cast<RegisterContext *>(*iter);
found = true;
break;
}
}

return found ? CHIP_NO_ERROR : CHIP_ERROR_KEY_NOT_FOUND;
}

MdnsContexts::~MdnsContexts()
{
std::vector<GenericContext *>::const_iterator iter = mContexts.cbegin();
Expand Down Expand Up @@ -500,6 +543,5 @@ InterfaceInfo::~InterfaceInfo()
}
Platform::MemoryFree(const_cast<TextEntry *>(service.mTextEntries));
}

} // namespace Dnssd
} // namespace chip
Loading