@@ -86,32 +86,16 @@ JNI_METHOD(jobject, getCastingPlayer)
86
86
return support::convertCastingPlayerFromCppToJava (std::shared_ptr<CastingPlayer>(endpoint->GetCastingPlayer ()));
87
87
}
88
88
89
- JNI_METHOD (void , getDeviceProxy)
90
- (JNIEnv * env, jobject thiz, jobject jSuccessHandler, jobject jFailureHandler)
89
+ static void FindOrEstablishConnectionTask (intptr_t context)
91
90
{
92
- chip::DeviceLayer::StackLock lock;
93
- ChipLogProgress (AppServer, " MatterEndpoint-JNI::getDeviceProxy() called" );
94
- Endpoint * endpoint = support::convertEndpointFromJavaToCpp (thiz);
95
- VerifyOrReturn (endpoint != nullptr , ChipLogError (AppServer, " MatterEndpoint-JNI::getDeviceProxy() endpoint == nullptr" ));
96
-
97
- SessionContextJNI * context = new SessionContextJNI ();
98
- context->successHandler = jSuccessHandler;
99
- context->failureHandler = jFailureHandler;
100
-
101
- DeviceProxyMatterSuccessHandlerJNI successHandler;
102
- successHandler.SetUp (env, jSuccessHandler);
103
-
104
- /* chip::Controller::GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast<chip::Controller::GetConnectedDeviceCallback *>(callbackHandle);
105
-
106
- chip::NodeId nodeId = endpoint->GetCastingPlayer()->GetNodeId();
107
-
108
- chip::Server::GetInstance().GetCASESessionManager()->FindOrEstablishSession(
109
- chip::ScopedNodeId(endpoint->GetCastingPlayer()->GetNodeId(), endpoint->GetCastingPlayer()->GetFabricIndex()), &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);*/
110
-
111
- // endpoint->GetCastingPlayer()->FindOrEstablishSession(&nodeId, &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);
112
- endpoint->GetCastingPlayer ()->FindOrEstablishSession (context,
91
+ ChipLogProgress (AppServer, " FindOrEstablishConnectionTask called" );
92
+ if (context != 0 )
93
+ {
94
+ SessionContextJNI * __context = reinterpret_cast <SessionContextJNI *>(context);
95
+ __context->endpoint ->GetCastingPlayer ()->FindOrEstablishSession (__context,
113
96
[](void * context, chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) {
114
97
ChipLogProgress (AppServer, " MatterEndpointJNI::FindOrEstablishSessionTask() success" );
98
+ // chip::DeviceLayer::StackLock lock;
115
99
JNIEnv * env = chip::JniReferences::GetInstance ().GetEnvForCurrentThread ();
116
100
OperationalDeviceProxy * device = new OperationalDeviceProxy (&exchangeMgr, sessionHandle);
117
101
SessionContextJNI * _context = static_cast <SessionContextJNI *>(context);
@@ -132,6 +116,37 @@ JNI_METHOD(void, getDeviceProxy)
132
116
133
117
SessionContextJNI * __context = static_cast <SessionContextJNI *>(context);
134
118
});
119
+
120
+ }
121
+ }
122
+
123
+ JNI_METHOD (void , getDeviceProxy)
124
+ (JNIEnv * env, jobject thiz, jobject jSuccessHandler, jobject jFailureHandler)
125
+ {
126
+ chip::DeviceLayer::StackLock lock;
127
+ ChipLogProgress (AppServer, " MatterEndpoint-JNI::getDeviceProxy() called" );
128
+ Endpoint * endpoint = support::convertEndpointFromJavaToCpp (thiz);
129
+ VerifyOrReturn (endpoint != nullptr , ChipLogError (AppServer, " MatterEndpoint-JNI::getDeviceProxy() endpoint == nullptr" ));
130
+
131
+ SessionContextJNI * context = new SessionContextJNI ();
132
+ context->endpoint = endpoint;
133
+ context->successHandler = env->NewGlobalRef (jSuccessHandler);
134
+ context->failureHandler = env->NewGlobalRef (jFailureHandler);
135
+
136
+ DeviceProxyMatterSuccessHandlerJNI successHandler;
137
+ successHandler.SetUp (env, jSuccessHandler);
138
+
139
+ /* chip::Controller::GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast<chip::Controller::GetConnectedDeviceCallback *>(callbackHandle);
140
+
141
+ chip::NodeId nodeId = endpoint->GetCastingPlayer()->GetNodeId();
142
+
143
+ chip::Server::GetInstance().GetCASESessionManager()->FindOrEstablishSession(
144
+ chip::ScopedNodeId(endpoint->GetCastingPlayer()->GetNodeId(), endpoint->GetCastingPlayer()->GetFabricIndex()), &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);*/
145
+
146
+ // endpoint->GetCastingPlayer()->FindOrEstablishSession(&nodeId, &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure);
147
+ chip::DeviceLayer::PlatformMgr ().ScheduleWork (FindOrEstablishConnectionTask, reinterpret_cast <intptr_t >(context));
148
+
149
+
135
150
136
151
/* MatterEndpointJNIMgr().Init();
137
152
// Setup completableFuture
0 commit comments