forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux tv-casting-app: simplified CastingPlayer.VerifyOrEstablishConne…
…ction API
- Loading branch information
1 parent
71ef633
commit 666427f
Showing
16 changed files
with
1,465 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 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. | ||
*/ | ||
#include "simple-app-helper.h" | ||
|
||
#include "app/clusters/bindings/BindingManager.h" | ||
#include <inttypes.h> | ||
#include <lib/core/CHIPCore.h> | ||
#include <lib/shell/Commands.h> | ||
#include <lib/shell/Engine.h> | ||
#include <lib/shell/commands/Help.h> | ||
#include <lib/support/CHIPArgParser.hpp> | ||
#include <lib/support/CHIPMem.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <platform/CHIPDeviceLayer.h> | ||
|
||
DiscoveryDelegateImpl * DiscoveryDelegateImpl::_discoveryDelegateImpl = nullptr; | ||
|
||
DiscoveryDelegateImpl * DiscoveryDelegateImpl::GetInstance() | ||
{ | ||
if (_discoveryDelegateImpl == nullptr) | ||
{ | ||
_discoveryDelegateImpl = new DiscoveryDelegateImpl(); | ||
} | ||
return _discoveryDelegateImpl; | ||
} | ||
|
||
void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player) | ||
{ | ||
if (commissionersCount == 0) | ||
{ | ||
ChipLogProgress(AppServer, "Select discovered Casting Player (start index = 0) to request commissioning"); | ||
|
||
ChipLogProgress(AppServer, "Example: cast request 0"); | ||
} | ||
ChipLogProgress(AppServer, "Discovered CastingPlayer #%d", commissionersCount); | ||
++commissionersCount; | ||
player->LogDetail(); | ||
} | ||
|
||
void DiscoveryDelegateImpl::HandleOnUpdated(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player) | ||
{ | ||
ChipLogProgress(AppServer, "Updated CastingPlayer with ID: %s", player->GetId()); | ||
} | ||
|
||
void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer) | ||
{ | ||
ChipLogProgress(AppServer, "ConnectionHandler called with %" CHIP_ERROR_FORMAT, err.Format()); | ||
} | ||
|
||
#if defined(ENABLE_CHIP_SHELL) | ||
void RegisterCommands() | ||
{ | ||
static const chip::Shell::shell_command_t sDeviceComand = { &CommandHandler, "cast", | ||
"Casting commands. Usage: cast [command_name]" }; | ||
|
||
// Register the root `device` command with the top-level shell. | ||
chip::Shell::Engine::Root().RegisterCommands(&sDeviceComand, 1); | ||
} | ||
|
||
CHIP_ERROR CommandHandler(int argc, char ** argv) | ||
{ | ||
if (argc == 0 || strcmp(argv[0], "help") == 0) | ||
{ | ||
return PrintAllCommands(); | ||
} | ||
if (strcmp(argv[0], "discover") == 0) | ||
{ | ||
ChipLogProgress(AppServer, "discover"); | ||
|
||
return matter::casting::core::CastingPlayerDiscovery::GetInstance()->StartDiscovery(kTargetPlayerDeviceType); | ||
} | ||
if (strcmp(argv[0], "stop-discovery") == 0) | ||
{ | ||
ChipLogProgress(AppServer, "stop-discovery"); | ||
return matter::casting::core::CastingPlayerDiscovery::GetInstance()->StopDiscovery(); | ||
} | ||
if (strcmp(argv[0], "request") == 0) | ||
{ | ||
ChipLogProgress(AppServer, "request"); | ||
if (argc < 2) | ||
{ | ||
return PrintAllCommands(); | ||
} | ||
char * eptr; | ||
unsigned long index = static_cast<unsigned long>(strtol(argv[1], &eptr, 10)); | ||
std::vector<matter::casting::memory::Strong<matter::casting::core::CastingPlayer>> castingPlayers = | ||
matter::casting::core::CastingPlayerDiscovery::GetInstance()->GetCastingPlayers(); | ||
VerifyOrReturnValue(0 <= index && index < castingPlayers.size(), CHIP_ERROR_INVALID_ARGUMENT, | ||
ChipLogError(AppServer, "Invalid casting player index provided: %lu", index)); | ||
std::shared_ptr<matter::casting::core::CastingPlayer> targetCastingPlayer = castingPlayers.at(index); | ||
targetCastingPlayer->VerifyOrEstablishConnection(ConnectionHandler); | ||
return CHIP_NO_ERROR; | ||
} | ||
if (strcmp(argv[0], "print-bindings") == 0) | ||
{ | ||
PrintBindings(); | ||
return CHIP_NO_ERROR; | ||
} | ||
if (strcmp(argv[0], "print-fabrics") == 0) | ||
{ | ||
PrintFabrics(); | ||
return CHIP_NO_ERROR; | ||
} | ||
if (strcmp(argv[0], "delete-fabric") == 0) | ||
{ | ||
char * eptr; | ||
chip::FabricIndex fabricIndex = (chip::FabricIndex) strtol(argv[1], &eptr, 10); | ||
chip::Server::GetInstance().GetFabricTable().Delete(fabricIndex); | ||
return CHIP_NO_ERROR; | ||
} | ||
return CHIP_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
CHIP_ERROR PrintAllCommands() | ||
{ | ||
chip::Shell::streamer_t * sout = chip::Shell::streamer_get(); | ||
streamer_printf(sout, " help Usage: cast <subcommand>\r\n"); | ||
streamer_printf(sout, " print-bindings Usage: cast print-bindings\r\n"); | ||
streamer_printf(sout, " print-fabrics Usage: cast print-fabrics\r\n"); | ||
streamer_printf( | ||
sout, | ||
" delete-fabric <index> Delete a fabric from the casting client's fabric store. Usage: cast delete-fabric 1\r\n"); | ||
streamer_printf(sout, " discover Discover Casting Players. Usage: cast discover\r\n"); | ||
streamer_printf(sout, " stop-discovery Stop Discovery of Casting Players. Usage: cast stop-discovery\r\n"); | ||
streamer_printf( | ||
sout, " request <index> Request connecting to discovered Casting Player with [index]. Usage: cast request 0\r\n"); | ||
streamer_printf(sout, "\r\n"); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void PrintBindings() | ||
{ | ||
for (const auto & binding : chip::BindingTable::GetInstance()) | ||
{ | ||
ChipLogProgress(AppServer, | ||
"Binding type=%d fab=%d nodeId=0x" ChipLogFormatX64 | ||
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI, | ||
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local, | ||
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0))); | ||
} | ||
} | ||
|
||
void PrintFabrics() | ||
{ | ||
// set fabric to be the first in the list | ||
for (const auto & fb : chip::Server::GetInstance().GetFabricTable()) | ||
{ | ||
chip::FabricIndex fabricIndex = fb.GetFabricIndex(); | ||
ChipLogError(AppServer, "Next Fabric index=%d", fabricIndex); | ||
if (!fb.IsInitialized()) | ||
{ | ||
ChipLogError(AppServer, " -- Not initialized"); | ||
continue; | ||
} | ||
chip::NodeId myNodeId = fb.GetNodeId(); | ||
ChipLogProgress(AppServer, | ||
"---- Current Fabric nodeId=0x" ChipLogFormatX64 " fabricId=0x" ChipLogFormatX64 " fabricIndex=%d", | ||
ChipLogValueX64(myNodeId), ChipLogValueX64(fb.GetFabricId()), fabricIndex); | ||
} | ||
} | ||
|
||
#endif // ENABLE_CHIP_SHELL |
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,92 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "core/CastingPlayer.h" | ||
#include "core/CastingPlayerDiscovery.h" | ||
#include "core/Types.h" | ||
|
||
#include <platform/CHIPDeviceLayer.h> | ||
|
||
/** | ||
* @brief Matter deviceType that the Linux tv-casting-app will discover over Commissionable Node discovery (DNS-SD) | ||
* | ||
* 35 represents device type of Matter Video Player | ||
*/ | ||
const uint64_t kTargetPlayerDeviceType = 35; | ||
|
||
/** | ||
* @brief Singleton that reacts to CastingPlayer discovery results | ||
*/ | ||
class DiscoveryDelegateImpl : public matter::casting::core::DiscoveryDelegate | ||
{ | ||
private: | ||
DiscoveryDelegateImpl(){}; | ||
static DiscoveryDelegateImpl * _discoveryDelegateImpl; | ||
int commissionersCount = 0; | ||
|
||
public: | ||
static DiscoveryDelegateImpl * GetInstance(); | ||
|
||
/** | ||
* @brief Called when a new CastingPlayer is discovered | ||
* | ||
* @param player the discovered CastingPlayer | ||
*/ | ||
void HandleOnAdded(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player) override; | ||
|
||
/** | ||
* @brief Called when there are updates to the Attributes of a previously discovered CastingPlayer | ||
* | ||
* @param player the updated CastingPlayer | ||
*/ | ||
void HandleOnUpdated(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player) override; | ||
}; | ||
|
||
/** | ||
* @brief Linux tv-casting-app's onCompleted handler for CastingPlayer.VerifyOrEstablishConnection API | ||
*/ | ||
void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer); | ||
|
||
#if defined(ENABLE_CHIP_SHELL) | ||
/** | ||
* @brief Register CHIP Shell commands for the Linux tv-casting-app CLI | ||
*/ | ||
void RegisterCommands(); | ||
|
||
/** | ||
* @brief Top level handler that parses text entered on the Linux tv-casting-app CLI and invokes the appropriate handler | ||
*/ | ||
CHIP_ERROR CommandHandler(int argc, char ** argv); | ||
|
||
/** | ||
* @brief Prints all the commands available on the Linux tv-casting-app CLI | ||
*/ | ||
CHIP_ERROR PrintAllCommands(); | ||
|
||
/** | ||
* @brief Implements the "print-bindings" command | ||
*/ | ||
void PrintBindings(); | ||
|
||
/** | ||
* @brief Implements the "print-fabrics" command | ||
*/ | ||
void PrintFabrics(); | ||
#endif |
Oops, something went wrong.