From d3956f99bcbccbfb0941a3a740605b234a8970f7 Mon Sep 17 00:00:00 2001 From: Martin Turon Date: Wed, 18 Mar 2020 20:03:53 -0700 Subject: [PATCH] [style] Run 'make pretty' to reapply style guide on codebase. --- src/ble/BLEEndPoint.h | 4 +- src/ble/BleError.h | 1 - src/ble/BleLayer.h | 7 +- src/ble/BlePlatformDelegate.h | 7 +- src/ble/CHIPBleServiceData.h | 42 ++--- src/ble/CHIPoBle.h | 4 +- src/inet/AsyncDNSResolverSockets.h | 42 ++--- src/inet/DNSResolver.h | 51 +++--- src/inet/EndPointBasis.h | 42 ++--- src/inet/IANAConstants.h | 34 ++-- src/inet/IPAddress.h | 54 +++--- src/inet/IPEndPointBasis.h | 49 +++--- src/inet/IPPrefix.h | 16 +- src/inet/InetBuffer.h | 4 +- src/inet/InetError.h | 9 +- src/inet/InetFaultInjection.h | 14 +- src/inet/InetInterface.h | 25 +-- src/inet/InetLayer.h | 161 +++++++++--------- src/inet/InetLayerBasis.h | 54 +++--- src/inet/InetLayerEvents.h | 27 ++- src/inet/InetTimer.h | 14 +- src/inet/RawEndPoint.h | 26 +-- src/inet/TCPEndPoint.h | 119 +++++++------ src/inet/TunEndPoint.h | 59 +++---- src/inet/UDPEndPoint.h | 24 +-- src/lwip/tests/tests.c | 16 +- .../QRCodeSetupPayloadGenerator.h | 2 +- src/setup_payload/SetupCodeUtils.h | 2 +- src/setup_payload/SetupPayload.cpp | 2 +- src/setup_payload/SetupPayload.h | 52 +++--- src/setup_payload/tests/tests.cpp | 2 +- src/system/SystemAlignSize.h | 2 +- src/system/SystemClock.h | 14 +- src/system/SystemConfig.h | 2 +- src/system/SystemError.h | 6 +- src/system/SystemEvent.h | 6 +- src/system/SystemFaultInjection.h | 25 ++- src/system/SystemLayer.h | 79 ++++----- src/system/SystemMutex.h | 24 ++- src/system/SystemObject.h | 100 ++++++----- src/system/SystemPacketBuffer.h | 43 +++-- src/system/SystemStats.h | 73 ++++---- src/system/SystemTimer.h | 48 +++--- 43 files changed, 668 insertions(+), 719 deletions(-) diff --git a/src/ble/BLEEndPoint.h b/src/ble/BLEEndPoint.h index 73f709d3add5b6..b14478e0da3c15 100644 --- a/src/ble/BLEEndPoint.h +++ b/src/ble/BLEEndPoint.h @@ -222,8 +222,8 @@ class DLL_EXPORT BLEEndPoint : public BleLayerObject inline void QueueTxLock() { mTxQueueMutex.Lock(); }; inline void QueueTxUnlock() { mTxQueueMutex.Unlock(); }; #else - inline void QueueTxLock() { }; - inline void QueueTxUnlock() { }; + inline void QueueTxLock(){}; + inline void QueueTxUnlock(){}; #endif void QueueTx(PacketBuffer * data, PacketType_t type); }; diff --git a/src/ble/BleError.h b/src/ble/BleError.h index 1ec925bdc63fc8..fba20bab38da9b 100644 --- a/src/ble/BleError.h +++ b/src/ble/BleError.h @@ -425,5 +425,4 @@ extern bool FormatBleLayerError(char * buf, uint16_t bufSize, int32_t err); } /* namespace Ble */ } /* namespace chip */ - #endif /* BLEERROR_H_ */ diff --git a/src/ble/BleLayer.h b/src/ble/BleLayer.h index 871698d550e501..88f4cb5019a314 100644 --- a/src/ble/BleLayer.h +++ b/src/ble/BleLayer.h @@ -78,7 +78,7 @@ using ::chip::System::PacketBuffer; * versions encapsulated in a BleTransportCapabilitiesRequest. Defined by chip * over BLE protocol specification. */ -#define NUM_SUPPORTED_PROTOCOL_VERSIONS 8 +#define NUM_SUPPORTED_PROTOCOL_VERSIONS 8 /// Version(s) of the CHIP BLE Transport Protocol that this stack supports. #define CHIP_BLE_TRANSPORT_PROTOCOL_MIN_SUPPORTED_VERSION kBleTransportProtocolVersion_V2 #define CHIP_BLE_TRANSPORT_PROTOCOL_MAX_SUPPORTED_VERSION kBleTransportProtocolVersion_V3 @@ -250,8 +250,7 @@ class DLL_EXPORT BleLayer // Public functions: BleLayer(void); - BLE_ERROR Init(BlePlatformDelegate * platformDelegate, BleApplicationDelegate * appDelegate, - chip::System::Layer * systemLayer); + BLE_ERROR Init(BlePlatformDelegate * platformDelegate, BleApplicationDelegate * appDelegate, chip::System::Layer * systemLayer); #if BLE_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES BLE_ERROR Init(BlePlatformDelegate * platformDelegate, BleApplicationDelegate * appDelegate, Inet::InetLayer * inetLayer); @@ -261,7 +260,7 @@ class DLL_EXPORT BleLayer BLE_ERROR NewBleEndPoint(BLEEndPoint ** retEndPoint, BLE_CONNECTION_OBJECT connObj, BleRole role, bool autoClose); - chip::System::Error ScheduleWork(chip::System::Layer::TimerCompleteFunct aComplete, void* aAppState) + chip::System::Error ScheduleWork(chip::System::Layer::TimerCompleteFunct aComplete, void * aAppState) { return mSystemLayer->ScheduleWork(aComplete, aAppState); } diff --git a/src/ble/BlePlatformDelegate.h b/src/ble/BlePlatformDelegate.h index 8b087f0c5012f4..92b849b7a1f037 100644 --- a/src/ble/BlePlatformDelegate.h +++ b/src/ble/BlePlatformDelegate.h @@ -43,8 +43,7 @@ class DLL_EXPORT BlePlatformDelegate // Following APIs must be implemented by platform: // Subscribe to updates and indications on the specfied characteristic - virtual bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const chipBleUUID * svcId, - const chipBleUUID * charId) = 0; + virtual bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const chipBleUUID * svcId, const chipBleUUID * charId) = 0; // Unsubscribe from updates and indications on the specified characteristic virtual bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const chipBleUUID * svcId, @@ -87,8 +86,8 @@ class DLL_EXPORT BlePlatformDelegate PacketBuffer * pBuf) = 0; // Send response to remote host's GATT chacteristic read response - virtual bool SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext, - const chipBleUUID * svcId, const chipBleUUID * charId) = 0; + virtual bool SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext, const chipBleUUID * svcId, + const chipBleUUID * charId) = 0; }; } /* namespace Ble */ diff --git a/src/ble/CHIPBleServiceData.h b/src/ble/CHIPBleServiceData.h index e73ba80f99f483..c9c992e6c0c2a2 100644 --- a/src/ble/CHIPBleServiceData.h +++ b/src/ble/CHIPBleServiceData.h @@ -31,8 +31,8 @@ namespace Ble { */ enum chipBLEServiceDataType { - kchipBLEServiceDataType_DeviceIdentificationInfo = 0x01, - kchipBLEServiceDataType_TokenIdentificationInfo = 0x02, + kchipBLEServiceDataType_DeviceIdentificationInfo = 0x01, + kchipBLEServiceDataType_TokenIdentificationInfo = 0x02, }; /** @@ -45,8 +45,8 @@ struct chipBLEDeviceIdentificationInfo { enum { - kMajorVersion = 0, - kMinorVersion = 1, + kMajorVersion = 0, + kMinorVersion = 1, }; enum @@ -67,41 +67,23 @@ struct chipBLEDeviceIdentificationInfo void Init() { memset(this, 0, sizeof(*this)); - BlockLen = sizeof(*this) - sizeof(BlockLen); // size of all fields EXCEPT BlockLen - BlockType = kchipBLEServiceDataType_DeviceIdentificationInfo; + BlockLen = sizeof(*this) - sizeof(BlockLen); // size of all fields EXCEPT BlockLen + BlockType = kchipBLEServiceDataType_DeviceIdentificationInfo; MajorVersion = kMajorVersion; MinorVersion = kMinorVersion; } - uint16_t GetVendorId(void) - { - return chip::Encoding::LittleEndian::Get16(DeviceVendorId); - } + uint16_t GetVendorId(void) { return chip::Encoding::LittleEndian::Get16(DeviceVendorId); } - void SetVendorId(uint16_t vendorId) - { - chip::Encoding::LittleEndian::Put16(DeviceVendorId, vendorId); - } + void SetVendorId(uint16_t vendorId) { chip::Encoding::LittleEndian::Put16(DeviceVendorId, vendorId); } - uint16_t GetProductId(void) - { - return chip::Encoding::LittleEndian::Get16(DeviceProductId); - } + uint16_t GetProductId(void) { return chip::Encoding::LittleEndian::Get16(DeviceProductId); } - void SetProductId(uint16_t productId) - { - chip::Encoding::LittleEndian::Put16(DeviceProductId, productId); - } + void SetProductId(uint16_t productId) { chip::Encoding::LittleEndian::Put16(DeviceProductId, productId); } - uint64_t GetDeviceId(void) - { - return chip::Encoding::LittleEndian::Get64(DeviceId); - } + uint64_t GetDeviceId(void) { return chip::Encoding::LittleEndian::Get64(DeviceId); } - void SetDeviceId(uint64_t deviceId) - { - chip::Encoding::LittleEndian::Put64(DeviceId, deviceId); - } + void SetDeviceId(uint64_t deviceId) { chip::Encoding::LittleEndian::Put64(DeviceId, deviceId); } } __attribute__((packed)); } /* namespace Ble */ diff --git a/src/ble/CHIPoBle.h b/src/ble/CHIPoBle.h index e9801f449b288e..c3f4d018ed8941 100644 --- a/src/ble/CHIPoBle.h +++ b/src/ble/CHIPoBle.h @@ -91,8 +91,8 @@ class CHIPoBle public: // Public functions: - CHIPoBle(void) { }; - ~CHIPoBle(void) { }; + CHIPoBle(void){}; + ~CHIPoBle(void){}; BLE_ERROR Init(void * an_app_state, bool expect_first_ack); diff --git a/src/inet/AsyncDNSResolverSockets.h b/src/inet/AsyncDNSResolverSockets.h index 7da65796054e18..8535d53a227699 100644 --- a/src/inet/AsyncDNSResolverSockets.h +++ b/src/inet/AsyncDNSResolverSockets.h @@ -53,40 +53,42 @@ class AsyncDNSResolverSockets { friend class InetLayer; friend class DNSResolver; -public: - INET_ERROR EnqueueRequest(DNSResolver &resolver); +public: + INET_ERROR EnqueueRequest(DNSResolver & resolver); - INET_ERROR Init(InetLayer *inet); + INET_ERROR Init(InetLayer * inet); - INET_ERROR Cancel(DNSResolver &resolver); + INET_ERROR Cancel(DNSResolver & resolver); INET_ERROR Shutdown(void); - INET_ERROR PrepareDNSResolver(DNSResolver &resolver, const char *hostName, uint16_t hostNameLen, - uint8_t options, uint8_t maxAddrs, IPAddress *addrArray, - DNSResolver::OnResolveCompleteFunct onComplete, void *appState); + INET_ERROR PrepareDNSResolver(DNSResolver & resolver, const char * hostName, uint16_t hostNameLen, uint8_t options, + uint8_t maxAddrs, IPAddress * addrArray, DNSResolver::OnResolveCompleteFunct onComplete, + void * appState); private: - pthread_t mAsyncDNSThreadHandle[INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT]; - pthread_mutex_t mAsyncDNSMutex; /* Mutex for accessing the DNSResolver queue. */ - pthread_cond_t mAsyncDNSCondVar; /* Condition Variable for thread synchronization. */ - volatile DNSResolver *mAsyncDNSQueueHead; /* The head of the asynchronous DNSResolver object queue. */ - volatile DNSResolver *mAsyncDNSQueueTail; /* The tail of the asynchronous DNSResolver object queue. */ - InetLayer *mInet; /* The pointer to the InetLayer. */ - static void DNSResultEventHandler(chip::System::Layer* aLayer, void* aAppState, chip::System::Error aError); /* Timer event handler function for asynchronous DNS notification */ - - INET_ERROR DequeueRequest(DNSResolver **outResolver); + pthread_t mAsyncDNSThreadHandle[INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT]; + pthread_mutex_t mAsyncDNSMutex; /* Mutex for accessing the DNSResolver queue. */ + pthread_cond_t mAsyncDNSCondVar; /* Condition Variable for thread synchronization. */ + volatile DNSResolver * mAsyncDNSQueueHead; /* The head of the asynchronous DNSResolver object queue. */ + volatile DNSResolver * mAsyncDNSQueueTail; /* The tail of the asynchronous DNSResolver object queue. */ + InetLayer * mInet; /* The pointer to the InetLayer. */ + static void + DNSResultEventHandler(chip::System::Layer * aLayer, void * aAppState, + chip::System::Error aError); /* Timer event handler function for asynchronous DNS notification */ + + INET_ERROR DequeueRequest(DNSResolver ** outResolver); bool ShouldThreadShutdown(void); - void Resolve(DNSResolver &resolver); + void Resolve(DNSResolver & resolver); - void UpdateDNSResult(DNSResolver &resolver, struct addrinfo *lookupRes); + void UpdateDNSResult(DNSResolver & resolver, struct addrinfo * lookupRes); - static void *AsyncDNSThreadRun(void *args); + static void * AsyncDNSThreadRun(void * args); - static void NotifyChipThread(DNSResolver *resolver); + static void NotifyChipThread(DNSResolver * resolver); void AsyncMutexLock(void); diff --git a/src/inet/DNSResolver.h b/src/inet/DNSResolver.h index 58fdcaaa86b3f2..049c98554c8548 100644 --- a/src/inet/DNSResolver.h +++ b/src/inet/DNSResolver.h @@ -29,7 +29,7 @@ #include #include "InetLayerBasis.h" -#define NL_DNS_HOSTNAME_MAX_LEN (253) +#define NL_DNS_HOSTNAME_MAX_LEN (253) struct addrinfo; @@ -43,25 +43,24 @@ class InetLayer; */ enum DNSOptions { - kDNSOption_AddrFamily_Mask = 0x07, ///< Bits within a DNSOptions integer value representing the desired address family. - kDNSOption_Flags_Mask = 0xF8, ///< Bits within a DNSOptions integer value reserved for flags. + kDNSOption_AddrFamily_Mask = 0x07, ///< Bits within a DNSOptions integer value representing the desired address family. + kDNSOption_Flags_Mask = 0xF8, ///< Bits within a DNSOptions integer value reserved for flags. // Address Family Choices - kDNSOption_AddrFamily_Any = 0x00, ///< Return IPv4 and/or IPv6 addresses in the order returned by the nameserver. + kDNSOption_AddrFamily_Any = 0x00, ///< Return IPv4 and/or IPv6 addresses in the order returned by the nameserver. #if INET_CONFIG_ENABLE_IPV4 - kDNSOption_AddrFamily_IPv4Only = 0x01, ///< Return only IPv4 addresses. - kDNSOption_AddrFamily_IPv4Preferred = 0x02, ///< Return IPv4 and/or IPv6 addresses, with IPv4 addresses listed first. + kDNSOption_AddrFamily_IPv4Only = 0x01, ///< Return only IPv4 addresses. + kDNSOption_AddrFamily_IPv4Preferred = 0x02, ///< Return IPv4 and/or IPv6 addresses, with IPv4 addresses listed first. #endif - kDNSOption_AddrFamily_IPv6Only = 0x03, ///< Return only IPv6 addresses. - kDNSOption_AddrFamily_IPv6Preferred = 0x04, ///< Return IPv4 and/or IPv6 addresses, with IPv6 addresses listed first. + kDNSOption_AddrFamily_IPv6Only = 0x03, ///< Return only IPv6 addresses. + kDNSOption_AddrFamily_IPv6Preferred = 0x04, ///< Return IPv4 and/or IPv6 addresses, with IPv6 addresses listed first. // NOTE: At present there are no DNSOption flags define. - kDNSOption_ValidFlags = 0, ///< Set of all valid DNSOption flags. + kDNSOption_ValidFlags = 0, ///< Set of all valid DNSOption flags. - kDNSOption_Default = kDNSOption_AddrFamily_Any + kDNSOption_Default = kDNSOption_AddrFamily_Any }; - /** * @class DNSResolver * @@ -71,7 +70,7 @@ enum DNSOptions * interface available for the application layer. * */ -class DNSResolver: public InetLayerBasis +class DNSResolver : public InetLayerBasis { private: friend class InetLayer; @@ -81,12 +80,11 @@ class DNSResolver: public InetLayerBasis friend class AsyncDNSResolverSockets; /// States of the DNSResolver object with respect to hostname resolution. - typedef enum DNSResolverState - { - kState_Unused = 0, /// sPool; @@ -115,7 +113,7 @@ class DNSResolver: public InetLayerBasis /** * A pointer to the DNS table that stores a list of resolved addresses. */ - IPAddress *AddrArray; + IPAddress * AddrArray; /** * The maximum number of addresses that could be stored in the DNS table. @@ -146,7 +144,7 @@ class DNSResolver: public InetLayerBasis INET_ERROR asyncDNSResolveResult; /* The next DNSResolver object in the asynchronous DNS resolution queue. */ - DNSResolver *pNextAsyncDNSResolver; + DNSResolver * pNextAsyncDNSResolver; DNSResolverState mState; @@ -156,17 +154,16 @@ class DNSResolver: public InetLayerBasis #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - INET_ERROR Resolve(const char *hostName, uint16_t hostNameLen, uint8_t options, - uint8_t maxAddrs, IPAddress *addrArray, - OnResolveCompleteFunct onComplete, void *appState); + INET_ERROR Resolve(const char * hostName, uint16_t hostNameLen, uint8_t options, uint8_t maxAddrs, IPAddress * addrArray, + OnResolveCompleteFunct onComplete, void * appState); INET_ERROR Cancel(void); #if CHIP_SYSTEM_CONFIG_USE_LWIP void HandleResolveComplete(void); #if LWIP_VERSION_MAJOR > 1 - static void LwIPHandleResolveComplete(const char *name, const ip_addr_t *ipaddr, void *callback_arg); -#else // LWIP_VERSION_MAJOR <= 1 - static void LwIPHandleResolveComplete(const char *name, ip_addr_t *ipaddr, void *callback_arg); + static void LwIPHandleResolveComplete(const char * name, const ip_addr_t * ipaddr, void * callback_arg); +#else // LWIP_VERSION_MAJOR <= 1 + static void LwIPHandleResolveComplete(const char * name, ip_addr_t * ipaddr, void * callback_arg); #endif // LWIP_VERSION_MAJOR <= 1 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP }; diff --git a/src/inet/EndPointBasis.h b/src/inet/EndPointBasis.h index c4f42eee60ad25..766b07fba60d04 100644 --- a/src/inet/EndPointBasis.h +++ b/src/inet/EndPointBasis.h @@ -62,8 +62,9 @@ class DLL_EXPORT EndPointBasis : public InetLayerBasis { public: /** Common state codes */ - enum { - kBasisState_Closed = 0 /**< Encapsulated descriptor is not valid. */ + enum + { + kBasisState_Closed = 0 /**< Encapsulated descriptor is not valid. */ }; #if CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -81,38 +82,38 @@ class DLL_EXPORT EndPointBasis : public InetLayerBasis protected: #if CHIP_SYSTEM_CONFIG_USE_SOCKETS - int mSocket; /**< Encapsulated socket descriptor. */ - IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */ - SocketEvents mPendingIO; /**< Socket event masks */ -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS + int mSocket; /**< Encapsulated socket descriptor. */ + IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */ + SocketEvents mPendingIO; /**< Socket event masks */ +#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS #if CHIP_SYSTEM_CONFIG_USE_LWIP /** Encapsulated LwIP protocol control block */ union { - const void* mVoid; /**< An untyped protocol control buffer reference */ + const void * mVoid; /**< An untyped protocol control buffer reference */ #if INET_CONFIG_ENABLE_RAW_ENDPOINT - raw_pcb* mRaw; /**< Raw network interface protocol control */ -#endif // INET_CONFIG_ENABLE_RAW_ENDPOINT + raw_pcb * mRaw; /**< Raw network interface protocol control */ +#endif // INET_CONFIG_ENABLE_RAW_ENDPOINT #if INET_CONFIG_ENABLE_UDP_ENDPOINT - udp_pcb* mUDP; /**< User datagram protocol (UDP) control */ -#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT + udp_pcb * mUDP; /**< User datagram protocol (UDP) control */ +#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT #if INET_CONFIG_ENABLE_TCP_ENDPOINT - tcp_pcb* mTCP; /**< Transmission control protocol (TCP) control */ -#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT + tcp_pcb * mTCP; /**< Transmission control protocol (TCP) control */ +#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT #if INET_CONFIG_ENABLE_TUN_ENDPOINT - netif* mNetIf; /**< Tunnel interface control */ -#endif // INET_CONFIG_ENABLE_TUN_ENDPOINT + netif * mNetIf; /**< Tunnel interface control */ +#endif // INET_CONFIG_ENABLE_TUN_ENDPOINT }; enum { kLwIPEndPointType_Unknown = 0, - kLwIPEndPointType_Raw = 1, - kLwIPEndPointType_UDP = 2, - kLwIPEndPointType_UCP = 3, - kLwIPEndPointType_TCP = 4 + kLwIPEndPointType_Raw = 1, + kLwIPEndPointType_UDP = 2, + kLwIPEndPointType_UCP = 3, + kLwIPEndPointType_TCP = 4 }; uint8_t mLwIPEndPointType; @@ -120,7 +121,7 @@ class DLL_EXPORT EndPointBasis : public InetLayerBasis void DeferredFree(chip::System::Object::ReleaseDeferralErrorTactic aTactic); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP - void InitEndPointBasis(InetLayer& aInetLayer, void* aAppState = NULL); + void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = NULL); }; #if CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -166,7 +167,6 @@ inline void EndPointBasis::DeferredFree(chip::System::Object::ReleaseDeferralErr } #endif // CHIP_SYSTEM_CONFIG_USE_LWIP - } // namespace Inet } // namespace chip diff --git a/src/inet/IANAConstants.h b/src/inet/IANAConstants.h index f7036ed2d3f97d..bec5118467c42f 100644 --- a/src/inet/IANAConstants.h +++ b/src/inet/IANAConstants.h @@ -38,10 +38,10 @@ namespace Inet { */ typedef enum { - kIPVersion_6 = 6, /**< IPv6 */ + kIPVersion_6 = 6, /**< IPv6 */ #if INET_CONFIG_ENABLE_IPV4 - kIPVersion_4 = 4, /**< IPv4 */ -#endif // INET_CONFIG_ENABLE_IPV4 + kIPVersion_4 = 4, /**< IPv4 */ +#endif // INET_CONFIG_ENABLE_IPV4 } IPVersion; /** @@ -52,10 +52,10 @@ typedef enum */ typedef enum { - kIPProtocol_ICMPv6 = 58, /**< ICMPv6 */ + kIPProtocol_ICMPv6 = 58, /**< ICMPv6 */ #if INET_CONFIG_ENABLE_IPV4 - kIPProtocol_ICMPv4 = 1, /**< ICMPv4 */ -#endif // INET_CONFIG_ENABLE_IPV4 + kIPProtocol_ICMPv4 = 1, /**< ICMPv4 */ +#endif // INET_CONFIG_ENABLE_IPV4 } IPProtocol; /** @@ -70,30 +70,30 @@ typedef enum typedef enum { /** Interface-local scope. */ - kIPv6MulticastScope_Interface = 1, + kIPv6MulticastScope_Interface = 1, /** Link-local scope. */ - kIPv6MulticastScope_Link = 2, + kIPv6MulticastScope_Link = 2, #if INET_CONFIG_ENABLE_IPV4 /** Realm-local ("IPv4") scope. */ - kIPv6MulticastScope_IPv4 = 3, -#else // !INET_CONFIG_ENABLE_IPV4 + kIPv6MulticastScope_IPv4 = 3, +#else // !INET_CONFIG_ENABLE_IPV4 /** Realm-local scope. */ - kIPv6MulticastScope_Realm = 3, + kIPv6MulticastScope_Realm = 3, #endif // !INET_CONFIG_ENABLE_IPV4 /** Realm-local scope. */ - kIPv6MulticastScope_Admin = 4, + kIPv6MulticastScope_Admin = 4, /** Realm-local scope. */ - kIPv6MulticastScope_Site = 5, + kIPv6MulticastScope_Site = 5, /** Organization-local scope. */ - kIPv6MulticastScope_Organization = 8, + kIPv6MulticastScope_Organization = 8, /** Global scope. */ - kIPv6MulticastScope_Global = 14 + kIPv6MulticastScope_Global = 14 } IPv6MulticastScope; /** @@ -106,8 +106,8 @@ typedef enum */ enum IPV6MulticastGroup { - kIPV6MulticastGroup_AllNodes = 1, /** RFC 4291 */ - kIPV6MulticastGroup_AllRouters = 2 /** RFC 4291 */ + kIPV6MulticastGroup_AllNodes = 1, /** RFC 4291 */ + kIPV6MulticastGroup_AllRouters = 2 /** RFC 4291 */ }; } // namespace Inet diff --git a/src/inet/IPAddress.h b/src/inet/IPAddress.h index 5a9012739e5493..5073954f473339 100644 --- a/src/inet/IPAddress.h +++ b/src/inet/IPAddress.h @@ -49,8 +49,8 @@ #include #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS -#define NL_INET_IPV6_ADDR_LEN_IN_BYTES (16) -#define NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES (14) +#define NL_INET_IPV6_ADDR_LEN_IN_BYTES (16) +#define NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES (14) /** * @brief Adaptation for LwIP ip4_addr_t type. @@ -84,18 +84,18 @@ namespace Inet { typedef enum { /** Not used. */ - kIPAddressType_Unknown = 0, + kIPAddressType_Unknown = 0, #if INET_CONFIG_ENABLE_IPV4 /** Internet protocol version 4. */ - kIPAddressType_IPv4 = 1, + kIPAddressType_IPv4 = 1, #endif // INET_CONFIG_ENABLE_IPV4 /** Internet protocol version 6. */ - kIPAddressType_IPv6 = 2, + kIPAddressType_IPv6 = 2, /** The unspecified internet address (independent of protocol version) */ - kIPAddressType_Any = 3 + kIPAddressType_Any = 3 } IPAddressType; /** @@ -113,7 +113,7 @@ typedef enum kIPv6MulticastFlag_Transient = 0x01, /** The multicast address is (1) based on a network prefix. */ - kIPv6MulticastFlag_Prefix = 0x02 + kIPv6MulticastFlag_Prefix = 0x02 } IPv6MulticastFlag; /** @@ -126,7 +126,6 @@ typedef enum class DLL_EXPORT IPAddress { public: - /** * @brief Opaque word array to contain IP addresses (independent of protocol version) * @@ -275,7 +274,7 @@ class DLL_EXPORT IPAddress * @retval true If equivalent to \c other * @retval false Otherwise */ - bool operator ==(const IPAddress& other) const; + bool operator==(const IPAddress & other) const; /** * @brief Compare this IP address with another for inequivalence. @@ -285,7 +284,7 @@ class DLL_EXPORT IPAddress * @retval true If equivalent to \c other * @retval false Otherwise */ - bool operator !=(const IPAddress& other) const; + bool operator!=(const IPAddress & other) const; /** * @brief Conventional assignment operator. @@ -294,7 +293,7 @@ class DLL_EXPORT IPAddress * * @return A reference to this object. */ - IPAddress& operator =(const IPAddress& other); + IPAddress & operator=(const IPAddress & other); /** * @brief Emit the IP address in conventional text presentation format. @@ -313,7 +312,7 @@ class DLL_EXPORT IPAddress * * @return The argument \c buf if no formatting error, or zero otherwise. */ - char *ToString(char *buf, uint32_t bufSize) const; + char * ToString(char * buf, uint32_t bufSize) const; /** * @brief Scan the IP address from its conventional presentation text. @@ -329,7 +328,7 @@ class DLL_EXPORT IPAddress * @retval true The presentation format is valid * @retval false Otherwise */ - static bool FromString(const char *str, IPAddress& output); + static bool FromString(const char * str, IPAddress & output); /** * @brief Scan the IP address from its conventional presentation text. @@ -346,7 +345,7 @@ class DLL_EXPORT IPAddress * @retval true The presentation format is valid * @retval false Otherwise */ - static bool FromString(const char *str, size_t strLen, IPAddress& output); + static bool FromString(const char * str, size_t strLen, IPAddress & output); /** * @brief Emit the IP address in standard network representation. @@ -359,7 +358,7 @@ class DLL_EXPORT IPAddress * addresses are encoded according to section 2.5.5.1 "IPv4-Compatible * IPv6 Address" (V4COMPAT). */ - void WriteAddress(uint8_t *&p) const; + void WriteAddress(uint8_t *& p) const; /** * @brief Emit the IP address in standard network representation. @@ -371,7 +370,7 @@ class DLL_EXPORT IPAddress * Use ReadAddress(uint8_t *&p, IPAddress &output) to decode * the IP address at \c p to the object \c output. */ - static void ReadAddress(const uint8_t *&p, IPAddress &output); + static void ReadAddress(const uint8_t *& p, IPAddress & output); /** * @brief Test whether address is IPv4 compatible. @@ -508,7 +507,7 @@ class DLL_EXPORT IPAddress * * @return The constructed IP address. */ - static IPAddress FromLwIPAddr(const ip_addr_t &addr); + static IPAddress FromLwIPAddr(const ip_addr_t & addr); /** * @brief Convert the INET layer address type to its underlying LwIP type. @@ -521,11 +520,11 @@ class DLL_EXPORT IPAddress #endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip6_addr_t ToIPv6(void) const; - static IPAddress FromIPv6(const ip6_addr_t &addr); + static IPAddress FromIPv6(const ip6_addr_t & addr); #if INET_CONFIG_ENABLE_IPV4 ip4_addr_t ToIPv4(void) const; - static IPAddress FromIPv4(const ip4_addr_t &addr); + static IPAddress FromIPv4(const ip4_addr_t & addr); #endif // INET_CONFIG_ENABLE_IPV4 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP @@ -533,11 +532,11 @@ class DLL_EXPORT IPAddress #if CHIP_SYSTEM_CONFIG_USE_SOCKETS struct in6_addr ToIPv6(void) const; - static IPAddress FromIPv6(const struct in6_addr &addr); + static IPAddress FromIPv6(const struct in6_addr & addr); #if INET_CONFIG_ENABLE_IPV4 struct in_addr ToIPv4(void) const; - static IPAddress FromIPv4(const struct in_addr &addr); + static IPAddress FromIPv4(const struct in_addr & addr); #endif // INET_CONFIG_ENABLE_IPV4 /** @@ -549,7 +548,7 @@ class DLL_EXPORT IPAddress * * @return The constructed IP address. */ - static IPAddress FromSockAddr(const struct sockaddr& sockaddr); + static IPAddress FromSockAddr(const struct sockaddr & sockaddr); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -564,8 +563,7 @@ class DLL_EXPORT IPAddress * * @return The constructed IP address. */ - static IPAddress MakeULA(uint64_t globalId, uint16_t subnet, - uint64_t interfaceId); + static IPAddress MakeULA(uint64_t globalId, uint16_t subnet, uint64_t interfaceId); /** * @brief Construct an IPv6 link-local address (LL) from its IID. @@ -589,7 +587,8 @@ class DLL_EXPORT IPAddress * * @return The constructed IP address. */ - static IPAddress MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]); + static IPAddress MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, + const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]); /** * @brief Construct an IPv6 multicast address from its parts. @@ -627,7 +626,8 @@ class DLL_EXPORT IPAddress * * @return The constructed IP address. */ - static IPAddress MakeIPv6TransientMulticast(uint8_t aFlags, uint8_t aScope, const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]); + static IPAddress MakeIPv6TransientMulticast(uint8_t aFlags, uint8_t aScope, + const uint8_t aGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES]); /** * @brief Construct a transient, prefix IPv6 multicast address from its parts. @@ -641,7 +641,7 @@ class DLL_EXPORT IPAddress * * @return The constructed IP address. */ - static IPAddress MakeIPv6PrefixMulticast(uint8_t aScope, uint8_t aPrefixLength, const uint64_t &aPrefix, uint32_t aGroupId); + static IPAddress MakeIPv6PrefixMulticast(uint8_t aScope, uint8_t aPrefixLength, const uint64_t & aPrefix, uint32_t aGroupId); /** * @brief Construct an IPv4 broadcast address. diff --git a/src/inet/IPEndPointBasis.h b/src/inet/IPEndPointBasis.h index a8211e05ee6000..332241c7de25cf 100644 --- a/src/inet/IPEndPointBasis.h +++ b/src/inet/IPEndPointBasis.h @@ -70,17 +70,19 @@ class DLL_EXPORT IPEndPointBasis : public EndPointBasis * now closed" that existed previously in the \c kState_Ready and * \c kState_Closed states. */ - enum { - kState_Ready = kBasisState_Closed, /**< Endpoint initialized, but not open. */ - kState_Bound = 1, /**< Endpoint bound, but not listening. */ - kState_Listening = 2, /**< Endpoint receiving datagrams. */ - kState_Closed = 3 /**< Endpoint closed, ready for release. */ + enum + { + kState_Ready = kBasisState_Closed, /**< Endpoint initialized, but not open. */ + kState_Bound = 1, /**< Endpoint bound, but not listening. */ + kState_Listening = 2, /**< Endpoint receiving datagrams. */ + kState_Closed = 3 /**< Endpoint closed, ready for release. */ } mState; /** * @brief Transmit option flags for the \c SendMsg method. */ - enum { + enum + { /** Do not destructively queue the message directly. Queue a copy. */ kSendFlag_RetainBuffer = 0x0040 }; @@ -97,7 +99,8 @@ class DLL_EXPORT IPEndPointBasis : public EndPointBasis * member to process message text reception events on \c endPoint where * \c msg is the message text received from the sender at \c senderAddr. */ - typedef void (*OnMessageReceivedFunct)(IPEndPointBasis *endPoint, chip::System::PacketBuffer *msg, const IPPacketInfo *pktInfo); + typedef void (*OnMessageReceivedFunct)(IPEndPointBasis * endPoint, chip::System::PacketBuffer * msg, + const IPPacketInfo * pktInfo); /** The endpoint's message reception event handling function delegate. */ OnMessageReceivedFunct OnMessageReceived; @@ -113,26 +116,26 @@ class DLL_EXPORT IPEndPointBasis : public EndPointBasis * member to process reception error events on \c endPoint. The \c err * argument provides specific detail about the type of the error. */ - typedef void (*OnReceiveErrorFunct)(IPEndPointBasis *endPoint, INET_ERROR err, const IPPacketInfo *pktInfo); + typedef void (*OnReceiveErrorFunct)(IPEndPointBasis * endPoint, INET_ERROR err, const IPPacketInfo * pktInfo); /** The endpoint's receive error event handling function delegate. */ OnReceiveErrorFunct OnReceiveError; INET_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback); - INET_ERROR JoinMulticastGroup(InterfaceId aInterfaceId, const IPAddress &aAddress); - INET_ERROR LeaveMulticastGroup(InterfaceId aInterfaceId, const IPAddress &aAddress); + INET_ERROR JoinMulticastGroup(InterfaceId aInterfaceId, const IPAddress & aAddress); + INET_ERROR LeaveMulticastGroup(InterfaceId aInterfaceId, const IPAddress & aAddress); protected: - void Init(InetLayer *aInetLayer); + void Init(InetLayer * aInetLayer); #if CHIP_SYSTEM_CONFIG_USE_LWIP public: - static struct netif *FindNetifFromInterfaceId(InterfaceId aInterfaceId); + static struct netif * FindNetifFromInterfaceId(InterfaceId aInterfaceId); protected: - void HandleDataReceived(chip::System::PacketBuffer *aBuffer); + void HandleDataReceived(chip::System::PacketBuffer * aBuffer); - static IPPacketInfo *GetPacketInfo(chip::System::PacketBuffer *buf); + static IPPacketInfo * GetPacketInfo(chip::System::PacketBuffer * buf); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -141,23 +144,23 @@ class DLL_EXPORT IPEndPointBasis : public EndPointBasis INET_ERROR Bind(IPAddressType aAddressType, IPAddress aAddress, uint16_t aPort, InterfaceId aInterfaceId); INET_ERROR BindInterface(IPAddressType aAddressType, InterfaceId aInterfaceId); - INET_ERROR SendMsg(const IPPacketInfo *aPktInfo, chip::System::PacketBuffer *aBuffer, uint16_t aSendFlags); + INET_ERROR SendMsg(const IPPacketInfo * aPktInfo, chip::System::PacketBuffer * aBuffer, uint16_t aSendFlags); INET_ERROR GetSocket(IPAddressType aAddressType, int aType, int aProtocol); SocketEvents PrepareIO(void); void HandlePendingIO(uint16_t aPort); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS private: - IPEndPointBasis(void); // not defined - IPEndPointBasis(const IPEndPointBasis &); // not defined - ~IPEndPointBasis(void); // not defined + IPEndPointBasis(void); // not defined + IPEndPointBasis(const IPEndPointBasis &); // not defined + ~IPEndPointBasis(void); // not defined }; #if CHIP_SYSTEM_CONFIG_USE_LWIP -inline struct netif *IPEndPointBasis::FindNetifFromInterfaceId(InterfaceId aInterfaceId) +inline struct netif * IPEndPointBasis::FindNetifFromInterfaceId(InterfaceId aInterfaceId) { - struct netif *lRetval = NULL; + struct netif * lRetval = NULL; #if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 0 && defined(NETIF_FOREACH) NETIF_FOREACH(lRetval) @@ -165,8 +168,9 @@ inline struct netif *IPEndPointBasis::FindNetifFromInterfaceId(InterfaceId aInte if (lRetval == aInterfaceId) break; } -#else // LWIP_VERSION_MAJOR < 2 || !defined(NETIF_FOREACH) - for (lRetval = netif_list; lRetval != NULL && lRetval != aInterfaceId; lRetval = lRetval->next); +#else // LWIP_VERSION_MAJOR < 2 || !defined(NETIF_FOREACH) + for (lRetval = netif_list; lRetval != NULL && lRetval != aInterfaceId; lRetval = lRetval->next) + ; #endif // LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 0 && defined(NETIF_FOREACH) return (lRetval); @@ -174,7 +178,6 @@ inline struct netif *IPEndPointBasis::FindNetifFromInterfaceId(InterfaceId aInte #endif // CHIP_SYSTEM_CONFIG_USE_LWIP - } // namespace Inet } // namespace chip diff --git a/src/inet/IPPrefix.h b/src/inet/IPPrefix.h index a86449308aa0ec..054e3a68c4c95d 100644 --- a/src/inet/IPPrefix.h +++ b/src/inet/IPPrefix.h @@ -29,8 +29,8 @@ #include -#define CHIP_INET_IPV6_DEFAULT_PREFIX_LEN (64) -#define CHIP_INET_IPV6_MAX_PREFIX_LEN (128) +#define CHIP_INET_IPV6_DEFAULT_PREFIX_LEN (64) +#define CHIP_INET_IPV6_MAX_PREFIX_LEN (128) namespace chip { namespace Inet { @@ -46,7 +46,7 @@ class IPPrefix { public: /** An IPv6 or IPv4 address. */ - IPAddress IPAddr; + IPAddress IPAddr; /** * @brief Length of the prefix. @@ -57,7 +57,7 @@ class IPPrefix * \c kIPAddressType_IPv4 and Length <= 128 where the type of * \c IPAddr is \c kIPAddressType_IPv6. */ - uint8_t Length; + uint8_t Length; /** * A distinguished object where the type of \c IPAddr is @@ -85,7 +85,7 @@ class IPPrefix * * @return \c true if equivalent, else \c false. */ - bool operator ==(const IPPrefix& other) const; + bool operator==(const IPPrefix & other) const; /** * @brief Compares the prefix with another for inequivalence. @@ -96,7 +96,7 @@ class IPPrefix * * @return \c false if equivalent, else \c false. */ - bool operator !=(const IPPrefix& other) const; + bool operator!=(const IPPrefix & other) const; /** * @brief Conventional assignment operator. @@ -105,7 +105,7 @@ class IPPrefix * * @return a reference to this object. */ - IPPrefix& operator =(const IPPrefix& other); + IPPrefix & operator=(const IPPrefix & other); /** * @brief Test if an address matches the prefix. @@ -114,7 +114,7 @@ class IPPrefix * * @return \c true if \c addr has the prefix, else \c false. */ - bool MatchAddress(const IPAddress& addr) const; + bool MatchAddress(const IPAddress & addr) const; }; } // namespace Inet diff --git a/src/inet/InetBuffer.h b/src/inet/InetBuffer.h index 65ec192b50f00a..eea4f5be991c02 100644 --- a/src/inet/InetBuffer.h +++ b/src/inet/InetBuffer.h @@ -40,7 +40,9 @@ namespace Inet { typedef chip::System::PacketBuffer InetBuffer; #if !CHIP_SYSTEM_CONFIG_USE_LWIP -struct pbuf : public chip::System::pbuf { }; +struct pbuf : public chip::System::pbuf +{ +}; #endif // !CHIP_SYSTEM_CONFIG_USE_LWIP } // namespace Inet diff --git a/src/inet/InetError.h b/src/inet/InetError.h index 120f40af7b263e..09f0749127d077 100644 --- a/src/inet/InetError.h +++ b/src/inet/InetError.h @@ -377,7 +377,6 @@ extern bool FormatInetLayerError(char * buf, uint16_t bufSize, int32_t err); } // namespace Inet } // namespace chip - #if INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES /** @@ -389,7 +388,7 @@ extern bool FormatInetLayerError(char * buf, uint16_t bufSize, int32_t err); #if INET_CONFIG_WILL_OVERRIDE_OS_ERROR_FUNCS extern INET_ERROR INET_MapOSError(int e); -extern const char *INET_DescribeOSError(INET_ERROR err); +extern const char * INET_DescribeOSError(INET_ERROR err); extern bool INET_IsOSError(INET_ERROR err); #else // !INET_CONFIG_WILL_OVERRIDE_OS_ERROR_FUNCS @@ -422,7 +421,7 @@ static inline INET_ERROR INET_MapOSError(int e) * describing the error. * */ -static inline const char *INET_DescribeOSError(INET_ERROR err) +static inline const char * INET_DescribeOSError(INET_ERROR err) { return ::chip::System::DescribeErrorPOSIX(err); } @@ -450,7 +449,7 @@ static inline bool INET_IsOSError(INET_ERROR err) #if INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS extern INET_ERROR INET_MapLwIPError(err_t e); -extern const char *INET_DescribeLwIPError(INET_ERROR err); +extern const char * INET_DescribeLwIPError(INET_ERROR err); extern bool INET_IsLwIPError(INET_ERROR err); #else // !INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS @@ -483,7 +482,7 @@ static inline INET_ERROR INET_MapLwIPError(err_t e) * describing the error. * */ -static inline const char *INET_DescribeLwIPError(INET_ERROR err) +static inline const char * INET_DescribeLwIPError(INET_ERROR err) { return ::chip::System::DescribeErrorLwIP(err); } diff --git a/src/inet/InetFaultInjection.h b/src/inet/InetFaultInjection.h index d441dc3e20ddd0..1a88863f526ca7 100644 --- a/src/inet/InetFaultInjection.h +++ b/src/inet/InetFaultInjection.h @@ -46,13 +46,13 @@ namespace FaultInjection { */ typedef enum { - kFault_DNSResolverNew, /**< Fail the allocation of a DNSResolver object */ - kFault_Send, /**< Fail sending a message over TCP or UDP */ - kFault_SendNonCritical, /**< Fail sending a UDP message returning an error considered non-critical by WRMP */ + kFault_DNSResolverNew, /**< Fail the allocation of a DNSResolver object */ + kFault_Send, /**< Fail sending a message over TCP or UDP */ + kFault_SendNonCritical, /**< Fail sending a UDP message returning an error considered non-critical by WRMP */ kFault_NumItems, } InetFaultInjectionID; -DLL_EXPORT nl::FaultInjection::Manager &GetManager(void); +DLL_EXPORT nl::FaultInjection::Manager & GetManager(void); } // namespace FaultInjection } // namespace Inet @@ -65,14 +65,12 @@ DLL_EXPORT nl::FaultInjection::Manager &GetManager(void); * @param[in] aFaultID An Inet fault-injection id * @param[in] aStatements Statements to be executed if the fault is enabled. */ -#define INET_FAULT_INJECT( aFaultID, aStatement ) \ - nlFAULT_INJECT(Inet::FaultInjection::GetManager(), aFaultID, aStatement) +#define INET_FAULT_INJECT(aFaultID, aStatement) nlFAULT_INJECT(Inet::FaultInjection::GetManager(), aFaultID, aStatement) #else // INET_CONFIG_TEST -#define INET_FAULT_INJECT( aFaultID, aStatement ) +#define INET_FAULT_INJECT(aFaultID, aStatement) #endif // INET_CONFIG_TEST - #endif // INET_FAULT_INJECTION_H_ diff --git a/src/inet/InetInterface.h b/src/inet/InetInterface.h index b186fbfa637319..8ad86a7d2245e5 100644 --- a/src/inet/InetInterface.h +++ b/src/inet/InetInterface.h @@ -46,7 +46,6 @@ namespace Inet { class IPAddress; class IPPrefix; - /** * @typedef InterfaceId * @@ -63,14 +62,13 @@ class IPPrefix; */ #if CHIP_SYSTEM_CONFIG_USE_LWIP -typedef struct netif *InterfaceId; +typedef struct netif * InterfaceId; #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_USE_SOCKETS typedef unsigned InterfaceId; #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - /** * @def INET_NULL_INTERFACEID * @@ -91,7 +89,6 @@ typedef unsigned InterfaceId; #define INET_NULL_INTERFACEID 0 #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - /** * @brief Test \c ID for inequivalence with \c INET_NULL_INTERFACEID * @@ -101,8 +98,8 @@ typedef unsigned InterfaceId; */ #define IsInterfaceIdPresent(intfId) ((intfId) != INET_NULL_INTERFACEID) -extern INET_ERROR GetInterfaceName(InterfaceId intfId, char *nameBuf, size_t nameBufSize); -extern INET_ERROR InterfaceNameToId(const char *intfName, InterfaceId& intfId); +extern INET_ERROR GetInterfaceName(InterfaceId intfId, char * nameBuf, size_t nameBufSize); +extern INET_ERROR InterfaceNameToId(const char * intfName, InterfaceId & intfId); extern uint8_t NetmaskToPrefixLength(const uint8_t * netmask, uint16_t netmaskLen); /** @@ -147,7 +144,7 @@ class InterfaceIterator #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_USE_SOCKETS - struct if_nameindex * mIntfArray; + struct if_nameindex * mIntfArray; size_t mCurIntf; short mIntfFlags; bool mIntfFlagsCached; @@ -214,7 +211,6 @@ class DLL_EXPORT InterfaceAddressIterator #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS }; - #if CHIP_SYSTEM_CONFIG_USE_LWIP inline InterfaceIterator::InterfaceIterator(void) @@ -222,9 +218,7 @@ inline InterfaceIterator::InterfaceIterator(void) mCurNetif = netif_list; } -inline InterfaceIterator::~InterfaceIterator(void) -{ -} +inline InterfaceIterator::~InterfaceIterator(void) {} inline bool InterfaceIterator::HasCurrent(void) { @@ -238,16 +232,13 @@ inline InterfaceId InterfaceIterator::GetInterfaceId(void) inline InterfaceAddressIterator::InterfaceAddressIterator(void) { - mCurAddrIndex = kBeforeStartIndex; + mCurAddrIndex = kBeforeStartIndex; } -inline InterfaceAddressIterator::~InterfaceAddressIterator(void) -{ -} +inline InterfaceAddressIterator::~InterfaceAddressIterator(void) {} #endif // CHIP_SYSTEM_CONFIG_USE_LWIP - /** * @brief Deprecated alias for \c GetInterfaceId(void) */ @@ -269,7 +260,7 @@ inline InterfaceId InterfaceAddressIterator::GetInterface(void) */ inline uint8_t InterfaceAddressIterator::GetIPv6PrefixLength(void) { - return GetPrefixLength(); + return GetPrefixLength(); } } // namespace Inet diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index fa3d7a301f37c8..71859cc1a14f2e 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -118,20 +118,20 @@ class InetLayer; namespace Platform { namespace InetLayer { - extern INET_ERROR WillInit(Inet::InetLayer *aLayer, void *aContext); - extern void DidInit(Inet::InetLayer *aLayer, void *aContext, INET_ERROR anError); +extern INET_ERROR WillInit(Inet::InetLayer * aLayer, void * aContext); +extern void DidInit(Inet::InetLayer * aLayer, void * aContext, INET_ERROR anError); - extern INET_ERROR WillShutdown(Inet::InetLayer *aLayer, void *aContext); - extern void DidShutdown(Inet::InetLayer *aLayer, void *aContext, INET_ERROR anError); +extern INET_ERROR WillShutdown(Inet::InetLayer * aLayer, void * aContext); +extern void DidShutdown(Inet::InetLayer * aLayer, void * aContext, INET_ERROR anError); #if INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES #if CHIP_SYSTEM_CONFIG_USE_LWIP - extern INET_ERROR PostEvent(Inet::InetLayer *aLayer, void *aContext, InetLayerBasis *aTarget, InetEventType aType, - uintptr_t anArg); - extern INET_ERROR DispatchEvents(Inet::InetLayer *aLayer, void *aContext); - extern INET_ERROR DispatchEvent(Inet::InetLayer *aLayer, void *aContext, InetEvent anEvent); - extern INET_ERROR StartTimer(Inet::InetLayer *aLayer, void *aContext, uint32_t aDurMS); +extern INET_ERROR PostEvent(Inet::InetLayer * aLayer, void * aContext, InetLayerBasis * aTarget, InetEventType aType, + uintptr_t anArg); +extern INET_ERROR DispatchEvents(Inet::InetLayer * aLayer, void * aContext); +extern INET_ERROR DispatchEvent(Inet::InetLayer * aLayer, void * aContext, InetEvent anEvent); +extern INET_ERROR StartTimer(Inet::InetLayer * aLayer, void * aContext, uint32_t aDurMS); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #endif // INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES @@ -185,45 +185,44 @@ class DLL_EXPORT InetLayer #endif // INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - public: +public: /** * The current state of the InetLayer object. * */ - volatile enum - { - kState_NotInitialized = 0, /**< Not initialized state. */ - kState_Initialized = 1, /**< Initialized state. */ - kState_ShutdownInProgress = 2, /**< State where Shutdown has been triggered. */ - } State; /**< [READ-ONLY] Current state. */ + volatile enum { + kState_NotInitialized = 0, /**< Not initialized state. */ + kState_Initialized = 1, /**< Initialized state. */ + kState_ShutdownInProgress = 2, /**< State where Shutdown has been triggered. */ + } State; /**< [READ-ONLY] Current state. */ InetLayer(void); #if INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES - INET_ERROR Init(void *aContext); + INET_ERROR Init(void * aContext); #endif // INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES - INET_ERROR Init(chip::System::Layer& aSystemLayer, void* aContext); + INET_ERROR Init(chip::System::Layer & aSystemLayer, void * aContext); INET_ERROR Shutdown(void); - chip::System::Layer* SystemLayer(void) const; + chip::System::Layer * SystemLayer(void) const; // End Points #if INET_CONFIG_ENABLE_RAW_ENDPOINT - INET_ERROR NewRawEndPoint(IPVersion ipVer, IPProtocol ipProto, RawEndPoint **retEndPoint); + INET_ERROR NewRawEndPoint(IPVersion ipVer, IPProtocol ipProto, RawEndPoint ** retEndPoint); #endif // INET_CONFIG_ENABLE_RAW_ENDPOINT #if INET_CONFIG_ENABLE_TCP_ENDPOINT - INET_ERROR NewTCPEndPoint(TCPEndPoint **retEndPoint); + INET_ERROR NewTCPEndPoint(TCPEndPoint ** retEndPoint); #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT #if INET_CONFIG_ENABLE_UDP_ENDPOINT - INET_ERROR NewUDPEndPoint(UDPEndPoint **retEndPoint); + INET_ERROR NewUDPEndPoint(UDPEndPoint ** retEndPoint); #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT #if INET_CONFIG_ENABLE_TUN_ENDPOINT - INET_ERROR NewTunEndPoint(TunEndPoint **retEndPoint); + INET_ERROR NewTunEndPoint(TunEndPoint ** retEndPoint); #endif // INET_CONFIG_ENABLE_TUN_ENDPOINT // DNS Resolution @@ -232,22 +231,20 @@ class DLL_EXPORT InetLayer typedef DNSResolver::OnResolveCompleteFunct DNSResolveCompleteFunct; - INET_ERROR ResolveHostAddress(const char *hostName, uint16_t hostNameLen, uint8_t options, - uint8_t maxAddrs, IPAddress *addrArray, - DNSResolveCompleteFunct onComplete, void *appState); - INET_ERROR ResolveHostAddress(const char *hostName, uint16_t hostNameLen, - uint8_t maxAddrs, IPAddress *addrArray, - DNSResolveCompleteFunct onComplete, void *appState); - INET_ERROR ResolveHostAddress(const char *hostName, uint8_t maxAddrs, IPAddress *addrArray, - DNSResolveCompleteFunct onComplete, void *appState); - void CancelResolveHostAddress(DNSResolveCompleteFunct onComplete, void *appState); + INET_ERROR ResolveHostAddress(const char * hostName, uint16_t hostNameLen, uint8_t options, uint8_t maxAddrs, + IPAddress * addrArray, DNSResolveCompleteFunct onComplete, void * appState); + INET_ERROR ResolveHostAddress(const char * hostName, uint16_t hostNameLen, uint8_t maxAddrs, IPAddress * addrArray, + DNSResolveCompleteFunct onComplete, void * appState); + INET_ERROR ResolveHostAddress(const char * hostName, uint8_t maxAddrs, IPAddress * addrArray, + DNSResolveCompleteFunct onComplete, void * appState); + void CancelResolveHostAddress(DNSResolveCompleteFunct onComplete, void * appState); #endif // INET_CONFIG_ENABLE_DNS_RESOLVER - INET_ERROR GetInterfaceFromAddr(const IPAddress& addr, InterfaceId& intfId); + INET_ERROR GetInterfaceFromAddr(const IPAddress & addr, InterfaceId & intfId); - INET_ERROR GetLinkLocalAddr(InterfaceId link, IPAddress *llAddr); - bool MatchLocalIPv6Subnet(const IPAddress& addr); + INET_ERROR GetLinkLocalAddr(InterfaceId link, IPAddress * llAddr); + bool MatchLocalIPv6Subnet(const IPAddress & addr); #if INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES /** @@ -262,15 +259,15 @@ class DLL_EXPORT InetLayer * * @param[in] err #INET_NO_ERROR unconditionally. */ - typedef void (*TimerCompleteFunct)(InetLayer *inetLayer, void *appState, INET_ERROR err); - INET_ERROR StartTimer(uint32_t durMS, TimerCompleteFunct onComplete, void *appState); - void CancelTimer(TimerCompleteFunct onComplete, void *appState); + typedef void (*TimerCompleteFunct)(InetLayer * inetLayer, void * appState, INET_ERROR err); + INET_ERROR StartTimer(uint32_t durMS, TimerCompleteFunct onComplete, void * appState); + void CancelTimer(TimerCompleteFunct onComplete, void * appState); #if CHIP_SYSTEM_CONFIG_USE_LWIP - INET_ERROR PostEvent(InetLayerBasis *target, InetEventType type, uintptr_t arg); + INET_ERROR PostEvent(InetLayerBasis * target, InetEventType type, uintptr_t arg); INET_ERROR DispatchEvents(void); INET_ERROR DispatchEvent(InetEvent aEvent); - INET_ERROR HandleEvent(InetLayerBasis &target, InetEventType type, uintptr_t arg); + INET_ERROR HandleEvent(InetLayerBasis & target, InetEventType type, uintptr_t arg); // Timer Management INET_ERROR StartPlatformTimer(uint32_t inDurMS); @@ -283,18 +280,18 @@ class DLL_EXPORT InetLayer #endif // INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES #if CHIP_SYSTEM_CONFIG_USE_SOCKETS - void PrepareSelect(int& nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval& sleepTime); - void HandleSelectResult(int selectRes, fd_set *readfds, fd_set *writefds, fd_set *exceptfds); + void PrepareSelect(int & nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval & sleepTime); + void HandleSelectResult(int selectRes, fd_set * readfds, fd_set * writefds, fd_set * exceptfds); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - static void UpdateSnapshot(chip::System::Stats::Snapshot &aSnapshot); + static void UpdateSnapshot(chip::System::Stats::Snapshot & aSnapshot); - void *GetPlatformData(void); - void SetPlatformData(void *aPlatformData); + void * GetPlatformData(void); + void SetPlatformData(void * aPlatformData); #if CHIP_SYSTEM_CONFIG_USE_LWIP - static chip::System::Error HandleInetLayerEvent(chip::System::Object& aTarget, chip::System::EventType aEventType, - uintptr_t aArgument); + static chip::System::Error HandleInetLayerEvent(chip::System::Object & aTarget, chip::System::EventType aEventType, + uintptr_t aArgument); static chip::System::LwIPEventHandlerDelegate sInetEventHandlerDelegate; @@ -313,7 +310,7 @@ class DLL_EXPORT InetLayer // higher level protocols. #if INET_CONFIG_MAX_DROPPABLE_EVENTS - inline static bool IsDroppableEvent(chip::System::EventType type) + inline static bool IsDroppableEvent(chip::System::EventType type) { return #if INET_CONFIG_ENABLE_TUN_ENDPOINT @@ -328,9 +325,9 @@ class DLL_EXPORT InetLayer false; } - INET_ERROR InitQueueLimiter(void); - bool CanEnqueueDroppableEvent(void); - void DroppableEventDequeued(void); + INET_ERROR InitQueueLimiter(void); + bool CanEnqueueDroppableEvent(void); + void DroppableEventDequeued(void); #if CHIP_SYSTEM_CONFIG_NO_LOCKING volatile int32_t mDroppableEvents; @@ -343,63 +340,62 @@ class DLL_EXPORT InetLayer SemaphoreHandle_t mDroppableEvents; #endif // CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING -#else // !INET_CONFIG_MAX_DROPPABLE_EVENTS +#else // !INET_CONFIG_MAX_DROPPABLE_EVENTS - inline static bool IsDroppableEvent(chip::System::EventType aType) { return false; } + inline static bool IsDroppableEvent(chip::System::EventType aType) { return false; } - inline INET_ERROR InitQueueLimiter(void) { return INET_NO_ERROR; } - inline bool CanEnqueueDroppableEvent(void) { return true; } - inline void DroppableEventDequeued(void) { return; } + inline INET_ERROR InitQueueLimiter(void) { return INET_NO_ERROR; } + inline bool CanEnqueueDroppableEvent(void) { return true; } + inline void DroppableEventDequeued(void) { return; } #endif // !INET_CONFIG_MAX_DROPPABLE_EVENTS #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES - chip::System::Layer mImplicitSystemLayer; + chip::System::Layer mImplicitSystemLayer; #endif // INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES #if INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL > 0 - static void HandleTCPInactivityTimer(chip::System::Layer* aSystemLayer, void* aAppState, chip::System::Error aError); + static void HandleTCPInactivityTimer(chip::System::Layer * aSystemLayer, void * aAppState, chip::System::Error aError); #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL > 0 private: - void* mContext; - void* mPlatformData; - chip::System::Layer* mSystemLayer; + void * mContext; + void * mPlatformData; + chip::System::Layer * mSystemLayer; #if CHIP_SYSTEM_CONFIG_USE_SOCKETS #if INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS AsyncDNSResolverSockets mAsyncDNSResolver; #endif // INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - friend INET_ERROR Platform::InetLayer::WillInit(Inet::InetLayer *aLayer, void *aContext); - friend void Platform::InetLayer::DidInit(Inet::InetLayer *aLayer, void *aContext, INET_ERROR anError); + friend INET_ERROR Platform::InetLayer::WillInit(Inet::InetLayer * aLayer, void * aContext); + friend void Platform::InetLayer::DidInit(Inet::InetLayer * aLayer, void * aContext, INET_ERROR anError); - friend INET_ERROR Platform::InetLayer::WillShutdown(Inet::InetLayer *aLayer, void *aContext); - friend void Platform::InetLayer::DidShutdown(Inet::InetLayer *aLayer, void *aContext, INET_ERROR anError); + friend INET_ERROR Platform::InetLayer::WillShutdown(Inet::InetLayer * aLayer, void * aContext); + friend void Platform::InetLayer::DidShutdown(Inet::InetLayer * aLayer, void * aContext, INET_ERROR anError); bool IsIdleTimerRunning(void); #if INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES #if CHIP_SYSTEM_CONFIG_USE_LWIP - friend INET_ERROR Platform::InetLayer::PostEvent(Inet::InetLayer *aLayer, void *aContext, InetLayerBasis *aTarget, - InetEventType aType, uintptr_t anArg); - friend INET_ERROR Platform::InetLayer::DispatchEvents(Inet::InetLayer *aLayer, void *aContext); - friend INET_ERROR Platform::InetLayer::DispatchEvent(Inet::InetLayer *aLayer, void *aContext, InetEvent anEvent); - friend INET_ERROR Platform::InetLayer::StartTimer(Inet::InetLayer *aLayer, void *aContext, uint32_t aDurMS); + friend INET_ERROR Platform::InetLayer::PostEvent(Inet::InetLayer * aLayer, void * aContext, InetLayerBasis * aTarget, + InetEventType aType, uintptr_t anArg); + friend INET_ERROR Platform::InetLayer::DispatchEvents(Inet::InetLayer * aLayer, void * aContext); + friend INET_ERROR Platform::InetLayer::DispatchEvent(Inet::InetLayer * aLayer, void * aContext, InetEvent anEvent); + friend INET_ERROR Platform::InetLayer::StartTimer(Inet::InetLayer * aLayer, void * aContext, uint32_t aDurMS); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #endif // INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES }; -inline chip::System::Layer* InetLayer::SystemLayer(void) const +inline chip::System::Layer * InetLayer::SystemLayer(void) const { return mSystemLayer; } #if INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES -inline INET_ERROR InetLayer::Init(void* aContext) +inline INET_ERROR InetLayer::Init(void * aContext) { return Init(mImplicitSystemLayer, aContext); } @@ -410,7 +406,7 @@ inline INET_ERROR InetLayer::DispatchEvent(InetEvent aEvent) return mSystemLayer->DispatchEvent(aEvent); } -inline INET_ERROR InetLayer::HandleEvent(InetLayerBasis& target, InetEventType type, uintptr_t arg) +inline INET_ERROR InetLayer::HandleEvent(InetLayerBasis & target, InetEventType type, uintptr_t arg) { return mSystemLayer->HandleEvent(target, type, arg); } @@ -437,19 +433,20 @@ inline void InetLayer::WakeSelect(void) class IPPacketInfo { public: - IPAddress SrcAddress; /**< The source IPAddress in the packet. */ - IPAddress DestAddress; /**< The destination IPAddress in the packet. */ - InterfaceId Interface; /**< The interface identifier for the connection. */ - uint16_t SrcPort; /**< The source port in the packet. */ - uint16_t DestPort; /**< The destination port in the packet. */ + IPAddress SrcAddress; /**< The source IPAddress in the packet. */ + IPAddress DestAddress; /**< The destination IPAddress in the packet. */ + InterfaceId Interface; /**< The interface identifier for the connection. */ + uint16_t SrcPort; /**< The source port in the packet. */ + uint16_t DestPort; /**< The destination port in the packet. */ void Clear(void); }; +extern INET_ERROR ParseHostAndPort(const char * aString, uint16_t aStringLen, const char *& aHost, uint16_t & aHostLen, + uint16_t & aPort); -extern INET_ERROR ParseHostAndPort(const char *aString, uint16_t aStringLen, const char *&aHost, uint16_t &aHostLen, uint16_t &aPort); - -extern INET_ERROR ParseHostPortAndInterface(const char *aString, uint16_t aStringLen, const char *&aHost, uint16_t &aHostLen, uint16_t &aPort, const char *&aInterface, uint16_t &aInterfaceLen); +extern INET_ERROR ParseHostPortAndInterface(const char * aString, uint16_t aStringLen, const char *& aHost, uint16_t & aHostLen, + uint16_t & aPort, const char *& aInterface, uint16_t & aInterfaceLen); } // namespace Inet } // namespace chip diff --git a/src/inet/InetLayerBasis.h b/src/inet/InetLayerBasis.h index ae96daec0e4d83..4081106ceaaf06 100644 --- a/src/inet/InetLayerBasis.h +++ b/src/inet/InetLayerBasis.h @@ -52,20 +52,20 @@ class InetLayer; class InetLayerBasis : public chip::System::Object { public: - InetLayer& Layer(void) const; - bool IsCreatedByInetLayer(const InetLayer& aInetLayer) const; + InetLayer & Layer(void) const; + bool IsCreatedByInetLayer(const InetLayer & aInetLayer) const; protected: - void InitInetLayerBasis(InetLayer& aInetLayer, void* aAppState = NULL); + void InitInetLayerBasis(InetLayer & aInetLayer, void * aAppState = NULL); private: - InetLayer* mInetLayer; /**< Pointer to the InetLayer object that owns this object. */ + InetLayer * mInetLayer; /**< Pointer to the InetLayer object that owns this object. */ }; /** * Returns a reference to the Inet layer object that owns this basis object. */ -inline InetLayer& InetLayerBasis::Layer(void) const +inline InetLayer & InetLayerBasis::Layer(void) const { return *mInetLayer; } @@ -81,14 +81,14 @@ inline InetLayer& InetLayerBasis::Layer(void) const * Does not check whether the object is actually obtained by the system layer instance associated with the INET layer * instance. It merely tests whether \c aInetLayer is the INET layer instance that was provided to \c InitInetLayerBasis. */ -inline bool InetLayerBasis::IsCreatedByInetLayer(const InetLayer& aInetLayer) const +inline bool InetLayerBasis::IsCreatedByInetLayer(const InetLayer & aInetLayer) const { return mInetLayer == &aInetLayer; } -inline void InetLayerBasis::InitInetLayerBasis(InetLayer& aInetLayer, void* aAppState) +inline void InetLayerBasis::InitInetLayerBasis(InetLayer & aInetLayer, void * aAppState) { - AppState = aAppState; + AppState = aAppState; mInetLayer = &aInetLayer; } @@ -110,24 +110,24 @@ class SocketEvents public: enum { - kRead = 0x01, /**< Bit flag indicating if there is a read event on a socket. */ - kWrite = 0x02, /**< Bit flag indicating if there is a write event on a socket. */ - kError = 0x04, /**< Bit flag indicating if there is an error event on a socket. */ + kRead = 0x01, /**< Bit flag indicating if there is a read event on a socket. */ + kWrite = 0x02, /**< Bit flag indicating if there is a write event on a socket. */ + kError = 0x04, /**< Bit flag indicating if there is an error event on a socket. */ }; - int Value; /**< Contains the bit flags for the socket event. */ + int Value; /**< Contains the bit flags for the socket event. */ /** * Constructor for the SocketEvents class. * */ - SocketEvents() { Value = 0; } + SocketEvents() { Value = 0; } /** * Copy constructor for the SocketEvents class. * */ - SocketEvents(const SocketEvents& other) { Value = other.Value; } + SocketEvents(const SocketEvents & other) { Value = other.Value; } /** * Check if any of the bit flags for the socket events are set. @@ -135,7 +135,7 @@ class SocketEvents * @return true if set, otherwise false. * */ - bool IsSet() const { return Value != 0; } + bool IsSet() const { return Value != 0; } /** * Check if the bit flags indicate that the socket is readable. @@ -143,7 +143,7 @@ class SocketEvents * @return true if socket is readable, otherwise false. * */ - bool IsReadable() const { return (Value & kRead) != 0; } + bool IsReadable() const { return (Value & kRead) != 0; } /** * Check if the bit flags indicate that the socket is writable. @@ -151,7 +151,7 @@ class SocketEvents * @return true if socket is writable, otherwise false. * */ - bool IsWriteable() const { return (Value & kWrite) != 0; } + bool IsWriteable() const { return (Value & kWrite) != 0; } /** * Check if the bit flags indicate that the socket has an error. @@ -159,52 +159,52 @@ class SocketEvents * @return true if socket has an error, otherwise false. * */ - bool IsError() const { return (Value & kError) != 0; } + bool IsError() const { return (Value & kError) != 0; } /** * Set the read bit flag for the socket. * */ - void SetRead() { Value |= kRead; } + void SetRead() { Value |= kRead; } /** * Set the write bit flag for the socket. * */ - void SetWrite() { Value |= kWrite; } + void SetWrite() { Value |= kWrite; } /** * Set the error bit flag for the socket. * */ - void SetError() { Value |= kError; } + void SetError() { Value |= kError; } /** * Clear the bit flags for the socket. * */ - void Clear() { Value = 0; } + void Clear() { Value = 0; } /** * Clear the read bit flag for the socket. * */ - void ClearRead() { Value &= ~kRead; } + void ClearRead() { Value &= ~kRead; } /** * Clear the write bit flag for the socket. * */ - void ClearWrite() { Value &= ~kWrite; } + void ClearWrite() { Value &= ~kWrite; } /** * Clear the error bit flag for the socket. * */ - void ClearError() { Value &= ~kError; } + void ClearError() { Value &= ~kError; } - void SetFDs(int socket, int& nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds); - static SocketEvents FromFDs(int socket, fd_set *readfds, fd_set *writefds, fd_set *exceptfds); + void SetFDs(int socket, int & nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds); + static SocketEvents FromFDs(int socket, fd_set * readfds, fd_set * writefds, fd_set * exceptfds); }; /** diff --git a/src/inet/InetLayerEvents.h b/src/inet/InetLayerEvents.h index 145c00d91c5d76..7a517905c7b0a6 100644 --- a/src/inet/InetLayerEvents.h +++ b/src/inet/InetLayerEvents.h @@ -53,20 +53,20 @@ typedef INET_CONFIG_EVENT_OBJECT_TYPE InetEvent; #endif // INET_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES /** -* The Inet layer event type definitions. -* -*/ + * The Inet layer event type definitions. + * + */ enum { - kInetEvent_TCPConnectComplete = _INET_CONFIG_EVENT(0), /**< The event for TCP connection completion */ - kInetEvent_TCPConnectionReceived = _INET_CONFIG_EVENT(1), /**< The event for TCP connection reception */ - kInetEvent_TCPDataReceived = _INET_CONFIG_EVENT(2), /**< The event for data reception over a TCP connection */ - kInetEvent_TCPDataSent = _INET_CONFIG_EVENT(3), /**< The event for data transmission over a TCP connection */ - kInetEvent_TCPError = _INET_CONFIG_EVENT(4), /**< The event for an error on a TCP connection */ - kInetEvent_UDPDataReceived = _INET_CONFIG_EVENT(5), /**< The event for data reception over UDP */ - kInetEvent_DNSResolveComplete = _INET_CONFIG_EVENT(6), /**< The event for DNS name resolution completion */ - kInetEvent_TunDataReceived = _INET_CONFIG_EVENT(7), /**< The event for data reception over a chip tunnel */ - kInetEvent_RawDataReceived = _INET_CONFIG_EVENT(8) /**< The event for data reception over an InetLayer raw endpoint */ + kInetEvent_TCPConnectComplete = _INET_CONFIG_EVENT(0), /**< The event for TCP connection completion */ + kInetEvent_TCPConnectionReceived = _INET_CONFIG_EVENT(1), /**< The event for TCP connection reception */ + kInetEvent_TCPDataReceived = _INET_CONFIG_EVENT(2), /**< The event for data reception over a TCP connection */ + kInetEvent_TCPDataSent = _INET_CONFIG_EVENT(3), /**< The event for data transmission over a TCP connection */ + kInetEvent_TCPError = _INET_CONFIG_EVENT(4), /**< The event for an error on a TCP connection */ + kInetEvent_UDPDataReceived = _INET_CONFIG_EVENT(5), /**< The event for data reception over UDP */ + kInetEvent_DNSResolveComplete = _INET_CONFIG_EVENT(6), /**< The event for DNS name resolution completion */ + kInetEvent_TunDataReceived = _INET_CONFIG_EVENT(7), /**< The event for data reception over a chip tunnel */ + kInetEvent_RawDataReceived = _INET_CONFIG_EVENT(8) /**< The event for data reception over an InetLayer raw endpoint */ }; /** @@ -79,8 +79,7 @@ enum */ static inline bool INET_IsInetEvent(chip::System::EventType aType) { - return (aType >= kInetEvent_TCPConnectComplete && - aType <= kInetEvent_RawDataReceived); + return (aType >= kInetEvent_TCPConnectComplete && aType <= kInetEvent_RawDataReceived); } } // namespace Inet diff --git a/src/inet/InetTimer.h b/src/inet/InetTimer.h index 795f5ea7e074ec..bb6f3cb578635a 100644 --- a/src/inet/InetTimer.h +++ b/src/inet/InetTimer.h @@ -38,27 +38,27 @@ * Number of nanoseconds in a microsecond */ -#define INET_NANOSECONDS_PER_MICROSECOND chip::System::kTimerFactor_nano_per_micro +#define INET_NANOSECONDS_PER_MICROSECOND chip::System::kTimerFactor_nano_per_micro /** * Number of nanoseconds in a millisecond */ -#define INET_NANOSECONDS_PER_MILLISECOND chip::System::kTimerFactor_nano_per_milli +#define INET_NANOSECONDS_PER_MILLISECOND chip::System::kTimerFactor_nano_per_milli /** * Number of microseconds in a millisecond */ -#define INET_MICROSECONDS_PER_MILLISECOND chip::System::kTimerFactor_micro_per_milli +#define INET_MICROSECONDS_PER_MILLISECOND chip::System::kTimerFactor_micro_per_milli /** * Number of milliseconds in a second */ -#define INET_MILLISECONDS_PER_SECOND chip::System::kTimerFactor_milli_per_unit +#define INET_MILLISECONDS_PER_SECOND chip::System::kTimerFactor_milli_per_unit /** * Number of microseconds in a second */ -#define INET_MICROSECONDS_PER_SECOND chip::System::kTimerFactor_micro_per_unit +#define INET_MICROSECONDS_PER_SECOND chip::System::kTimerFactor_micro_per_unit namespace chip { namespace Inet { @@ -70,8 +70,8 @@ class InetTimer friend class InetLayer; InetTimer(void); - InetTimer(const InetTimer&); - InetTimer& operator =(const InetTimer&); + InetTimer(const InetTimer &); + InetTimer & operator=(const InetTimer &); public: typedef chip::System::Timer::Epoch Time; diff --git a/src/inet/RawEndPoint.h b/src/inet/RawEndPoint.h index cb8c4bfd4f4a83..0beb7544a0d71b 100644 --- a/src/inet/RawEndPoint.h +++ b/src/inet/RawEndPoint.h @@ -58,7 +58,7 @@ class DLL_EXPORT RawEndPoint : public IPEndPointBasis * While this field is a mutable class variable, it is an invariant of the * class that it not be modified. */ - IPVersion IPVer; // This data member is read-only + IPVersion IPVer; // This data member is read-only /** * @brief version of the Internet Control Message Protocol (ICMP) @@ -74,33 +74,33 @@ class DLL_EXPORT RawEndPoint : public IPEndPointBasis INET_ERROR BindInterface(IPAddressType addrType, InterfaceId intf); InterfaceId GetBoundInterface(void); INET_ERROR Listen(void); - INET_ERROR SendTo(IPAddress addr, chip::System::PacketBuffer *msg, uint16_t sendFlags = 0); - INET_ERROR SendTo(IPAddress addr, InterfaceId intfId, chip::System::PacketBuffer *msg, uint16_t sendFlags = 0); - INET_ERROR SendMsg(const IPPacketInfo *pktInfo, chip::System::PacketBuffer *msg, uint16_t sendFlags = 0); + INET_ERROR SendTo(IPAddress addr, chip::System::PacketBuffer * msg, uint16_t sendFlags = 0); + INET_ERROR SendTo(IPAddress addr, InterfaceId intfId, chip::System::PacketBuffer * msg, uint16_t sendFlags = 0); + INET_ERROR SendMsg(const IPPacketInfo * pktInfo, chip::System::PacketBuffer * msg, uint16_t sendFlags = 0); INET_ERROR SetICMPFilter(uint8_t numICMPTypes, const uint8_t * aICMPTypes); void Close(void); void Free(void); private: - RawEndPoint(void); // not defined - RawEndPoint(const RawEndPoint&); // not defined - ~RawEndPoint(void); // not defined + RawEndPoint(void); // not defined + RawEndPoint(const RawEndPoint &); // not defined + ~RawEndPoint(void); // not defined static chip::System::ObjectPool sPool; - void Init(InetLayer *inetLayer, IPVersion ipVer, IPProtocol ipProto); + void Init(InetLayer * inetLayer, IPVersion ipVer, IPProtocol ipProto); #if CHIP_SYSTEM_CONFIG_USE_LWIP uint8_t NumICMPTypes; - const uint8_t *ICMPTypes; + const uint8_t * ICMPTypes; - void HandleDataReceived(chip::System::PacketBuffer *msg); + void HandleDataReceived(chip::System::PacketBuffer * msg); INET_ERROR GetPCB(IPAddressType addrType); #if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - static u8_t LwIPReceiveRawMessage(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr); -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - static u8_t LwIPReceiveRawMessage(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *addr); + static u8_t LwIPReceiveRawMessage(void * arg, struct raw_pcb * pcb, struct pbuf * p, const ip_addr_t * addr); +#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 + static u8_t LwIPReceiveRawMessage(void * arg, struct raw_pcb * pcb, struct pbuf * p, ip_addr_t * addr); #endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP diff --git a/src/inet/TCPEndPoint.h b/src/inet/TCPEndPoint.h index c7571db8322ce2..b69019a441ac85 100644 --- a/src/inet/TCPEndPoint.h +++ b/src/inet/TCPEndPoint.h @@ -66,16 +66,17 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * existing \c kState_Closed exists to identify separately the distinction between "not opened yet" and "previously opened now * closed" that existed previously in the \c kState_Ready and \c kState_Closed states. */ - enum { - kState_Ready = kBasisState_Closed, /**< Endpoint initialized, but not bound. */ - kState_Bound = 1, /**< Endpoint bound, but not listening. */ - kState_Listening = 2, /**< Endpoint receiving connections. */ - kState_Connecting = 3, /**< Endpoint attempting to connect. */ - kState_Connected = 4, /**< Endpoint connected, ready for tx/rx. */ - kState_SendShutdown = 5, /**< Endpoint initiated its half-close. */ - kState_ReceiveShutdown = 6, /**< Endpoint responded to half-close. */ - kState_Closing = 7, /**< Endpoint closing bidirectionally. */ - kState_Closed = 8 /**< Endpoint closed, ready for release. */ + enum + { + kState_Ready = kBasisState_Closed, /**< Endpoint initialized, but not bound. */ + kState_Bound = 1, /**< Endpoint bound, but not listening. */ + kState_Listening = 2, /**< Endpoint receiving connections. */ + kState_Connecting = 3, /**< Endpoint attempting to connect. */ + kState_Connected = 4, /**< Endpoint connected, ready for tx/rx. */ + kState_SendShutdown = 5, /**< Endpoint initiated its half-close. */ + kState_ReceiveShutdown = 6, /**< Endpoint responded to half-close. */ + kState_Closing = 7, /**< Endpoint closing bidirectionally. */ + kState_Closed = 8 /**< Endpoint closed, ready for release. */ } State; /** @@ -166,7 +167,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * @details * Do not use \c NULL pointer values for either argument. */ - INET_ERROR GetPeerInfo(IPAddress *retAddr, uint16_t *retPort) const; + INET_ERROR GetPeerInfo(IPAddress * retAddr, uint16_t * retPort) const; /** * @brief Extract IP address and TCP port of local endpoint. @@ -181,7 +182,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * @details * Do not use \c NULL pointer values for either argument. */ - INET_ERROR GetLocalInfo(IPAddress *retAddr, uint16_t *retPort); + INET_ERROR GetLocalInfo(IPAddress * retAddr, uint16_t * retPort); /** * @brief Send message text on TCP connection. @@ -196,7 +197,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * The chip::System::PacketBuffer::Free method is called on the \c data argument * regardless of whether the transmission is successful or failed. */ - INET_ERROR Send(chip::System::PacketBuffer *data, bool push = true); + INET_ERROR Send(chip::System::PacketBuffer * data, bool push = true); /** * @brief Disable reception. @@ -309,7 +310,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * portion remaining after the bytes acknowledged by a prior call to the * AckReceive(uint16_t len) method. */ - INET_ERROR PutBackReceivedData(chip::System::PacketBuffer *data); + INET_ERROR PutBackReceivedData(chip::System::PacketBuffer * data); /** * @brief Extract the length of the data awaiting first transmit. @@ -407,7 +408,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * member to process connection establishment events on \c endPoint. The * \c err argument distinguishes successful connections from failures. */ - typedef void (*OnConnectCompleteFunct)(TCPEndPoint *endPoint, INET_ERROR err); + typedef void (*OnConnectCompleteFunct)(TCPEndPoint * endPoint, INET_ERROR err); /** * The endpoint's connection establishment event handling function @@ -430,7 +431,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * the \c AckReceive method. The \c Free method on the data buffer must * also be invoked unless the \c PutBackReceivedData is used instead. */ - typedef void (*OnDataReceivedFunct)(TCPEndPoint *endPoint, chip::System::PacketBuffer *data); + typedef void (*OnDataReceivedFunct)(TCPEndPoint * endPoint, chip::System::PacketBuffer * data); /** * The endpoint's message text reception event handling function delegate. @@ -449,7 +450,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * is the length of the message text added to the TCP transmit window, * which are eligible for sending by the underlying network stack. */ - typedef void (*OnDataSentFunct)(TCPEndPoint *endPoint, uint16_t len); + typedef void (*OnDataSentFunct)(TCPEndPoint * endPoint, uint16_t len); /** * The endpoint's message text transmission event handling function @@ -468,7 +469,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * member to process connection termination events on \c endPoint. The * \c err argument distinguishes successful terminations from failures. */ - typedef void (*OnConnectionClosedFunct)(TCPEndPoint *endPoint, INET_ERROR err); + typedef void (*OnConnectionClosedFunct)(TCPEndPoint * endPoint, INET_ERROR err); /** The endpoint's close event handling function delegate. */ OnConnectionClosedFunct OnConnectionClosed; @@ -482,7 +483,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * Provide a function of this type to the \c OnPeerClose delegate member * to process connection termination events on \c endPoint. */ - typedef void (*OnPeerCloseFunct)(TCPEndPoint *endPoint); + typedef void (*OnPeerCloseFunct)(TCPEndPoint * endPoint); /** The endpoint's half-close receive event handling function delegate. */ OnPeerCloseFunct OnPeerClose; @@ -501,8 +502,8 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * The newly received endpoint \c conEndPoint is located at IP address * \c peerAddr and TCP port \c peerPort. */ - typedef void (*OnConnectionReceivedFunct)(TCPEndPoint *listeningEndPoint, TCPEndPoint *conEndPoint, - const IPAddress &peerAddr, uint16_t peerPort); + typedef void (*OnConnectionReceivedFunct)(TCPEndPoint * listeningEndPoint, TCPEndPoint * conEndPoint, + const IPAddress & peerAddr, uint16_t peerPort); /** The endpoint's connection receive event handling function delegate. */ OnConnectionReceivedFunct OnConnectionReceived; @@ -518,7 +519,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * member to process connection acceptance error events on \c endPoint. The * \c err argument provides specific detail about the type of the error. */ - typedef void (*OnAcceptErrorFunct)(TCPEndPoint *endPoint, INET_ERROR err); + typedef void (*OnAcceptErrorFunct)(TCPEndPoint * endPoint, INET_ERROR err); /** * The endpoint's connection acceptance event handling function delegate. @@ -538,7 +539,7 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis * member to process the event of the send channel of the TCPEndPoint * changing state between being idle and not idle. */ - typedef void (*OnTCPSendIdleChangedFunct)(TCPEndPoint *endPoint, bool isIdle); + typedef void (*OnTCPSendIdleChangedFunct)(TCPEndPoint * endPoint, bool isIdle); /** The event handling function delegate of the endpoint signaling when the * idleness of the TCP connection's send channel changes. This is utilized @@ -550,34 +551,34 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis private: static chip::System::ObjectPool sPool; - chip::System::PacketBuffer *mRcvQueue; - chip::System::PacketBuffer *mSendQueue; + chip::System::PacketBuffer * mRcvQueue; + chip::System::PacketBuffer * mSendQueue; #if INET_TCP_IDLE_CHECK_INTERVAL > 0 - uint16_t mIdleTimeout; // in units of INET_TCP_IDLE_CHECK_INTERVAL; zero means no timeout - uint16_t mRemainingIdleTime; // in units of INET_TCP_IDLE_CHECK_INTERVAL -#endif // INET_TCP_IDLE_CHECK_INTERVAL > 0 + uint16_t mIdleTimeout; // in units of INET_TCP_IDLE_CHECK_INTERVAL; zero means no timeout + uint16_t mRemainingIdleTime; // in units of INET_TCP_IDLE_CHECK_INTERVAL +#endif // INET_TCP_IDLE_CHECK_INTERVAL > 0 - uint32_t mConnectTimeoutMsecs; // This is the timeout to wait for a Connect call to succeed or - // return an error; zero means use system defaults. + uint32_t mConnectTimeoutMsecs; // This is the timeout to wait for a Connect call to succeed or + // return an error; zero means use system defaults. #if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT - uint32_t mUserTimeoutMillis; // The configured TCP user timeout value in milliseconds. - // If 0, assume not set. + uint32_t mUserTimeoutMillis; // The configured TCP user timeout value in milliseconds. + // If 0, assume not set. #if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS - bool mIsTCPSendIdle; // Indicates whether the send channel of the TCPEndPoint is Idle. + bool mIsTCPSendIdle; // Indicates whether the send channel of the TCPEndPoint is Idle. - uint16_t mTCPSendQueueRemainingPollCount; // The current remaining number of TCP SendQueue polls before - // the TCP User timeout period is reached. + uint16_t mTCPSendQueueRemainingPollCount; // The current remaining number of TCP SendQueue polls before + // the TCP User timeout period is reached. - uint32_t mTCPSendQueuePollPeriodMillis; // The configured period of active polling of the TCP - // SendQueue. If 0, assume not set. + uint32_t mTCPSendQueuePollPeriodMillis; // The configured period of active polling of the TCP + // SendQueue. If 0, assume not set. void SetTCPSendIdleAndNotifyChange(bool aIsSendIdle); #endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS - bool mUserTimeoutTimerRunning; // Indicates whether the TCP UserTimeout timer has been started. + bool mUserTimeoutTimerRunning; // Indicates whether the TCP UserTimeout timer has been started. - static void TCPUserTimeoutHandler(chip::System::Layer* aSystemLayer, void* aAppState, chip::System::Error aError); + static void TCPUserTimeoutHandler(chip::System::Layer * aSystemLayer, void * aAppState, chip::System::Error aError); void StartTCPUserTimeoutTimer(void); @@ -592,21 +593,21 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis #endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS #if CHIP_SYSTEM_CONFIG_USE_SOCKETS - uint32_t mBytesWrittenSinceLastProbe; // This counts the number of bytes written on the TCP socket since the - // last probe into the TCP outqueue was made. + uint32_t mBytesWrittenSinceLastProbe; // This counts the number of bytes written on the TCP socket since the + // last probe into the TCP outqueue was made. - uint32_t mLastTCPKernelSendQueueLen; // This is the measured size(in bytes) of the kernel TCP send queue - // at the end of the last user timeout window. - INET_ERROR CheckConnectionProgress(bool &IsProgressing); + uint32_t mLastTCPKernelSendQueueLen; // This is the measured size(in bytes) of the kernel TCP send queue + // at the end of the last user timeout window. + INET_ERROR CheckConnectionProgress(bool & IsProgressing); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS #endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT - TCPEndPoint(void); // not defined - TCPEndPoint(const TCPEndPoint&); // not defined - ~TCPEndPoint(void); // not defined + TCPEndPoint(void); // not defined + TCPEndPoint(const TCPEndPoint &); // not defined + ~TCPEndPoint(void); // not defined - void Init(InetLayer *inetLayer); + void Init(InetLayer * inetLayer); INET_ERROR DriveSending(void); void DriveReceiving(void); void HandleConnectComplete(INET_ERROR err); @@ -614,26 +615,26 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis INET_ERROR DoClose(INET_ERROR err, bool suppressCallback); static bool IsConnected(int state); - static void TCPConnectTimeoutHandler(chip::System::Layer* aSystemLayer, void* aAppState, chip::System::Error aError); + static void TCPConnectTimeoutHandler(chip::System::Layer * aSystemLayer, void * aAppState, chip::System::Error aError); void StartConnectTimerIfSet(void); void StopConnectTimer(void); #if CHIP_SYSTEM_CONFIG_USE_LWIP - chip::System::PacketBuffer *mUnsentQueue; + chip::System::PacketBuffer * mUnsentQueue; uint16_t mUnsentOffset; INET_ERROR GetPCB(IPAddressType addrType); void HandleDataSent(uint16_t len); - void HandleDataReceived(chip::System::PacketBuffer *buf); - void HandleIncomingConnection(TCPEndPoint *pcb); + void HandleDataReceived(chip::System::PacketBuffer * buf); + void HandleIncomingConnection(TCPEndPoint * pcb); void HandleError(INET_ERROR err); - static err_t LwIPHandleConnectComplete(void *arg, struct tcp_pcb *tpcb, err_t lwipErr); - static err_t LwIPHandleIncomingConnection(void *arg, struct tcp_pcb *tcpConPCB, err_t lwipErr); - static err_t LwIPHandleDataReceived(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); - static err_t LwIPHandleDataSent(void *arg, struct tcp_pcb *tpcb, u16_t len); - static void LwIPHandleError(void *arg, err_t err); + static err_t LwIPHandleConnectComplete(void * arg, struct tcp_pcb * tpcb, err_t lwipErr); + static err_t LwIPHandleIncomingConnection(void * arg, struct tcp_pcb * tcpConPCB, err_t lwipErr); + static err_t LwIPHandleDataReceived(void * arg, struct tcp_pcb * tpcb, struct pbuf * p, err_t err); + static err_t LwIPHandleDataSent(void * arg, struct tcp_pcb * tpcb, u16_t len); + static void LwIPHandleError(void * arg, err_t err); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP @@ -645,7 +646,6 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis void HandleIncomingConnection(void); INET_ERROR BindSrcAddrFromIntf(IPAddressType addrType, InterfaceId intf); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - }; #if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS && INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT @@ -654,8 +654,7 @@ inline uint16_t TCPEndPoint::MaxTCPSendQueuePolls(void) // If the UserTimeout is configured less than or equal to the poll interval, // return 1 to poll at least once instead of returning zero and timing out // immediately. - return (mUserTimeoutMillis > mTCPSendQueuePollPeriodMillis) ? - (mUserTimeoutMillis / mTCPSendQueuePollPeriodMillis) : 1; + return (mUserTimeoutMillis > mTCPSendQueuePollPeriodMillis) ? (mUserTimeoutMillis / mTCPSendQueuePollPeriodMillis) : 1; } #endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS && INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT diff --git a/src/inet/TunEndPoint.h b/src/inet/TunEndPoint.h index 5cb7faddc78eba..0bb71e712d40f6 100644 --- a/src/inet/TunEndPoint.h +++ b/src/inet/TunEndPoint.h @@ -94,12 +94,11 @@ class IPPacketInfo; * and LwIP systems with an IP-in-IP tunneling mechanism for supporting the * chip tunnel agent. */ -class DLL_EXPORT TunEndPoint: public EndPointBasis +class DLL_EXPORT TunEndPoint : public EndPointBasis { friend class InetLayer; public: - /** * @brief Basic dynamic state of the underlying tunnel. * @@ -109,8 +108,8 @@ class DLL_EXPORT TunEndPoint: public EndPointBasis */ enum { - kState_Open = 0, - kState_Closed = 1 + kState_Open = 0, + kState_Closed = 1 } mState; /** @@ -122,27 +121,27 @@ class DLL_EXPORT TunEndPoint: public EndPointBasis */ typedef enum RouteOp { - kRouteTunIntf_Add = 0, /**< Add route for a prefix. */ - kRouteTunIntf_Del = 1 /**< Remove route for a prefix. */ + kRouteTunIntf_Add = 0, /**< Add route for a prefix. */ + kRouteTunIntf_Del = 1 /**< Remove route for a prefix. */ } RouteOp; /** Pointer to application-specific state object. */ - void *mAppState; + void * mAppState; - void Init(InetLayer *inetLayer); + void Init(InetLayer * inetLayer); #if CHIP_SYSTEM_CONFIG_USE_LWIP INET_ERROR Open(void); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_USE_SOCKETS - INET_ERROR Open(const char *intfName); + INET_ERROR Open(const char * intfName); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS /** Close the tunnel and release handle on the object. */ void Free(void); - INET_ERROR Send(chip::System::PacketBuffer *message); + INET_ERROR Send(chip::System::PacketBuffer * message); bool IsInterfaceUp(void) const; @@ -160,7 +159,7 @@ class DLL_EXPORT TunEndPoint: public EndPointBasis * @param[in] endPoint A pointer to the TunEndPoint object. * @param[in] message A pointer to the chip::System::PacketBuffer message object. */ - typedef void (*OnPacketReceivedFunct)(TunEndPoint *endPoint, chip::System::PacketBuffer *message); + typedef void (*OnPacketReceivedFunct)(TunEndPoint * endPoint, chip::System::PacketBuffer * message); /** The endpoint's packet receive event handler delegate. */ OnPacketReceivedFunct OnPacketReceived; @@ -175,16 +174,15 @@ class DLL_EXPORT TunEndPoint: public EndPointBasis * @param[in] endPoint The TunEndPoint object. * @param[in] err Error code reported. */ - typedef void (*OnReceiveErrorFunct)(TunEndPoint *endPoint, INET_ERROR err); + typedef void (*OnReceiveErrorFunct)(TunEndPoint * endPoint, INET_ERROR err); OnReceiveErrorFunct OnReceiveError; InterfaceId GetTunnelInterfaceId(void); private: - - TunEndPoint(void); // not defined - TunEndPoint(const TunEndPoint&); // not defined - ~TunEndPoint(void); // not defined + TunEndPoint(void); // not defined + TunEndPoint(const TunEndPoint &); // not defined + ~TunEndPoint(void); // not defined static chip::System::ObjectPool sPool; @@ -192,47 +190,46 @@ class DLL_EXPORT TunEndPoint: public EndPointBasis void Close(void); // Function that performs some sanity tests for IPv6 packets. - INET_ERROR CheckV6Sanity(chip::System::PacketBuffer *message); + INET_ERROR CheckV6Sanity(chip::System::PacketBuffer * message); // Function for sending the IPv6 packets over Linux sockets or LwIP. - INET_ERROR TunDevSendMessage(chip::System::PacketBuffer *msg); + INET_ERROR TunDevSendMessage(chip::System::PacketBuffer * msg); #if CHIP_SYSTEM_CONFIG_USE_LWIP // Network interface structure holding the tunnel interface in LwIP. struct netif mTunNetIf; INET_ERROR TunDevOpen(void); - void HandleDataReceived(chip::System::PacketBuffer *msg); + void HandleDataReceived(chip::System::PacketBuffer * msg); - static err_t LwIPPostToInetEventQ(struct netif *netif, struct pbuf *p); + static err_t LwIPPostToInetEventQ(struct netif * netif, struct pbuf * p); #if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 #if LWIP_IPV4 - static err_t LwIPOutputIPv4(struct netif *netif, struct pbuf *p, const ip4_addr_t *addr); + static err_t LwIPOutputIPv4(struct netif * netif, struct pbuf * p, const ip4_addr_t * addr); #endif // LWIP_IPV4 #if LWIP_IPV6 - static err_t LwIPOutputIPv6(struct netif *netif, struct pbuf *p, const ip6_addr_t *addr); + static err_t LwIPOutputIPv6(struct netif * netif, struct pbuf * p, const ip6_addr_t * addr); #endif // LWIP_IPV6 -#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR < 5 - static err_t LwIPReceiveTunMessage(struct netif *netif, struct pbuf *p, ip4_addr_t *addr); +#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR < 5 + static err_t LwIPReceiveTunMessage(struct netif * netif, struct pbuf * p, ip4_addr_t * addr); #if LWIP_IPV6 - static err_t LwIPReceiveTunV6Message(struct netif *netif, struct pbuf *p, ip6_addr_t *addr); + static err_t LwIPReceiveTunV6Message(struct netif * netif, struct pbuf * p, ip6_addr_t * addr); #endif // LWIP_IPV6 #endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR < 5 - static err_t TunInterfaceNetifInit(struct netif *netif); + static err_t TunInterfaceNetifInit(struct netif * netif); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_USE_SOCKETS - //Tunnel interface name + // Tunnel interface name char tunIntfName[IFNAMSIZ]; - INET_ERROR TunDevOpen(const char *interfaceName); + INET_ERROR TunDevOpen(const char * interfaceName); void TunDevClose(void); - INET_ERROR TunDevRead(chip::System::PacketBuffer *msg); - static int TunGetInterface(int fd, struct ::ifreq *ifr); + INET_ERROR TunDevRead(chip::System::PacketBuffer * msg); + static int TunGetInterface(int fd, struct ::ifreq * ifr); SocketEvents PrepareIO(void); void HandlePendingIO(void); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - }; } // namespace Inet diff --git a/src/inet/UDPEndPoint.h b/src/inet/UDPEndPoint.h index c5f83d289013c8..c52bfadc3c402c 100644 --- a/src/inet/UDPEndPoint.h +++ b/src/inet/UDPEndPoint.h @@ -46,7 +46,7 @@ class IPPacketInfo; * endpoints (SOCK_DGRAM sockets on Linux and BSD-derived systems) or LwIP * UDP protocol control blocks, as the system is configured accordingly. */ - class DLL_EXPORT UDPEndPoint : public IPEndPointBasis +class DLL_EXPORT UDPEndPoint : public IPEndPointBasis { friend class InetLayer; @@ -56,28 +56,28 @@ class IPPacketInfo; InterfaceId GetBoundInterface(void); uint16_t GetBoundPort(void); INET_ERROR Listen(void); - INET_ERROR SendTo(IPAddress addr, uint16_t port, chip::System::PacketBuffer *msg, uint16_t sendFlags = 0); - INET_ERROR SendTo(IPAddress addr, uint16_t port, InterfaceId intfId, chip::System::PacketBuffer *msg, uint16_t sendFlags = 0); - INET_ERROR SendMsg(const IPPacketInfo *pktInfo, chip::System::PacketBuffer *msg, uint16_t sendFlags = 0); + INET_ERROR SendTo(IPAddress addr, uint16_t port, chip::System::PacketBuffer * msg, uint16_t sendFlags = 0); + INET_ERROR SendTo(IPAddress addr, uint16_t port, InterfaceId intfId, chip::System::PacketBuffer * msg, uint16_t sendFlags = 0); + INET_ERROR SendMsg(const IPPacketInfo * pktInfo, chip::System::PacketBuffer * msg, uint16_t sendFlags = 0); void Close(void); void Free(void); private: - UDPEndPoint(void); // not defined - UDPEndPoint(const UDPEndPoint&); // not defined - ~UDPEndPoint(void); // not defined + UDPEndPoint(void); // not defined + UDPEndPoint(const UDPEndPoint &); // not defined + ~UDPEndPoint(void); // not defined static chip::System::ObjectPool sPool; - void Init(InetLayer *inetLayer); + void Init(InetLayer * inetLayer); #if CHIP_SYSTEM_CONFIG_USE_LWIP - void HandleDataReceived(chip::System::PacketBuffer *msg); + void HandleDataReceived(chip::System::PacketBuffer * msg); INET_ERROR GetPCB(IPAddressType addrType4); #if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - static void LwIPReceiveUDPMessage(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port); -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - static void LwIPReceiveUDPMessage(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port); + static void LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb, struct pbuf * p, const ip_addr_t * addr, u16_t port); +#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 + static void LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb, struct pbuf * p, ip_addr_t * addr, u16_t port); #endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP diff --git a/src/lwip/tests/tests.c b/src/lwip/tests/tests.c index 2c98af4d78e6c1..470a871c5337f0 100644 --- a/src/lwip/tests/tests.c +++ b/src/lwip/tests/tests.c @@ -29,13 +29,15 @@ //#include "standalone/TapInterface.c" -void TapInterface_Init_test1() { - printf("---Running Test--- %s\n", __FUNCTION__); - // assert(TapInterface_Init(NULL, NULL, NULL) == ERR_ARG); +void TapInterface_Init_test1() +{ + printf("---Running Test--- %s\n", __FUNCTION__); + // assert(TapInterface_Init(NULL, NULL, NULL) == ERR_ARG); } -int main() { - printf("---Running Test--- tests from %s\n", __FILE__); - TapInterface_Init_test1(); - return 0; +int main() +{ + printf("---Running Test--- tests from %s\n", __FILE__); + TapInterface_Init_test1(); + return 0; } diff --git a/src/setup_payload/QRCodeSetupPayloadGenerator.h b/src/setup_payload/QRCodeSetupPayloadGenerator.h index b2b75238bdbfee..ba9c4e9eba7ed7 100644 --- a/src/setup_payload/QRCodeSetupPayloadGenerator.h +++ b/src/setup_payload/QRCodeSetupPayloadGenerator.h @@ -66,4 +66,4 @@ class QRCodeSetupPayloadGenerator }; // namespace chip -#endif /* _QR_CODE_SETUP_PAYLOAD_GENERATOR_ */ \ No newline at end of file +#endif /* _QR_CODE_SETUP_PAYLOAD_GENERATOR_ */ diff --git a/src/setup_payload/SetupCodeUtils.h b/src/setup_payload/SetupCodeUtils.h index caa339316d652f..9a8fdaa747a84c 100644 --- a/src/setup_payload/SetupCodeUtils.h +++ b/src/setup_payload/SetupCodeUtils.h @@ -34,4 +34,4 @@ std::string base45EncodedString(uint64_t input, size_t minLength); } // namespace chip -#endif /* _SETUP_CODE_UTILS_H_ */ \ No newline at end of file +#endif /* _SETUP_CODE_UTILS_H_ */ diff --git a/src/setup_payload/SetupPayload.cpp b/src/setup_payload/SetupPayload.cpp index a174089a24d0fc..18483992957509 100644 --- a/src/setup_payload/SetupPayload.cpp +++ b/src/setup_payload/SetupPayload.cpp @@ -57,4 +57,4 @@ bool SetupPayload::isValid() return true; } -} // namespace chip \ No newline at end of file +} // namespace chip diff --git a/src/setup_payload/SetupPayload.h b/src/setup_payload/SetupPayload.h index 73d5c699f45278..e691df294e4bea 100644 --- a/src/setup_payload/SetupPayload.h +++ b/src/setup_payload/SetupPayload.h @@ -21,7 +21,6 @@ * data enumerated from a byte stream */ - #ifndef _SETUP_PAYLOAD_H_ #define _SETUP_PAYLOAD_H_ @@ -29,40 +28,35 @@ namespace chip { // TODO this shuould point to the spec -const int kVersionFieldLengthInBits = 3; -const int kVendorIDFieldLengthInBits = 16; -const int kProductIDFieldLengthInBits = 16; -const int kCustomFlowRequiredFieldLengthInBits = 1; -const int kRendezvousInfoFieldLengthInBits = 8; +const int kVersionFieldLengthInBits = 3; +const int kVendorIDFieldLengthInBits = 16; +const int kProductIDFieldLengthInBits = 16; +const int kCustomFlowRequiredFieldLengthInBits = 1; +const int kRendezvousInfoFieldLengthInBits = 8; const int kPayloadDiscriminatorFieldLengthInBits = 8; -const int kSetupPINCodeFieldLengthInBits = 27; -const int kReservedFieldLengthInBits = 1; +const int kSetupPINCodeFieldLengthInBits = 27; +const int kReservedFieldLengthInBits = 1; -const int kTotalPayloadDataSizeInBits = ( kVersionFieldLengthInBits + \ - kVendorIDFieldLengthInBits + \ - kProductIDFieldLengthInBits + \ - kCustomFlowRequiredFieldLengthInBits + \ - kRendezvousInfoFieldLengthInBits + \ - kPayloadDiscriminatorFieldLengthInBits + \ - kSetupPINCodeFieldLengthInBits + \ - kReservedFieldLengthInBits - ); +const int kTotalPayloadDataSizeInBits = + (kVersionFieldLengthInBits + kVendorIDFieldLengthInBits + kProductIDFieldLengthInBits + kCustomFlowRequiredFieldLengthInBits + + kRendezvousInfoFieldLengthInBits + kPayloadDiscriminatorFieldLengthInBits + kSetupPINCodeFieldLengthInBits + + kReservedFieldLengthInBits); class SetupPayload { - public: - uint8_t version; - uint16_t vendorID; - uint16_t productID; - uint8_t requiresCustomFlow; - uint16_t rendezvousInformation; - uint16_t discriminator; - uint32_t setUpPINCode; - - // Test that the Setup Payload is within expected value ranges - bool isValid(); +public: + uint8_t version; + uint16_t vendorID; + uint16_t productID; + uint8_t requiresCustomFlow; + uint16_t rendezvousInformation; + uint16_t discriminator; + uint32_t setUpPINCode; + + // Test that the Setup Payload is within expected value ranges + bool isValid(); }; }; // namespace chip -#endif /* _SETUP_PAYLOAD_H_ */ \ No newline at end of file +#endif /* _SETUP_PAYLOAD_H_ */ diff --git a/src/setup_payload/tests/tests.cpp b/src/setup_payload/tests/tests.cpp index 34ad882d733118..25d97c4266cea4 100644 --- a/src/setup_payload/tests/tests.cpp +++ b/src/setup_payload/tests/tests.cpp @@ -129,4 +129,4 @@ int main(int argc, char ** argv) testPayloadBase45Rep(); testBase45Encoding(); testSetupPayloadVerify(); -} \ No newline at end of file +} diff --git a/src/system/SystemAlignSize.h b/src/system/SystemAlignSize.h index 05b6b66c66d71a..a1d81095f523e7 100644 --- a/src/system/SystemAlignSize.h +++ b/src/system/SystemAlignSize.h @@ -25,6 +25,6 @@ #ifndef SYSTEMALIGNSIZE_H #define SYSTEMALIGNSIZE_H -#define CHIP_SYSTEM_ALIGN_SIZE(ELEMENT, ALIGNMENT) (((ELEMENT) + (ALIGNMENT) - 1) & ~((ALIGNMENT) - 1)) +#define CHIP_SYSTEM_ALIGN_SIZE(ELEMENT, ALIGNMENT) (((ELEMENT) + (ALIGNMENT) -1) & ~((ALIGNMENT) -1)) #endif // defined(SYSTEMALIGNSIZE_H) diff --git a/src/system/SystemClock.h b/src/system/SystemClock.h index a972b5bf44b384..0f4efad5fe1f73 100644 --- a/src/system/SystemClock.h +++ b/src/system/SystemClock.h @@ -32,17 +32,17 @@ #include - namespace chip { namespace System { -enum { - kTimerFactor_nano_per_micro = 1000, /** Number of nanoseconds in a microsecond. */ - kTimerFactor_micro_per_milli = 1000, /** Number of microseconds in a millisecond. */ - kTimerFactor_milli_per_unit = 1000, /** Number of milliseconds in a second. */ +enum +{ + kTimerFactor_nano_per_micro = 1000, /** Number of nanoseconds in a microsecond. */ + kTimerFactor_micro_per_milli = 1000, /** Number of microseconds in a millisecond. */ + kTimerFactor_milli_per_unit = 1000, /** Number of milliseconds in a second. */ - kTimerFactor_nano_per_milli = 1000000, /** Number of nanoseconds in a millisecond. */ - kTimerFactor_micro_per_unit = 1000000 /** Number of microseconds in a second. */ + kTimerFactor_nano_per_milli = 1000000, /** Number of nanoseconds in a millisecond. */ + kTimerFactor_micro_per_unit = 1000000 /** Number of microseconds in a second. */ }; namespace Platform { diff --git a/src/system/SystemConfig.h b/src/system/SystemConfig.h index 58da86ffddb727..bac08c6979459c 100644 --- a/src/system/SystemConfig.h +++ b/src/system/SystemConfig.h @@ -530,7 +530,7 @@ struct LwIPEvent; */ #ifndef CHIP_SYSTEM_CONFIG_HEADER_RESERVE_SIZE #if CHIP_SYSTEM_CONFIG_USE_LWIP -#define CHIP_SYSTEM_CONFIG_HEADER_RESERVE_SIZE \ +#define CHIP_SYSTEM_CONFIG_HEADER_RESERVE_SIZE \ (PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN + CHIP_SYSTEM_HEADER_RESERVE_SIZE) #else /* !CHIP_SYSTEM_CONFIG_USE_LWIP */ #define CHIP_SYSTEM_CONFIG_HEADER_RESERVE_SIZE (CHIP_SYSTEM_HEADER_RESERVE_SIZE) diff --git a/src/system/SystemError.h b/src/system/SystemError.h index 2d0010daa3bc14..72e187273758b1 100644 --- a/src/system/SystemError.h +++ b/src/system/SystemError.h @@ -165,10 +165,8 @@ * @} */ - #ifdef __cplusplus - namespace chip { namespace System { @@ -183,7 +181,7 @@ extern void RegisterSystemLayerErrorFormatter(void); extern bool FormatSystemLayerError(char * buf, uint16_t bufSize, int32_t err); extern Error MapErrorPOSIX(int code); -extern const char* DescribeErrorPOSIX(Error code); +extern const char * DescribeErrorPOSIX(Error code); extern bool IsErrorPOSIX(Error code); extern void RegisterPOSIXErrorFormatter(void); extern bool FormatPOSIXError(char * buf, uint16_t bufSize, int32_t err); @@ -191,7 +189,7 @@ extern bool FormatPOSIXError(char * buf, uint16_t bufSize, int32_t err); #if CHIP_SYSTEM_CONFIG_USE_LWIP extern Error MapErrorLwIP(err_t code); -extern const char* DescribeErrorLwIP(Error code); +extern const char * DescribeErrorLwIP(Error code); extern bool IsErrorLwIP(Error code); extern void RegisterLwIPErrorFormatter(void); extern bool FormatLwIPError(char * buf, uint16_t bufSize, int32_t err); diff --git a/src/system/SystemEvent.h b/src/system/SystemEvent.h index b7a1529418a265..d9df38887600c9 100644 --- a/src/system/SystemEvent.h +++ b/src/system/SystemEvent.h @@ -51,9 +51,9 @@ typedef CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE EventType; typedef CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE Event; /** -* The Inet layer event type definitions. -* -*/ + * The Inet layer event type definitions. + * + */ enum { kEvent_ReleaseObj = _CHIP_SYSTEM_CONFIG_LWIP_EVENT(0), /**< The event for the drop of a SystemLayer object */ diff --git a/src/system/SystemFaultInjection.h b/src/system/SystemFaultInjection.h index 5ed5caef44dcb0..9cd4c034afaba9 100644 --- a/src/system/SystemFaultInjection.h +++ b/src/system/SystemFaultInjection.h @@ -46,15 +46,15 @@ using nl::FaultInjection::Manager; */ typedef enum { - kFault_PacketBufferNew, /**< Fail the allocation of a PacketBuffer */ - kFault_TimeoutImmediate, /**< Override the timeout value of a timer being started with 0 */ - kFault_AsyncEvent, /**< Inject asynchronous events; when the fault is enabled, it expects - one integer argument, which is passed to application to signal the event - to be injected; @see CHIP_SYSTEM_FAULT_INJECT_ASYNC_EVENT */ + kFault_PacketBufferNew, /**< Fail the allocation of a PacketBuffer */ + kFault_TimeoutImmediate, /**< Override the timeout value of a timer being started with 0 */ + kFault_AsyncEvent, /**< Inject asynchronous events; when the fault is enabled, it expects + one integer argument, which is passed to application to signal the event + to be injected; @see CHIP_SYSTEM_FAULT_INJECT_ASYNC_EVENT */ kFault_NumberOfFaultIdentifiers, } Id; -DLL_EXPORT nl::FaultInjection::Manager& GetManager(void); +DLL_EXPORT nl::FaultInjection::Manager & GetManager(void); /** * Callback to the application that returns how many asynchronous events the application could @@ -87,7 +87,6 @@ DLL_EXPORT void SetAsyncEventCallbacks(GetNumEventsAvailableCb aGetNumEventsAvai */ DLL_EXPORT void InjectAsyncEvent(void); - } // namespace FaultInjection } // namespace System } // namespace chip @@ -99,8 +98,8 @@ DLL_EXPORT void InjectAsyncEvent(void); * @param[in] aFaultID A System fault-injection id * @param[in] aStatements Statements to be executed if the fault is enabled. */ -#define CHIP_SYSTEM_FAULT_INJECT(aFaultId, aStatement) \ - nlFAULT_INJECT(::chip::System::FaultInjection::GetManager(), aFaultId, aStatement) +#define CHIP_SYSTEM_FAULT_INJECT(aFaultId, aStatement) \ + nlFAULT_INJECT(::chip::System::FaultInjection::GetManager(), aFaultId, aStatement) /** * This macro implements the injection of asynchronous events. @@ -114,12 +113,12 @@ DLL_EXPORT void InjectAsyncEvent(void); * the macro stores the return value of GetNumEventsAvailableCb into the Records arguments, * so that the application can log it from a callback installed into the fault. */ -#define CHIP_SYSTEM_FAULT_INJECT_ASYNC_EVENT() \ - do { \ - chip::System::FaultInjection::InjectAsyncEvent(); \ +#define CHIP_SYSTEM_FAULT_INJECT_ASYNC_EVENT() \ + do \ + { \ + chip::System::FaultInjection::InjectAsyncEvent(); \ } while (0) - #else // CHIP_SYSTEM_CONFIG_TEST #define CHIP_SYSTEM_FAULT_INJECT(aFaultId, aStatement) diff --git a/src/system/SystemLayer.h b/src/system/SystemLayer.h index c1691bfda2d05e..545af3ecabfad1 100644 --- a/src/system/SystemLayer.h +++ b/src/system/SystemLayer.h @@ -75,17 +75,17 @@ using ::chip::System::Layer; using ::chip::System::Object; #endif // CHIP_SYSTEM_CONFIG_USE_LWIP -extern Error WillInit(Layer& aLayer, void* aContext); -extern Error WillShutdown(Layer& aLayer, void* aContext); +extern Error WillInit(Layer & aLayer, void * aContext); +extern Error WillShutdown(Layer & aLayer, void * aContext); -extern void DidInit(Layer& aLayer, void* aContext, Error aStatus); -extern void DidShutdown(Layer& aLayer, void* aContext, Error aStatus); +extern void DidInit(Layer & aLayer, void * aContext, Error aStatus); +extern void DidShutdown(Layer & aLayer, void * aContext, Error aStatus); #if CHIP_SYSTEM_CONFIG_USE_LWIP -extern Error PostEvent(Layer& aLayer, void* aContext, Object& aTarget, EventType aType, uintptr_t aArgument); -extern Error DispatchEvents(Layer& aLayer, void* aContext); -extern Error DispatchEvent(Layer& aLayer, void* aContext, Event aEvent); -extern Error StartTimer(Layer& aLayer, void* aContext, uint32_t aMilliseconds); +extern Error PostEvent(Layer & aLayer, void * aContext, Object & aTarget, EventType aType, uintptr_t aArgument); +extern Error DispatchEvents(Layer & aLayer, void * aContext); +extern Error DispatchEvent(Layer & aLayer, void * aContext, Event aEvent); +extern Error StartTimer(Layer & aLayer, void * aContext, uint32_t aMilliseconds); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP } // namespace Layer @@ -98,12 +98,12 @@ extern Error StartTimer(Layer& aLayer, void* aContext, uint32_t aMilliseconds); */ enum LayerState { - kLayerState_NotInitialized = 0, /**< Not initialized state. */ - kLayerState_Initialized = 1 /**< Initialized state. */ + kLayerState_NotInitialized = 0, /**< Not initialized state. */ + kLayerState_Initialized = 1 /**< Initialized state. */ }; #if CHIP_SYSTEM_CONFIG_USE_LWIP -typedef Error (*LwIPEventHandlerFunction)(Object& aTarget, EventType aEventType, uintptr_t aArgument); +typedef Error (*LwIPEventHandlerFunction)(Object & aTarget, EventType aEventType, uintptr_t aArgument); class LwIPEventHandlerDelegate { @@ -112,11 +112,11 @@ class LwIPEventHandlerDelegate public: bool IsInitialized(void) const; void Init(LwIPEventHandlerFunction aFunction); - void Prepend(const LwIPEventHandlerDelegate*& aDelegateList); + void Prepend(const LwIPEventHandlerDelegate *& aDelegateList); private: LwIPEventHandlerFunction mFunction; - const LwIPEventHandlerDelegate* mNextDelegate; + const LwIPEventHandlerDelegate * mNextDelegate; }; #endif // CHIP_SYSTEM_CONFIG_USE_LWIP @@ -137,37 +137,37 @@ class DLL_EXPORT Layer public: Layer(void); - Error Init(void* aContext); + Error Init(void * aContext); Error Shutdown(void); - void *GetPlatformData(void) const; - void SetPlatformData(void *aPlatformData); + void * GetPlatformData(void) const; + void SetPlatformData(void * aPlatformData); LayerState State(void) const; - Error NewTimer(Timer*& aTimerPtr); + Error NewTimer(Timer *& aTimerPtr); - typedef void (*TimerCompleteFunct)(Layer* aLayer, void* aAppState, Error aError); - Error StartTimer(uint32_t aMilliseconds, TimerCompleteFunct aComplete, void* aAppState); - void CancelTimer(TimerCompleteFunct aOnComplete, void* aAppState); + typedef void (*TimerCompleteFunct)(Layer * aLayer, void * aAppState, Error aError); + Error StartTimer(uint32_t aMilliseconds, TimerCompleteFunct aComplete, void * aAppState); + void CancelTimer(TimerCompleteFunct aOnComplete, void * aAppState); - Error ScheduleWork(TimerCompleteFunct aComplete, void* aAppState); + Error ScheduleWork(TimerCompleteFunct aComplete, void * aAppState); #if CHIP_SYSTEM_CONFIG_USE_SOCKETS - void PrepareSelect(int& aSetSize, fd_set* aReadSet, fd_set* aWriteSet, fd_set* aExceptionSet, struct timeval& aSleepTime); - void HandleSelectResult(int aSetSize, fd_set* aReadSet, fd_set* aWriteSet, fd_set* aExceptionSet); + void PrepareSelect(int & aSetSize, fd_set * aReadSet, fd_set * aWriteSet, fd_set * aExceptionSet, struct timeval & aSleepTime); + void HandleSelectResult(int aSetSize, fd_set * aReadSet, fd_set * aWriteSet, fd_set * aExceptionSet); void WakeSelect(void); #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS #if CHIP_SYSTEM_CONFIG_USE_LWIP - typedef Error (*EventHandler)(Object& aTarget, EventType aEventType, uintptr_t aArgument); - Error AddEventHandlerDelegate(LwIPEventHandlerDelegate& aDelegate); + typedef Error (*EventHandler)(Object & aTarget, EventType aEventType, uintptr_t aArgument); + Error AddEventHandlerDelegate(LwIPEventHandlerDelegate & aDelegate); // Event Handling - Error PostEvent(Object& aTarget, EventType aEventType, uintptr_t aArgument); + Error PostEvent(Object & aTarget, EventType aEventType, uintptr_t aArgument); Error DispatchEvents(void); Error DispatchEvent(Event aEvent); - Error HandleEvent(Object& aTarget, EventType aEventType, uintptr_t aArgument); + Error HandleEvent(Object & aTarget, EventType aEventType, uintptr_t aArgument); // Timer Management Error HandlePlatformTimer(void); @@ -182,14 +182,14 @@ class DLL_EXPORT Layer private: LayerState mLayerState; - void* mContext; - void* mPlatformData; + void * mContext; + void * mPlatformData; #if CHIP_SYSTEM_CONFIG_USE_LWIP static LwIPEventHandlerDelegate sSystemEventHandlerDelegate; - const LwIPEventHandlerDelegate* mEventDelegateList; - Timer* mTimerList; + const LwIPEventHandlerDelegate * mEventDelegateList; + Timer * mTimerList; bool mTimerComplete; #endif // CHIP_SYSTEM_CONFIG_USE_LWIP @@ -203,25 +203,26 @@ class DLL_EXPORT Layer #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS #if CHIP_SYSTEM_CONFIG_USE_LWIP - static Error HandleSystemLayerEvent(Object& aTarget, EventType aEventType, uintptr_t aArgument); + static Error HandleSystemLayerEvent(Object & aTarget, EventType aEventType, uintptr_t aArgument); Error StartPlatformTimer(uint32_t aDelayMilliseconds); - friend Error Platform::Layer::PostEvent(Layer& aLayer, void* aContext, Object& aTarget, EventType aType, uintptr_t aArgument); - friend Error Platform::Layer::DispatchEvents(Layer& aLayer, void* aContext); - friend Error Platform::Layer::DispatchEvent(Layer& aLayer, void* aContext, Event aEvent); - friend Error Platform::Layer::StartTimer(Layer& aLayer, void* aContext, uint32_t aMilliseconds); + friend Error Platform::Layer::PostEvent(Layer & aLayer, void * aContext, Object & aTarget, EventType aType, + uintptr_t aArgument); + friend Error Platform::Layer::DispatchEvents(Layer & aLayer, void * aContext); + friend Error Platform::Layer::DispatchEvent(Layer & aLayer, void * aContext, Event aEvent); + friend Error Platform::Layer::StartTimer(Layer & aLayer, void * aContext, uint32_t aMilliseconds); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP // Copy and assignment NOT DEFINED - Layer(const Layer&); - Layer& operator =(const Layer&); + Layer(const Layer &); + Layer & operator=(const Layer &); friend class Timer; #if CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES friend class Inet::InetLayer; - void CancelAllMatchingInetTimers(Inet::InetLayer& aInetLayer, void* aOnCompleteInetLayer, void* aAppState); + void CancelAllMatchingInetTimers(Inet::InetLayer & aInetLayer, void * aOnCompleteInetLayer, void * aAppState); #endif // CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES }; diff --git a/src/system/SystemMutex.h b/src/system/SystemMutex.h index 65678647121190..4194b054a1beab 100644 --- a/src/system/SystemMutex.h +++ b/src/system/SystemMutex.h @@ -52,9 +52,9 @@ namespace System { * * @brief * This class represents a simple mutual exclusion lock used on platforms with preemptively scheduled multi-threaded - * programming environments, for example, POSIX threads and FreeRTOS. The lock is non-recursive, and may not be used in a hardware - * interrupt context. The constructor and destructor are defined as null functions to facilitate using objects with \c static - * storage duration and uninitialized memory. Use \c Init method to initialize. The copy/move operators are not provided. + * programming environments, for example, POSIX threads and FreeRTOS. The lock is non-recursive, and may not be used in a + * hardware interrupt context. The constructor and destructor are defined as null functions to facilitate using objects with \c + * static storage duration and uninitialized memory. Use \c Init method to initialize. The copy/move operators are not provided. * */ class DLL_EXPORT Mutex @@ -63,10 +63,10 @@ class DLL_EXPORT Mutex Mutex(void); ~Mutex(void); - static Error Init(Mutex& aMutex); + static Error Init(Mutex & aMutex); - void Lock(void); /**< Acquire the mutual exclusion lock, blocking the current thread indefinitely if necessary. */ - void Unlock(void); /**< Release the mutual exclusion lock (can block on some systems until scheduler completes). */ + void Lock(void); /**< Acquire the mutual exclusion lock, blocking the current thread indefinitely if necessary. */ + void Unlock(void); /**< Release the mutual exclusion lock (can block on some systems until scheduler completes). */ private: #if CHIP_SYSTEM_CONFIG_POSIX_LOCKING @@ -81,17 +81,13 @@ class DLL_EXPORT Mutex volatile int mInitialized; #endif // CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING - Mutex(const Mutex&) /* = delete */; - Mutex& operator =(const Mutex&) /* = delete */; + Mutex(const Mutex &) /* = delete */; + Mutex & operator=(const Mutex &) /* = delete */; }; -inline Mutex::Mutex(void) -{ -} +inline Mutex::Mutex(void) {} -inline Mutex::~Mutex(void) -{ -} +inline Mutex::~Mutex(void) {} #if CHIP_SYSTEM_CONFIG_POSIX_LOCKING inline void Mutex::Lock(void) diff --git a/src/system/SystemObject.h b/src/system/SystemObject.h index d900cf41d038aa..288c70f57224e9 100644 --- a/src/system/SystemObject.h +++ b/src/system/SystemObject.h @@ -50,7 +50,8 @@ namespace System { // Forward class and class template declarations class Layer; -template class ObjectPool; +template +class ObjectPool; /** * @class Object @@ -70,24 +71,25 @@ template class ObjectPool; */ class DLL_EXPORT Object { - template friend class ObjectPool; + template + friend class ObjectPool; public: /** Test whether this object is retained by \c aLayer. Concurrency safe. */ - bool IsRetained(const Layer& aLayer) const; + bool IsRetained(const Layer & aLayer) const; void Retain(void); void Release(void); - Layer& SystemLayer(void) const; + Layer & SystemLayer(void) const; protected: #if CHIP_SYSTEM_CONFIG_USE_LWIP /**< What to do when DeferredRelease fails to post a kEvent_ReleaseObj. */ enum ReleaseDeferralErrorTactic { - kReleaseDeferralErrorTactic_Ignore, /**< No action. */ - kReleaseDeferralErrorTactic_Release, /**< Release immediately. */ - kReleaseDeferralErrorTactic_Die, /**< Die with message. */ + kReleaseDeferralErrorTactic_Ignore, /**< No action. */ + kReleaseDeferralErrorTactic_Release, /**< Release immediately. */ + kReleaseDeferralErrorTactic_Die, /**< Die with message. */ }; void DeferredRelease(ReleaseDeferralErrorTactic aTactic); @@ -96,17 +98,17 @@ class DLL_EXPORT Object private: Object(void); ~Object(void); - Object(const Object&) /* = delete */; - Object& operator =(const Object&) /* = delete */; + Object(const Object &) /* = delete */; + Object & operator=(const Object &) /* = delete */; - Layer* volatile mSystemLayer; /**< Pointer to the layer object that owns this object. */ - unsigned int mRefCount; /**< Count of remaining calls to Release before object is dead. */ + Layer * volatile mSystemLayer; /**< Pointer to the layer object that owns this object. */ + unsigned int mRefCount; /**< Count of remaining calls to Release before object is dead. */ /** If not already retained, attempt initial retention of this object for \c aLayer and zero up to \c aOctets. */ - bool TryCreate(Layer& aLayer, size_t aOctets); + bool TryCreate(Layer & aLayer, size_t aOctets); public: - void* AppState; /**< Generic pointer to app-specific data associated with the object. */ + void * AppState; /**< Generic pointer to app-specific data associated with the object. */ }; /** @@ -118,7 +120,7 @@ class DLL_EXPORT Object * cannot have previously retained the object for \c aLayer. If it returns \c true, then the logic using \c aLayer is * responsible for ensuring concurrency safety for this object. */ -inline bool Object::IsRetained(const Layer& aLayer) const +inline bool Object::IsRetained(const Layer & aLayer) const { return this->mSystemLayer == &aLayer; } @@ -137,20 +139,16 @@ inline void Object::Retain(void) * Returns a reference to the CHIP System Layer object provided when the object was initially retained from its corresponding * object pool instance. The object is assumed to be live. */ -inline Layer& Object::SystemLayer(void) const +inline Layer & Object::SystemLayer(void) const { return *this->mSystemLayer; } /** Deleted. */ -inline Object::Object(void) -{ -} +inline Object::Object(void) {} /** Deleted. */ -inline Object::~Object(void) -{ -} +inline Object::~Object(void) {} /** * @brief @@ -159,8 +157,9 @@ inline Object::~Object(void) * @tparam ALIGN a typename with the alignment properties for the block. * @tparam SIZE a constant size of the block in bytes. */ -template -union ObjectArena { +template +union ObjectArena +{ uint8_t uMemory[SIZE]; ALIGN uAlign; }; @@ -172,24 +171,24 @@ union ObjectArena { * @tparam T a subclass of Object to be allocated from the arena. * @tparam N a positive integer number of objects of class T to allocate from the arena. */ -template +template class ObjectPool { public: static size_t Size(void); - T* Get(const Layer& aLayer, size_t aIndex); - T* TryCreate(Layer& aLayer); - void GetStatistics(chip::System::Stats::count_t& aNumInUse, chip::System::Stats::count_t& aHighWatermark); + T * Get(const Layer & aLayer, size_t aIndex); + T * TryCreate(Layer & aLayer); + void GetStatistics(chip::System::Stats::count_t & aNumInUse, chip::System::Stats::count_t & aHighWatermark); private: friend class TestObject; - ObjectArena mArena; + ObjectArena mArena; #if CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS - void GetNumObjectsInUse(unsigned int aStartIndex, unsigned int& aNumInUse); - void UpdateHighWatermark(const unsigned int& aCandidate); + void GetNumObjectsInUse(unsigned int aStartIndex, unsigned int & aNumInUse); + void UpdateHighWatermark(const unsigned int & aCandidate); volatile unsigned int mHighWatermark; #endif }; @@ -198,7 +197,7 @@ class ObjectPool * @brief * Returns the number of objects that can be simultaneously retained from a pool. */ -template +template inline size_t ObjectPool::Size(void) { return N; @@ -208,15 +207,15 @@ inline size_t ObjectPool::Size(void) * @brief * Returns a pointer the object at \c aIndex or \c NULL if the object is not retained by \c aLayer. */ -template -inline T* ObjectPool::Get(const Layer& aLayer, size_t aIndex) +template +inline T * ObjectPool::Get(const Layer & aLayer, size_t aIndex) { - T* lReturn = NULL; + T * lReturn = NULL; if (aIndex < N) - lReturn = &reinterpret_cast(mArena.uMemory)[aIndex]; + lReturn = &reinterpret_cast(mArena.uMemory)[aIndex]; - (void) static_cast(lReturn); /* In C++-11, this would be a static_assert that T inherits Object. */ + (void) static_cast(lReturn); /* In C++-11, this would be a static_assert that T inherits Object. */ return (lReturn != NULL) && lReturn->IsRetained(aLayer) ? lReturn : NULL; } @@ -225,10 +224,10 @@ inline T* ObjectPool::Get(const Layer& aLayer, size_t aIndex) * @brief * Tries to initially retain the first object in the pool that is not retained by any layer. */ -template -inline T* ObjectPool::TryCreate(Layer& aLayer) +template +inline T * ObjectPool::TryCreate(Layer & aLayer) { - T* lReturn = NULL; + T * lReturn = NULL; unsigned int lIndex; #if CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS unsigned int lNumInUse = 0; @@ -236,8 +235,7 @@ inline T* ObjectPool::TryCreate(Layer& aLayer) for (lIndex = 0; lIndex < N; ++lIndex) { - T& lObject = reinterpret_cast(mArena.uMemory)[lIndex]; - + T & lObject = reinterpret_cast(mArena.uMemory)[lIndex]; if (lObject.TryCreate(aLayer, sizeof(T))) { @@ -265,15 +263,15 @@ inline T* ObjectPool::TryCreate(Layer& aLayer) } #if CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS -template -inline void ObjectPool::UpdateHighWatermark(const unsigned int& aCandidate) +template +inline void ObjectPool::UpdateHighWatermark(const unsigned int & aCandidate) { unsigned int lTmp; while (aCandidate > (lTmp = mHighWatermark)) { SYSTEM_OBJECT_HWM_TEST_HOOK(); - (void)__sync_bool_compare_and_swap(&mHighWatermark, lTmp, aCandidate); + (void) __sync_bool_compare_and_swap(&mHighWatermark, lTmp, aCandidate); } } @@ -285,14 +283,14 @@ inline void ObjectPool::UpdateHighWatermark(const unsigned int& aCandidate * @param[in/out] aNumInUse The number of objects in use. If aStartIndex is not 0, * the function adds to the counter without resetting it first. */ -template -inline void ObjectPool::GetNumObjectsInUse(unsigned int aStartIndex, unsigned int& aNumInUse) +template +inline void ObjectPool::GetNumObjectsInUse(unsigned int aStartIndex, unsigned int & aNumInUse) { unsigned int count = 0; for (unsigned int lIndex = aStartIndex; lIndex < N; ++lIndex) { - T& lObject = reinterpret_cast(mArena.uMemory)[lIndex]; + T & lObject = reinterpret_cast(mArena.uMemory)[lIndex]; if (lObject.mSystemLayer != NULL) { @@ -309,10 +307,8 @@ inline void ObjectPool::GetNumObjectsInUse(unsigned int aStartIndex, unsig } #endif // CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS - -template -inline void ObjectPool::GetStatistics(chip::System::Stats::count_t& aNumInUse, - chip::System::Stats::count_t& aHighWatermark) +template +inline void ObjectPool::GetStatistics(chip::System::Stats::count_t & aNumInUse, chip::System::Stats::count_t & aHighWatermark) { #if CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS unsigned int lNumInUse; @@ -329,7 +325,7 @@ inline void ObjectPool::GetStatistics(chip::System::Stats::count_t& aNumIn { lHighWatermark = CHIP_SYS_STATS_COUNT_MAX; } - aNumInUse = static_cast(lNumInUse); + aNumInUse = static_cast(lNumInUse); aHighWatermark = static_cast(lHighWatermark); #endif } diff --git a/src/system/SystemPacketBuffer.h b/src/system/SystemPacketBuffer.h index 58ad8dbf613581..9d8679860c7df5 100644 --- a/src/system/SystemPacketBuffer.h +++ b/src/system/SystemPacketBuffer.h @@ -48,8 +48,8 @@ namespace System { #if !CHIP_SYSTEM_CONFIG_USE_LWIP struct pbuf { - struct pbuf* next; - void* payload; + struct pbuf * next; + void * payload; uint16_t tot_len; uint16_t len; uint16_t ref; @@ -95,11 +95,11 @@ class DLL_EXPORT PacketBuffer : private pbuf public: size_t AllocSize(void) const; - uint8_t* Start(void) const; - void SetStart(uint8_t* aNewStart); + uint8_t * Start(void) const; + void SetStart(uint8_t * aNewStart); uint16_t DataLength(void) const; - void SetDataLength(uint16_t aNewLen, PacketBuffer* aChainHead = NULL); + void SetDataLength(uint16_t aNewLen, PacketBuffer * aChainHead = NULL); uint16_t TotalLength(void) const; @@ -108,34 +108,34 @@ class DLL_EXPORT PacketBuffer : private pbuf uint16_t ReservedSize(void) const; - PacketBuffer* Next(void) const; + PacketBuffer * Next(void) const; - void AddToEnd(PacketBuffer* aPacket); - PacketBuffer* DetachTail(void); + void AddToEnd(PacketBuffer * aPacket); + PacketBuffer * DetachTail(void); void CompactHead(void); - PacketBuffer* Consume(uint16_t aConsumeLength); + PacketBuffer * Consume(uint16_t aConsumeLength); void ConsumeHead(uint16_t aConsumeLength); bool EnsureReservedSize(uint16_t aReservedSize); bool AlignPayload(uint16_t aAlignBytes); void AddRef(void); - static PacketBuffer* NewWithAvailableSize(size_t aAvailableSize); - static PacketBuffer* NewWithAvailableSize(uint16_t aReservedSize, size_t aAvailableSize); + static PacketBuffer * NewWithAvailableSize(size_t aAvailableSize); + static PacketBuffer * NewWithAvailableSize(uint16_t aReservedSize, size_t aAvailableSize); - static PacketBuffer* New(void); - static PacketBuffer* New(uint16_t aReservedSize); + static PacketBuffer * New(void); + static PacketBuffer * New(uint16_t aReservedSize); - static PacketBuffer* RightSize(PacketBuffer *aPacket); + static PacketBuffer * RightSize(PacketBuffer * aPacket); - static void Free(PacketBuffer* aPacket); - static PacketBuffer* FreeHead(PacketBuffer* aPacket); + static void Free(PacketBuffer * aPacket); + static PacketBuffer * FreeHead(PacketBuffer * aPacket); private: #if !CHIP_SYSTEM_CONFIG_USE_LWIP && CHIP_SYSTEM_CONFIG_PACKETBUFFER_MAXALLOC - static PacketBuffer* sFreeList; + static PacketBuffer * sFreeList; - static PacketBuffer* BuildFreeList(void); + static PacketBuffer * BuildFreeList(void); #endif // !CHIP_SYSTEM_CONFIG_USE_LWIP && CHIP_SYSTEM_CONFIG_PACKETBUFFER_MAXALLOC void Clear(void); @@ -160,7 +160,6 @@ class DLL_EXPORT PacketBuffer : private pbuf #define CHIP_SYSTEM_PACKETBUFFER_HEADER_SIZE CHIP_SYSTEM_ALIGN_SIZE(sizeof(::chip::System::PacketBuffer), 4) #endif // CHIP_SYSTEM_CONFIG_USE_LWIP - /** * @def CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX * @@ -217,13 +216,13 @@ inline size_t PacketBuffer::AllocSize(void) const return LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) - CHIP_SYSTEM_PACKETBUFFER_HEADER_SIZE; else return LWIP_MEM_ALIGN_SIZE(memp_sizes[this->pool]) - CHIP_SYSTEM_PACKETBUFFER_HEADER_SIZE; -#else // !LWIP_PBUF_FROM_CUSTOM_POOLS +#else // !LWIP_PBUF_FROM_CUSTOM_POOLS return LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) - CHIP_SYSTEM_PACKETBUFFER_HEADER_SIZE; #endif // !LWIP_PBUF_FROM_CUSTOM_POOLS -#else // !CHIP_SYSTEM_CONFIG_USE_LWIP +#else // !CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_PACKETBUFFER_MAXALLOC == 0 return static_cast(this->alloc_size); -#else // CHIP_SYSTEM_CONFIG_PACKETBUFFER_MAXALLOC != 0 +#else // CHIP_SYSTEM_CONFIG_PACKETBUFFER_MAXALLOC != 0 extern BufferPoolElement gDummyBufferPoolElement; return sizeof(gDummyBufferPoolElement.Block) - CHIP_SYSTEM_PACKETBUFFER_HEADER_SIZE; #endif // CHIP_SYSTEM_CONFIG_PACKETBUFFER_MAXALLOC != 0 diff --git a/src/system/SystemStats.h b/src/system/SystemStats.h index 8e70e990354af4..3f7c6afd68d08a 100644 --- a/src/system/SystemStats.h +++ b/src/system/SystemStats.h @@ -101,7 +101,6 @@ enum kWDMLegacy_NumTransactions, #endif // CHIP_CONFIG_LEGACY_WDM - kNumEntries }; @@ -115,22 +114,21 @@ extern count_t HighWatermarks[kNumEntries]; class Snapshot { public: - count_t mResourcesInUse[kNumEntries]; count_t mHighWatermarks[kNumEntries]; }; -bool Difference(Snapshot &result, Snapshot &after, Snapshot &before); -void UpdateSnapshot(Snapshot &aSnapshot); -count_t *GetResourcesInUse(void); -count_t *GetHighWatermarks(void); +bool Difference(Snapshot & result, Snapshot & after, Snapshot & before); +void UpdateSnapshot(Snapshot & aSnapshot); +count_t * GetResourcesInUse(void); +count_t * GetHighWatermarks(void); #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS void UpdateLwipPbufCounts(void); #endif -typedef const char *Label; -const Label *GetStrings(void); +typedef const char * Label; +const Label * GetStrings(void); } // namespace Stats } // namespace System @@ -138,49 +136,54 @@ const Label *GetStrings(void); #if CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS -#define SYSTEM_STATS_INCREMENT(entry) \ - do { \ - chip::System::Stats::count_t new_value = ++(chip::System::Stats::GetResourcesInUse()[entry]); \ - if (chip::System::Stats::GetHighWatermarks()[entry] < new_value) \ - { \ - chip::System::Stats::GetHighWatermarks()[entry] = new_value; \ - } \ +#define SYSTEM_STATS_INCREMENT(entry) \ + do \ + { \ + chip::System::Stats::count_t new_value = ++(chip::System::Stats::GetResourcesInUse()[entry]); \ + if (chip::System::Stats::GetHighWatermarks()[entry] < new_value) \ + { \ + chip::System::Stats::GetHighWatermarks()[entry] = new_value; \ + } \ } while (0); -#define SYSTEM_STATS_DECREMENT(entry) \ - do { \ - chip::System::Stats::GetResourcesInUse()[entry]--; \ +#define SYSTEM_STATS_DECREMENT(entry) \ + do \ + { \ + chip::System::Stats::GetResourcesInUse()[entry]--; \ } while (0); -#define SYSTEM_STATS_DECREMENT_BY_N(entry, count) \ - do { \ - chip::System::Stats::GetResourcesInUse()[entry] -= (count); \ +#define SYSTEM_STATS_DECREMENT_BY_N(entry, count) \ + do \ + { \ + chip::System::Stats::GetResourcesInUse()[entry] -= (count); \ } while (0); -#define SYSTEM_STATS_SET(entry, count) \ - do { \ - chip::System::Stats::count_t new_value = chip::System::Stats::GetResourcesInUse()[entry] = (count); \ - if (chip::System::Stats::GetHighWatermarks()[entry] < new_value) \ - { \ - chip::System::Stats::GetHighWatermarks()[entry] = new_value; \ - } \ +#define SYSTEM_STATS_SET(entry, count) \ + do \ + { \ + chip::System::Stats::count_t new_value = chip::System::Stats::GetResourcesInUse()[entry] = (count); \ + if (chip::System::Stats::GetHighWatermarks()[entry] < new_value) \ + { \ + chip::System::Stats::GetHighWatermarks()[entry] = new_value; \ + } \ } while (0); -#define SYSTEM_STATS_RESET(entry) \ - do { \ - chip::System::Stats::GetResourcesInUse()[entry] = 0; \ +#define SYSTEM_STATS_RESET(entry) \ + do \ + { \ + chip::System::Stats::GetResourcesInUse()[entry] = 0; \ } while (0); #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS -#define SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS() \ - do { \ - chip::System::Stats::UpdateLwipPbufCounts(); \ +#define SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS() \ + do \ + { \ + chip::System::Stats::UpdateLwipPbufCounts(); \ } while (0); #else // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS #define SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS() #endif // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS - #else // CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS #define SYSTEM_STATS_INCREMENT(entry) diff --git a/src/system/SystemTimer.h b/src/system/SystemTimer.h index d637be9a3fc48d..02b2d38795cb28 100644 --- a/src/system/SystemTimer.h +++ b/src/system/SystemTimer.h @@ -75,21 +75,21 @@ class DLL_EXPORT Timer : public Object typedef uint64_t Epoch; static Epoch GetCurrentEpoch(void); - static bool IsEarlierEpoch(const Epoch &first, const Epoch &second); + static bool IsEarlierEpoch(const Epoch & first, const Epoch & second); - typedef void (*OnCompleteFunct)(Layer* aLayer, void* aAppState, Error aError); + typedef void (*OnCompleteFunct)(Layer * aLayer, void * aAppState, Error aError); OnCompleteFunct OnComplete; - Error Start(uint32_t aDelayMilliseconds, OnCompleteFunct aOnComplete, void* aAppState); + Error Start(uint32_t aDelayMilliseconds, OnCompleteFunct aOnComplete, void * aAppState); Error Cancel(void); - static void GetStatistics(chip::System::Stats::count_t& aNumInUse, chip::System::Stats::count_t& aHighWatermark); + static void GetStatistics(chip::System::Stats::count_t & aNumInUse, chip::System::Stats::count_t & aHighWatermark); #if CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES - void AttachInetLayer(Inet::InetLayer& aInetLayer, void* aOnCompleteInetLayer, void* aAppStateInetLayer); - Inet::InetLayer* InetLayer(void) const; - void* OnCompleteInetLayer(void) const; - void* AppStateInetLayer(void) const; + void AttachInetLayer(Inet::InetLayer & aInetLayer, void * aOnCompleteInetLayer, void * aAppStateInetLayer); + Inet::InetLayer * InetLayer(void) const; + void * OnCompleteInetLayer(void) const; + void * AppStateInetLayer(void) const; #endif // CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES private: @@ -98,52 +98,50 @@ class DLL_EXPORT Timer : public Object Epoch mAwakenEpoch; #if CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES - Inet::InetLayer* mInetLayer; - void* mOnCompleteInetLayer; - void* mAppStateInetLayer; + Inet::InetLayer * mInetLayer; + void * mOnCompleteInetLayer; + void * mAppStateInetLayer; #endif // CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES void HandleComplete(void); - Error ScheduleWork(OnCompleteFunct aOnComplete, void* aAppState); + Error ScheduleWork(OnCompleteFunct aOnComplete, void * aAppState); #if CHIP_SYSTEM_CONFIG_USE_LWIP - Timer *mNextTimer; + Timer * mNextTimer; - static Error HandleExpiredTimers(Layer& aLayer); + static Error HandleExpiredTimers(Layer & aLayer); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP // Not defined - Timer(const Timer&); - Timer& operator =(const Timer&); + Timer(const Timer &); + Timer & operator=(const Timer &); }; - -inline void Timer::GetStatistics(chip::System::Stats::count_t& aNumInUse, - chip::System::Stats::count_t& aHighWatermark) +inline void Timer::GetStatistics(chip::System::Stats::count_t & aNumInUse, chip::System::Stats::count_t & aHighWatermark) { sPool.GetStatistics(aNumInUse, aHighWatermark); } #if CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES -inline void Timer::AttachInetLayer(Inet::InetLayer& aInetLayer, void* aOnCompleteInetLayer, void* aAppStateInetLayer) +inline void Timer::AttachInetLayer(Inet::InetLayer & aInetLayer, void * aOnCompleteInetLayer, void * aAppStateInetLayer) { - this->mInetLayer = &aInetLayer; + this->mInetLayer = &aInetLayer; this->mOnCompleteInetLayer = aOnCompleteInetLayer; - this->mAppStateInetLayer = aAppStateInetLayer; + this->mAppStateInetLayer = aAppStateInetLayer; } -inline Inet::InetLayer* Timer::InetLayer(void) const +inline Inet::InetLayer * Timer::InetLayer(void) const { return this->mInetLayer; } -inline void* Timer::OnCompleteInetLayer(void) const +inline void * Timer::OnCompleteInetLayer(void) const { return this->mOnCompleteInetLayer; } -inline void* Timer::AppStateInetLayer(void) const +inline void * Timer::AppStateInetLayer(void) const { return this->mAppStateInetLayer; }