forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[platform] add platform api for mDNS (project-chip#3241)
* [platform] add platform api for mdns * add timeout for tests * use pragma once * use nlTest * nit * splict text key and val * modify interface for better cross-platform compatibility * fix address * fix code reviews * fix race * move to happy tests * update base build image * fix build * add feature flags for mdns * enable mdns in cirque
- Loading branch information
Showing
23 changed files
with
1,280 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.4.11 | ||
0.4.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* This file defines the platform API to publish and subscribe mDNS | ||
* services. | ||
* | ||
* You can find the implementation in src/platform/<PLATFORM>/MdnsImpl.cpp. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#include "core/CHIPError.h" | ||
#include "inet/IPAddress.h" | ||
#include "inet/InetInterface.h" | ||
#include "lib/core/Optional.h" | ||
|
||
namespace chip { | ||
namespace Protocols { | ||
namespace Mdns { | ||
|
||
static constexpr uint8_t kMdnsNameMaxSize = 32; | ||
static constexpr uint8_t kMdnsTypeMaxSize = 32; | ||
static constexpr uint16_t kMdnsTextMaxSize = 64; | ||
|
||
enum class MdnsServiceProtocol : uint8_t | ||
{ | ||
kMdnsProtocolUdp = 0, | ||
kMdnsProtocolTcp, | ||
kMdnsProtocolUnknown = 255, | ||
}; | ||
|
||
struct TextEntry | ||
{ | ||
const char * mKey; | ||
const uint8_t * mData; | ||
size_t mDataSize; | ||
}; | ||
|
||
struct MdnsService | ||
{ | ||
char mName[kMdnsNameMaxSize + 1]; | ||
char mType[kMdnsTypeMaxSize + 1]; | ||
MdnsServiceProtocol mProtocol; | ||
uint16_t mPort; | ||
chip::Inet::InterfaceId interface; | ||
TextEntry * mTextEntryies; | ||
size_t mTextEntrySize; | ||
Optional<chip::Inet::IPAddress> mAddress; | ||
}; | ||
|
||
/** | ||
* The callback function for mDNS resolve. | ||
* | ||
* The callback function SHALL NOT take the ownership of the result->mService.mTextEntries | ||
* memory. | ||
* | ||
* @param[in] context The context passed to ChipMdnsBrowse or ChipMdnsResolve. | ||
* @param[in] result The mdns resolve result, can be nullptr if error happens. | ||
* @param[in] error The error code. | ||
* | ||
*/ | ||
using MdnsResolveCallback = void (*)(void * context, MdnsService * result, CHIP_ERROR error); | ||
|
||
/** | ||
* The callback function for mDNS browse. | ||
* | ||
* The callback function SHALL NOT take the ownership of the service->mTextEntries | ||
* memory. | ||
* | ||
* @param[in] context The context passed to ChipMdnsBrowse or ChipMdnsResolve. | ||
* @param[in] services The service list, can be nullptr. | ||
* @param[in] serciesSize The size of the service list. | ||
* @param[in] error The error code. | ||
* | ||
*/ | ||
using MdnsBrowseCallback = void (*)(void * context, MdnsService * services, size_t servicesSize, CHIP_ERROR error); | ||
|
||
using MdnsAsnycReturnCallback = void (*)(void * context, CHIP_ERROR error); | ||
|
||
/** | ||
* This function intializes the mdns module | ||
* | ||
* @param[in] initCallback The callback for notifying the initialization result. | ||
* @param[in] errorCallback The callback for notifying internal errors. | ||
* @param[in] context The context passed to the callbacks. | ||
* | ||
* @retval CHIP_NO_ERROR The initialization succeeds. | ||
* @retval Error code The initialization fails | ||
* | ||
*/ | ||
CHIP_ERROR ChipMdnsInit(MdnsAsnycReturnCallback initCallback, MdnsAsnycReturnCallback errorCallback, void * context); | ||
|
||
/** | ||
* This function publishes an service via mDNS. | ||
* | ||
* Calling the function again with the same service name, type, protocol, | ||
* interface and port but different text will update the text published. | ||
* This function will NOT take the ownership of service->mTextEntries memory. | ||
* | ||
* @param[in] service The service entry. | ||
* | ||
* @retval CHIP_NO_ERROR The publish succeeds. | ||
* @retval CHIP_ERROR_INVALID_ARGUMENT The service is nullptr. | ||
* @retval Error code The publish fails. | ||
* | ||
*/ | ||
CHIP_ERROR ChipMdnsPublishService(const MdnsService * service); | ||
|
||
/** | ||
* This function stops publishing service via mDNS. | ||
* | ||
* @retval CHIP_NO_ERROR The publish stops successfully. | ||
* @retval Error code Stopping the publish fails. | ||
* | ||
*/ | ||
CHIP_ERROR ChipMdnsStopPublish(); | ||
|
||
/** | ||
* This function browses the services published by mdns | ||
* | ||
* @param[in] type The service type. | ||
* @param[in] protocol The service protocol. | ||
* @param[in] interface The interface to send queries. | ||
* @param[in] callback The callback for found services. | ||
* @param[in] context The user context. | ||
* | ||
* @retval CHIP_NO_ERROR The browse succeeds. | ||
* @retval CHIP_ERROR_INVALID_ARGUMENT The type or callback is nullptr. | ||
* @retval Error code The browse fails. | ||
* | ||
*/ | ||
CHIP_ERROR ChipMdnsBrowse(const char * type, MdnsServiceProtocol protocol, chip::Inet::InterfaceId interface, | ||
MdnsBrowseCallback callback, void * context); | ||
|
||
/** | ||
* This function resolves the services published by mdns | ||
* | ||
* @param[in] browseResult The service entry returned by @ref ChipMdnsBrowse | ||
* @param[in] callback The callback for found services. | ||
* @param[in] context The user context. | ||
* | ||
* @retval CHIP_NO_ERROR The resolve succeeds. | ||
* @retval CHIP_ERROR_INVALID_ARGUMENT The name, type or callback is nullptr. | ||
* @retval Error code The resolve fails. | ||
* | ||
*/ | ||
CHIP_ERROR ChipMdnsResolve(MdnsService * browseResult, chip::Inet::InterfaceId interface, MdnsResolveCallback callback, | ||
void * context); | ||
|
||
} // namespace Mdns | ||
} // namespace Protocols | ||
} // namespace chip |
Oops, something went wrong.