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.
- Loading branch information
1 parent
b481c7d
commit bb4ce80
Showing
8 changed files
with
300 additions
and
260 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...les/tv-casting-app/android/App/app/src/main/jni/cpp/clusters/MatterCommandObjects-JNI.cpp
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,95 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020-24 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 "MatterCommandObjects-JNI.h" | ||
|
||
namespace matter { | ||
namespace casting { | ||
namespace clusters { | ||
|
||
CHIP_ERROR ContentLauncherClusterLaunchURLCommand::GetCppRequestFromJava( | ||
jobject inRequest, chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type & outRequest) | ||
{ | ||
VerifyOrReturnValue(inRequest != nullptr, CHIP_NO_ERROR); | ||
|
||
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); | ||
|
||
jclass jRequestClass; | ||
ReturnErrorOnFailure(chip::JniReferences::GetInstance().GetClassRef( | ||
env, "com/matter/casting/clusters/MatterCommands$ContentLauncherClusterLaunchURLRequest", jRequestClass)); | ||
|
||
jfieldID jContentURLField = env->GetFieldID(jRequestClass, "contentURL", "Ljava/lang/String;"); | ||
jstring jContentURLObj = (jstring) env->GetObjectField(inRequest, jContentURLField); | ||
VerifyOrReturnError(jContentURLObj != nullptr, CHIP_ERROR_INVALID_ARGUMENT); | ||
outRequest.contentURL = chip::CharSpan::fromCharString(env->GetStringUTFChars(jContentURLObj, 0)); | ||
|
||
jfieldID jDisplayStringField = env->GetFieldID(jRequestClass, "displayString", "Ljava/lang/String;"); | ||
jstring jDisplayStringObj = (jstring) env->GetObjectField(inRequest, jDisplayStringField); | ||
if (jDisplayStringObj != nullptr) | ||
{ | ||
const char * nativeValue = env->GetStringUTFChars(jDisplayStringObj, 0); | ||
outRequest.displayString = chip::Optional<chip::CharSpan>(chip::CharSpan::fromCharString(nativeValue)); | ||
} | ||
else | ||
{ | ||
outRequest.displayString = chip::NullOptional; | ||
} | ||
|
||
// TODO: translate brandingInformation | ||
outRequest.brandingInformation = | ||
chip::MakeOptional(chip::app::Clusters::ContentLauncher::Structs::BrandingInformationStruct::Type()); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
jobject ContentLauncherClusterLaunchURLCommand::GetJResponseFromCpp( | ||
const chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type::ResponseType * response) | ||
{ | ||
VerifyOrReturnValue(response != nullptr, nullptr); | ||
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); | ||
|
||
jclass responseTypeClass = nullptr; | ||
VerifyOrReturnValue( | ||
chip::JniReferences::GetInstance().GetClassRef( | ||
env, "com/matter/casting/clusters/MatterCommands$ContentLauncherClusterResponse", responseTypeClass) == CHIP_NO_ERROR, | ||
nullptr, ChipLogError(AppServer, "convertResponseFromCppToJava could not get ContentLauncherClusterResponse class ref")); | ||
|
||
jmethodID constructor = env->GetMethodID(responseTypeClass, "<init>", "()V"); | ||
jobject jResponseObj = env->NewObject(responseTypeClass, constructor); | ||
|
||
if (response->data.HasValue()) | ||
{ | ||
jfieldID dataField = env->GetFieldID(responseTypeClass, "data", "Ljava/lang/String;"); | ||
char * buffer = new char[response->data.Value().size() + 1]; | ||
strncpy(buffer, response->data.Value().data(), response->data.Value().size()); | ||
buffer[response->data.Value().size()] = '\0'; | ||
env->SetObjectField(jResponseObj, dataField, env->NewStringUTF(buffer)); | ||
delete[] buffer; | ||
} | ||
|
||
jclass integerClass = env->FindClass("java/lang/Integer"); | ||
jmethodID valueOf = env->GetStaticMethodID(integerClass, "valueOf", "(I)Ljava/lang/Integer;"); | ||
jobject statusObj = env->CallStaticObjectMethod(integerClass, valueOf, static_cast<jint>(response->status)); | ||
jfieldID statusField = env->GetFieldID(responseTypeClass, "status", "Ljava/lang/Integer;"); | ||
env->SetObjectField(jResponseObj, statusField, statusObj); | ||
|
||
return jResponseObj; | ||
} | ||
|
||
}; // namespace clusters | ||
}; // namespace casting | ||
}; // namespace matter |
66 changes: 66 additions & 0 deletions
66
examples/tv-casting-app/android/App/app/src/main/jni/cpp/clusters/MatterCommandObjects-JNI.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,66 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020-24 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/MatterCommandTemplate-JNI.h" | ||
|
||
#include <app-common/zap-generated/cluster-objects.h> | ||
|
||
#include <jni.h> | ||
#include <lib/support/JniReferences.h> | ||
#include <lib/support/JniTypeWrappers.h> | ||
|
||
namespace matter { | ||
namespace casting { | ||
namespace clusters { | ||
|
||
class ContentLauncherClusterLaunchURLCommand | ||
: public core::MatterCommandTemplateJNI<chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type> | ||
{ | ||
public: | ||
ContentLauncherClusterLaunchURLCommand(jobject jCommand) : | ||
core::MatterCommandTemplateJNI<chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type>(jCommand) | ||
{} | ||
|
||
CHIP_ERROR GetCppRequestFromJava(jobject inRequest, | ||
chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type & outRequest); | ||
jobject GetJResponseFromCpp(const chip::app::Clusters::ContentLauncher::Commands::LaunchURL::Type::ResponseType * response); | ||
}; | ||
|
||
class MatterCommandManager | ||
{ | ||
public: | ||
static jobject Invoke(jobject jCommand, jobject jRequest, jobject jTimedInvokeTimeoutMs) | ||
{ | ||
const char * commandClassName = core::MatterCommandJNI::GetCommandClassName(jCommand); | ||
VerifyOrReturnValue(commandClassName != nullptr, nullptr, | ||
ChipLogError(AppServer, "MatterCommandManager: Could not get commandClassName from jCommand")); | ||
|
||
if (strcmp(commandClassName, "com.matter.casting.clusters.MatterCommands$ContentLauncherClusterLaunchURLCommand") == 0) | ||
{ | ||
auto * command = new clusters::ContentLauncherClusterLaunchURLCommand(jCommand); | ||
return command->Invoke(jRequest, jTimedInvokeTimeoutMs); | ||
} | ||
return nullptr; | ||
} | ||
}; | ||
|
||
}; // namespace clusters | ||
}; // namespace casting | ||
}; // namespace matter |
95 changes: 0 additions & 95 deletions
95
examples/tv-casting-app/android/App/app/src/main/jni/cpp/clusters/MatterCommands-JNI.cpp
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
examples/tv-casting-app/android/App/app/src/main/jni/cpp/clusters/MatterCommands-JNI.h
This file was deleted.
Oops, something went wrong.
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.