[posix-app] move die functions to misc.c (#3264)

This commit is contained in:
Yakun Xu
2018-11-03 14:48:13 -07:00
committed by Jonathan Hui
parent 9ba3fc1d9b
commit 85c21ae1df
3 changed files with 60 additions and 23 deletions
+31
View File
@@ -35,6 +35,7 @@
#include <openthread/platform/misc.h>
#include "openthread-system.h"
#include "common/logging.hpp"
extern jmp_buf gResetJump;
@@ -89,3 +90,33 @@ otPlatMcuPowerState otPlatGetMcuPowerState(otInstance *aInstance)
(void)aInstance;
return gPlatMcuPowerState;
}
void SuccessOrDie(otError aError)
{
int exitCode;
switch (aError)
{
case OT_ERROR_NONE:
return;
case OT_ERROR_INVALID_ARGS:
exitCode = OT_EXIT_INVALID_ARGUMENTS;
break;
default:
exitCode = OT_EXIT_FAILURE;
break;
}
otLogCritPlat("Error: %s", otThreadErrorToString(aError));
exit(exitCode);
}
void VerifyOrDie(bool aCondition, int aExitCode)
{
if (!aCondition)
{
exit(aExitCode);
}
}
+24 -1
View File
@@ -91,7 +91,12 @@ enum
/**
* Incompatible radio spinel.
*/
OT_EXIT_INCOMPATIBLE_RADIO_SPINEL = 3,
OT_EXIT_RADIO_SPINEL_INCOMPATIBLE = 3,
/**
* Unexpected radio spinel reset.
*/
OT_EXIT_RADIO_SPINEL_RESET = 4,
};
/**
@@ -353,6 +358,24 @@ void platformUdpProcess(otInstance *aInstance, const fd_set *aReadSet);
*/
void platformUdpUpdateFdSet(otInstance *aInstance, fd_set *aReadFdSet, int *aMaxFd);
/**
* This function ends the current process with exit code @p aExitCode if @p aCondition is false.
*
* @param[in] aCondition The condition to verify
* @param[in] aExitCode The exit code if exits.
*
*/
void VerifyOrDie(bool aCondition, int aExitCode);
/**
* This function ends the current process if @p aError is not OT_ERROR_NONE.
* The error code will be mapped from @p aError.
*
* @param[in] aError The OpenThread error code.
*
*/
void SuccessOrDie(otError aError);
#ifdef __cplusplus
}
#endif
+5 -22
View File
@@ -142,23 +142,6 @@ static inline bool isAckRequested(const uint8_t *frame)
return (frame[0] & IEEE802154_ACK_REQUEST) != 0;
}
static inline void SuccessOrDie(otError aError)
{
if (aError != OT_ERROR_NONE)
{
// fprintf(stderr, "Operation failed: %s\r\n", otThreadErrorToString(aError));
exit(OT_EXIT_FAILURE);
}
}
static inline void VerifyOrDie(bool aCondition)
{
if (!aCondition)
{
exit(OT_EXIT_FAILURE);
}
}
namespace ot {
static otError SpinelStatusToOtError(spinel_status_t aError)
@@ -543,7 +526,7 @@ void RadioSpinel::Init(const char *aRadioFile, const char *aRadioConfig)
else
{
otLogCritPlat("Radio file '%s' not supported", aRadioFile);
exit(OT_EXIT_INVALID_ARGUMENTS);
ExitNow(error = OT_ERROR_INVALID_ARGS);
}
SuccessOrExit(error = SendReset());
@@ -581,7 +564,7 @@ otError RadioSpinel::CheckSpinelVersion(void)
{
otLogCritPlat("Spinel version mismatch - PosixApp:%d.%d, RCP:%d.%d", SPINEL_PROTOCOL_VERSION_THREAD_MAJOR,
SPINEL_PROTOCOL_VERSION_THREAD_MINOR, versionMajor, versionMinor);
exit(OT_EXIT_INCOMPATIBLE_RADIO_SPINEL);
exit(OT_EXIT_RADIO_SPINEL_INCOMPATIBLE);
}
exit:
@@ -623,7 +606,7 @@ otError RadioSpinel::CheckCapabilities(void)
if (!supportsRawRadio)
{
otLogCritPlat("RCP capability list does not include support for radio/raw mode");
exit(OT_EXIT_INCOMPATIBLE_RADIO_SPINEL);
exit(OT_EXIT_RADIO_SPINEL_INCOMPATIBLE);
}
exit:
@@ -648,7 +631,7 @@ otError RadioSpinel::CheckRadioCapabilities(void)
(mRadioCaps & OT_RADIO_CAPS_TRANSMIT_RETRIES) ? "yes" : "no",
(mRadioCaps & OT_RADIO_CAPS_CSMA_BACKOFF) ? "yes" : "no");
exit(OT_EXIT_INCOMPATIBLE_RADIO_SPINEL);
exit(OT_EXIT_RADIO_SPINEL_INCOMPATIBLE);
}
exit:
@@ -858,7 +841,7 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer,
mIsReady = true;
// If RCP crashes/resets while radio was enabled, posix app exits.
VerifyOrDie(!IsEnabled());
VerifyOrDie(!IsEnabled(), OT_EXIT_RADIO_SPINEL_RESET);
}
else
{