Skip to content

Commit

Permalink
[Android, Java, Kotlin] Divide IM API in java and kotlin. (project-ch…
Browse files Browse the repository at this point in the history
…ip#31758)

* Divide Matter Interaction client JNI API

* Remove java class name in JNI

* Move to Jni layer implementation

* divide java,kotlin jni function

* Restyled by whitespace

* Restyled by google-java-format

* Restyled by clang-format

* Restyled by gn

* Fix static check

* Chaange AsString -> Format

* Add kotlin config

* Fix kotlin build error

* Add Kotlin Callback api

* Modify interaction class

* Fix from comments

* Restyled by whitespace

* Restyled by clang-format

* Fix kotlin static error

* Add to support wildcard value

* Update kotlin codestyle

* add null set

* add header file in gn

* Update from comment

* Restyled by clang-format

* Add err code check

* Update from comments

* Update from comments

* Restyled by whitespace

* Restyled by google-java-format

* Restyled by clang-format

* Update kotlin detect

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
joonhaengHeo and restyled-commits authored Feb 16, 2024
1 parent 8753139 commit bc86710
Show file tree
Hide file tree
Showing 35 changed files with 2,449 additions and 1,319 deletions.
12 changes: 12 additions & 0 deletions kotlin-detect-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ style:
- "**/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/clusterinteraction/ClusterInteractionFragment.kt"
- "**/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt"
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.kt"
- "**/src/controller/java/src/matter/controller/ReportCallbackJni.kt"
- "**/src/controller/java/src/matter/onboardingpayload/Base38.kt"
- "**/src/controller/java/generated/java/**/*"
ForbiddenComment:
Expand Down Expand Up @@ -184,6 +185,9 @@ style:
excludes:
- "**/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt"
- "**/src/controller/java/generated/java/**/*"
- "**/src/controller/java/src/matter/controller/Messages.kt"
- "**/src/controller/java/src/matter/controller/model/Paths.kt"
- "**/src/controller/java/src/matter/controller/ReportCallbackJni.kt"
- "**/src/controller/java/src/matter/onboardingpayload/OnboardingPayload.kt"
UseCheckOrError:
excludes:
Expand All @@ -205,6 +209,7 @@ style:
FunctionOnlyReturningConstant:
excludes:
- "**/src/controller/java/generated/java/**/*"
- "**/src/controller/java/src/matter/controller/Messages.kt"
- "**/src/controller/java/src/matter/onboardingpayload/QRCodeOnboardingPayloadGenerator.kt"

exceptions:
Expand Down Expand Up @@ -301,6 +306,8 @@ complexity:
- "**/src/controller/java/src/matter/controller/MatterControllerImpl.kt"
- "**/src/controller/java/src/matter/controller/CompletionListenerAdapter.kt"
- "**/src/controller/java/src/matter/controller/MatterController.kt"
- "**/src/controller/java/src/matter/controller/ReportCallbackJni.kt"
- "**/src/controller/java/src/matter/controller/model/States.kt"
- "**/src/controller/java/tests/matter/jsontlv/JsonToTlvToJsonTest.kt"
- "**/src/controller/java/tests/matter/onboardingpayload/ManualCodeTest.kt"
- "**/src/controller/java/tests/matter/onboardingpayload/QRCodeTest.kt"
Expand All @@ -314,12 +321,17 @@ complexity:
- "**/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/clusterinteraction/ClusterDetailFragment.kt"
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Command.kt"
- "**/src/controller/java/generated/java/**/*"
- "**/src/controller/java/src/matter/controller/MatterControllerImpl.kt"
- "**/src/controller/java/src/matter/controller/InvokeCallbackJni.kt"
- "**/src/controller/java/src/matter/controller/ReportCallbackJni.kt"
- "**/src/controller/java/src/matter/controller/model/States.kt"
- "**/src/controller/java/src/matter/onboardingpayload/OnboardingPayload.kt"
LongMethod:
excludes:
- "**/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/AddressCommissioningFragment.kt"
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.kt"
- "**/src/controller/java/generated/java/**/*"
- "**/src/controller/java/src/matter/controller/MatterControllerImpl.kt"
- "**/src/controller/java/src/matter/onboardingpayload/Base38.kt"
- "**/src/controller/java/src/matter/onboardingpayload/ManualOnboardingPayloadGenerator.kt"
- "**/src/controller/java/src/matter/onboardingpayload/ManualOnboardingPayloadParser.kt"
Expand Down
46 changes: 12 additions & 34 deletions src/controller/java/AndroidCallbacks-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,44 @@ using namespace chip::Controller;

JNI_METHOD(jlong, GetConnectedDeviceCallbackJni, newCallback)(JNIEnv * env, jobject self, jobject callback)
{
chip::DeviceLayer::StackLock lock;
GetConnectedDeviceCallback * connectedDeviceCallback = chip::Platform::New<GetConnectedDeviceCallback>(self, callback);
return reinterpret_cast<jlong>(connectedDeviceCallback);
return newConnectedDeviceCallback(env, self, callback);
}

JNI_METHOD(void, GetConnectedDeviceCallbackJni, deleteCallback)(JNIEnv * env, jobject self, jlong callbackHandle)
{
chip::DeviceLayer::StackLock lock;
GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast<GetConnectedDeviceCallback *>(callbackHandle);
VerifyOrReturn(connectedDeviceCallback != nullptr, ChipLogError(Controller, "GetConnectedDeviceCallback handle is nullptr"));
chip::Platform::Delete(connectedDeviceCallback);
deleteConnectedDeviceCallback(env, self, callbackHandle);
}

JNI_METHOD(jlong, ReportCallbackJni, newCallback)
(JNIEnv * env, jobject self, jobject subscriptionEstablishedCallbackJava, jobject reportCallbackJava,
jobject resubscriptionAttemptCallbackJava)
(JNIEnv * env, jobject self, jobject subscriptionEstablishedCallbackJava, jobject resubscriptionAttemptCallbackJava)
{
chip::DeviceLayer::StackLock lock;
ReportCallback * reportCallback = chip::Platform::New<ReportCallback>(self, subscriptionEstablishedCallbackJava,
reportCallbackJava, resubscriptionAttemptCallbackJava);
return reinterpret_cast<jlong>(reportCallback);
return newReportCallback(env, self, subscriptionEstablishedCallbackJava, resubscriptionAttemptCallbackJava,
"()Lchip/devicecontroller/model/NodeState;");
}

JNI_METHOD(void, ReportCallbackJni, deleteCallback)(JNIEnv * env, jobject self, jlong callbackHandle)
{
chip::DeviceLayer::StackLock lock;
ReportCallback * reportCallback = reinterpret_cast<ReportCallback *>(callbackHandle);
VerifyOrReturn(reportCallback != nullptr, ChipLogError(Controller, "ReportCallback handle is nullptr"));
chip::Platform::Delete(reportCallback);
deleteReportCallback(env, self, callbackHandle);
}

JNI_METHOD(jlong, WriteAttributesCallbackJni, newCallback)
(JNIEnv * env, jobject self, jobject writeAttributesCallbackJava)
(JNIEnv * env, jobject self)
{
chip::DeviceLayer::StackLock lock;
WriteAttributesCallback * writeAttributesCallback =
chip::Platform::New<WriteAttributesCallback>(self, writeAttributesCallbackJava);
return reinterpret_cast<jlong>(writeAttributesCallback);
return newWriteAttributesCallback(env, self);
}

JNI_METHOD(void, WriteAttributesCallbackJni, deleteCallback)(JNIEnv * env, jobject self, jlong callbackHandle)
{
chip::DeviceLayer::StackLock lock;
WriteAttributesCallback * writeAttributesCallback = reinterpret_cast<WriteAttributesCallback *>(callbackHandle);
VerifyOrReturn(writeAttributesCallback != nullptr, ChipLogError(Controller, "WriteAttributesCallback handle is nullptr"));
chip::Platform::Delete(writeAttributesCallback);
deleteWriteAttributesCallback(env, self, callbackHandle);
}

JNI_METHOD(jlong, InvokeCallbackJni, newCallback)
(JNIEnv * env, jobject self, jobject invokeCallbackJava)
(JNIEnv * env, jobject self)
{
chip::DeviceLayer::StackLock lock;
InvokeCallback * invokeCallback = chip::Platform::New<InvokeCallback>(self, invokeCallbackJava);
return reinterpret_cast<jlong>(invokeCallback);
return newInvokeCallback(env, self);
}

JNI_METHOD(void, InvokeCallbackJni, deleteCallback)(JNIEnv * env, jobject self, jlong callbackHandle)
{
chip::DeviceLayer::StackLock lock;
InvokeCallback * invokeCallback = reinterpret_cast<InvokeCallback *>(callbackHandle);
VerifyOrReturn(invokeCallback != nullptr, ChipLogError(Controller, "InvokeCallback handle is nullptr"));
chip::Platform::Delete(invokeCallback);
deleteInvokeCallback(env, self, callbackHandle);
}
Loading

0 comments on commit bc86710

Please sign in to comment.