From b7ce31b6569f453c2ea7db2380377f5ef1c5cdfc Mon Sep 17 00:00:00 2001 From: Sharad Binjola Date: Thu, 27 Jul 2023 15:55:19 -0700 Subject: [PATCH] Addressing cliffamzn@ feedback --- .../chip/casting/app/ConnectionFragment.java | 16 ++--- .../chip/casting/CommissioningCallbacks.java | 61 +++++++++++++------ .../main/jni/cpp/MatterCallbackHandler-JNI.h | 14 ++++- .../CastingServerBridge.h | 4 +- 4 files changed, 66 insertions(+), 29 deletions(-) diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java index 748727a21d2d31..d2a0f7952b6485 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java @@ -121,7 +121,7 @@ private void beginCommissioning( FailureCallback onConnectionFailure, SuccessCallback onNewOrUpdatedEndpoints) { Log.d(TAG, "Running commissioning"); - Object commissioningComplete = + MatterCallbackHandler commissioningCompleteCallback = new MatterCallbackHandler() { @Override public void handle(MatterError error) { @@ -161,12 +161,14 @@ public void handle(MatterError error) { } }; - CommissioningCallbacks commissioningCallbacks = new CommissioningCallbacks(); - commissioningCallbacks.setCommissioningComplete(commissioningComplete); - commissioningCallbacks.setSessionEstablishmentStarted(sessionEstablishmentStartedCallback); - commissioningCallbacks.setSessionEstablished(sessionEstablishedCallback); - commissioningCallbacks.setSessionEstablishmentError(sessionEstablishmentErrorCallback); - commissioningCallbacks.setSessionEstablishmentStopped(sessionEstablishmentStoppedCallback); + CommissioningCallbacks commissioningCallbacks = + new CommissioningCallbacks.Builder() + .commissioningComplete(commissioningCompleteCallback) + .sessionEstablishmentStarted(sessionEstablishmentStartedCallback) + .sessionEstablished(sessionEstablishedCallback) + .sessionEstablishmentError(sessionEstablishmentErrorCallback) + .sessionEstablishmentStopped(sessionEstablishmentStoppedCallback) + .build(); this.openCommissioningWindowSuccess = tvCastingApp.openBasicCommissioningWindow( diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java index 35cef2aa33b4ff..4d9105fd900661 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java @@ -46,43 +46,68 @@ public class CommissioningCallbacks { /** This is called when the commissioning has been completed */ private Object commissioningComplete; - public SuccessCallback getSessionEstablishmentStarted() { - return sessionEstablishmentStarted; + private CommissioningCallbacks(Builder builder) { + this.sessionEstablishmentStarted = builder.sessionEstablishmentStarted; + this.sessionEstablished = builder.sessionEstablished; + this.sessionEstablishmentError = builder.sessionEstablishmentError; + this.sessionEstablishmentStopped = builder.sessionEstablishmentStopped; + this.commissioningComplete = builder.commissioningComplete; } - public void setSessionEstablishmentStarted(SuccessCallback sessionEstablishmentStarted) { - this.sessionEstablishmentStarted = sessionEstablishmentStarted; + public SuccessCallback getSessionEstablishmentStarted() { + return sessionEstablishmentStarted; } public SuccessCallback getSessionEstablished() { return sessionEstablished; } - public void setSessionEstablished(SuccessCallback sessionEstablished) { - this.sessionEstablished = sessionEstablished; - } - public FailureCallback getSessionEstablishmentError() { return sessionEstablishmentError; } - public void setSessionEstablishmentError(FailureCallback sessionEstablishmentStopped) { - this.sessionEstablishmentError = sessionEstablishmentError; - } - public FailureCallback getSessionEstablishmentStopped() { return sessionEstablishmentStopped; } - public void setSessionEstablishmentStopped(FailureCallback sessionEstablishmentStopped) { - this.sessionEstablishmentStopped = sessionEstablishmentStopped; - } - public Object getCommissioningComplete() { return commissioningComplete; } - public void setCommissioningComplete(Object commissioningComplete) { - this.commissioningComplete = commissioningComplete; + public static class Builder { + private SuccessCallback sessionEstablishmentStarted; + private SuccessCallback sessionEstablished; + private FailureCallback sessionEstablishmentError; + private FailureCallback sessionEstablishmentStopped; + private Object commissioningComplete; + + public Builder sessionEstablishmentStarted(SuccessCallback sessionEstablishmentStarted) { + this.sessionEstablishmentStarted = sessionEstablishmentStarted; + return this; + } + + public Builder sessionEstablished(SuccessCallback sessionEstablished) { + this.sessionEstablished = sessionEstablished; + return this; + } + + public Builder sessionEstablishmentError(FailureCallback sessionEstablishmentError) { + this.sessionEstablishmentError = sessionEstablishmentError; + return this; + } + + public Builder sessionEstablishmentStopped(FailureCallback sessionEstablishmentStopped) { + this.sessionEstablishmentStopped = sessionEstablishmentStopped; + return this; + } + + public Builder commissioningComplete(Object commissioningComplete) { + this.commissioningComplete = commissioningComplete; + return this; + } + + public CommissioningCallbacks build() { + return new CommissioningCallbacks(this); + } } } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h index 9c4c72ddcfe2c2..c05eef016f32b3 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h @@ -108,14 +108,24 @@ class SessionEstablishmentStartedHandlerJNI : public SuccessHandlerJNI { public: SessionEstablishmentStartedHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {} - jobject ConvertToJObject(void * responseData) { return nullptr; } + jobject ConvertToJObject(void * responseData) + { + // return nullptr because the Java callback extends SuccessCallback and its handle() expects a Void param. + // It expects a Void becauase no value is passed as part of this callback. + return nullptr; + } }; class SessionEstablishedHandlerJNI : public SuccessHandlerJNI { public: SessionEstablishedHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {} - jobject ConvertToJObject(void * responseData) { return nullptr; } + jobject ConvertToJObject(void * responseData) + { + // return nullptr because the Java callback extends SuccessCallback and its handle() expects a Void param. + // It expects a Void becauase no value is passed as part of this callback. + return nullptr; + } }; class OnConnectionSuccessHandlerJNI : public SuccessHandlerJNI diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h index 162b536330e427..2489f982fb0645 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h @@ -110,14 +110,14 @@ @param clientQueue Queue to dispatch the call to the commissioningWindowRequestedHandler on + @param commissioningCallbackHandlers Optional parameter to specific handlers for callbacks during commissioning + @param onConnectionSuccessCallback Handles a VideoPlayer * once connection is successfully established @param onConnectionFailureCallback Handles MatterError if there is a failure in establishing connection @param onNewOrUpdatedEndpointCallback Handles a ContentApp * for each new ContentApp is found. May be called multiple times based on the number of ContentApp - - @param commissioningCallbackHandlers Optional parameter to specific handlers for callbacks during commissioning */ - (void)openBasicCommissioningWindow:(dispatch_queue_t _Nonnull)clientQueue commissioningCallbackHandlers:(CommissioningCallbackHandlers * _Nullable)commissioningCallbackHandlers