Skip to content

Commit

Permalink
[genio] Correct dnssd api usage (#23848)
Browse files Browse the repository at this point in the history
* [genio] correct dnssd api usage

* [genio] remove unuse variables

* Restyled by clang-format

* [genio] clean up comment-out code and correct ntohs to htons

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
j8xixo12 and restyled-commits authored Dec 6, 2022
1 parent 0b8ecc8 commit b149561
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 108 deletions.
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

0 comments on commit b149561

Please sign in to comment.