@@ -87,13 +87,20 @@ JNI_METHOD(jobject, getCastingPlayer)
87
87
}
88
88
89
89
JNI_METHOD (void , getDeviceProxy)
90
- (JNIEnv * env, jobject thiz, jobject callbackHandle )
90
+ (JNIEnv * env, jobject thiz, jobject jSuccessHandler, jobject jFailureHandler )
91
91
{
92
92
chip::DeviceLayer::StackLock lock;
93
93
ChipLogProgress (AppServer, " MatterEndpoint-JNI::getDeviceProxy() called" );
94
94
Endpoint * endpoint = support::convertEndpointFromJavaToCpp (thiz);
95
95
VerifyOrReturn (endpoint != nullptr , ChipLogError (AppServer, " MatterEndpoint-JNI::getDeviceProxy() endpoint == nullptr" ));
96
96
97
+ SessionContextJNI * context = new SessionContextJNI ();
98
+ context->successHandler = jSuccessHandler;
99
+ context->failureHandler = jFailureHandler;
100
+
101
+ DeviceProxyMatterSuccessHandlerJNI successHandler;
102
+ successHandler.SetUp (env, jSuccessHandler);
103
+
97
104
/* chip::Controller::GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast<chip::Controller::GetConnectedDeviceCallback *>(callbackHandle);
98
105
99
106
chip::NodeId nodeId = endpoint->GetCastingPlayer()->GetNodeId();
@@ -102,39 +109,30 @@ JNI_METHOD(void, getDeviceProxy)
102
109
chip::ScopedNodeId(endpoint->GetCastingPlayer()->GetNodeId(), endpoint->GetCastingPlayer()->GetFabricIndex()), &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);*/
103
110
104
111
// endpoint->GetCastingPlayer()->FindOrEstablishSession(&nodeId, &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);
105
- /*
112
+ endpoint-> GetCastingPlayer ()-> FindOrEstablishSession (context,
106
113
[](void * context, chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) {
107
114
ChipLogProgress (AppServer, " MatterEndpointJNI::FindOrEstablishSessionTask() success" );
108
- GetConnectedDeviceCallback * connectedDeviceCallback = static_cast<GetConnectedDeviceCallback *>(context);
109
-
110
- SessionContextJNI * __context = static_cast<SessionContextJNI *>(context);
111
-
112
115
JNIEnv * env = chip::JniReferences::GetInstance ().GetEnvForCurrentThread ();
113
- //chip::DeviceLayer::StackUnlock unlock;
114
116
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);
118
118
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));
121
122
},
122
123
[](void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error) {
123
124
ChipLogError (AppServer, " MatterEndpointJNI::FindOrEstablishSessionTask() failure" );
124
- SessionContextJNI * __context = static_cast<SessionContextJNI *>(context);
125
-
126
125
JNIEnv * env = chip::JniReferences::GetInstance ().GetEnvForCurrentThread ();
127
126
jstring errorMessage = env->NewStringUTF (error.Format ());
128
127
VerifyOrReturn (errorMessage != nullptr ,
129
128
ChipLogError (AppServer, " MatterEndpointJNI::FindOrEstablishSessionTask() Could not create errorMessage" ));
130
129
jobject throwableObject = env->NewObject (MatterEndpointJNIMgr ().mThrowableClass , MatterEndpointJNIMgr ().mThrowableConstructor , errorMessage);
131
130
VerifyOrReturn (throwableObject != nullptr ,
132
- ChipLogError(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() Could not create throwableObject"));*/
131
+ ChipLogError (AppServer, " MatterEndpointJNI::FindOrEstablishSessionTask() Could not create throwableObject" ));
133
132
134
- // chip::DeviceLayer::StackUnlock unlock;
135
- /* env->CallBooleanMethod(__context->completableFuture, MatterEndpointJNIMgr().mCompleteExceptionallyMethod, throwableObject);
133
+ SessionContextJNI * __context = static_cast <SessionContextJNI *>(context);
136
134
});
137
- */
135
+
138
136
/* MatterEndpointJNIMgr().Init();
139
137
// Setup completableFuture
140
138
jobject completableFuture = env->NewGlobalRef(env->NewObject(MatterEndpointJNIMgr().mCompletableFutureClass, MatterEndpointJNIMgr().mCompletableFutureConstructor));
0 commit comments