Skip to content

Commit

Permalink
Merge 6f688d7 into 0807f5e
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcosb authored Jan 10, 2023
2 parents 0807f5e + 6f688d7 commit 2676201
Show file tree
Hide file tree
Showing 20 changed files with 478 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/OperationalSessionSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class OperationalDeviceProxy : public DeviceProxy
* application code does incorrectly hold onto this information so do not follow those incorrect
* implementations as an example.
*/
typedef void (*OnDeviceConnected)(void * context, Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle);
typedef void (*OnDeviceConnected)(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
typedef void (*OnDeviceConnectionFailure)(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);

/**
Expand Down
5 changes: 3 additions & 2 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ CHIP_ERROR ReadClient::RefreshLivenessCheckTimer()
timeout = System::Clock::Seconds16(mMaxInterval) + publisherTransmissionTimeout;
}

// EFR32/MBED/INFINION/K32W's chrono count return long unsinged, but other platform returns unsigned
// EFR32/MBED/INFINION/K32W's chrono count return long unsigned, but other platform returns unsigned
ChipLogProgress(
DataManagement,
"Refresh LivenessCheckTime for %lu milliseconds with SubscriptionId = 0x%08" PRIx32 " Peer = %02x:" ChipLogFormatX64,
Expand Down Expand Up @@ -1068,7 +1068,8 @@ CHIP_ERROR ReadClient::DefaultResubscribePolicy(CHIP_ERROR aTerminationCause)
return CHIP_NO_ERROR;
}

void ReadClient::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle)
void ReadClient::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr,
const SessionHandle & sessionHandle)
{
ReadClient * const _this = static_cast<ReadClient *>(context);
VerifyOrDie(_this != nullptr);
Expand Down
3 changes: 2 additions & 1 deletion src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ class ReadClient : public Messaging::ExchangeDelegate
void StopResubscription();
void ClearActiveSubscriptionState();

static void HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle);
static void HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr,
const SessionHandle & sessionHandle);
static void HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);

CHIP_ERROR GetMinEventNumber(const ReadPrepareParams & aReadPrepareParams, Optional<EventNumber> & aEventMin);
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ void DeviceCommissioner::CommissioningStageComplete(CHIP_ERROR err, Commissionin
}

void DeviceCommissioner::OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr,
SessionHandle & sessionHandle)
const SessionHandle & sessionHandle)
{
// CASE session established.
DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
/* Callback called when adding root cert to device results in failure */
static void OnRootCertFailureResponse(void * context, CHIP_ERROR error);

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

static void OnDeviceAttestationInformationVerification(void * context,
Expand Down
4 changes: 2 additions & 2 deletions src/controller/CommissioningWindowOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow(NodeId deviceId, S
}

CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindowInternal(Messaging::ExchangeManager & exchangeMgr,
SessionHandle & sessionHandle)
const SessionHandle & sessionHandle)
{
ChipLogProgress(Controller, "OpenCommissioningWindow for device ID %" PRIu64, mNodeId);

Expand Down Expand Up @@ -259,7 +259,7 @@ void CommissioningWindowOpener::OnOpenCommissioningWindowFailure(void * context,
}

void CommissioningWindowOpener::OnDeviceConnectedCallback(void * context, Messaging::ExchangeManager & exchangeMgr,
SessionHandle & sessionHandle)
const SessionHandle & sessionHandle)
{
auto * self = static_cast<CommissioningWindowOpener *>(context);

Expand Down
5 changes: 3 additions & 2 deletions src/controller/CommissioningWindowOpener.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ class CommissioningWindowOpener
kOpenCommissioningWindow,
};

CHIP_ERROR OpenCommissioningWindowInternal(Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle);
CHIP_ERROR OpenCommissioningWindowInternal(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
static void OnPIDReadResponse(void * context, uint16_t value);
static void OnVIDReadResponse(void * context, VendorId value);
static void OnVIDPIDReadFailureResponse(void * context, CHIP_ERROR error);
static void OnOpenCommissioningWindowSuccess(void * context, const app::DataModel::NullObjectType &);
static void OnOpenCommissioningWindowFailure(void * context, CHIP_ERROR error);
static void OnDeviceConnectedCallback(void * context, Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle);
static void OnDeviceConnectedCallback(void * context, Messaging::ExchangeManager & exchangeMgr,
const SessionHandle & sessionHandle);
static void OnDeviceConnectionFailureCallback(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);

DeviceController * const mController = nullptr;
Expand Down
8 changes: 5 additions & 3 deletions src/controller/CurrentFabricRemover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ CHIP_ERROR CurrentFabricRemover::RemoveCurrentFabric(NodeId remoteNodeId, Callba
return mController->GetConnectedDevice(remoteNodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
}

CHIP_ERROR CurrentFabricRemover::ReadCurrentFabricIndex(Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle)
CHIP_ERROR CurrentFabricRemover::ReadCurrentFabricIndex(Messaging::ExchangeManager & exchangeMgr,
const SessionHandle & sessionHandle)
{
using TypeInfo = chip::app::Clusters::OperationalCredentials::Attributes::CurrentFabricIndex::TypeInfo;
OperationalCredentialsCluster cluster(exchangeMgr, sessionHandle, kRootEndpointId);

return cluster.ReadAttribute<TypeInfo>(this, OnSuccessReadCurrentFabricIndex, OnReadAttributeFailure);
}

CHIP_ERROR CurrentFabricRemover::SendRemoveFabricIndex(Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle)
CHIP_ERROR CurrentFabricRemover::SendRemoveFabricIndex(Messaging::ExchangeManager & exchangeMgr,
const SessionHandle & sessionHandle)
{
if (mFabricIndex == kUndefinedFabricIndex)
{
Expand All @@ -59,7 +61,7 @@ CHIP_ERROR CurrentFabricRemover::SendRemoveFabricIndex(Messaging::ExchangeManage
}

void CurrentFabricRemover::OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr,
SessionHandle & sessionHandle)
const SessionHandle & sessionHandle)
{
CHIP_ERROR err = CHIP_NO_ERROR;
auto * self = static_cast<CurrentFabricRemover *>(context);
Expand Down
6 changes: 3 additions & 3 deletions src/controller/CurrentFabricRemover.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class CurrentFabricRemover
FabricIndex mFabricIndex = kUndefinedFabricIndex;
Step mNextStep = Step::kAcceptRemoveFabricStart;

CHIP_ERROR ReadCurrentFabricIndex(Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle);
CHIP_ERROR SendRemoveFabricIndex(Messaging::ExchangeManager & exchangeMgr, SessionHandle & sessionHandle);
CHIP_ERROR ReadCurrentFabricIndex(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
CHIP_ERROR SendRemoveFabricIndex(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);

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

static void OnSuccessReadCurrentFabricIndex(void * context, FabricIndex fabricIndex);
Expand Down
52 changes: 52 additions & 0 deletions src/controller/java/AndroidCallbacks-ForTestJNI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
*
* Copyright (c) 2020-2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <jni.h>

#include "AndroidCallbacks.h"
#include "lib/support/CHIPMem.h"
#include "lib/support/CodeUtils.h"
#include "lib/support/logging/CHIPLogging.h"
#include "messaging/tests/MessagingContext.h"

#define JNI_METHOD(RETURN, CLASS_NAME, METHOD_NAME) \
extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_##CLASS_NAME##_##METHOD_NAME

using namespace chip;
using namespace chip::Controller;
using namespace chip::Test;

JNI_METHOD(void, GetConnectedDeviceCallbackForTestJni, onDeviceConnected)
(JNIEnv * env, jobject self, jlong callbackHandle, jlong messagingContextHandle)
{
GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast<GetConnectedDeviceCallback *>(callbackHandle);
VerifyOrReturn(connectedDeviceCallback != nullptr, ChipLogError(Controller, "GetConnectedDeviceCallbackJni handle is nullptr"));

MessagingContext * messagingContext = reinterpret_cast<MessagingContext *>(messagingContextHandle);
VerifyOrReturn(messagingContext != nullptr, ChipLogError(Controller, "MessagingContext handle is nullptr"));

GetConnectedDeviceCallback::OnDeviceConnectedFn(connectedDeviceCallback, messagingContext->GetExchangeManager(),
messagingContext->GetSessionBobToAlice());
}

JNI_METHOD(void, GetConnectedDeviceCallbackForTestJni, onDeviceConnectionFailure)
(JNIEnv * env, jobject self, jlong callbackHandle, jint errorCode)
{
GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast<GetConnectedDeviceCallback *>(callbackHandle);
VerifyOrReturn(connectedDeviceCallback != nullptr, ChipLogError(Controller, "GetConnectedDeviceCallbackJni handle is nullptr"));

GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(connectedDeviceCallback, ScopedNodeId(), chip::ChipError(errorCode));
}
2 changes: 1 addition & 1 deletion src/controller/java/AndroidCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ GetConnectedDeviceCallback::~GetConnectedDeviceCallback()
}

void GetConnectedDeviceCallback::OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr,
SessionHandle & sessionHandle)
const SessionHandle & sessionHandle)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
auto * self = static_cast<GetConnectedDeviceCallback *>(context);
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/AndroidCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct GetConnectedDeviceCallback
GetConnectedDeviceCallback(jobject wrapperCallback, jobject javaCallback);
~GetConnectedDeviceCallback();

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

Callback::Callback<OnDeviceConnected> mOnSuccess;
Expand Down
94 changes: 94 additions & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@ shared_library("jni") {
ldflags = [ "-Wl,--gc-sections" ]
}

shared_library("jni_for_test") {
sources = [ "AndroidCallbacks-ForTestJNI.cpp" ]
output_name = "libCHIPForTestController"

public_configs = [ "${chip_root}/src:includes" ]

deps = [
":jni",
"${chip_root}/src/messaging/tests:helpers",
]

if (build_java_matter_controller) {
defines = [ "JAVA_MATTER_CONTROLLER_TEST" ]
include_dirs = java_matter_controller_dependent_paths

deps += [ "${chip_root}/src/platform/Linux" ]

cflags = [ "-Wno-unknown-pragmas" ]

output_dir = "${root_out_dir}/lib/jni"
} else {
deps += [ "${chip_root}/src/platform/android" ]

output_dir = "${root_out_dir}/lib/jni/${android_abi}"
}

ldflags = [ "-Wl,--gc-sections" ]
}

android_library("java") {
output_name = "CHIPController.jar"

Expand Down Expand Up @@ -157,6 +186,71 @@ android_library("java") {
# ..../platforms/android-21/android.jar to access BLE items)
}

android_library("java_for_test") {
output_name = "CHIPControllerForTest.jar"

deps = [ "${chip_root}/third_party/java_deps:annotation" ]

data_deps = [
":jni",
":jni_for_test",
]

sources =
[ "src/chip/devicecontroller/GetConnectedDeviceCallbackForTestJni.java" ]

if (build_java_matter_controller) {
deps += [
"${chip_root}/third_party/java_deps:json",
"${chip_root}/third_party/java_deps/stub_src",
]
} else {
deps += [ ":android" ]

data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
}

javac_flags = [ "-Xlint:deprecation" ]

# TODO: add classpath support (we likely need to add something like
# ..../platforms/android-21/android.jar to access BLE items)
}

android_library("tests") {
output_name = "CHIPControllerTests.jar"

deps = [
":java_for_test",
"${chip_root}/src/messaging/tests/java",
"${chip_root}/third_party/java_deps:annotation",
]

data_deps = [
":jni",
":jni_for_test",
"${chip_root}/src/messaging/tests/java:jni",
]

sources =
[ "tests/chip/devicecontroller/GetConnectedDeviceCallbackJniTest.java" ]

if (build_java_matter_controller) {
deps += [
"${chip_root}/third_party/java_deps:json",
"${chip_root}/third_party/java_deps/stub_src",
]
} else {
deps += [ ":android" ]

data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
}

javac_flags = [ "-Xlint:deprecation" ]

# TODO: add classpath support (we likely need to add something like
# ..../platforms/android-21/android.jar to access BLE items)
}

if (!build_java_matter_controller) {
java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2020-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package chip.devicecontroller;

import chip.testing.MessagingContext;

/** Utilities for unit testing {@link GetConnectedDeviceCallbackJni}. */
public final class GetConnectedDeviceCallbackForTestJni {
private final MessagingContext messagingContext;

static {
System.loadLibrary("CHIPForTestController");
}

public GetConnectedDeviceCallbackForTestJni(MessagingContext messagingContext) {
this.messagingContext = messagingContext;
}

public void onDeviceConnected(GetConnectedDeviceCallbackJni callback) {
onDeviceConnected(callback.getCallbackHandle(), messagingContext.getMessagingContextHandle());
}

private native void onDeviceConnected(long callbackHandle, long messagingContextHandle);

public void onDeviceConnectionFailure(GetConnectedDeviceCallbackJni callback, int errorCode) {
onDeviceConnectionFailure(callback.getCallbackHandle(), errorCode);
}

private native void onDeviceConnectionFailure(long callbackHandle, int errorCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/** JNI wrapper callback class for getting a connected device. */
public class GetConnectedDeviceCallbackJni {
private GetConnectedDeviceCallback wrappedCallback;
private final GetConnectedDeviceCallback wrappedCallback;
private long callbackHandle;

public GetConnectedDeviceCallbackJni(GetConnectedDeviceCallback wrappedCallback) {
Expand Down
Loading

0 comments on commit 2676201

Please sign in to comment.