Skip to content

Commit dc8187b

Browse files
Linux: Tidy up ifdefs around app options (#33721)
* Linux: Tidy up ifdefs around app options Use consistent ifdef conditions between member definitions, option definition, option handling code, and help text. * There is no need to hand-allocate option numbers
1 parent bfb3a4d commit dc8187b

File tree

2 files changed

+56
-54
lines changed

2 files changed

+56
-54
lines changed

examples/platform/linux/Options.cpp

+48-48
Original file line numberDiff line numberDiff line change
@@ -54,57 +54,57 @@ LinuxDeviceOptions gDeviceOptions;
5454
// Follow the code style of command line arguments in case we need to add more options in the future.
5555
enum
5656
{
57-
kDeviceOption_BleDevice = 0x1000,
58-
kDeviceOption_WiFi = 0x1001,
59-
kDeviceOption_Thread = 0x1002,
60-
kDeviceOption_Version = 0x1003,
61-
kDeviceOption_VendorID = 0x1004,
62-
kDeviceOption_ProductID = 0x1005,
63-
kDeviceOption_CustomFlow = 0x1006,
64-
kDeviceOption_Capabilities = 0x1007,
65-
kDeviceOption_Discriminator = 0x1008,
66-
kDeviceOption_Passcode = 0x1009,
57+
kDeviceOption_BleDevice = 0x1000,
58+
kDeviceOption_WiFi,
59+
kDeviceOption_Thread,
60+
kDeviceOption_Version,
61+
kDeviceOption_VendorID,
62+
kDeviceOption_ProductID,
63+
kDeviceOption_CustomFlow,
64+
kDeviceOption_Capabilities,
65+
kDeviceOption_Discriminator,
66+
kDeviceOption_Passcode,
6767
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
68-
kDeviceOption_SecuredDevicePort = 0x100a,
69-
kDeviceOption_UnsecuredCommissionerPort = 0x100b,
68+
kDeviceOption_SecuredDevicePort,
69+
kDeviceOption_UnsecuredCommissionerPort,
7070
#endif
7171
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
72-
kDeviceOption_SecuredCommissionerPort = 0x100c,
72+
kDeviceOption_SecuredCommissionerPort,
73+
kCommissionerOption_FabricID,
7374
#endif
74-
kDeviceOption_Command = 0x100d,
75-
kDeviceOption_PICS = 0x100e,
76-
kDeviceOption_KVS = 0x100f,
77-
kDeviceOption_InterfaceId = 0x1010,
78-
kDeviceOption_Spake2pVerifierBase64 = 0x1011,
79-
kDeviceOption_Spake2pSaltBase64 = 0x1012,
80-
kDeviceOption_Spake2pIterations = 0x1013,
81-
kDeviceOption_TraceFile = 0x1014,
82-
kDeviceOption_TraceLog = 0x1015,
83-
kDeviceOption_TraceDecode = 0x1016,
84-
kOptionCSRResponseCSRIncorrectType = 0x1017,
85-
kOptionCSRResponseCSRNonceIncorrectType = 0x1018,
86-
kOptionCSRResponseCSRNonceTooLong = 0x1019,
87-
kOptionCSRResponseCSRNonceInvalid = 0x101a,
88-
kOptionCSRResponseNOCSRElementsTooLong = 0x101b,
89-
kOptionCSRResponseAttestationSignatureIncorrectType = 0x101c,
90-
kOptionCSRResponseAttestationSignatureInvalid = 0x101d,
91-
kOptionCSRResponseCSRExistingKeyPair = 0x101e,
92-
kDeviceOption_TestEventTriggerEnableKey = 0x101f,
93-
kCommissionerOption_FabricID = 0x1020,
94-
kTraceTo = 0x1021,
95-
kOptionSimulateNoInternalTime = 0x1022,
75+
kDeviceOption_Command,
76+
kDeviceOption_PICS,
77+
kDeviceOption_KVS,
78+
kDeviceOption_InterfaceId,
79+
kDeviceOption_Spake2pVerifierBase64,
80+
kDeviceOption_Spake2pSaltBase64,
81+
kDeviceOption_Spake2pIterations,
82+
kDeviceOption_TraceFile,
83+
kDeviceOption_TraceLog,
84+
kDeviceOption_TraceDecode,
85+
kOptionCSRResponseCSRIncorrectType,
86+
kOptionCSRResponseCSRNonceIncorrectType,
87+
kOptionCSRResponseCSRNonceTooLong,
88+
kOptionCSRResponseCSRNonceInvalid,
89+
kOptionCSRResponseNOCSRElementsTooLong,
90+
kOptionCSRResponseAttestationSignatureIncorrectType,
91+
kOptionCSRResponseAttestationSignatureInvalid,
92+
kOptionCSRResponseCSRExistingKeyPair,
93+
kDeviceOption_TestEventTriggerEnableKey,
94+
kTraceTo,
95+
kOptionSimulateNoInternalTime,
9696
#if defined(PW_RPC_ENABLED)
97-
kOptionRpcServerPort = 0x1023,
97+
kOptionRpcServerPort,
9898
#endif
9999
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
100-
kDeviceOption_SubscriptionCapacity = 0x1024,
100+
kDeviceOption_SubscriptionCapacity,
101101
#endif
102-
kDeviceOption_WiFiSupports5g = 0x1025,
102+
kDeviceOption_WiFiSupports5g,
103103
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
104-
kDeviceOption_SubscriptionResumptionRetryIntervalSec = 0x1026,
104+
kDeviceOption_SubscriptionResumptionRetryIntervalSec,
105105
#endif
106106
#if CHIP_WITH_NLFAULTINJECTION
107-
kDeviceOption_FaultInjection = 0x1027,
107+
kDeviceOption_FaultInjection,
108108
#endif
109109
};
110110

@@ -137,6 +137,7 @@ OptionDef sDeviceOptionDefs[] = {
137137
#endif
138138
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
139139
{ "secured-commissioner-port", kArgumentRequired, kDeviceOption_SecuredCommissionerPort },
140+
{ "commissioner-fabric-id", kArgumentRequired, kCommissionerOption_FabricID },
140141
#endif
141142
{ "command", kArgumentRequired, kDeviceOption_Command },
142143
{ "PICS", kArgumentRequired, kDeviceOption_PICS },
@@ -156,7 +157,6 @@ OptionDef sDeviceOptionDefs[] = {
156157
{ "cert_error_attestation_signature_incorrect_type", kNoArgument, kOptionCSRResponseAttestationSignatureIncorrectType },
157158
{ "cert_error_attestation_signature_invalid", kNoArgument, kOptionCSRResponseAttestationSignatureInvalid },
158159
{ "enable-key", kArgumentRequired, kDeviceOption_TestEventTriggerEnableKey },
159-
{ "commissioner-fabric-id", kArgumentRequired, kCommissionerOption_FabricID },
160160
#if ENABLE_TRACING
161161
{ "trace-to", kArgumentRequired, kTraceTo },
162162
#endif
@@ -239,15 +239,15 @@ const char * sDeviceOptionHelp =
239239
" A 16-bit unsigned integer specifying the port to use for unsecured commissioner messages (default is 5550).\n"
240240
"\n"
241241
#endif
242-
#if CHIP_DEVICE_ENABLE_PORT_PARAMS
242+
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
243243
" --secured-commissioner-port <port>\n"
244244
" A 16-bit unsigned integer specifying the listen port to use for secure commissioner messages (default is 5552). Only "
245245
"valid when app is both device and commissioner\n"
246246
"\n"
247-
#endif
248247
" --commissioner-fabric-id <fabricid>\n"
249248
" The fabric ID to be used when this device is a commissioner (default in code is 1).\n"
250249
"\n"
250+
#endif
251251
" --command <command-name>\n"
252252
" A name for a command to execute during startup.\n"
253253
"\n"
@@ -476,6 +476,11 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
476476
case kDeviceOption_SecuredCommissionerPort:
477477
LinuxDeviceOptions::GetInstance().securedCommissionerPort = static_cast<uint16_t>(atoi(aValue));
478478
break;
479+
case kCommissionerOption_FabricID: {
480+
char * eptr;
481+
LinuxDeviceOptions::GetInstance().commissionerFabricId = (chip::FabricId) strtoull(aValue, &eptr, 0);
482+
break;
483+
}
479484
#endif
480485

481486
case kDeviceOption_Command:
@@ -550,11 +555,6 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
550555

551556
break;
552557
}
553-
case kCommissionerOption_FabricID: {
554-
char * eptr;
555-
LinuxDeviceOptions::GetInstance().commissionerFabricId = (chip::FabricId) strtoull(aValue, &eptr, 0);
556-
break;
557-
}
558558
#if ENABLE_TRACING
559559
case kTraceTo:
560560
LinuxDeviceOptions::GetInstance().traceTo.push_back(aValue);

examples/platform/linux/Options.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,23 @@ struct LinuxDeviceOptions
5252
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
5353
uint16_t securedDevicePort = CHIP_PORT;
5454
uint16_t unsecuredCommissionerPort = CHIP_UDC_PORT;
55-
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
55+
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
5656
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
57-
uint16_t securedCommissionerPort = CHIP_PORT + 12; // TODO: why + 12?
58-
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
57+
uint16_t securedCommissionerPort = CHIP_PORT + 12; // TODO: why + 12?
58+
chip::FabricId commissionerFabricId = chip::kUndefinedFabricId;
59+
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
5960
const char * command = nullptr;
6061
const char * PICS = nullptr;
6162
const char * KVS = nullptr;
6263
chip::Inet::InterfaceId interfaceId = chip::Inet::InterfaceId::Null();
63-
bool traceStreamDecodeEnabled = false;
64-
bool traceStreamToLogEnabled = false;
64+
#if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
65+
bool traceStreamDecodeEnabled = false;
66+
bool traceStreamToLogEnabled = false;
6567
chip::Optional<std::string> traceStreamFilename;
68+
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
6669
chip::Credentials::DeviceAttestationCredentialsProvider * dacProvider = nullptr;
6770
chip::CSRResponseOptions mCSRResponseOptions;
6871
uint8_t testEventTriggerEnableKey[16] = { 0 };
69-
chip::FabricId commissionerFabricId = chip::kUndefinedFabricId;
7072
std::vector<std::string> traceTo;
7173
bool mSimulateNoInternalTime = false;
7274
#if defined(PW_RPC_ENABLED)

0 commit comments

Comments
 (0)