Skip to content

Commit 26aa4cb

Browse files
authored
Define new JF server variables for JF Admins only (#39095)
1 parent 06cf5b8 commit 26aa4cb

File tree

7 files changed

+113
-3
lines changed

7 files changed

+113
-3
lines changed

examples/jf-admin-app/linux/args.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ chip_enable_additional_data_advertising = true
3434
chip_enable_rotating_device_id = true
3535

3636
chip_enable_read_client = false
37+
38+
chip_device_config_enable_joint_fabric = true

src/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ if (chip_build_tests) {
168168
output_name = "libCHIP_tests"
169169
output_dir = "${root_out_dir}/lib"
170170
}
171+
172+
if (chip_device_config_enable_joint_fabric) {
173+
tests += [ "${chip_root}/src/app/server/tests" ]
174+
}
171175
}
172176

173177
chip_test_group("example_tests") {

src/app/clusters/joint-fabric-datastore-server/joint-fabric-datastore-server.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <app/reporting/reporting.h>
2828
#include <app/server/Server.h>
2929
#include <app/util/attribute-storage.h>
30+
#include <platform/CHIPDeviceConfig.h>
31+
32+
#if CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC
3033

3134
using namespace chip;
3235
using namespace chip::app;
@@ -459,3 +462,5 @@ void MatterJointFabricDatastorePluginServerInitCallback()
459462

460463
Server::GetInstance().GetJointFabricDatastore().AddListener(gJointFabricDatastoreAttrAccess);
461464
}
465+
466+
#endif // CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC

src/app/server/BUILD.gn

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import("//build_overrides/chip.gni")
1616
import("${chip_root}/src/access/access.gni")
1717
import("${chip_root}/src/app/common_flags.gni")
1818
import("${chip_root}/src/app/icd/icd.gni")
19+
import("${chip_root}/src/platform/device.gni")
1920

2021
config("server_config") {
2122
defines = []
@@ -41,6 +42,18 @@ source_set("terms_and_conditions") {
4142
]
4243
}
4344

45+
source_set("joint_fabric_datastore") {
46+
sources = [
47+
"JointFabricDatastore.cpp",
48+
"JointFabricDatastore.h",
49+
]
50+
51+
public_deps = [
52+
"${chip_root}/src/lib/core",
53+
"${chip_root}/zzz_generated/app-common/clusters/JointFabricDatastore",
54+
]
55+
}
56+
4457
static_library("server") {
4558
output_name = "libCHIPAppServer"
4659

@@ -57,8 +70,6 @@ static_library("server") {
5770
"Dnssd.h",
5871
"EchoHandler.cpp",
5972
"EchoHandler.h",
60-
"JointFabricDatastore.cpp",
61-
"JointFabricDatastore.h",
6273
"Server.cpp",
6374
"Server.h",
6475
]
@@ -88,6 +99,10 @@ static_library("server") {
8899
public_deps += [ ":terms_and_conditions" ]
89100
}
90101

102+
if (chip_device_config_enable_joint_fabric) {
103+
public_deps += [ ":joint_fabric_datastore" ]
104+
}
105+
91106
# TODO: Server.cpp uses TestGroupData.h. Unsure why test code would be in such a central place
92107
# This dependency is split since it should probably be removed (or naming should
93108
# be updated if this is not really "testing" even though headers are Test*.h)

src/app/server/Server.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <app/server/AppDelegate.h>
3434
#include <app/server/CommissioningWindowManager.h>
3535
#include <app/server/DefaultAclStorage.h>
36-
#include <app/server/JointFabricDatastore.h>
3736
#include <credentials/CertificateValidityPolicy.h>
3837
#include <credentials/FabricTable.h>
3938
#include <credentials/GroupDataProvider.h>
@@ -82,6 +81,10 @@
8281
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
8382
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
8483

84+
#if CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC
85+
#include <app/server/JointFabricDatastore.h> //nogncheck
86+
#endif // CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC
87+
8588
namespace chip {
8689

8790
inline constexpr size_t kMaxBlePendingPackets = 1;
@@ -419,7 +422,9 @@ class Server
419422

420423
app::reporting::ReportScheduler * GetReportScheduler() { return mReportScheduler; }
421424

425+
#if CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC
422426
app::JointFabricDatastore & GetJointFabricDatastore() { return mJointFabricDatastore; }
427+
#endif // CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC
423428

424429
#if CHIP_CONFIG_ENABLE_ICD_SERVER
425430
app::ICDManager & GetICDManager() { return mICDManager; }
@@ -700,7 +705,9 @@ class Server
700705
Access::AccessControl mAccessControl;
701706
app::AclStorage * mAclStorage;
702707

708+
#if CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC
703709
app::JointFabricDatastore mJointFabricDatastore;
710+
#endif // CHIP_DEVICE_CONFIG_ENABLE_JOINT_FABRIC
704711

705712
TestEventTriggerDelegate * mTestEventTriggerDelegate;
706713
Crypto::OperationalKeystore * mOperationalKeystore;

src/app/server/tests/BUILD.gn

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2025 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
import("//build_overrides/pigweed.gni")
18+
19+
import("${chip_root}/build/chip/chip_test_suite.gni")
20+
21+
chip_test_suite("tests") {
22+
output_name = "jointFabricDatastoreTests"
23+
24+
test_sources = [ "TestJointFabricDatastore.cpp" ]
25+
26+
public_deps = [
27+
"${chip_root}/src/app/server",
28+
"${chip_root}/src/app/server:joint_fabric_datastore",
29+
"${chip_root}/src/lib/core",
30+
"${chip_root}/src/lib/support:testing",
31+
]
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "app/server/JointFabricDatastore.h"
2+
#include <pw_unit_test/framework.h>
3+
4+
using namespace chip;
5+
using namespace chip::app;
6+
7+
namespace {
8+
9+
class DummyListener : public JointFabricDatastore::Listener
10+
{
11+
public:
12+
void MarkNodeListChanged() override { mNotified = true; }
13+
void Reset() { mNotified = false; }
14+
15+
bool mNotified = false;
16+
};
17+
18+
TEST(JointFabricDatastoreTest, AddPendingNodeNotifiesListener)
19+
{
20+
JointFabricDatastore store;
21+
DummyListener listener;
22+
23+
store.AddListener(listener);
24+
25+
// Add a pending node — should notify the listener via MarkNodeListChange
26+
store.AddPendingNode(123, CharSpan::fromCharString("controller-a"));
27+
28+
EXPECT_TRUE(listener.mNotified);
29+
}
30+
31+
TEST(JointFabricDatastoreTest, RemoveListenerPreventsNotification)
32+
{
33+
JointFabricDatastore store;
34+
DummyListener listener;
35+
36+
store.AddListener(listener);
37+
store.RemoveListener(listener);
38+
listener.Reset();
39+
40+
store.AddPendingNode(456, CharSpan::fromCharString("controller-b"));
41+
42+
EXPECT_FALSE(listener.mNotified);
43+
}
44+
45+
} // namespace

0 commit comments

Comments
 (0)