Skip to content

Commit

Permalink
Linux: Tidy up ifdefs around app options
Browse files Browse the repository at this point in the history
Use consistent ifdef conditions between member definitions, option definition,
option handling code, and help text.
  • Loading branch information
ksperling-apple committed Jun 3, 2024
1 parent 9217d22 commit f2c7d8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
18 changes: 9 additions & 9 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
kDeviceOption_SecuredCommissionerPort = 0x100c,
kCommissionerOption_FabricID = 0x1020,
#endif
kDeviceOption_Command = 0x100d,
kDeviceOption_PICS = 0x100e,
Expand All @@ -90,7 +91,6 @@ enum
kOptionCSRResponseAttestationSignatureInvalid = 0x101d,
kOptionCSRResponseCSRExistingKeyPair = 0x101e,
kDeviceOption_TestEventTriggerEnableKey = 0x101f,
kCommissionerOption_FabricID = 0x1020,
kTraceTo = 0x1021,
kOptionSimulateNoInternalTime = 0x1022,
#if defined(PW_RPC_ENABLED)
Expand Down Expand Up @@ -137,6 +137,7 @@ OptionDef sDeviceOptionDefs[] = {
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
{ "secured-commissioner-port", kArgumentRequired, kDeviceOption_SecuredCommissionerPort },
{ "commissioner-fabric-id", kArgumentRequired, kCommissionerOption_FabricID },
#endif
{ "command", kArgumentRequired, kDeviceOption_Command },
{ "PICS", kArgumentRequired, kDeviceOption_PICS },
Expand All @@ -156,7 +157,6 @@ OptionDef sDeviceOptionDefs[] = {
{ "cert_error_attestation_signature_incorrect_type", kNoArgument, kOptionCSRResponseAttestationSignatureIncorrectType },
{ "cert_error_attestation_signature_invalid", kNoArgument, kOptionCSRResponseAttestationSignatureInvalid },
{ "enable-key", kArgumentRequired, kDeviceOption_TestEventTriggerEnableKey },
{ "commissioner-fabric-id", kArgumentRequired, kCommissionerOption_FabricID },
#if ENABLE_TRACING
{ "trace-to", kArgumentRequired, kTraceTo },
#endif
Expand Down Expand Up @@ -239,15 +239,15 @@ const char * sDeviceOptionHelp =
" A 16-bit unsigned integer specifying the port to use for unsecured commissioner messages (default is 5550).\n"
"\n"
#endif
#if CHIP_DEVICE_ENABLE_PORT_PARAMS
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
" --secured-commissioner-port <port>\n"
" A 16-bit unsigned integer specifying the listen port to use for secure commissioner messages (default is 5552). Only "
"valid when app is both device and commissioner\n"
"\n"
#endif
" --commissioner-fabric-id <fabricid>\n"
" The fabric ID to be used when this device is a commissioner (default in code is 1).\n"
"\n"
#endif
" --command <command-name>\n"
" A name for a command to execute during startup.\n"
"\n"
Expand Down Expand Up @@ -476,6 +476,11 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
case kDeviceOption_SecuredCommissionerPort:
LinuxDeviceOptions::GetInstance().securedCommissionerPort = static_cast<uint16_t>(atoi(aValue));
break;
case kCommissionerOption_FabricID: {
char * eptr;
LinuxDeviceOptions::GetInstance().commissionerFabricId = (chip::FabricId) strtoull(aValue, &eptr, 0);
break;
}
#endif

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

break;
}
case kCommissionerOption_FabricID: {
char * eptr;
LinuxDeviceOptions::GetInstance().commissionerFabricId = (chip::FabricId) strtoull(aValue, &eptr, 0);
break;
}
#if ENABLE_TRACING
case kTraceTo:
LinuxDeviceOptions::GetInstance().traceTo.push_back(aValue);
Expand Down
14 changes: 8 additions & 6 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,23 @@ struct LinuxDeviceOptions
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
uint16_t securedDevicePort = CHIP_PORT;
uint16_t unsecuredCommissionerPort = CHIP_UDC_PORT;
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
uint16_t securedCommissionerPort = CHIP_PORT + 12; // TODO: why + 12?
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
uint16_t securedCommissionerPort = CHIP_PORT + 12; // TODO: why + 12?
chip::FabricId commissionerFabricId = chip::kUndefinedFabricId;
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
const char * command = nullptr;
const char * PICS = nullptr;
const char * KVS = nullptr;
chip::Inet::InterfaceId interfaceId = chip::Inet::InterfaceId::Null();
bool traceStreamDecodeEnabled = false;
bool traceStreamToLogEnabled = false;
#if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
bool traceStreamDecodeEnabled = false;
bool traceStreamToLogEnabled = false;
chip::Optional<std::string> traceStreamFilename;
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
chip::Credentials::DeviceAttestationCredentialsProvider * dacProvider = nullptr;
chip::CSRResponseOptions mCSRResponseOptions;
uint8_t testEventTriggerEnableKey[16] = { 0 };
chip::FabricId commissionerFabricId = chip::kUndefinedFabricId;
std::vector<std::string> traceTo;
bool mSimulateNoInternalTime = false;
#if defined(PW_RPC_ENABLED)
Expand Down

0 comments on commit f2c7d8c

Please sign in to comment.