Skip to content

Commit

Permalink
Add ability to run tv casting app cert tests from the UI (#24559)
Browse files Browse the repository at this point in the history
* Add ability to run tv casting app cert tests from the UI

* Restyled by clang-format

* Remove some comments added by the IDE

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Dec 8, 2023
1 parent 52927fb commit 2310480
Show file tree
Hide file tree
Showing 6 changed files with 584 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1137,5 +1137,52 @@
requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler
successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback
failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback;
/*!
@brief Send a OnOff:On request to a TV
@param contentApp Content app endpoint to target
@param responseCallback Callback for when the response has been received
@param clientQueue Queue to invoke callbacks on
@param requestSentHandler Handler to call on sending the request
*/
- (void)onOff_on:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;

/*!
@brief Send a OnOff:Off request to a TV
@param contentApp Content app endpoint to target
@param responseCallback Callback for when the response has been received
@param clientQueue Queue to invoke callbacks on
@param requestSentHandler Handler to call on sending the request
*/
- (void)onOff_off:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;

/*!
@brief Send a OnOff:Toggle request to a TV
@param contentApp Content app endpoint to target
@param responseCallback Callback for when the response has been received
@param clientQueue Queue to invoke callbacks on
@param requestSentHandler Handler to call on sending the request
*/
- (void)onOff_toggle:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;
@end
#endif /* CastingServerBridge_h */
Original file line number Diff line number Diff line change
Expand Up @@ -2156,4 +2156,74 @@ - (void)applicationBasic_readApplicationVersion:(ContentApp * _Nonnull)contentAp
});
}

- (void)onOff_on:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler
{
ChipLogProgress(AppServer, "CastingServerBridge().onOff_on() called on Content App with endpoint ID %d", contentApp.endpointId);

[_commandResponseCallbacks setObject:responseCallback forKey:@"onOff_on"];
dispatch_async(_chipWorkQueue, ^{
TargetEndpointInfo endpoint;
[ConversionUtils convertToCppTargetEndpointInfoFrom:contentApp outTargetEndpointInfo:endpoint];

CHIP_ERROR err = CastingServer::GetInstance()->OnOff_On(&endpoint, [](CHIP_ERROR err) {
void (^responseCallback)(bool) =
[[CastingServerBridge getSharedInstance].commandResponseCallbacks objectForKey:@"onOff_on"];
responseCallback(CHIP_NO_ERROR == err);
});
dispatch_async(clientQueue, ^{
requestSentHandler(CHIP_NO_ERROR == err);
});
});
}

- (void)onOff_off:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler
{
ChipLogProgress(
AppServer, "CastingServerBridge().onOff_off() called on Content App with endpoint ID %d", contentApp.endpointId);

[_commandResponseCallbacks setObject:responseCallback forKey:@"onOff_off"];
dispatch_async(_chipWorkQueue, ^{
TargetEndpointInfo endpoint;
[ConversionUtils convertToCppTargetEndpointInfoFrom:contentApp outTargetEndpointInfo:endpoint];

CHIP_ERROR err = CastingServer::GetInstance()->OnOff_Off(&endpoint, [](CHIP_ERROR err) {
void (^responseCallback)(bool) =
[[CastingServerBridge getSharedInstance].commandResponseCallbacks objectForKey:@"onOff_off"];
responseCallback(CHIP_NO_ERROR == err);
});
dispatch_async(clientQueue, ^{
requestSentHandler(CHIP_NO_ERROR == err);
});
});
}

- (void)onOff_toggle:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler
{
ChipLogProgress(
AppServer, "CastingServerBridge().onOff_toggle() called on Content App with endpoint ID %d", contentApp.endpointId);

[_commandResponseCallbacks setObject:responseCallback forKey:@"onOff_toggle"];
dispatch_async(_chipWorkQueue, ^{
TargetEndpointInfo endpoint;
[ConversionUtils convertToCppTargetEndpointInfoFrom:contentApp outTargetEndpointInfo:endpoint];

CHIP_ERROR err = CastingServer::GetInstance()->OnOff_Toggle(&endpoint, [](CHIP_ERROR err) {
void (^responseCallback)(bool) =
[[CastingServerBridge getSharedInstance].commandResponseCallbacks objectForKey:@"onOff_toggle"];
responseCallback(CHIP_NO_ERROR == err);
});
dispatch_async(clientQueue, ^{
requestSentHandler(CHIP_NO_ERROR == err);
});
});
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
3CCB8748286A5D0F00771BAD /* CommissioningViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C7507B82853EFF000D7DB3A /* CommissioningViewModel.swift */; };
3CCB8749286A5D0F00771BAD /* ContentLauncherView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CA19434285BA780004768D5 /* ContentLauncherView.swift */; };
3CCB874A286A5D0F00771BAD /* ContentLauncherViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CA19436285BA877004768D5 /* ContentLauncherViewModel.swift */; };
EAF14299296D561900E17793 /* CertTestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF14298296D561900E17793 /* CertTestView.swift */; };
EAF1429B296D57DF00E17793 /* CertTestViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF1429A296D57DF00E17793 /* CertTestViewModel.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -64,6 +66,8 @@
3CC0E9002841DD3500EC6A18 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
3CC0E90C2841DECC00EC6A18 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
3CCB872A28690A5D00771BAD /* MatterTvCastingBridge.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = MatterTvCastingBridge.framework; sourceTree = BUILT_PRODUCTS_DIR; };
EAF14298296D561900E17793 /* CertTestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertTestView.swift; sourceTree = "<group>"; };
EAF1429A296D57DF00E17793 /* CertTestViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertTestViewModel.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -109,6 +113,8 @@
children = (
3CC0E8FD2841DD3500EC6A18 /* Assets.xcassets */,
3C75075E284C1DF800D7DB3A /* TvCasting.entitlements */,
EAF14298296D561900E17793 /* CertTestView.swift */,
EAF1429A296D57DF00E17793 /* CertTestViewModel.swift */,
3CC0E8F92841DD3400EC6A18 /* TvCastingApp.swift */,
3CC0E8FB2841DD3400EC6A18 /* ContentView.swift */,
3C81C75228F8C79E001CB9D1 /* StartFromCacheView.swift */,
Expand Down Expand Up @@ -226,11 +232,13 @@
3CCB8746286A5D0F00771BAD /* CommissionerDiscoveryViewModel.swift in Sources */,
3C81C75928F8E42D001CB9D1 /* ConnectionViewModel.swift in Sources */,
3CA1CA7A28E281080023ED44 /* ClusterSelectorView.swift in Sources */,
EAF14299296D561900E17793 /* CertTestView.swift in Sources */,
3CCB8747286A5D0F00771BAD /* CommissioningView.swift in Sources */,
3CCB8748286A5D0F00771BAD /* CommissioningViewModel.swift in Sources */,
3CA1CA7E28E284950023ED44 /* MediaPlaybackViewModel.swift in Sources */,
3CCB8749286A5D0F00771BAD /* ContentLauncherView.swift in Sources */,
3CCB874A286A5D0F00771BAD /* ContentLauncherViewModel.swift in Sources */,
EAF1429B296D57DF00E17793 /* CertTestViewModel.swift in Sources */,
3C81C75728F8E418001CB9D1 /* ConnectionView.swift in Sources */,
3CC0E8FC2841DD3400EC6A18 /* ContentView.swift in Sources */,
3CA1CA7C28E282150023ED44 /* MediaPlaybackView.swift in Sources */,
Expand Down Expand Up @@ -371,7 +379,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"TvCasting/Preview Content\"";
DEVELOPMENT_TEAM = R7NUZ7N74U;
DEVELOPMENT_TEAM = KCRB72LX9T;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -441,7 +449,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"TvCasting/Preview Content\"";
DEVELOPMENT_TEAM = R7NUZ7N74U;
DEVELOPMENT_TEAM = KCRB72LX9T;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

/**
*
* Copyright (c) 2020-2022 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.
*/

import SwiftUI

struct CertTestView: View {
@StateObject var viewModel = CertTestViewModel()
@State private var targetContentAppId: String = ""

var body: some View {
VStack(alignment: .leading) {
if(viewModel.contentAppIds.isEmpty)
{
Text("No Content Launcher cluster supporting content apps found on this video player!")
}
else
{
HStack() {
Text("Content App Endpoint Id")

VStack()
{
Picker("Select", selection: $targetContentAppId) {
Text("Select").tag(nil as String?)
ForEach(viewModel.contentAppIds, id: \.self) { contentAppId in
Text(String(contentAppId))
}
}
.pickerStyle(.menu)
.padding(2)
}
.border(.secondary)
}

Button("Launch Test") {
viewModel.launchTest(targetContentAppId: targetContentAppId)
}
.background(Color.blue)
.foregroundColor(Color.white)
.cornerRadius(4)
.border(Color.black, width: 1)
.padding()

Text(viewModel.status ?? "")
}

}
.navigationTitle("Cert Test Launcher")
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .top)
.onAppear(perform: {
viewModel.populateAndInitializeEndpoints()
})
}
}
Loading

0 comments on commit 2310480

Please sign in to comment.