Skip to content

Commit e576227

Browse files
Added logging statements
1 parent 06f638d commit e576227

File tree

8 files changed

+101
-46
lines changed

8 files changed

+101
-46
lines changed

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

+36-23
Original file line numberDiff line numberDiff line change
@@ -86,37 +86,50 @@ public void onConnectionFailure(long nodeId, Exception error) {
8686

8787
public void testGetCluster()
8888
{
89-
CompletableFuture<Long> deviceProxyFuture = getDeviceProxy();
89+
System.out.println("CHIPController loading");
90+
System.loadLibrary("CHIPController");
91+
System.out.println("CHIPController loaded");
92+
93+
getDeviceProxy(new SuccessCallback<Long>() {
94+
@Override
95+
public void handle(Long deviceProxyPtr) {
96+
97+
ChipClusters.ContentLauncherCluster cluster = new ChipClusters.ContentLauncherCluster(deviceProxyPtr, getId());
98+
Log.d(TAG, "Content launcher cluster created " + cluster);
99+
cluster.launchURL(new ChipClusters.ContentLauncherCluster.LauncherResponseCallback() {
100+
@Override
101+
public void onSuccess(Integer status, Optional<String> data) {
102+
Log.d(TAG, "Content launcher success " + status + data);
103+
}
104+
105+
@Override
106+
public void onError(Exception error) {
107+
Log.e(TAG, "Content launcher failure " + error);
108+
}
109+
}
110+
,"my test url",
111+
Optional.of("my display str"),
112+
Optional.empty()
113+
);
114+
}
115+
}, new FailureCallback() {
116+
@Override
117+
public void handle(MatterError err) {
118+
Log.e(TAG, "getDeviceProxy err" + err);
119+
}
120+
});
121+
122+
/* CompletableFuture<Long> deviceProxyFuture = getDeviceProxy();
90123
Log.d(TAG, "getDeviceProxy returned CompletableFuture");
91124
try {
92125
Long deviceProxy = deviceProxyFuture.get(5, TimeUnit.SECONDS);
93126
Log.d(TAG, "getDeviceProxy returned value " + deviceProxy);
94127
95-
System.out.println("CHIPController loading");
96-
System.loadLibrary("CHIPController");
97-
System.out.println("CHIPController loaded");
98-
99-
ChipClusters.ContentLauncherCluster cluster = new ChipClusters.ContentLauncherCluster(deviceProxy, getId());
100-
Log.d(TAG, "Content launcher cluster created " + cluster);
101-
cluster.launchURL(new ChipClusters.ContentLauncherCluster.LauncherResponseCallback() {
102-
@Override
103-
public void onSuccess(Integer status, Optional<String> data) {
104-
Log.d(TAG, "Content launcher success " + status + data);
105-
}
106-
107-
@Override
108-
public void onError(Exception error) {
109-
Log.e(TAG, "Content launcher failure " + error);
110-
}
111-
}
112-
,"my test url",
113-
Optional.of("my display str"),
114-
Optional.empty()
115-
);
128+
116129
117130
} catch (ExecutionException | InterruptedException | TimeoutException e) {
118131
Log.e(TAG, "getDeviceProxy exception" + e);
119-
}
132+
}*/
120133
Log.d(TAG, "getDeviceProxy ending");
121134
}
122135

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

+38-23
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,16 @@ JNI_METHOD(jobject, getCastingPlayer)
8686
return support::convertCastingPlayerFromCppToJava(std::shared_ptr<CastingPlayer>(endpoint->GetCastingPlayer()));
8787
}
8888

89-
JNI_METHOD(void, getDeviceProxy)
90-
(JNIEnv * env, jobject thiz, jobject jSuccessHandler, jobject jFailureHandler)
89+
static void FindOrEstablishConnectionTask(intptr_t context)
9190
{
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,
11396
[](void * context, chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) {
11497
ChipLogProgress(AppServer, "MatterEndpointJNI::FindOrEstablishSessionTask() success");
98+
//chip::DeviceLayer::StackLock lock;
11599
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
116100
OperationalDeviceProxy * device = new OperationalDeviceProxy(&exchangeMgr, sessionHandle);
117101
SessionContextJNI * _context = static_cast<SessionContextJNI *>(context);
@@ -132,6 +116,37 @@ JNI_METHOD(void, getDeviceProxy)
132116

133117
SessionContextJNI * __context = static_cast<SessionContextJNI *>(context);
134118
});
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+
135150

136151
/*MatterEndpointJNIMgr().Init();
137152
// Setup completableFuture

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

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace core {
3131
struct SessionContextJNI
3232
{
3333
public:
34+
Endpoint *endpoint;
3435
jobject successHandler;
3536
jobject failureHandler;
3637
};

src/app/CommandSender.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ CommandSender::CommandSender(Callback * apCallback, Messaging::ExchangeManager *
6565
mExchangeCtx(*this),
6666
mCallbackHandle(apCallback), mpExchangeMgr(apExchangeMgr), mSuppressResponse(aSuppressResponse), mTimedRequest(aIsTimedRequest)
6767
{
68+
ChipLogProgress(Controller, "CommandSender::CommandSender 1");
6869
assertChipStackLockedByCurrentThread();
6970
}
7071

@@ -74,11 +75,13 @@ CommandSender::CommandSender(ExtendableCallback * apExtendableCallback, Messagin
7475
mCallbackHandle(apExtendableCallback), mpExchangeMgr(apExchangeMgr), mSuppressResponse(aSuppressResponse),
7576
mTimedRequest(aIsTimedRequest), mUseExtendableCallback(true)
7677
{
78+
ChipLogProgress(Controller, "CommandSender::CommandSender 2");
7779
assertChipStackLockedByCurrentThread();
7880
}
7981

8082
CommandSender::~CommandSender()
8183
{
84+
ChipLogProgress(Controller, "CommandSender::CommandSender 3");
8285
assertChipStackLockedByCurrentThread();
8386
}
8487

@@ -108,16 +111,19 @@ CHIP_ERROR CommandSender::AllocateBuffer()
108111

109112
CHIP_ERROR CommandSender::SendCommandRequestInternal(const SessionHandle & session, Optional<System::Clock::Timeout> timeout)
110113
{
114+
ChipLogProgress(Controller, "CommandSender::SendCommandRequestInternal");
111115
VerifyOrReturnError(mState == State::AddedCommand, CHIP_ERROR_INCORRECT_STATE);
112116

113117
ReturnErrorOnFailure(Finalize(mPendingInvokeData));
114118

115119
// Create a new exchange context.
116120
auto exchange = mpExchangeMgr->NewContext(session, this);
117121
VerifyOrReturnError(exchange != nullptr, CHIP_ERROR_NO_MEMORY);
122+
ChipLogProgress(Controller, "CommandSender::SendCommandRequestInternal after mpExchangeMgr->NewContext");
118123

119124
mExchangeCtx.Grab(exchange);
120125
VerifyOrReturnError(!mExchangeCtx->IsGroupExchangeContext(), CHIP_ERROR_INVALID_MESSAGE_TYPE);
126+
ChipLogProgress(Controller, "CommandSender::SendCommandRequestInternal after mpExchangeMgr->Grab");
121127

122128
mExchangeCtx->SetResponseTimeout(timeout.ValueOr(session->ComputeRoundTripTimeout(app::kExpectedIMProcessingTime)));
123129

@@ -128,6 +134,7 @@ CHIP_ERROR CommandSender::SendCommandRequestInternal(const SessionHandle & sessi
128134
return CHIP_NO_ERROR;
129135
}
130136

137+
ChipLogProgress(Controller, "CommandSender::SendCommandRequestInternal before SendInvokeRequest");
131138
return SendInvokeRequest();
132139
}
133140

@@ -178,9 +185,13 @@ CHIP_ERROR CommandSender::SendInvokeRequest()
178185
using namespace Protocols::InteractionModel;
179186
using namespace Messaging;
180187

188+
ChipLogProgress(Controller, "CommandSender::SendInvokeRequest before sendMessage");
189+
181190
ReturnErrorOnFailure(
182191
mExchangeCtx->SendMessage(MsgType::InvokeCommandRequest, std::move(mPendingInvokeData), SendMessageFlags::kExpectResponse));
192+
ChipLogProgress(Controller, "CommandSender::SendInvokeRequest after sendMessage");
183193
MoveToState(State::AwaitingResponse);
194+
ChipLogProgress(Controller, "CommandSender::SendInvokeRequest after MoveToState");
184195

185196
return CHIP_NO_ERROR;
186197
}

src/controller/java/CHIPDeviceController-JNI.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2752,12 +2752,14 @@ JNI_METHOD(void, invoke)
27522752
? Optional<uint16_t>(convertedTimedRequestTimeoutMs)
27532753
: Optional<uint16_t>::Missing()));
27542754

2755+
ChipLogProgress(Controller, "Before commandSender->SendCommandRequest");
27552756
SuccessOrExit(err = device->GetSecureSession().Value()->IsGroupSession()
27562757
? commandSender->SendGroupCommandRequest(device->GetSecureSession().Value())
27572758
: commandSender->SendCommandRequest(device->GetSecureSession().Value(),
27582759
imTimeoutMs != 0
27592760
? MakeOptional(System::Clock::Milliseconds32(imTimeoutMs))
27602761
: Optional<System::Clock::Timeout>::Missing()));
2762+
ChipLogProgress(Controller, "After commandSender->SendCommandRequest");
27612763

27622764
callback->mCommandSender = commandSender;
27632765

src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ bool GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_IsChipStackLockedByCurrent
157157
#if INCLUDE_xSemaphoreGetMutexHolder != 1
158158
#error Must either set INCLUDE_xSemaphoreGetMutexHolder = 1 in FreeRTOSConfig.h or set chip_stack_lock_tracking = "none" in Matter gn configuration.
159159
#endif
160+
ChipLogProgress(NotSpecified, "GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_IsChipStackLockedByCurrentThread()");
160161
// If we have not started our event loop yet, return true because in that
161162
// case we can't be racing against the (not yet started) event loop.
162163
//

src/include/platform/internal/GenericPlatformManagerImpl_POSIX.ipp

+2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ bool GenericPlatformManagerImpl_POSIX<ImplClass>::_IsChipStackLockedByCurrentThr
125125
{
126126
// If no Matter thread is currently running we do not have to worry about
127127
// locking. Hence, this function always returns true in that case.
128+
ChipLogProgress(DeviceLayer, "GenericPlatformManagerImpl_POSIX<ImplClass>::_IsChipStackLockedByCurrentThread()");
128129
if (mState.load(std::memory_order_relaxed) == State::kStopped)
129130
return true;
131+
ChipLogProgress(DeviceLayer, "GenericPlatformManagerImpl_POSIX<ImplClass>::_IsChipStackLockedByCurrentThread() mChipStackIsLocked: %d", mChipStackIsLocked);
130132
return mChipStackIsLocked && (pthread_equal(pthread_self(), mChipStackLockOwnerThread));
131133
}
132134
#endif

src/messaging/ExchangeContext.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ void ExchangeContext::SetResponseTimeout(Timeout timeout)
9595
CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgType, PacketBufferHandle && msgBuf,
9696
const SendFlags & sendFlags)
9797
{
98+
99+
ChipLogProgress(Controller, "ExchangeContext::SendMessage");
98100
// This is the first point all outgoing messages funnel through. Ensure
99101
// that our message sends are all synchronized correctly.
100102
assertChipStackLockedByCurrentThread();
103+
ChipLogProgress(Controller, "ExchangeContext::SendMessage after assert");
101104

102105
bool isStandaloneAck =
103106
(protocolId == Protocols::SecureChannel::Id) && msgType == to_underlying(Protocols::SecureChannel::MsgType::StandaloneAck);
@@ -107,16 +110,19 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
107110

108111
// Don't let method get called on a freed object.
109112
VerifyOrDie(mExchangeMgr != nullptr && GetReferenceCount() > 0);
113+
ChipLogProgress(Controller, "ExchangeContext::SendMessage after mExchangeMgr != nullptr && GetReferenceCount() > 0");
110114

111115
// we hold the exchange context here in case the entity that
112116
// originally generated it tries to close it as a result of
113117
// an error arising below. at the end, we have to close it.
114118
ExchangeHandle ref(*this);
119+
ChipLogProgress(Controller, "ExchangeContext::SendMessage after ExchangeHandle ref(*this)");
115120

116121
// If session requires MRP, NoAutoRequestAck send flag is not specified and is not a group exchange context, request reliable
117122
// transmission.
118123
bool reliableTransmissionRequested =
119124
GetSessionHandle()->AllowsMRP() && !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck) && !IsGroupExchangeContext();
125+
ChipLogProgress(Controller, "ExchangeContext::SendMessage after reliableTransmissionRequested");
120126

121127
bool currentMessageExpectResponse = false;
122128
// If a response message is expected...
@@ -134,7 +140,9 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
134140
// Arm the response timer if a timeout has been specified.
135141
if (mResponseTimeout > System::Clock::kZero)
136142
{
143+
ChipLogProgress(Controller, "ExchangeContext::SendMessage before StartResponseTimer");
137144
CHIP_ERROR err = StartResponseTimer();
145+
ChipLogProgress(Controller, "ExchangeContext::SendMessage after StartResponseTimer");
138146
if (err != CHIP_NO_ERROR)
139147
{
140148
SetResponseExpected(false);
@@ -217,6 +225,8 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
217225
}
218226
}
219227

228+
ChipLogProgress(Controller, "ExchangeContext::SendMessage before return err");
229+
220230
return err;
221231
}
222232
}

0 commit comments

Comments
 (0)