Cleanup error code usage. Avoid raising errors when value is unchanged. (#787)

This change is attempting to address two issues:

1.  Returning `kThreadError_Busy`, when `kThreadError_Already`,
    `kThreadError_InvalidState`, or even the lazy
    `kThreadError_Failed` would be more-appropriate/less-misleading.
2.  Setters returning an error when the value to be changed is already
    set to the requested value.

Number one hurts debuggability. Number two makes the code more fragile.
The cases where both intersect can be maddening.

This change replaces cases inappropriately returning
`kThreadError_Busy` with a better, more specific error code. It also
makes some "setter" functions (Including `otInterfaceUp()` and
`otThreadStart()`) return success if the value is already set.
This commit is contained in:
Robert Quattlebaum
2016-10-12 14:18:55 -07:00
committed by Jonathan Hui
parent 2d5c4c58f2
commit 104ca6d10d
29 changed files with 163 additions and 170 deletions
+8 -7
View File
@@ -203,8 +203,8 @@ void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aShortAddress);
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::kThreadError_None Successfully transitioned to Sleep.
* @retval ::kThreadError_Busy The radio was already enabled.
* @retval ::kThreadError_None Successfully enabled.
* @retval ::kThreadError_Failure The radio could not be enabled.
*/
ThreadError otPlatRadioEnable(otInstance *aInstance);
@@ -233,8 +233,9 @@ bool otPlatRadioIsEnabled(otInstance *aInstance);
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::kThreadError_None Successfully transitioned to Sleep.
* @retval ::kThreadError_Busy The radio was not in the Receive state.
* @retval ::kThreadError_None Successfully transitioned to Sleep.
* @retval ::kThreadError_Busy The radio was transmitting
* @retval ::kThreadError_InvalidState The radio was disabled
*/
ThreadError otPlatRadioSleep(otInstance *aInstance);
@@ -245,8 +246,8 @@ ThreadError otPlatRadioSleep(otInstance *aInstance);
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aChannel The channel to use for receiving.
*
* @retval ::kThreadError_None Successfully transitioned to Receive.
* @retval ::kThreadError_Busy The radio was not in the Sleep state.
* @retval ::kThreadError_None Successfully transitioned to Receive.
* @retval ::kThreadError_InvalidState The radio was disabled or transmitting.
*/
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel);
@@ -355,7 +356,7 @@ RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance);
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::kThreadError_None Successfully transitioned to Transmit.
* @retval ::kThreadError_Busy The radio was not in the Receive state.
* @retval ::kThreadError_InvalidState The radio was not in the Receive state.
*/
ThreadError otPlatRadioTransmit(otInstance *aInstance);