Skip to content

Commit 633888e

Browse files
Added code to test ContentLauncher
1 parent 77df561 commit 633888e

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/ContentLauncherLaunchURLExampleFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public View onCreateView(
140140
return null;
141141
});*/
142142

143-
//endpoint.testGetCluster();
143+
endpoint.testGetCluster();
144144
};
145145

146146
return inflater.inflate(R.layout.fragment_content_launcher, container, false);

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/Endpoint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public interface Endpoint {
3535

3636
boolean hasCluster(Class<? extends Cluster> clusterClass);
3737

38-
//void testGetCluster();
38+
void testGetCluster();
3939

4040
}

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayerDiscovery.java

-11
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,10 @@ public final class MatterCastingPlayerDiscovery implements CastingPlayerDiscover
3333
private static final String TAG = MatterCastingPlayerDiscovery.class.getSimpleName();
3434
private static MatterCastingPlayerDiscovery matterCastingPlayerDiscoveryInstance;
3535

36-
// Methods:
3736
public static MatterCastingPlayerDiscovery getInstance() {
3837
if (matterCastingPlayerDiscoveryInstance == null) {
3938
matterCastingPlayerDiscoveryInstance = new MatterCastingPlayerDiscovery();
4039
}
41-
42-
try
43-
{
44-
ChipDeviceController c = new ChipDeviceController(null);
45-
}
46-
catch(Throwable t)
47-
{
48-
Log.d(TAG, "Caught: " + t);
49-
}
50-
5140
return matterCastingPlayerDiscoveryInstance;
5241
};
5342

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterEndpoint.java

+22
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@
2424
import com.matter.casting.support.SuccessCallback;
2525
import java.util.List;
2626
import java.util.Objects;
27+
import java.util.Optional;
2728
import java.util.concurrent.CompletableFuture;
2829
import java.util.concurrent.ExecutionException;
2930
import java.util.concurrent.TimeUnit;
3031
import java.util.concurrent.TimeoutException;
3132

33+
import chip.devicecontroller.ChipClusters;
34+
import chip.devicecontroller.ChipStructs;
35+
3236
public class MatterEndpoint implements Endpoint {
3337
private static final String TAG = MatterEndpoint.class.getSimpleName();
3438
protected long _cppEndpoint;
@@ -53,6 +57,7 @@ public class MatterEndpoint implements Endpoint {
5357
protected CompletableFuture<Long> getDeviceProxy()
5458
{
5559
CompletableFuture<Long> future = new CompletableFuture<>();
60+
5661
getDeviceProxy(new SuccessCallback<Long>() {
5762
@Override
5863
public void handle(Long deviceProxyPtr) {
@@ -86,6 +91,23 @@ public void testGetCluster()
8691
try {
8792
Long deviceProxy = deviceProxyFuture.get(5, TimeUnit.SECONDS);
8893
Log.d(TAG, "getDeviceProxy returned value " + deviceProxy);
94+
ChipClusters.ContentLauncherCluster cluster = new ChipClusters.ContentLauncherCluster(deviceProxy, getId());
95+
cluster.launchURL(new ChipClusters.ContentLauncherCluster.LauncherResponseCallback() {
96+
@Override
97+
public void onSuccess(Integer status, Optional<String> data) {
98+
Log.d(TAG, "Content launcher success " + status + data);
99+
}
100+
101+
@Override
102+
public void onError(Exception error) {
103+
Log.e(TAG, "Content launcher failure " + error);
104+
}
105+
}
106+
,"my test url",
107+
Optional.of("my display str"),
108+
Optional.empty()
109+
);
110+
89111
} catch (ExecutionException | InterruptedException | TimeoutException e) {
90112
Log.e(TAG, "getDeviceProxy exception" + e);
91113
}

examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/MatterEndpoint-JNI.cpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,20 @@ JNI_METHOD(jobject, getCastingPlayer)
8787
}
8888

8989
JNI_METHOD(void, getDeviceProxy)
90-
(JNIEnv * env, jobject thiz, jobject callbackHandle)
90+
(JNIEnv * env, jobject thiz, jobject jSuccessHandler, jobject jFailureHandler)
9191
{
9292
chip::DeviceLayer::StackLock lock;
9393
ChipLogProgress(AppServer, "MatterEndpoint-JNI::getDeviceProxy() called");
9494
Endpoint * endpoint = support::convertEndpointFromJavaToCpp(thiz);
9595
VerifyOrReturn(endpoint != nullptr, ChipLogError(AppServer, "MatterEndpoint-JNI::getDeviceProxy() endpoint == nullptr"));
9696

97+
SessionContextJNI * context = new SessionContextJNI();
98+
context->successHandler = jSuccessHandler;
99+
context->failureHandler = jFailureHandler;
100+
101+
DeviceProxyMatterSuccessHandlerJNI successHandler;
102+
successHandler.SetUp(env, jSuccessHandler);
103+
97104
/*chip::Controller::GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast<chip::Controller::GetConnectedDeviceCallback *>(callbackHandle);
98105
99106
chip::NodeId nodeId = endpoint->GetCastingPlayer()->GetNodeId();
@@ -102,39 +109,30 @@ JNI_METHOD(void, getDeviceProxy)
102109
chip::ScopedNodeId(endpoint->GetCastingPlayer()->GetNodeId(), endpoint->GetCastingPlayer()->GetFabricIndex()), &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);*/
103110

104111
//endpoint->GetCastingPlayer()->FindOrEstablishSession(&nodeId, &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);
105-
/*
112+
endpoint->GetCastingPlayer()->FindOrEstablishSession(context,
106113
[](void * context, chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) {
107114
ChipLogProgress(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() success");
108-
GetConnectedDeviceCallback * connectedDeviceCallback = static_cast<GetConnectedDeviceCallback *>(context);
109-
110-
SessionContextJNI * __context = static_cast<SessionContextJNI *>(context);
111-
112115
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
113-
//chip::DeviceLayer::StackUnlock unlock;
114116
OperationalDeviceProxy * device = new OperationalDeviceProxy(&exchangeMgr, sessionHandle);
115-
ChipLogProgress(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() before CallBooleanMethod");
116-
jclass completableFutureClass = env->GetObjectClass(__context->completableFuture);
117-
jmethodID getMethod = env->GetMethodID(completableFutureClass, "complete", "(Ljava/lang/Object;)Z");
117+
SessionContextJNI * _context = static_cast<SessionContextJNI *>(context);
118118

119-
env->CallBooleanMethod(__context->completableFuture, getMethod, device);
120-
ChipLogProgress(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() after CallBooleanMethod");
119+
DeviceProxyMatterSuccessHandlerJNI successHandler;
120+
successHandler.SetUp(env, _context->successHandler);
121+
successHandler.Handle(reinterpret_cast<jlong>(device));
121122
},
122123
[](void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error) {
123124
ChipLogError(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() failure");
124-
SessionContextJNI * __context = static_cast<SessionContextJNI *>(context);
125-
126125
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
127126
jstring errorMessage = env->NewStringUTF(error.Format());
128127
VerifyOrReturn(errorMessage != nullptr,
129128
ChipLogError(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() Could not create errorMessage"));
130129
jobject throwableObject = env->NewObject(MatterEndpointJNIMgr().mThrowableClass, MatterEndpointJNIMgr().mThrowableConstructor, errorMessage);
131130
VerifyOrReturn(throwableObject != nullptr,
132-
ChipLogError(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() Could not create throwableObject"));*/
131+
ChipLogError(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() Could not create throwableObject"));
133132

134-
//chip::DeviceLayer::StackUnlock unlock;
135-
/* env->CallBooleanMethod(__context->completableFuture, MatterEndpointJNIMgr().mCompleteExceptionallyMethod, throwableObject);
133+
SessionContextJNI * __context = static_cast<SessionContextJNI *>(context);
136134
});
137-
*/
135+
138136
/*MatterEndpointJNIMgr().Init();
139137
// Setup completableFuture
140138
jobject completableFuture = env->NewGlobalRef(env->NewObject(MatterEndpointJNIMgr().mCompletableFutureClass, MatterEndpointJNIMgr().mCompletableFutureConstructor));

examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/MatterEndpoint-JNI.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace core {
3131
struct SessionContextJNI
3232
{
3333
public:
34-
Endpoint *endpoint;
35-
jobject completableFuture;
34+
jobject successHandler;
35+
jobject failureHandler;
3636
};
3737

3838
class MatterEndpointJNI

examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/MatterCallback-JNI.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ CHIP_ERROR MatterCallbackBaseJNI::SetUp(JNIEnv * env, jobject inHandler)
2626
mObject = env->NewGlobalRef(inHandler);
2727
VerifyOrExit(mObject != nullptr, ChipLogError(AppServer, "Failed to NewGlobalRef for handler object"));
2828

29-
mClazz = env->GetObjectClass(mObject);
29+
mClazz = env->GetObjectClass(inHandler);
3030
VerifyOrExit(mClazz != nullptr, ChipLogError(AppServer, "Failed to get handler Java class"));
3131

3232
mSuperClazz = env->GetSuperclass(mClazz);
3333
VerifyOrExit(mSuperClazz != nullptr, ChipLogError(AppServer, "Failed to get handler's parent's Java class"));
3434

35-
mMethod = env->GetMethodID(mSuperClazz, "handleInternal", mMethodSignature);
35+
mMethod = env->GetMethodID(mClazz, "handleInternal", mMethodSignature);
3636
if (mMethod == nullptr)
3737
{
3838
ChipLogError(AppServer, "Failed to access 'handleInternal' method with signature %s", mMethodSignature);

examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/MatterCallback-JNI.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ template <typename T>
4747
class MatterSuccessHandlerJNI : public MatterCallbackBaseJNI
4848
{
4949
public:
50-
MatterSuccessHandlerJNI(const char * methodSignature) : MatterCallbackBaseJNI(methodSignature) {}
50+
MatterSuccessHandlerJNI() : MatterCallbackBaseJNI("(Ljava/lang/Object;)V") {}
5151

5252
virtual ~MatterSuccessHandlerJNI() = 0;
5353

@@ -76,10 +76,8 @@ class MatterSuccessHandlerJNI : public MatterCallbackBaseJNI
7676
template <typename T>
7777
MatterSuccessHandlerJNI<T>::~MatterSuccessHandlerJNI(){};
7878

79-
class DeviceProxyMatterSuccessHandlerJNI
80-
: public MatterSuccessHandlerJNI<jlong>
79+
class DeviceProxyMatterSuccessHandlerJNI: public MatterSuccessHandlerJNI<jlong>
8180
{
8281
public:
83-
DeviceProxyMatterSuccessHandlerJNI() : MatterSuccessHandlerJNI("(Ljava/lang/Long;)V") {}
8482
jobject ConvertToJObject(jlong responseData);
8583
};

0 commit comments

Comments
 (0)