@@ -112,12 +112,10 @@ DNSServiceProtocol GetProtocol(const chip::Inet::IPAddressType & addressType)
112
112
return kDNSServiceProtocol_IPv6 ;
113
113
#endif
114
114
}
115
-
116
115
} // namespace
117
116
118
117
namespace chip {
119
118
namespace Dnssd {
120
-
121
119
CHIP_ERROR GenericContext::Finalize (DNSServiceErrorType err)
122
120
{
123
121
if (MdnsContexts::GetInstance ().Has (this ) == CHIP_NO_ERROR)
@@ -139,6 +137,51 @@ CHIP_ERROR GenericContext::Finalize(DNSServiceErrorType err)
139
137
return Error::ToChipError (err);
140
138
}
141
139
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
+
142
185
MdnsContexts::~MdnsContexts ()
143
186
{
144
187
std::vector<GenericContext *>::const_iterator iter = mContexts .cbegin ();
@@ -500,6 +543,5 @@ InterfaceInfo::~InterfaceInfo()
500
543
}
501
544
Platform::MemoryFree (const_cast <TextEntry *>(service.mTextEntries ));
502
545
}
503
-
504
546
} // namespace Dnssd
505
547
} // namespace chip
0 commit comments