Skip to content

Commit

Permalink
Fix 17211: TV Casting does not work on Mac (#17214)
Browse files Browse the repository at this point in the history
* Fix MDns instance filter and iPK storage

* Fix commissioning when BLE disabled

* Add proper shell to tv-casting-app

* Fix re-use of discovery controller

* Add shell commands for launching content and printing bindings

* Address comments

* Address comments

* Address comments

* Address comments, formatting

* fix resolve by service name

* Restyled by clang-format (#17218)

Co-authored-by: Restyled.io <[email protected]>

* fix TIDY

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Feb 13, 2024
1 parent b131036 commit 1106792
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 48 deletions.
8 changes: 8 additions & 0 deletions examples/tv-casting-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("args.gni")

import("${chip_root}/build/chip/tools.gni")

Expand All @@ -22,6 +23,9 @@ assert(chip_build_tools)
executable("chip-tv-casting-app") {
sources = [
"${chip_root}/examples/tv-casting-app/tv-casting-common/include/CHIPProjectAppConfig.h",
"Casting.h",
"CastingShellCommands.cpp",
"CastingShellCommands.h",
"main.cpp",
]

Expand All @@ -35,6 +39,10 @@ executable("chip-tv-casting-app") {

cflags = [ "-Wconversion" ]

if (chip_build_libshell) {
cflags += [ "-DENABLE_CHIP_SHELL" ]
}

output_dir = root_out_dir
}

Expand Down
32 changes: 32 additions & 0 deletions examples/tv-casting-app/linux/Casting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* Copyright (c) 2021 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 <app/server/Dnssd.h>
#include <app/server/Server.h>
#include <lib/core/CHIPError.h>
#include <lib/core/NodeId.h>

CHIP_ERROR DiscoverCommissioners();
CHIP_ERROR RequestCommissioning(int index);
void ReadServerClustersForNode(chip::NodeId nodeId);
CHIP_ERROR ContentLauncherLaunchURL(const char * contentUrl, const char * contentDisplayStr);
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
CHIP_ERROR SendUDC(chip::Transport::PeerAddress commissioner);
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
123 changes: 123 additions & 0 deletions examples/tv-casting-app/linux/CastingShellCommands.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
*
* Copyright (c) 2021 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 Contains shell commands for a ContentApp relating to Content App platform of the Video Player.
*/

#include "CastingShellCommands.h"
#include "Casting.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>

namespace chip {
namespace Shell {

static CHIP_ERROR PrintAllCommands()
{
streamer_t * sout = streamer_get();
streamer_printf(sout, " help Usage: app <subcommand>\r\n");
streamer_printf(sout, " discover Discover commissioners. Usage: cast discover\r\n");
streamer_printf(
sout, " request <index> Request commissioning from discovered commissioner with [index]. Usage: cast request 0\r\n");
streamer_printf(sout, " launch <url> <display> Launch content. Usage: cast launc https://www.yahoo.com Hello\r\n");
streamer_printf(
sout,
" access <node> Read and display clusters on each endpoint for <node>. Usage: cast access 0xFFFFFFEFFFFFFFFF\r\n");
streamer_printf(sout, " sendudc <address> <port> Send UDC message to address. Usage: cast sendudc ::1 5543\r\n");
streamer_printf(sout, "\r\n");

return CHIP_NO_ERROR;
}

static CHIP_ERROR CastingHandler(int argc, char ** argv)
{
if (argc == 0 || strcmp(argv[0], "help") == 0)
{
return PrintAllCommands();
}
if (strcmp(argv[0], "discover") == 0)
{
ChipLogProgress(DeviceLayer, "discover");

return DiscoverCommissioners();
}
if (strcmp(argv[0], "request") == 0)
{
ChipLogProgress(DeviceLayer, "request");
if (argc < 2)
{
return PrintAllCommands();
}
char * eptr;
int index = (int) strtol(argv[1], &eptr, 10);
return RequestCommissioning(index);
}
if (strcmp(argv[0], "launch") == 0)
{
ChipLogProgress(DeviceLayer, "launch");
if (argc < 3)
{
return PrintAllCommands();
}
char * url = argv[1];
char * display = argv[2];
return ContentLauncherLaunchURL(url, display);
}
if (strcmp(argv[0], "access") == 0)
{
ChipLogProgress(DeviceLayer, "access");
if (argc < 2)
{
return PrintAllCommands();
}
char * eptr;
chip::NodeId node = (chip::NodeId) strtoull(argv[1], &eptr, 0);
ReadServerClustersForNode(node);
return CHIP_NO_ERROR;
}
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
if (strcmp(argv[0], "sendudc") == 0)
{
char * eptr;
chip::Inet::IPAddress commissioner;
chip::Inet::IPAddress::FromString(argv[1], commissioner);
uint16_t port = (uint16_t) strtol(argv[2], &eptr, 10);
return SendUDC(chip::Transport::PeerAddress::UDP(commissioner, port));
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
return CHIP_ERROR_INVALID_ARGUMENT;
}

void RegisterCastingCommands()
{

static const shell_command_t sDeviceComand = { &CastingHandler, "cast", "Casting commands. Usage: cast [command_name]" };

// Register the root `device` command with the top-level shell.
Engine::Root().RegisterCommands(&sDeviceComand, 1);
}

} // namespace Shell
} // namespace chip
31 changes: 31 additions & 0 deletions examples/tv-casting-app/linux/CastingShellCommands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Copyright (c) 2021 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.
*/

/**
* @brief Contains shell commands for a Casting App.
*/

#include <platform/CHIPDeviceLayer.h>

namespace chip {
namespace Shell {

void RegisterCastingCommands();

} // namespace Shell
} // namespace chip
Loading

0 comments on commit 1106792

Please sign in to comment.