Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
Expand Down Expand Up @@ -78,6 +80,8 @@ MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
NamespaceMacros:
- WeaveMakeManagedNamespace
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
Expand Down
36 changes: 36 additions & 0 deletions build/scripts/format-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

SED=/bin/sed
PERL=/usr/bin/perl
CLANGFORMAT=clang-format-9

FILENAME=${1}

# do anything iff we have clang-format
if ! clang-format -version; then
echo "Missing clang-format, please install it prior to reformatting the code"
exit 1
fi
# clang format has difficulty recognizing the
# WeaveMakeManagedNamespaceIdentifier() macro as a valid namespace;
# temporarily change the namespace name to something more palatable to
# clang-format

sed -i -e 's:^[ ]*namespace[ ]\+WeaveMakeManagedNamespaceIdentifier(\([^ ,()]\+\),[ ]*\([^ ,()]\+\))[ ]*{[ ]*$:namespace WeaveMakeManagedNamespaceIdentifier_\1_\2 {:g' ${FILENAME}

${CLANGFORMAT} -i -style=file ${FILENAME}

sed -i -e 's:namespace WeaveMakeManagedNamespaceIdentifier_\([^_]\+\)_\([^ ]\+\):namespace WeaveMakeManagedNamespaceIdentifier(\1, \2):g' ${FILENAME}

# clang formatter does not seem to provide an option to insert a space into the empty expression i.e., {}, so we hit this with sed
sed -i -e 's:{}:{ }:g' ${FILENAME}
sed -i -e 's:;):; ):g' ${FILENAME}

# weave prefers to separate the keyword operator from the operator itself
sed -i -e 's:operator\([-+/*|&=~!%<>[(]\):operator \1:g' ${FILENAME}

#space before the opening brace in short functions
sed -i -e 's:){:) {:g' ${FILENAME}
sed -i -e 's:({:( {:g' ${FILENAME}

sed -i -e 's:\(.\)\([^ "@]\){:\1\2 {:g' ${FILENAME}
10,388 changes: 5,194 additions & 5,194 deletions src/adaptations/device-layer/TestDeviceIds.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,24 @@ class ConnectivityManager
*/
struct ConnectivityManager::ThreadPollingConfig
{
uint32_t ActivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when
when there are active Weave exchanges in progress. Only meaningful
when the device is acting as a sleepy end node. */

uint32_t InactivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when
when there are NO active Weave exchanges in progress. Only meaningful
when the device is acting as a sleepy end node. */

/**
* Interval at which the device polls its parent Thread router when
* when there are active Weave exchanges in progress. Only meaningful
* when the device is acting as a sleepy end node.
*/
uint32_t ActivePollingIntervalMS;

/**
* Interval at which the device polls its parent Thread router when
* when there are NO active Weave exchanges in progress. Only meaningful
* when the device is acting as a sleepy end node.
*/
uint32_t InactivePollingIntervalMS;

/**
* Clear the structure, setting all members to 0.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of enforcing prefix documentation for inline definitions? This is particularly onerous on readability.

I see a lot of places in this PR where the requirement is suppressed. If we don't like the way it looks, then why would we turn it on in the first place?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one of the first files I changed, and I was still evolving a style. In a few places earlier on I thought the right path forward was to switch to prefix and rely on the clang format down the road. As the set of changes evolved, I've started using the // clang-format off directive more easily and I am happy to make those changes.

void Clear() { memset(this, 0, sizeof(*this)); }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class DeviceNetworkInfo
kThreadPSKcLength = 16,
};

// clang-format off

NetworkType_t NetworkType; /**< The type of network. */
uint32_t NetworkId; /**< The network id assigned to the network by the device. */

Expand Down Expand Up @@ -100,6 +102,8 @@ class DeviceNetworkInfo
bool ThreadPSKc : 1; /**< True if the ThreadPSKc field is present. */
} FieldPresent;

// clang-format on

void Reset();
WEAVE_ERROR Decode(::nl::Weave::TLV::TLVReader & reader);
WEAVE_ERROR Encode(::nl::Weave::TLV::TLVWriter & writer) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void RunConfigUnitTest(void)
}

// ===== Test 7: Store and read binary data
// clang-format off
{
const static uint8_t kTestData[] =
{
Expand Down Expand Up @@ -159,7 +160,7 @@ void RunConfigUnitTest(void)
VerifyOrDie(dataLen == sizeof(kTestData));
VerifyOrDie(memcmp(buf, kTestData, dataLen) == 0);
}

// clang-format on
// ===== Test 8: Clear binary data
{
uint8_t buf[512];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class NRF5Config
// *** CAUTION ***: Changing the FDS file or record ids of these values will *break* existing devices.

// Limits/definitions imposed by the Nordic SDK
// clang-format off
static constexpr uint16_t kFDSFileIdMin = 0x0000; /**< Minimum value that can be used for a FDS file id (per Nordic SDK) */
static constexpr uint16_t kFDSFileIdMax = 0xBFFF; /**< Maximum value that can be used for a FDS file id (per Nordic SDK) */
static constexpr uint16_t kFDSRecordKeyMin = 0x0001; /**< Minimum value that can be used for a FDS record key (per Nordic SDK) */
Expand Down Expand Up @@ -107,6 +108,7 @@ class NRF5Config
static constexpr uint16_t kPersistedCounterRecordKeyMax = kFDSRecordKeyMax;
/**< Max record key for records containing Weave persisted counter values. */

// clang-format on
static WEAVE_ERROR Init(void);

// Configuration methods used by the GenericConfigurationManagerImpl<> template.
Expand Down
67 changes: 34 additions & 33 deletions src/ble/BleError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,45 @@ bool FormatBleLayerError(char * buf, uint16_t bufSize, int32_t err)
{
return false;
}

// clang-format off
#if !WEAVE_CONFIG_SHORT_ERROR_STR
switch (err)
{
case BLE_ERROR_BAD_ARGS : desc = "Bad arguments"; break;
case BLE_ERROR_INCORRECT_STATE : desc = "Incorrect state"; break;
case BLE_ERROR_NO_ENDPOINTS : desc = "No more BLE endpoints"; break;
case BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK : desc = "No Weave over BLE connection received callback set"; break;
case BLE_ERROR_CENTRAL_UNSUBSCRIBED : desc = "BLE central unsubscribed"; break;
case BLE_ERROR_GATT_SUBSCRIBE_FAILED : desc = "GATT subscribe operation failed"; break;
case BLE_ERROR_GATT_UNSUBSCRIBE_FAILED : desc = "GATT unsubscribe operation failed"; break;
case BLE_ERROR_GATT_WRITE_FAILED : desc = "GATT write characteristic operation failed"; break;
case BLE_ERROR_GATT_INDICATE_FAILED : desc = "GATT indicate characteristic operation failed"; break;
case BLE_ERROR_NOT_IMPLEMENTED : desc = "Not implemented"; break;
case BLE_ERROR_WOBLE_PROTOCOL_ABORT : desc = "BLE transport protocol fired abort"; break;
case BLE_ERROR_REMOTE_DEVICE_DISCONNECTED : desc = "Remote device closed BLE connection"; break;
case BLE_ERROR_APP_CLOSED_CONNECTION : desc = "Application closed BLE connection"; break;
case BLE_ERROR_OUTBOUND_MESSAGE_TOO_BIG : desc = "Outbound message too big"; break;
case BLE_ERROR_NOT_WEAVE_DEVICE : desc = "BLE device doesn't seem to support Weave"; break;
case BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS : desc = "Incompatible BLE transport protocol versions"; break;
case BLE_ERROR_NO_MEMORY : desc = "No memory"; break;
case BLE_ERROR_MESSAGE_INCOMPLETE : desc = "Message incomplete"; break;
case BLE_ERROR_INVALID_FRAGMENT_SIZE : desc = "Invalid fragment size"; break;
case BLE_ERROR_START_TIMER_FAILED : desc = "Start timer failed"; break;
case BLE_ERROR_CONNECT_TIMED_OUT : desc = "Connect handshake timed out"; break;
case BLE_ERROR_RECEIVE_TIMED_OUT : desc = "Receive handshake timed out"; break;
case BLE_ERROR_INVALID_MESSAGE : desc = "Invalid message"; break;
case BLE_ERROR_FRAGMENT_ACK_TIMED_OUT : desc = "Message fragment acknowledgement timed out"; break;
case BLE_ERROR_KEEP_ALIVE_TIMED_OUT : desc = "Keep-alive receipt timed out"; break;
case BLE_ERRROR_NO_CONNECT_COMPLETE_CALLBACK : desc = "Missing required callback"; break;
case BLE_ERROR_INVALID_ACK : desc = "Received invalid BLE transport protocol fragment acknowledgement"; break;
case BLE_ERROR_REASSEMBLER_MISSING_DATA : desc = "BLE message reassembler did not receive enough data"; break;
case BLE_ERROR_INVALID_BTP_HEADER_FLAGS : desc = "Received invalid BLE transport protocol header flags"; break;
case BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER : desc = "Received invalid BLE transport protocol sequence number"; break;
case BLE_ERROR_REASSEMBLER_INCORRECT_STATE : desc = "BLE message reassembler received packet in incorrect state"; break;
case BLE_ERROR_RECEIVED_MESSAGE_TOO_BIG : desc = "Message received by BLE message reassembler was too large"; break;
case BLE_ERROR_BAD_ARGS : desc = "Bad arguments"; break;
case BLE_ERROR_INCORRECT_STATE : desc = "Incorrect state"; break;
case BLE_ERROR_NO_ENDPOINTS : desc = "No more BLE endpoints"; break;
case BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK : desc = "No Weave over BLE connection received callback set"; break;
case BLE_ERROR_CENTRAL_UNSUBSCRIBED : desc = "BLE central unsubscribed"; break;
case BLE_ERROR_GATT_SUBSCRIBE_FAILED : desc = "GATT subscribe operation failed"; break;
case BLE_ERROR_GATT_UNSUBSCRIBE_FAILED : desc = "GATT unsubscribe operation failed"; break;
case BLE_ERROR_GATT_WRITE_FAILED : desc = "GATT write characteristic operation failed"; break;
case BLE_ERROR_GATT_INDICATE_FAILED : desc = "GATT indicate characteristic operation failed"; break;
case BLE_ERROR_NOT_IMPLEMENTED : desc = "Not implemented"; break;
case BLE_ERROR_WOBLE_PROTOCOL_ABORT : desc = "BLE transport protocol fired abort"; break;
case BLE_ERROR_REMOTE_DEVICE_DISCONNECTED : desc = "Remote device closed BLE connection"; break;
case BLE_ERROR_APP_CLOSED_CONNECTION : desc = "Application closed BLE connection"; break;
case BLE_ERROR_OUTBOUND_MESSAGE_TOO_BIG : desc = "Outbound message too big"; break;
case BLE_ERROR_NOT_WEAVE_DEVICE : desc = "BLE device doesn't seem to support Weave"; break;
case BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS : desc = "Incompatible BLE transport protocol versions"; break;
case BLE_ERROR_NO_MEMORY : desc = "No memory"; break;
case BLE_ERROR_MESSAGE_INCOMPLETE : desc = "Message incomplete"; break;
case BLE_ERROR_INVALID_FRAGMENT_SIZE : desc = "Invalid fragment size"; break;
case BLE_ERROR_START_TIMER_FAILED : desc = "Start timer failed"; break;
case BLE_ERROR_CONNECT_TIMED_OUT : desc = "Connect handshake timed out"; break;
case BLE_ERROR_RECEIVE_TIMED_OUT : desc = "Receive handshake timed out"; break;
case BLE_ERROR_INVALID_MESSAGE : desc = "Invalid message"; break;
case BLE_ERROR_FRAGMENT_ACK_TIMED_OUT : desc = "Message fragment acknowledgement timed out"; break;
case BLE_ERROR_KEEP_ALIVE_TIMED_OUT : desc = "Keep-alive receipt timed out"; break;
case BLE_ERRROR_NO_CONNECT_COMPLETE_CALLBACK : desc = "Missing required callback"; break;
case BLE_ERROR_INVALID_ACK : desc = "Received invalid BLE transport protocol fragment acknowledgement"; break;
case BLE_ERROR_REASSEMBLER_MISSING_DATA : desc = "BLE message reassembler did not receive enough data"; break;
case BLE_ERROR_INVALID_BTP_HEADER_FLAGS : desc = "Received invalid BLE transport protocol header flags"; break;
case BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER : desc = "Received invalid BLE transport protocol sequence number"; break;
case BLE_ERROR_REASSEMBLER_INCORRECT_STATE : desc = "BLE message reassembler received packet in incorrect state"; break;
case BLE_ERROR_RECEIVED_MESSAGE_TOO_BIG : desc = "Message received by BLE message reassembler was too large"; break;
}
#endif // !WEAVE_CONFIG_SHORT_ERROR_STR
// clang-format on

FormatError(buf, bufSize, "Ble", err, desc);

Expand Down
Loading