Skip to content

Commit b149561

Browse files
[genio] Correct dnssd api usage (#23848)
* [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 <commits@restyled.io>
1 parent 0b8ecc8 commit b149561

File tree

4 files changed

+256
-108
lines changed

4 files changed

+256
-108
lines changed

examples/platform/mt793x/link_wrapper.c

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ void __assert_func(const char * file, int line, const char * func, const char *
5858
#include <assert.h>
5959
#include <stdlib.h>
6060

61+
void * __wrap__calloc_r(size_t nmemb, size_t size)
62+
{
63+
void * p = pvPortCalloc(nmemb, size);
64+
while (!p)
65+
;
66+
return p;
67+
}
68+
6169
void * __wrap__malloc_r(void * REENT, size_t size)
6270
{
6371
void * p = pvPortMalloc(size);

src/platform/mt793x/DnssdContexts.cpp

+45-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,10 @@ DNSServiceProtocol GetProtocol(const chip::Inet::IPAddressType & addressType)
112112
return kDNSServiceProtocol_IPv6;
113113
#endif
114114
}
115-
116115
} // namespace
117116

118117
namespace chip {
119118
namespace Dnssd {
120-
121119
CHIP_ERROR GenericContext::Finalize(DNSServiceErrorType err)
122120
{
123121
if (MdnsContexts::GetInstance().Has(this) == CHIP_NO_ERROR)
@@ -139,6 +137,51 @@ CHIP_ERROR GenericContext::Finalize(DNSServiceErrorType err)
139137
return Error::ToChipError(err);
140138
}
141139

140+
RegisterContext::RegisterContext(const char * sType, const char * instanceName, DnssdPublishCallback cb, void * cbContext)
141+
{
142+
type = ContextType::Register;
143+
context = cbContext;
144+
callback = cb;
145+
146+
mType = sType;
147+
mInstanceName = instanceName;
148+
}
149+
150+
void RegisterContext::DispatchFailure(DNSServiceErrorType err)
151+
{
152+
ChipLogError(Discovery, "Mdns: Register failure (%s)", Error::ToString(err));
153+
callback(context, nullptr, nullptr, Error::ToChipError(err));
154+
MdnsContexts::GetInstance().Remove(this);
155+
}
156+
157+
void RegisterContext::DispatchSuccess()
158+
{
159+
std::string typeWithoutSubTypes = GetFullTypeWithoutSubTypes(mType);
160+
callback(context, typeWithoutSubTypes.c_str(), mInstanceName.c_str(), CHIP_NO_ERROR);
161+
162+
// Once a service has been properly published it is normally unreachable because the hostname has not yet been
163+
// registered against the dns daemon. Register the records mapping the hostname to our IP.
164+
// mHostNameRegistrar.Register();
165+
}
166+
167+
CHIP_ERROR MdnsContexts::GetRegisterContextOfType(const char * type, RegisterContext ** context)
168+
{
169+
bool found = false;
170+
std::vector<GenericContext *>::iterator iter;
171+
172+
for (iter = mContexts.begin(); iter != mContexts.end(); iter++)
173+
{
174+
if ((*iter)->type == ContextType::Register && (static_cast<RegisterContext *>(*iter))->matches(type))
175+
{
176+
*context = static_cast<RegisterContext *>(*iter);
177+
found = true;
178+
break;
179+
}
180+
}
181+
182+
return found ? CHIP_NO_ERROR : CHIP_ERROR_KEY_NOT_FOUND;
183+
}
184+
142185
MdnsContexts::~MdnsContexts()
143186
{
144187
std::vector<GenericContext *>::const_iterator iter = mContexts.cbegin();
@@ -500,6 +543,5 @@ InterfaceInfo::~InterfaceInfo()
500543
}
501544
Platform::MemoryFree(const_cast<TextEntry *>(service.mTextEntries));
502545
}
503-
504546
} // namespace Dnssd
505547
} // namespace chip

0 commit comments

Comments
 (0)