-
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.
- Loading branch information
Showing
6 changed files
with
35,342 additions
and
34,988 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
56 changes: 56 additions & 0 deletions
56
src/controller/java/templates/CHIPClustersSubscribe-JNI.zapt
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,56 @@ | ||
{{> header}} | ||
{{#if (chip_has_client_clusters)}} | ||
#include "CHIPReadCallbacks.h" | ||
|
||
#include <app-common/zap-generated/cluster-objects.h> | ||
#include <zap-generated/CHIPClusters.h> | ||
|
||
#include <controller/java/AndroidClusterExceptions.h> | ||
#include <controller/java/CHIPDefaultCallbacks.h> | ||
#include <jni.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <platform/PlatformManager.h> | ||
|
||
#define JNI_METHOD(RETURN, CLASS_NAME, METHOD_NAME) \ | ||
extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipClusters_00024##CLASS_NAME##_##METHOD_NAME | ||
|
||
{{#chip_client_clusters}} | ||
{{#chip_server_cluster_attributes}} | ||
{{#unless (isStrEqual chipCallback.name "Unsupported")}} | ||
{{#if isReportableAttribute}} | ||
JNI_METHOD(void, {{asCamelCased ../name false}}Cluster, subscribe{{asCamelCased name false}}Attribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint minInterval, jint maxInterval) | ||
{ | ||
chip::DeviceLayer::StackLock lock; | ||
{{~#*inline "callbackName"~}} | ||
{{~#if_in_global_responses~}} | ||
CHIP{{chipCallback.name}}AttributeCallback | ||
{{~else~}} | ||
CHIP{{asCamelCased parent.name false}}{{asCamelCased name false}}AttributeCallback | ||
{{~/if_in_global_responses~}} | ||
{{~/inline}} | ||
|
||
std::unique_ptr<{{>callbackName}}, void (*)({{>callbackName}} *)> onSuccess(chip::Platform::New<{{>callbackName}}>(callback, true), chip::Platform::Delete<{{>callbackName}}>); | ||
VerifyOrReturn(onSuccess.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native success callback", CHIP_ERROR_NO_MEMORY)); | ||
|
||
std::unique_ptr<chip::CHIPDefaultFailureCallback, void (*)(chip::CHIPDefaultFailureCallback *)> onFailure(chip::Platform::New<chip::CHIPDefaultFailureCallback>(callback), chip::Platform::Delete<chip::CHIPDefaultFailureCallback>); | ||
VerifyOrReturn(onFailure.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native failure callback", CHIP_ERROR_NO_MEMORY)); | ||
|
||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
chip::Controller::{{asCamelCased ../name false}}Cluster * cppCluster = reinterpret_cast<chip::Controller::{{asCamelCased ../name false}}Cluster *>(clusterPtr); | ||
VerifyOrReturn(cppCluster != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Could not get native cluster", CHIP_ERROR_INCORRECT_STATE)); | ||
|
||
using TypeInfo = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo; | ||
auto successFn = chip::Callback::Callback<CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallbackType>::FromCancelable(onSuccess->Cancel()); | ||
auto failureFn = chip::Callback::Callback<CHIPDefaultFailureCallbackType>::FromCancelable(onFailure->Cancel()); | ||
|
||
err = cppCluster->SubscribeAttribute<TypeInfo>(onSuccess->mContext, successFn->mCall, failureFn->mCall, static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval), {{>callbackName}}::OnSubscriptionEstablished); | ||
VerifyOrReturn(err == CHIP_NO_ERROR, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error subscribing to attribute", err)); | ||
|
||
onSuccess.release(); | ||
onFailure.release(); | ||
} | ||
{{/if}} | ||
{{/unless}} | ||
{{/chip_server_cluster_attributes}} | ||
{{/chip_client_clusters}} | ||
{{/if}} |
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.