Skip to content

Commit

Permalink
Add terminate sleep time
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Dec 20, 2024
1 parent 8830a42 commit 019e300
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.matter.controller.commands.pairing.PairingCommand
import com.matter.controller.commands.pairing.PairingModeType
import com.matter.controller.commands.pairing.PairingNetworkType
import java.io.File
import java.util.concurrent.TimeUnit
import java.util.logging.Level
import java.util.logging.Logger

Expand Down Expand Up @@ -85,12 +86,19 @@ class PairOnNetworkLongDownloadLogCommand(
)
logger.log(Level.INFO, "Waiting response : ${getTimeoutMillis()}")
waitCompleteMs(getTimeoutMillis())
// For waiting both side terminating.
try {
TimeUnit.SECONDS.sleep(WAIT_FOR_TERMINATE)
} catch (e: InterruptedException) {
throw RuntimeException(e)
}
}

companion object {
private val logger = Logger.getLogger(PairOnNetworkLongDownloadLogCommand::class.java.name)

private const val MATTER_PORT = 5540
private const val MS_TO_SEC = 1000
private const val WAIT_FOR_TERMINATE = 1
}
}
1 change: 1 addition & 0 deletions kotlin-detect-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ exceptions:
TooGenericExceptionThrown:
excludes:
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/bdx/DownloadLogCommand.kt"
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/bdx/PairOnNetworkLongDownloadLogCommand.kt"
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt"
- "**/src/controller/java/generated/java/**/*"
ThrowingExceptionsWithoutMessageOrCause:
Expand Down
63 changes: 33 additions & 30 deletions src/controller/java/AndroidLogDownloadFromNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ CHIP_ERROR AndroidLogDownloadFromNode::SendRetrieveLogsRequest(Messaging::Exchan
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Make BDX URI failure : %" CHIP_ERROR_FORMAT, err.Format());
FinishLogDownloadFromNode(err);
FinishLogDownloadFromNode(static_cast<void *>(this), err);
}

mBdxReceiver =
Expand Down Expand Up @@ -132,18 +132,14 @@ void AndroidLogDownloadFromNode::OnDeviceConnectedFn(void * context, Messaging::
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Log Download failure : %" CHIP_ERROR_FORMAT, err.Format());
self->FinishLogDownloadFromNode(err);
FinishLogDownloadFromNode(context, err);
}
}

void AndroidLogDownloadFromNode::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR err)
{
ChipLogProgress(Controller, "OnDeviceConnectionFailureFn: %" CHIP_ERROR_FORMAT, err.Format());

auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
VerifyOrReturn(self != nullptr, ChipLogProgress(Controller, "Device connected failure callback with null context. Ignoring"));

self->FinishLogDownloadFromNode(err);
FinishLogDownloadFromNode(context, err);
}

void AndroidLogDownloadFromNode::OnResponseRetrieveLogs(void * context,
Expand All @@ -162,25 +158,25 @@ void AndroidLogDownloadFromNode::OnResponseRetrieveLogs(void * context,
{
CHIP_ERROR err = CHIP_NO_ERROR;
self->OnTransferCallback(self->mController->GetFabricIndex(), self->mRemoteNodeId, data.logContent, &err);
self->FinishLogDownloadFromNode(err);
FinishLogDownloadFromNode(context, err);
}
else if (data.status == StatusEnum::kNoLogs)
{
CHIP_ERROR err = CHIP_NO_ERROR;
self->OnTransferCallback(self->mController->GetFabricIndex(), self->mRemoteNodeId, ByteSpan(), &err);
self->FinishLogDownloadFromNode(err);
FinishLogDownloadFromNode(context, err);
}
else if (data.status == StatusEnum::kBusy)
{
self->FinishLogDownloadFromNode(CHIP_ERROR_BUSY);
FinishLogDownloadFromNode(context, CHIP_ERROR_BUSY);
}
else if (data.status == StatusEnum::kDenied)
{
self->FinishLogDownloadFromNode(CHIP_ERROR_ACCESS_DENIED);
FinishLogDownloadFromNode(context, CHIP_ERROR_ACCESS_DENIED);
}
else
{
self->FinishLogDownloadFromNode(CHIP_ERROR_INVALID_DATA_LIST);
FinishLogDownloadFromNode(context, CHIP_ERROR_INVALID_DATA_LIST);
}
}

Expand All @@ -191,53 +187,60 @@ void AndroidLogDownloadFromNode::OnCommandFailure(void * context, CHIP_ERROR err
auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
VerifyOrReturn(self != nullptr, ChipLogProgress(Controller, "Send command failure callback with null context. Ignoring"));

self->FinishLogDownloadFromNode(err);
FinishLogDownloadFromNode(context, err);
}

void AndroidLogDownloadFromNode::FinishLogDownloadFromNode(CHIP_ERROR err)
void AndroidLogDownloadFromNode::FinishLogDownloadFromNode(void * context, CHIP_ERROR err)
{
CHIP_ERROR jniErr = CHIP_NO_ERROR;
if (mBdxReceiver != nullptr)
auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
VerifyOrReturn(self != nullptr, ChipLogProgress(Controller, "Finish Log Download with null context. Ignoring"));

if (self->mBdxReceiver != nullptr)
{
if (mTimeout > 0)
if (self->mTimeout > 0 && err != CHIP_ERROR_TIMEOUT)
{
mBdxReceiver->CancelBDXTransferTimeout();
self->mBdxReceiver->CancelBDXTransferTimeout();
}
delete mBdxReceiver;
mBdxReceiver = nullptr;
delete self->mBdxReceiver;
self->mBdxReceiver = nullptr;
}

JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
CHIP_ERROR jniErr = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
JniLocalReferenceScope scope(env);

jobject jCallback = self->mJavaCallback.ObjectRef();
jint jFabricIndex = self->mController->GetFabricIndex();
jlong jremoteNodeId = self->mRemoteNodeId;

VerifyOrExit(env != nullptr, CHIP_ERROR_INCORRECT_STATE);

if (err == CHIP_NO_ERROR)
{
ChipLogProgress(Controller, "Log Download succeeded.");
jmethodID onSuccessMethod;
// Java method signature : boolean onSuccess(int fabricIndex, long nodeId)
jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onSuccess", "(IJ)V", &onSuccessMethod);
jniErr = JniReferences::GetInstance().FindMethod(env, jCallback, "onSuccess", "(IJ)V", &onSuccessMethod);

VerifyOrExit(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onSuccess method"));

env->CallVoidMethod(mJavaCallback.ObjectRef(), onSuccessMethod, static_cast<jint>(mController->GetFabricIndex()),
static_cast<jlong>(mRemoteNodeId));
env->CallVoidMethod(jCallback, onSuccessMethod, jFabricIndex, jremoteNodeId);
}
else
{
ChipLogError(Controller, "Log Download Failed : %" CHIP_ERROR_FORMAT, err.Format());

jmethodID onErrorMethod;
// Java method signature : void onError(int fabricIndex, long nodeId, long errorCode)
jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onError", "(IJJ)V", &onErrorMethod);
jniErr = JniReferences::GetInstance().FindMethod(env, jCallback, "onError", "(IJJ)V", &onErrorMethod);
VerifyOrExit(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onError method"));

env->CallVoidMethod(mJavaCallback.ObjectRef(), onErrorMethod, static_cast<jint>(mController->GetFabricIndex()),
static_cast<jlong>(mRemoteNodeId), static_cast<jlong>(err.AsInteger()));
env->CallVoidMethod(jCallback, onErrorMethod, jFabricIndex, jremoteNodeId, static_cast<jlong>(err.AsInteger()));
}

exit:
// Finish this function, this object will be deleted.
delete this;
delete self;
}

void AndroidLogDownloadFromNode::OnBdxTransferCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId,
Expand Down Expand Up @@ -282,7 +285,7 @@ void AndroidLogDownloadFromNode::OnBdxTransferSuccessCallback(void * context, Fa
auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
VerifyOrReturn(self != nullptr, ChipLogProgress(Controller, "Send command failure callback with null context. Ignoring"));

self->FinishLogDownloadFromNode(CHIP_NO_ERROR);
FinishLogDownloadFromNode(context, CHIP_NO_ERROR);
}

void AndroidLogDownloadFromNode::OnBdxTransferFailureCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId,
Expand All @@ -293,7 +296,7 @@ void AndroidLogDownloadFromNode::OnBdxTransferFailureCallback(void * context, Fa
auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
VerifyOrReturn(self != nullptr, ChipLogProgress(Controller, "Send command failure callback with null context. Ignoring"));

self->FinishLogDownloadFromNode(status);
FinishLogDownloadFromNode(context, status);
}
} // namespace Controller
} // namespace chip
4 changes: 3 additions & 1 deletion src/controller/java/AndroidLogDownloadFromNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class AndroidLogDownloadFromNode
AndroidLogDownloadFromNode(DeviceController * controller, NodeId remoteNodeId, app::Clusters::DiagnosticLogs::IntentEnum intent,
uint16_t timeout, jobject javaCallback);

~AndroidLogDownloadFromNode() {}

DeviceController * mController = nullptr;

chip::Callback::Callback<OnDeviceConnected> mOnDeviceConnectedCallback;
Expand All @@ -76,7 +78,7 @@ class AndroidLogDownloadFromNode
CHIP_ERROR SendRetrieveLogsRequest(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
void OnTransferCallback(FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data,
CHIP_ERROR * errInfoOnFailure);
void FinishLogDownloadFromNode(CHIP_ERROR err);
static void FinishLogDownloadFromNode(void * context, CHIP_ERROR err);

static void OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
Expand Down

0 comments on commit 019e300

Please sign in to comment.