|
85 | 85 | return;
|
86 | 86 | }
|
87 | 87 |
|
| 88 | + mAddedInstanceNames = [[NSMutableSet alloc] init]; |
| 89 | + |
88 | 90 | mInitialized = true;
|
89 | 91 |
|
90 | 92 | for (auto domain : kBrowseDomains) {
|
|
100 | 102 | {
|
101 | 103 | ChipLogProgress(Controller, "%p stopping persistent operational browse", this);
|
102 | 104 | if (mInitialized) {
|
| 105 | + mAddedInstanceNames = nil; |
103 | 106 | DNSServiceRefDeallocate(mBrowseRef);
|
104 | 107 | mInitialized = false;
|
105 | 108 | }
|
|
126 | 129 | return;
|
127 | 130 | }
|
128 | 131 |
|
129 |
| - chip::PeerId peerId; |
130 |
| - CHIP_ERROR err = chip::Dnssd::ExtractIdFromInstanceName(aName, &peerId); |
131 |
| - if (err != CHIP_NO_ERROR) { |
132 |
| - ChipLogError(Controller, "Invalid instance name: '%s'\n", aName); |
| 132 | + auto * newInstanceName = [NSString stringWithUTF8String:aName]; |
| 133 | + if (!(aFlags & kDNSServiceFlagsAdd)) { |
| 134 | + MTR_LOG("Matter operational instance advertisement removed: '%@'\n", newInstanceName); |
| 135 | + // Make sure that we don't notify about things that appear and then disappear. |
| 136 | + [self->mAddedInstanceNames removeObject:newInstanceName]; |
133 | 137 | return;
|
134 | 138 | }
|
135 | 139 |
|
136 |
| - if (!(aFlags & kDNSServiceFlagsAdd)) { |
137 |
| - // We mostly only care about new things appearing, but log it when things |
138 |
| - // disappear. |
139 |
| - MTR_LOG("Matter operational instance advertisement removed: '%s'\n", aName); |
| 140 | + [self->mAddedInstanceNames addObject:newInstanceName]; |
| 141 | + |
| 142 | + if (aFlags & kDNSServiceFlagsMoreComing) { |
| 143 | + // Just wait for those other notifications, so we coalesce everything. |
140 | 144 | return;
|
141 | 145 | }
|
142 | 146 |
|
143 |
| - ChipLogProgress(Controller, "Notifying controller factory about new operational instance: '%s'", aName); |
144 |
| - [self->mDeviceControllerFactory operationalInstanceAdded:peerId]; |
| 147 | + for (NSString * instanceName in self->mAddedInstanceNames) { |
| 148 | + chip::PeerId peerId; |
| 149 | + CHIP_ERROR err = chip::Dnssd::ExtractIdFromInstanceName(instanceName.UTF8String, &peerId); |
| 150 | + if (err != CHIP_NO_ERROR) { |
| 151 | + ChipLogError(Controller, "Invalid instance name: '%@'\n", instanceName); |
| 152 | + continue; |
| 153 | + } |
| 154 | + |
| 155 | + ChipLogProgress(Controller, "Notifying controller factory about new operational instance: '%@'", instanceName); |
| 156 | + [self->mDeviceControllerFactory operationalInstanceAdded:peerId]; |
| 157 | + } |
| 158 | + [self->mAddedInstanceNames removeAllObjects]; |
145 | 159 | }
|
146 | 160 |
|
147 | 161 | MTROperationalBrowser::~MTROperationalBrowser()
|
|
0 commit comments