-
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.
Adding support for Media commands (beyond LaunchURL) to tv-casting-co…
…mmon (#20779) * Adding support for Media commands (beyond LaunchURL) to tv-casting-common * Prefixed command names with cluster names for better organization
- Loading branch information
1 parent
bc706b7
commit 16cae34
Showing
16 changed files
with
840 additions
and
37 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
53 changes: 53 additions & 0 deletions
53
examples/tv-casting-app/tv-casting-common/include/ApplicationLauncher.h
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,53 @@ | ||
/* | ||
* | ||
* 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 "MediaCommandBase.h" | ||
|
||
#include <functional> | ||
#include <zap-generated/CHIPClusters.h> | ||
|
||
class LaunchAppCommand | ||
: public MediaCommandBase<chip::app::Clusters::ApplicationLauncher::Commands::LaunchApp::Type, | ||
chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::DecodableType> | ||
{ | ||
public: | ||
LaunchAppCommand() : MediaCommandBase(chip::app::Clusters::ApplicationLauncher::Id) {} | ||
|
||
CHIP_ERROR Invoke(chip::app::Clusters::ApplicationLauncher::Structs::Application::Type application, | ||
chip::Optional<chip::ByteSpan> data, std::function<void(CHIP_ERROR)> responseCallback); | ||
}; | ||
|
||
class StopAppCommand : public MediaCommandBase<chip::app::Clusters::ApplicationLauncher::Commands::StopApp::Type, | ||
chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::DecodableType> | ||
{ | ||
public: | ||
StopAppCommand() : MediaCommandBase(chip::app::Clusters::ApplicationLauncher::Id) {} | ||
|
||
CHIP_ERROR Invoke(chip::app::Clusters::ApplicationLauncher::Structs::Application::Type application, | ||
std::function<void(CHIP_ERROR)> responseCallback); | ||
}; | ||
|
||
class HideAppCommand : public MediaCommandBase<chip::app::Clusters::ApplicationLauncher::Commands::HideApp::Type, | ||
chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::DecodableType> | ||
{ | ||
public: | ||
HideAppCommand() : MediaCommandBase(chip::app::Clusters::ApplicationLauncher::Id) {} | ||
|
||
CHIP_ERROR Invoke(chip::app::Clusters::ApplicationLauncher::Structs::Application::Type application, | ||
std::function<void(CHIP_ERROR)> responseCallback); | ||
}; |
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
43 changes: 43 additions & 0 deletions
43
examples/tv-casting-app/tv-casting-common/include/ContentLauncher.h
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,43 @@ | ||
/* | ||
* | ||
* 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 "MediaCommandBase.h" | ||
|
||
#include <functional> | ||
#include <zap-generated/CHIPClusters.h> | ||
|
||
class LaunchURLCommand : public MediaCommandBase<chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type, | ||
chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::DecodableType> | ||
{ | ||
public: | ||
LaunchURLCommand() : MediaCommandBase(chip::app::Clusters::ContentLauncher::Id) {} | ||
|
||
CHIP_ERROR Invoke(const char * contentUrl, const char * contentDisplayStr, | ||
chip::Optional<chip::app::Clusters::ContentLauncher::Structs::BrandingInformation::Type> brandingInformation, | ||
std::function<void(CHIP_ERROR)> responseCallback); | ||
}; | ||
|
||
class LaunchContentCommand : public MediaCommandBase<chip::app::Clusters::ContentLauncher::Commands::LaunchContent::Type, | ||
chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::DecodableType> | ||
{ | ||
public: | ||
LaunchContentCommand() : MediaCommandBase(chip::app::Clusters::ContentLauncher::Id) {} | ||
|
||
CHIP_ERROR Invoke(chip::app::Clusters::ContentLauncher::Structs::ContentSearch::Type search, bool autoPlay, | ||
chip::Optional<chip::CharSpan> data, std::function<void(CHIP_ERROR)> responseCallback); | ||
}; |
31 changes: 31 additions & 0 deletions
31
examples/tv-casting-app/tv-casting-common/include/KeypadInput.h
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,31 @@ | ||
/* | ||
* | ||
* 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 "MediaCommandBase.h" | ||
|
||
#include <functional> | ||
#include <zap-generated/CHIPClusters.h> | ||
|
||
class SendKeyCommand : public MediaCommandBase<chip::app::Clusters::KeypadInput::Commands::SendKey::Type, | ||
chip::app::Clusters::KeypadInput::Commands::SendKeyResponse::DecodableType> | ||
{ | ||
public: | ||
SendKeyCommand() : MediaCommandBase(chip::app::Clusters::KeypadInput::Id) {} | ||
|
||
CHIP_ERROR Invoke(const chip::app::Clusters::KeypadInput::CecKeyCode keyCode, std::function<void(CHIP_ERROR)> responseCallback); | ||
}; |
42 changes: 42 additions & 0 deletions
42
examples/tv-casting-app/tv-casting-common/include/LevelControl.h
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,42 @@ | ||
/* | ||
* | ||
* 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 "MediaCommandBase.h" | ||
|
||
#include <functional> | ||
#include <zap-generated/CHIPClusters.h> | ||
|
||
class StepCommand | ||
: public MediaCommandBase<chip::app::Clusters::LevelControl::Commands::Step::Type, chip::app::DataModel::NullObjectType> | ||
{ | ||
public: | ||
StepCommand() : MediaCommandBase(chip::app::Clusters::LevelControl::Id) {} | ||
|
||
CHIP_ERROR Invoke(chip::app::Clusters::LevelControl::StepMode stepMode, uint8_t stepSize, uint16_t transitionTime, | ||
uint8_t optionMask, uint8_t optionOverride, std::function<void(CHIP_ERROR)> responseCallback); | ||
}; | ||
|
||
class MoveToLevelCommand | ||
: public MediaCommandBase<chip::app::Clusters::LevelControl::Commands::MoveToLevel::Type, chip::app::DataModel::NullObjectType> | ||
{ | ||
public: | ||
MoveToLevelCommand() : MediaCommandBase(chip::app::Clusters::LevelControl::Id) {} | ||
|
||
CHIP_ERROR Invoke(uint8_t level, uint16_t transitionTime, uint8_t optionMask, uint8_t optionOverride, | ||
std::function<void(CHIP_ERROR)> responseCallback); | ||
}; |
76 changes: 76 additions & 0 deletions
76
examples/tv-casting-app/tv-casting-common/include/MediaCommandBase.h
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,76 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
#pragma once | ||
|
||
#include "TargetVideoPlayerInfo.h" | ||
|
||
#include <controller/CHIPCluster.h> | ||
#include <functional> | ||
|
||
template <typename RequestType, typename ResponseType> | ||
class MediaCommandBase | ||
{ | ||
public: | ||
MediaCommandBase(chip::ClusterId clusterId) { mClusterId = clusterId; } | ||
|
||
CHIP_ERROR SetTarget(TargetVideoPlayerInfo & mTargetVideoPlayerInfo, chip::EndpointId tvEndpoint) | ||
{ | ||
mOperationalDeviceProxy = mTargetVideoPlayerInfo.GetOperationalDeviceProxy(); | ||
if (mOperationalDeviceProxy == nullptr) | ||
{ | ||
ChipLogError(AppServer, "Failed in getting an instance of OperationalDeviceProxy"); | ||
return CHIP_ERROR_PEER_NODE_NOT_FOUND; | ||
} | ||
|
||
mTvEndpoint = tvEndpoint; | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR Invoke(RequestType request, std::function<void(CHIP_ERROR)> responseCallback) | ||
{ | ||
VerifyOrDieWithMsg(mOperationalDeviceProxy != nullptr, AppServer, "Target unknown"); | ||
|
||
sResponseCallback = responseCallback; | ||
|
||
class MediaClusterBase : public chip::Controller::ClusterBase | ||
{ | ||
public: | ||
MediaClusterBase(chip::Messaging::ExchangeManager & exchangeManager, const chip::SessionHandle & session, | ||
chip::ClusterId cluster, chip::EndpointId endpoint) : | ||
ClusterBase(exchangeManager, session, cluster, endpoint) | ||
{} | ||
}; | ||
|
||
MediaClusterBase cluster(*mOperationalDeviceProxy->GetExchangeManager(), | ||
mOperationalDeviceProxy->GetSecureSession().Value(), mClusterId, mTvEndpoint); | ||
return cluster.InvokeCommand(request, nullptr, OnSuccess, OnFailure); | ||
} | ||
|
||
static void OnSuccess(void * context, const ResponseType & response) { sResponseCallback(CHIP_NO_ERROR); } | ||
|
||
static void OnFailure(void * context, CHIP_ERROR error) { sResponseCallback(error); } | ||
|
||
protected: | ||
chip::ClusterId mClusterId; | ||
chip::OperationalDeviceProxy * mOperationalDeviceProxy = nullptr; | ||
chip::EndpointId mTvEndpoint; | ||
static std::function<void(CHIP_ERROR)> sResponseCallback; | ||
}; | ||
|
||
template <typename RequestType, typename ResponseType> | ||
std::function<void(CHIP_ERROR)> MediaCommandBase<RequestType, ResponseType>::sResponseCallback = {}; |
Oops, something went wrong.