-
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.
stop using
controller-clusters.zap
in zap_generate_all (#26948)
* separate out zap input, so we have control over it * Switch zcl_clusters on for python * Fix more loops to use the generic non-zap helpers * Switch zap generate to use zcl * update generate.py and change CHIPClientCallbacks.zapt * Restyled by autopep8 * Fix another comment location * Remove import from optional to make linter happy * Skip restyling java generated files * Run zap_regen_all * Fix restyle path to include a glob * Switch global callbacks to jinja * update unit tests * Fix global logic and codegen * Codegen updated, validated that global callbacks is now identical * Fix lint issue * Update codegen logic to not depend on zap for src/controller/java/templates/ClusterInfo-java.zapt * Also fix src/controller/java/templates/ChipClusters-java.zapt * Use ANDROID_NDK_HOME env even for newer gradle build as the environment variable itself was deprecated (see https://github.com/android/ndk-samples/wiki/Configure-NDK-Path#android_ndk_home) * Fixed indent a bit * Updated comments a bit about controller-clusters.zap * Be explicit on matter file name on codegen * Remove duplicate output name * Fix file path for CHIPClientCallbacks.h * Update scripts/tools/zap_regen_all.py Co-authored-by: Boris Zbarsky <[email protected]> * Do some renames and code review updates --------- Co-authored-by: Andrei Litvin <[email protected]> Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Boris Zbarsky <[email protected]>
- Loading branch information
Showing
15 changed files
with
2,367 additions
and
857 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
76 changes: 76 additions & 0 deletions
76
scripts/py_matter_idl/matter_idl/generators/java/CHIPGlobalCallbacks_cpp.jinja
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 @@ | ||
#include <jni.h> | ||
#include <jni/CHIPReadCallbacks.h> | ||
#include <lib/support/JniReferences.h> | ||
#include <lib/support/JniTypeWrappers.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/SafeInt.h> | ||
#include <platform/PlatformManager.h> | ||
#include <controller/java/zap-generated/CHIPClientCallbacks.h> | ||
|
||
{% for type in globalTypes -%} | ||
{%- set typeLookup = idl | createLookupContext(None) -%} | ||
{%- set encodable = type.idl_type | globalAsEncodable(typeLookup) -%} | ||
CHIP{{type.name}}AttributeCallback::CHIP{{type.name}}AttributeCallback(jobject javaCallback, bool keepAlive) : | ||
chip::Callback::Callback<{{type.name}}AttributeCallback>(CallbackFn, this), keepAlive(keepAlive) | ||
{ | ||
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); | ||
if (env == nullptr) { | ||
ChipLogError(Zcl, "Could not create global reference for Java callback"); | ||
return; | ||
} | ||
javaCallbackRef = env->NewGlobalRef(javaCallback); | ||
if (javaCallbackRef == nullptr) { | ||
ChipLogError(Zcl, "Could not create global reference for Java callback"); | ||
} | ||
} | ||
|
||
CHIP{{type.name}}AttributeCallback::~CHIP{{type.name}}AttributeCallback() { | ||
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); | ||
if (env == nullptr) | ||
{ | ||
ChipLogError(Zcl, "Could not delete global reference for Java callback"); | ||
return; | ||
} | ||
env->DeleteGlobalRef(javaCallbackRef); | ||
} | ||
|
||
void CHIP{{type.name}}AttributeCallback::CallbackFn(void * context, {{type.cpp_type}} value) | ||
{ | ||
chip::DeviceLayer::StackUnlock unlock; | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
||
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); | ||
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNI env")); | ||
|
||
std::unique_ptr<CHIP{{type.name}}AttributeCallback, decltype(&maybeDestroy)> cppCallback(reinterpret_cast<CHIP{{type.name}}AttributeCallback *>(context), maybeDestroy); | ||
|
||
// It's valid for javaCallbackRef to be nullptr if the Java code passed in a | ||
// null callback. | ||
jobject javaCallbackRef = cppCallback.get()->javaCallbackRef; | ||
VerifyOrReturn(javaCallbackRef != nullptr, ChipLogDetail(Zcl, "Early return from attribute callback since Java callback is null")); | ||
|
||
jmethodID javaMethod; | ||
{%- if encodable.is_octet_string %} | ||
err = chip::JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B)V", &javaMethod); | ||
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Could not find onSuccess method")); | ||
|
||
VerifyOrReturn(chip::CanCastTo<uint32_t>(value.size()), ChipLogError(Zcl, "Value too long")); | ||
jbyteArray valueArr = env->NewByteArray(static_cast<uint32_t>(value.size())); | ||
env->ExceptionClear(); | ||
env->SetByteArrayRegion(valueArr, 0, static_cast<uint32_t>(value.size()), reinterpret_cast<const jbyte *>(value.data())); | ||
|
||
env->CallVoidMethod(javaCallbackRef, javaMethod, valueArr); | ||
{%- elif encodable.is_char_string %} | ||
err = chip::JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;)V", &javaMethod); | ||
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Could not find onSuccess method")); | ||
|
||
chip::UtfString valueStr(env, value); | ||
env->CallVoidMethod(javaCallbackRef, javaMethod, valueStr.jniValue()); | ||
{%- else %} | ||
err = chip::JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "({{encodable.unboxed_java_signature}})V", &javaMethod); | ||
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Could not find onSuccess method")); | ||
env->CallVoidMethod(javaCallbackRef, javaMethod, static_cast<{{encodable.jni_fundamental_type}}>(value)); | ||
{%- endif %} | ||
} | ||
|
||
{% endfor %} |
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
Oops, something went wrong.