From 932cd78f0487d6e96caf13513c7a63ee3971f15b Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Fri, 14 Jun 2019 12:45:39 -0700 Subject: [PATCH] [style] apply missing const declarations (#3921) --- src/core/coap/coap_secure.hpp | 4 ++-- src/core/common/settings.hpp | 2 +- src/core/common/tasklet.hpp | 2 +- src/core/mac/mac.cpp | 12 +----------- src/core/mac/mac.hpp | 8 ++++---- src/core/mac/mac_filter.cpp | 4 ++-- src/core/mac/mac_filter.hpp | 2 +- src/core/mac/mac_frame.hpp | 4 ++-- src/core/meshcop/dataset_manager.hpp | 2 -- src/core/meshcop/joiner_router.hpp | 4 ++-- src/core/meshcop/meshcop_tlvs.hpp | 4 ++-- src/core/net/ip6.hpp | 4 ++-- src/core/net/ip6_headers.hpp | 4 ++-- src/core/net/ip6_mpl.hpp | 2 +- src/core/net/netif.cpp | 13 ++++++------- src/core/net/netif.hpp | 4 ++-- src/core/thread/mesh_forwarder.cpp | 2 +- src/core/thread/mesh_forwarder.hpp | 2 +- src/core/thread/mle_router_ftd.hpp | 2 +- src/core/thread/mle_router_mtd.hpp | 6 +++--- src/core/thread/mle_tlvs.hpp | 6 +++--- src/core/utils/channel_manager.hpp | 2 +- src/ncp/ncp_base.hpp | 2 +- 23 files changed, 42 insertions(+), 55 deletions(-) diff --git a/src/core/coap/coap_secure.hpp b/src/core/coap/coap_secure.hpp index 5efaab298..9b7e831a9 100644 --- a/src/core/coap/coap_secure.hpp +++ b/src/core/coap/coap_secure.hpp @@ -123,7 +123,7 @@ public: * @retval FALSE If DTLS session is not active. * */ - bool IsConnectionActive(void) { return mDtls.IsConnectionActive(); } + bool IsConnectionActive(void) const { return mDtls.IsConnectionActive(); } /** * This method indicates whether or not the DTLS session is connected. @@ -132,7 +132,7 @@ public: * @retval FALSE The DTLS session is not connected. * */ - bool IsConnected(void) { return mDtls.IsConnected(); } + bool IsConnected(void) const { return mDtls.IsConnected(); } /** * This method stops the DTLS connection. diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 39bc0d627..9a481f2d9 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -383,7 +383,7 @@ public: * @retval FALSE The current entry is valid. * */ - bool IsDone(void) { return mIsDone; } + bool IsDone(void) const { return mIsDone; } /** * This method advances the iterator to move to the next Child Info entry in the list (if any). diff --git a/src/core/common/tasklet.hpp b/src/core/common/tasklet.hpp index 4b476a026..c98dbfda0 100644 --- a/src/core/common/tasklet.hpp +++ b/src/core/common/tasklet.hpp @@ -164,7 +164,7 @@ public: * @retval FALSE If there are no tasklets pending. * */ - bool AreTaskletsPending(void) { return mHead != NULL; } + bool AreTaskletsPending(void) const { return mHead != NULL; } /** * This method processes all tasklets queued when this is called. diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 82f41ed6f..fe2f77c4a 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -172,17 +172,7 @@ void Mac::Scan(Operation aScanOperation, uint32_t aScanChannels, uint16_t aScanD StartOperation(aScanOperation); } -bool Mac::IsActiveScanInProgress(void) -{ - return (mOperation == kOperationActiveScan) || (mPendingActiveScan); -} - -bool Mac::IsEnergyScanInProgress(void) -{ - return (mOperation == kOperationEnergyScan) || (mPendingEnergyScan); -} - -bool Mac::IsInTransmitState(void) +bool Mac::IsInTransmitState(void) const { return (mOperation == kOperationTransmitData) || (mOperation == kOperationTransmitBeacon) || (mOperation == kOperationTransmitOutOfBandFrame); diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 660fc480a..efece73e9 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -466,13 +466,13 @@ public: * This method returns if an active scan is in progress. * */ - bool IsActiveScanInProgress(void); + bool IsActiveScanInProgress(void) const { return (mOperation == kOperationActiveScan) || (mPendingActiveScan); } /** * This method returns if an energy scan is in progress. * */ - bool IsEnergyScanInProgress(void); + bool IsEnergyScanInProgress(void) const { return (mOperation == kOperationEnergyScan) || (mPendingEnergyScan); } /** * This method returns if the MAC layer is in transmit state. @@ -482,7 +482,7 @@ public: * Requests. * */ - bool IsInTransmitState(void); + bool IsInTransmitState(void) const; /** * This method registers a callback to provide received raw IEEE 802.15.4 frames. @@ -564,7 +564,7 @@ public: * @retval false Link layer is not enabled. * */ - bool IsEnabled(void) { return mEnabled; } + bool IsEnabled(void) const { return mEnabled; } /** * This method performs AES CCM on the frame which is going to be sent. diff --git a/src/core/mac/mac_filter.cpp b/src/core/mac/mac_filter.cpp index 4125302e8..653aa021e 100644 --- a/src/core/mac/mac_filter.cpp +++ b/src/core/mac/mac_filter.cpp @@ -142,13 +142,13 @@ void Filter::ClearAddresses(void) } } -otError Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) +otError Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const { otError error = OT_ERROR_NOT_FOUND; for (; aIterator < OT_ARRAY_LENGTH(mFilterEntries); aIterator++) { - FilterEntry &entry = mFilterEntries[aIterator]; + const FilterEntry &entry = mFilterEntries[aIterator]; if (entry.mFiltered) { diff --git a/src/core/mac/mac_filter.hpp b/src/core/mac/mac_filter.hpp index 43d8a5cd8..5fb722a17 100644 --- a/src/core/mac/mac_filter.hpp +++ b/src/core/mac/mac_filter.hpp @@ -144,7 +144,7 @@ public: * @retval OT_ERROR_NOT_FOUND No subsequent entry exists. * */ - otError GetNextAddress(Iterator &aIterator, Entry &aEntry); + otError GetNextAddress(Iterator &aIterator, Entry &aEntry) const; /** * This method sets the received signal strength for the messages from the Extended Address. diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index a7d2b7ec0..7ee619110 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -1319,7 +1319,7 @@ public: * @retval FALSE if the beacon does not appear to be a valid Thread Beacon message. * */ - bool IsValid(void) + bool IsValid(void) const { return (mSuperframeSpec == ot::Encoding::LittleEndian::HostSwap16(kSuperFrameSpec)) && (mGtsSpec == 0) && (mPendingAddressSpec == 0); @@ -1387,7 +1387,7 @@ public: * @retval FALSE if the beacon does not appear to be a valid Thread Beacon Payload. * */ - bool IsValid(void) { return (mProtocolId == kProtocolId); } + bool IsValid(void) const { return (mProtocolId == kProtocolId); } /** * This method returns the Protocol ID value. diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp index 169d0f8f6..a991b74fe 100644 --- a/src/core/meshcop/dataset_manager.hpp +++ b/src/core/meshcop/dataset_manager.hpp @@ -408,8 +408,6 @@ private: #if OPENTHREAD_FTD static void HandleSet(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo); void HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); - - bool IsTlvInitialized(Tlv::Type aType); #endif Coap::Resource mResourceGet; diff --git a/src/core/meshcop/joiner_router.hpp b/src/core/meshcop/joiner_router.hpp index 11777ecc9..f6c43aa45 100644 --- a/src/core/meshcop/joiner_router.hpp +++ b/src/core/meshcop/joiner_router.hpp @@ -216,7 +216,7 @@ public: * @retval TRUE If the message shall be sent before the given time. * @retval FALSE Otherwise. */ - bool IsEarlier(uint32_t aTime) { return (static_cast(aTime - mSendTime) > 0); } + bool IsEarlier(uint32_t aTime) const { return (static_cast(aTime - mSendTime) > 0); } /** * This method checks if the message shall be sent after the given time. @@ -226,7 +226,7 @@ public: * @retval TRUE If the message shall be sent after the given time. * @retval FALSE Otherwise. */ - bool IsLater(uint32_t aTime) { return (static_cast(aTime - mSendTime) < 0); } + bool IsLater(uint32_t aTime) const { return (static_cast(aTime - mSendTime) < 0); } private: Ip6::MessageInfo mMessageInfo; ///< Message info of the message to send. diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 4075187d1..03c5a2550 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -2445,7 +2445,7 @@ public: * @retval FALSE If the Joiner flag is not set. * */ - bool IsJoiner(void) { return (mFlags & kJoinerMask) != 0; } + bool IsJoiner(void) const { return (mFlags & kJoinerMask) != 0; } /** * This method sets the Joiner flag. @@ -2532,7 +2532,7 @@ public: * @retval FALSE If the Native Commissioner flag is not set. * */ - bool IsNativeCommissioner(void) { return (mFlags & kNativeMask) != 0; } + bool IsNativeCommissioner(void) const { return (mFlags & kNativeMask) != 0; } /** * This method sets the Native Commissioner flag. diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 386194a56..c98e81cb4 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -279,7 +279,7 @@ public: * @sa SetReceiveIp6FilterEnabled * */ - bool IsReceiveIp6FilterEnabled(void) { return mIsReceiveIp6FilterEnabled; } + bool IsReceiveIp6FilterEnabled(void) const { return mIsReceiveIp6FilterEnabled; } /** * This method sets whether or not Thread control traffic is filtered out when delivering IPv6 datagrams @@ -299,7 +299,7 @@ public: * @returns TRUE if IPv6 forwarding is enabled, FALSE otherwise. * */ - bool IsForwardingEnabled(void) { return mForwardingEnabled; } + bool IsForwardingEnabled(void) const { return mForwardingEnabled; } /** * This method enables/disables IPv6 forwarding. diff --git a/src/core/net/ip6_headers.hpp b/src/core/net/ip6_headers.hpp index 427901584..058dacd36 100644 --- a/src/core/net/ip6_headers.hpp +++ b/src/core/net/ip6_headers.hpp @@ -576,7 +576,7 @@ public: * @returns The Fragment Offset value. * */ - uint16_t GetOffset(void) { return (HostSwap16(mOffsetMore) & kOffsetMask) >> kOffsetOffset; } + uint16_t GetOffset(void) const { return (HostSwap16(mOffsetMore) & kOffsetMask) >> kOffsetOffset; } /** * This method sets the Fragment Offset value. @@ -596,7 +596,7 @@ public: * @returns The M flag value. * */ - bool IsMoreFlagSet(void) { return HostSwap16(mOffsetMore) & kMoreFlag; } + bool IsMoreFlagSet(void) const { return HostSwap16(mOffsetMore) & kMoreFlag; } /** * This method clears the M flag value. diff --git a/src/core/net/ip6_mpl.hpp b/src/core/net/ip6_mpl.hpp index de5783a22..2764df8e1 100644 --- a/src/core/net/ip6_mpl.hpp +++ b/src/core/net/ip6_mpl.hpp @@ -125,7 +125,7 @@ public: * @retval FALSE If the MPL M flag is not set. * */ - bool IsMaxFlagSet(void) { return (mControl & kMaxFlag) != 0; } + bool IsMaxFlagSet(void) const { return (mControl & kMaxFlag) != 0; } /** * This method clears the MPL M flag. diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index e6abd7387..93120da9a 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -302,23 +302,22 @@ exit: return error; } -otError Netif::GetNextExternalMulticast(uint8_t &aIterator, Address &aAddress) +otError Netif::GetNextExternalMulticast(uint8_t &aIterator, Address &aAddress) const { - otError error = OT_ERROR_NOT_FOUND; - size_t num = OT_ARRAY_LENGTH(mExtMulticastAddresses); - NetifMulticastAddress *entry; + otError error = OT_ERROR_NOT_FOUND; + size_t num = OT_ARRAY_LENGTH(mExtMulticastAddresses); VerifyOrExit(aIterator < num); // Find an available entry in the `mExtMulticastAddresses` array. for (uint8_t i = aIterator; i < num; i++) { - entry = &mExtMulticastAddresses[i]; + const NetifMulticastAddress &entry = mExtMulticastAddresses[i]; // In an unused/available entry, `mNext` points back to the entry itself. - if (entry->mNext != entry) + if (entry.mNext != &entry) { - aAddress = entry->GetAddress(); + aAddress = entry.GetAddress(); aIterator = i + 1; ExitNow(error = OT_ERROR_NONE); } diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index a7e436e83..a0cedf6e4 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -360,7 +360,7 @@ public: * @retval OT_ERROR_NOT_FOUND No subsequent external multicast address. * */ - otError GetNextExternalMulticast(uint8_t &aIterator, Address &aAddress); + otError GetNextExternalMulticast(uint8_t &aIterator, Address &aAddress) const; /** * This method subscribes the network interface to the external (to OpenThread) multicast address. @@ -400,7 +400,7 @@ public: * @retval TRUE If the multicast promiscuous mode is enabled. * @retval FALSE If the multicast promiscuous mode is disabled. */ - bool IsMulticastPromiscuousEnabled(void) { return mMulticastPromiscuous; } + bool IsMulticastPromiscuousEnabled(void) const { return mMulticastPromiscuous; } /** * This method enables multicast promiscuous mode on the network interface. diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 9eac97e4e..5be1c0fab 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -385,7 +385,7 @@ exit: return error; } -bool MeshForwarder::GetRxOnWhenIdle(void) +bool MeshForwarder::GetRxOnWhenIdle(void) const { return Get().GetRxOnWhenIdle(); } diff --git a/src/core/thread/mesh_forwarder.hpp b/src/core/thread/mesh_forwarder.hpp index aa4209643..0fb88da52 100644 --- a/src/core/thread/mesh_forwarder.hpp +++ b/src/core/thread/mesh_forwarder.hpp @@ -219,7 +219,7 @@ public: * @retval FALSE The rx-on-when-idle-mode is disabled. * */ - bool GetRxOnWhenIdle(void); + bool GetRxOnWhenIdle(void) const; /** * This method sets the rx-on-when-idle mode diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index 33c658338..2770ed6ee 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -282,7 +282,7 @@ public: * @returns The current router selection jitter timeout value. * */ - uint8_t GetRouterSelectionJitterTimeout(void) { return mRouterSelectionJitterTimeout; } + uint8_t GetRouterSelectionJitterTimeout(void) const { return mRouterSelectionJitterTimeout; } /** * This method returns the ROUTER_UPGRADE_THRESHOLD value. diff --git a/src/core/thread/mle_router_mtd.hpp b/src/core/thread/mle_router_mtd.hpp index 2523eec98..0b6bb8db8 100644 --- a/src/core/thread/mle_router_mtd.hpp +++ b/src/core/thread/mle_router_mtd.hpp @@ -62,12 +62,12 @@ public: bool IsRouterRoleEnabled(void) const { return false; } - bool IsSingleton(void) { return false; } + bool IsSingleton(void) const { return false; } otError BecomeRouter(ThreadStatusTlv::Status) { return OT_ERROR_NOT_CAPABLE; } otError BecomeLeader(void) { return OT_ERROR_NOT_CAPABLE; } - uint8_t GetRouterSelectionJitterTimeout(void) { return 0; } + uint8_t GetRouterSelectionJitterTimeout(void) const { return 0; } uint32_t GetPreviousPartitionId(void) const { return 0; } void SetPreviousPartitionId(uint32_t) {} @@ -84,7 +84,7 @@ public: otError RemoveNeighbor(const Mac::Address &) { return BecomeDetached(); } otError RemoveNeighbor(Neighbor &) { return BecomeDetached(); } - bool IsMinimalChild(uint16_t) { return false; } + bool IsMinimalChild(uint16_t) const { return false; } void RestoreChildren(void) {} otError RemoveStoredChild(uint16_t) { return OT_ERROR_NOT_IMPLEMENTED; } diff --git a/src/core/thread/mle_tlvs.hpp b/src/core/thread/mle_tlvs.hpp index 8861c47bd..4e6ddb157 100644 --- a/src/core/thread/mle_tlvs.hpp +++ b/src/core/thread/mle_tlvs.hpp @@ -1152,7 +1152,7 @@ public: * @retval OT_ERROR_NOT_FOUND No subsequent Tlv exists in TlvRequestTlv. * */ - otError GetNextTlv(TlvRequestIterator &aIterator, uint8_t &aTlv) + otError GetNextTlv(TlvRequestIterator &aIterator, uint8_t &aTlv) const { otError error = OT_ERROR_NOT_FOUND; @@ -1233,7 +1233,7 @@ public: * @retval TRUE If the Router flag is set. * @retval FALSE If the Router flag is not set. */ - bool IsRouterFlagSet(void) { return (mMask & kRouterFlag) != 0; } + bool IsRouterFlagSet(void) const { return (mMask & kRouterFlag) != 0; } /** * This method clears the End Device flag. @@ -1253,7 +1253,7 @@ public: * @retval TRUE If the End Device flag is set. * @retval FALSE If the End Device flag is not set. */ - bool IsEndDeviceFlagSet(void) { return (mMask & kEndDeviceFlag) != 0; } + bool IsEndDeviceFlagSet(void) const { return (mMask & kEndDeviceFlag) != 0; } /** * This method sets the Mask byte value. diff --git a/src/core/utils/channel_manager.hpp b/src/core/utils/channel_manager.hpp index 972115932..42325115f 100644 --- a/src/core/utils/channel_manager.hpp +++ b/src/core/utils/channel_manager.hpp @@ -196,7 +196,7 @@ public: * @returns The interval (in seconds). * */ - uint32_t GetAutoChannelSelectionInterval(void) { return mAutoSelectInterval; } + uint32_t GetAutoChannelSelectionInterval(void) const { return mAutoSelectInterval; } /** * This method gets the supported channel mask. diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 4f332c205..fd122d5b2 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -225,7 +225,7 @@ protected: uint16_t aValueLen); otError SendQueuedResponses(void); - bool IsResponseQueueEmpty(void) { return (mResponseQueueHead == mResponseQueueTail); } + bool IsResponseQueueEmpty(void) const { return (mResponseQueueHead == mResponseQueueTail); } otError EnqueueResponse(uint8_t aHeader, ResponseType aType, unsigned int aPropKeyOrStatus); otError PrepareGetResponse(uint8_t aHeader, spinel_prop_key_t aPropKey)