Skip to content

Commit 254010c

Browse files
Add orphan header files from src/controller to gn (project-chip#31882)
* Add files from src/controller to gn * Add more orphaned files from controller itself * Restyle * Move more files into sources since CHIPCluster actually includes them. Seems VERY odd to have this header used but not actually have any implementation. This is a bug! * Attempt to fix some of the include oddities. Controller is VERY broken and feels like a god object definition * Move more headers ... CHIPDeviceController strongly pulls the entire world. * Fix typo * One more header * Fix chef * Add more includes that seem needed * Add another dependency * Add includes config to controller as it needs relative includes * Restyle * Fix clang-tidy logic * Apply some clang-tidy fixes since I looked at controller. Minor nullptr usage and remove else after return * Ensure no errors about unused assignments * Yet another fix for logic to make sure all defined lists are used * Include only headers as the special targets to force include errors * Fix typo * Fix typo --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent 90726e5 commit 254010c

File tree

8 files changed

+78
-30
lines changed

8 files changed

+78
-30
lines changed

examples/platform/linux/AppMain.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#include <platform/CHIPDeviceLayer.h>
2020
#include <platform/PlatformManager.h>
2121

22-
#include "app/clusters/network-commissioning/network-commissioning.h"
22+
#include <app/InteractionModelEngine.h>
23+
#include <app/clusters/network-commissioning/network-commissioning.h>
2324
#include <app/server/Dnssd.h>
2425
#include <app/server/OnboardingCodesUtil.h>
2526
#include <app/server/Server.h>

examples/platform/linux/ControllerShellCommands.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace chip {
3737
namespace Shell {
3838

3939
using namespace chip;
40-
using namespace ::chip::Controller;
4140

4241
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY
4342
static CHIP_ERROR ResetUDC(bool printHeader)

src/app/icd/client/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ source_set("handler") {
4747
public_deps = [
4848
":manager",
4949
"${chip_root}/src/app",
50+
"${chip_root}/src/controller",
5051
"${chip_root}/src/lib/core",
5152
"${chip_root}/src/messaging",
5253
"${chip_root}/src/protocols",

src/controller/BUILD.gn

+59-12
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,87 @@ source_set("nodatamodel") {
2424
public_deps = [ "${chip_root}/src/app" ]
2525
}
2626

27+
CHIP_CONTROLLER_HEADERS = [ "ExampleOperationalCredentialsIssuer.h" ]
28+
CHIP_READ_CLIENT_HEADERS = [
29+
"CommissioningWindowOpener.h",
30+
"CurrentFabricRemover.h",
31+
]
32+
33+
# This source set exists specifically to deny including them without dependencies
34+
# if "controller" sources do not contain them
35+
#
36+
# They are NOT intended to be used directly.
37+
#
38+
# The intent for this is to force gn to be aware that these files are known and
39+
# error out as `include not allowed due to missing dependency` even if
40+
# controller is built without these sources
41+
source_set("gen_check_chip_controller_headers") {
42+
sources = CHIP_CONTROLLER_HEADERS
43+
}
44+
45+
source_set("gen_check_chip_read_client_headers") {
46+
sources = CHIP_READ_CLIENT_HEADERS
47+
}
48+
49+
source_set("delegates") {
50+
sources = [ "OperationalCredentialsDelegate.h" ]
51+
}
52+
2753
static_library("controller") {
2854
output_name = "libChipController"
2955

30-
sources = [ "CHIPCluster.h" ]
56+
sources = [
57+
# TODO: these dependencies are broken. Specifically:
58+
# a) ChipDeviceControllerFactory.h includes CHIPDeviceController.h
59+
# b) CHIPDeviceController.cpp is only compiled for read_client
60+
# These conditionals are NOT ok and should have been solved with separate
61+
# source sets - either include some functionality or do not
62+
#
63+
# Then CHIPDeviceController.h pulls in AbstractDnssdDiscoveryController and everything
64+
# cascades. In the end it looks like basically every header file is pulled in.
65+
#
66+
# Unfortunately this is hard to fix in one go, hence these odd list of header-only
67+
# dependencies
68+
"AbstractDnssdDiscoveryController.h",
69+
"AutoCommissioner.h",
70+
"CHIPCluster.h",
71+
"CHIPCommissionableNodeController.h",
72+
"CHIPDeviceController.h",
73+
"CHIPDeviceControllerSystemState.h",
74+
"CommandSenderAllocator.h",
75+
"CommissioneeDeviceProxy.h",
76+
"CommissioningDelegate.h",
77+
"DeviceDiscoveryDelegate.h",
78+
"DevicePairingDelegate.h",
79+
"InvokeInteraction.h",
80+
"ReadInteraction.h",
81+
"SetUpCodePairer.h",
82+
"TypedCommandCallback.h",
83+
"TypedReadCallback.h",
84+
"WriteInteraction.h",
85+
]
3186

3287
if (chip_controller && chip_build_controller) {
88+
sources += CHIP_CONTROLLER_HEADERS
3389
sources += [
3490
"AbstractDnssdDiscoveryController.cpp",
3591
"AutoCommissioner.cpp",
36-
"AutoCommissioner.h",
3792
"CHIPCommissionableNodeController.cpp",
38-
"CHIPCommissionableNodeController.h",
3993
"CHIPDeviceControllerFactory.cpp",
4094
"CHIPDeviceControllerFactory.h",
4195
"CommissioneeDeviceProxy.cpp",
42-
"CommissioneeDeviceProxy.h",
4396
"CommissionerDiscoveryController.cpp",
4497
"CommissionerDiscoveryController.h",
4598
"CommissioningDelegate.cpp",
46-
"DeviceDiscoveryDelegate.h",
47-
"DevicePairingDelegate.h",
4899
"ExampleOperationalCredentialsIssuer.cpp",
49-
"ExampleOperationalCredentialsIssuer.h",
50100
"SetUpCodePairer.cpp",
51-
"SetUpCodePairer.h",
52101
]
53102
if (chip_enable_read_client) {
103+
sources += CHIP_READ_CLIENT_HEADERS
54104
sources += [
55105
"CHIPDeviceController.cpp",
56-
"CHIPDeviceController.h",
57106
"CommissioningWindowOpener.cpp",
58-
"CommissioningWindowOpener.h",
59107
"CurrentFabricRemover.cpp",
60-
"CurrentFabricRemover.h",
61108
]
62109
}
63110
}
@@ -86,5 +133,5 @@ static_library("controller") {
86133
deps += [ "${chip_root}/src/lib/support:testing" ]
87134
}
88135

89-
defines = []
136+
public_configs = [ "${chip_root}/src:includes" ]
90137
}

src/controller/java/AndroidOperationalCredentialsIssuer.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ CHIP_ERROR AndroidOperationalCredentialsIssuer::GenerateNOCChain(const ByteSpan
135135
{
136136
return CallbackGenerateNOCChain(csrElements, csrNonce, attestationSignature, attestationChallenge, DAC, PAI, onCompletion);
137137
}
138-
else
139-
{
140-
return LocalGenerateNOCChain(csrElements, csrNonce, attestationSignature, attestationChallenge, DAC, PAI, onCompletion);
141-
}
138+
139+
return LocalGenerateNOCChain(csrElements, csrNonce, attestationSignature, attestationChallenge, DAC, PAI, onCompletion);
142140
}
143141

144142
CHIP_ERROR AndroidOperationalCredentialsIssuer::CallbackGenerateNOCChain(const ByteSpan & csrElements, const ByteSpan & csrNonce,

src/controller/java/CHIPDeviceController-JNI.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ JavaVM * sJVM;
106106

107107
pthread_t sIOThread = PTHREAD_NULL;
108108

109-
jclass sChipDeviceControllerExceptionCls = NULL;
109+
jclass sChipDeviceControllerExceptionCls = nullptr;
110110

111111
} // namespace
112112

@@ -131,7 +131,7 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved)
131131

132132
// Get a JNI environment object.
133133
env = JniReferences::GetInstance().GetEnvForCurrentThread();
134-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
134+
VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV);
135135

136136
ChipLogProgress(Controller, "Loading Java class references.");
137137

@@ -171,7 +171,7 @@ void JNI_OnUnload(JavaVM * jvm, void * reserved)
171171
// should be stopped before the library is unloaded.
172172
StopIOThread();
173173

174-
sJVM = NULL;
174+
sJVM = nullptr;
175175

176176
chip::Platform::MemoryShutdown();
177177
}
@@ -280,7 +280,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
280280
{
281281
chip::DeviceLayer::StackLock lock;
282282
CHIP_ERROR err = CHIP_NO_ERROR;
283-
AndroidDeviceControllerWrapper * wrapper = NULL;
283+
AndroidDeviceControllerWrapper * wrapper = nullptr;
284284
jlong result = 0;
285285

286286
ChipLogProgress(Controller, "newDeviceController() called");
@@ -478,7 +478,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
478478
// Create and start the IO thread. Must be called after Controller()->Init
479479
if (sIOThread == PTHREAD_NULL)
480480
{
481-
int pthreadErr = pthread_create(&sIOThread, NULL, IOThreadMain, NULL);
481+
int pthreadErr = pthread_create(&sIOThread, nullptr, IOThreadMain, nullptr);
482482
VerifyOrExit(pthreadErr == 0, err = CHIP_ERROR_POSIX(pthreadErr));
483483
}
484484

@@ -487,7 +487,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
487487
exit:
488488
if (err != CHIP_NO_ERROR)
489489
{
490-
if (wrapper != NULL)
490+
if (wrapper != nullptr)
491491
{
492492
delete wrapper;
493493
}
@@ -1391,7 +1391,7 @@ JNI_METHOD(void, releaseOperationalDevicePointer)(JNIEnv * env, jobject self, jl
13911391
{
13921392
chip::DeviceLayer::StackLock lock;
13931393
OperationalDeviceProxy * device = reinterpret_cast<OperationalDeviceProxy *>(devicePtr);
1394-
if (device != NULL)
1394+
if (device != nullptr)
13951395
{
13961396
delete device;
13971397
}
@@ -1422,7 +1422,7 @@ JNI_METHOD(void, releaseGroupDevicePointer)(JNIEnv * env, jobject self, jlong de
14221422
{
14231423
chip::DeviceLayer::StackLock lock;
14241424
GroupDeviceProxy * device = reinterpret_cast<GroupDeviceProxy *>(devicePtr);
1425-
if (device != NULL)
1425+
if (device != nullptr)
14261426
{
14271427
delete device;
14281428
}
@@ -2117,7 +2117,7 @@ JNI_METHOD(void, deleteDeviceController)(JNIEnv * env, jobject self, jlong handl
21172117

21182118
ChipLogProgress(Controller, "deleteDeviceController() called");
21192119

2120-
if (wrapper != NULL)
2120+
if (wrapper != nullptr)
21212121
{
21222122
delete wrapper;
21232123
}
@@ -3067,7 +3067,7 @@ void * IOThreadMain(void * arg)
30673067
// This allows the JVM to shutdown without waiting for this thread to exit.
30683068
attachArgs.version = JNI_VERSION_1_6;
30693069
attachArgs.name = (char *) "CHIP Device Controller IO Thread";
3070-
attachArgs.group = NULL;
3070+
attachArgs.group = nullptr;
30713071
#ifdef __ANDROID__
30723072
sJVM->AttachCurrentThreadAsDaemon(&env, (void *) &attachArgs);
30733073
#else
@@ -3081,7 +3081,7 @@ void * IOThreadMain(void * arg)
30813081
// Detach the thread from the JVM.
30823082
sJVM->DetachCurrentThread();
30833083

3084-
return NULL;
3084+
return nullptr;
30853085
}
30863086

30873087
// NOTE: This function SHALL be called with the stack lock held.
@@ -3094,7 +3094,7 @@ CHIP_ERROR StopIOThread()
30943094

30953095
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
30963096

3097-
pthread_join(sIOThread, NULL);
3097+
pthread_join(sIOThread, nullptr);
30983098
sIOThread = PTHREAD_NULL;
30993099
}
31003100

src/controller/tests/data_model/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ chip_test_suite_using_nltest("data_model") {
3434
"${chip_root}/src/app/common:cluster-objects",
3535
"${chip_root}/src/app/tests:helpers",
3636
"${chip_root}/src/app/util/mock:mock_ember",
37+
"${chip_root}/src/controller",
3738
"${chip_root}/src/lib/support:testing_nlunit",
3839
"${chip_root}/src/messaging/tests:helpers",
3940
"${chip_root}/src/transport/raw/tests:helpers",

src/credentials/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static_library("credentials") {
125125

126126
public_deps = [
127127
":build_time_header",
128+
"${chip_root}/src/controller:delegates",
128129
"${chip_root}/src/crypto",
129130
"${chip_root}/src/lib/asn1",
130131
"${chip_root}/src/lib/core",

0 commit comments

Comments
 (0)