-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved TargetEndpointInfo and TargetVideoPlayerInfo out of tv-casting-…
…app/linux/main.cpp (#17826) Refactored tv-casting-app/linux/main.cpp: Created CastingServer, renamed Casting->CastingUtils
- Loading branch information
1 parent
fec3cdd
commit 9a2af19
Showing
12 changed files
with
788 additions
and
544 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "CastingUtils.h" | ||
|
||
CHIP_ERROR DiscoverCommissioners() | ||
{ | ||
// Send discover commissioners request | ||
ReturnErrorOnFailure(CastingServer::GetInstance()->DiscoverCommissioners()); | ||
|
||
// Give commissioners some time to respond and then ScheduleWork to initiate commissioning | ||
return DeviceLayer::SystemLayer().StartTimer( | ||
chip::System::Clock::Milliseconds32(kCommissionerDiscoveryTimeoutInMs), | ||
[](System::Layer *, void *) { chip::DeviceLayer::PlatformMgr().ScheduleWork(InitCommissioningFlow); }, nullptr); | ||
} | ||
|
||
CHIP_ERROR RequestCommissioning(int index) | ||
{ | ||
const Dnssd::DiscoveredNodeData * selectedCommissioner = CastingServer::GetInstance()->GetDiscoveredCommissioner(index); | ||
if (selectedCommissioner == nullptr) | ||
{ | ||
ChipLogError(AppServer, "No such commissioner with index %d exists", index); | ||
return CHIP_ERROR_INVALID_ARGUMENT; | ||
} | ||
PrepareForCommissioning(selectedCommissioner); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
/** | ||
* Enters commissioning mode, opens commissioning window, logs onboarding payload. | ||
* If non-null selectedCommissioner is provided, sends user directed commissioning | ||
* request to the selectedCommissioner and advertises self as commissionable node over DNS-SD | ||
*/ | ||
void PrepareForCommissioning(const Dnssd::DiscoveredNodeData * selectedCommissioner) | ||
{ | ||
CastingServer::GetInstance()->InitServer(); | ||
|
||
CastingServer::GetInstance()->OpenBasicCommissioningWindow(); | ||
|
||
// Display onboarding payload | ||
chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig(); | ||
|
||
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT | ||
if (selectedCommissioner != nullptr) | ||
{ | ||
// Send User Directed commissioning request | ||
// Wait 1 second to allow our commissionee DNS records to publish (needed on Mac) | ||
int32_t expiration = 1; | ||
ReturnOnFailure(DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(expiration), HandleUDCSendExpiration, | ||
(void *) selectedCommissioner)); | ||
} | ||
else | ||
{ | ||
ChipLogProgress(AppServer, "To run discovery again, enter: cast discover"); | ||
} | ||
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT | ||
} | ||
|
||
void InitCommissioningFlow(intptr_t commandArg) | ||
{ | ||
int commissionerCount = 0; | ||
|
||
// Display discovered commissioner TVs to ask user to select one | ||
for (int i = 0; i < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES; i++) | ||
{ | ||
const Dnssd::DiscoveredNodeData * commissioner = CastingServer::GetInstance()->GetDiscoveredCommissioner(i); | ||
if (commissioner != nullptr) | ||
{ | ||
ChipLogProgress(AppServer, "Discovered Commissioner #%d", commissionerCount++); | ||
commissioner->LogDetail(); | ||
} | ||
} | ||
|
||
if (commissionerCount > 0) | ||
{ | ||
ChipLogProgress(AppServer, "%d commissioner(s) discovered. Select one (by number# above) to request commissioning from: ", | ||
commissionerCount); | ||
|
||
ChipLogProgress(AppServer, "Example: cast request 0"); | ||
} | ||
else | ||
{ | ||
ChipLogError(AppServer, "No commissioner discovered, commissioning must be initiated manually!"); | ||
PrepareForCommissioning(); | ||
} | ||
} | ||
|
||
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT | ||
void HandleUDCSendExpiration(System::Layer * aSystemLayer, void * context) | ||
{ | ||
Dnssd::DiscoveredNodeData * selectedCommissioner = (Dnssd::DiscoveredNodeData *) context; | ||
|
||
// Send User Directed commissioning request | ||
ReturnOnFailure(CastingServer::GetInstance()->SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP( | ||
selectedCommissioner->ipAddress[0], selectedCommissioner->port, selectedCommissioner->interfaceId))); | ||
} | ||
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT |
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
Oops, something went wrong.