-
Notifications
You must be signed in to change notification settings - Fork 7
Application Termination
Dave Glover edited this page Sep 28, 2021
·
2 revisions
The following exit code enums are defined in the dx_exit_codes.h file.
/// <summary>
/// Exit codes for the DevX library. These are used for the
/// library exit codes. They must all be between 150 and 255,
/// where zero is reserved for successful termination. Exit
/// codes 1 - 149 are reserved for application level exit codes.
/// </summary>
typedef enum {
DX_ExitCode_Success = 0,
DX_ExitCode_TermHandler_SigTerm = 254,
DX_ExitCode_Main_EventLoopFail = 253,
DX_ExitCode_Missing_ID_Scope = 252,
DX_ExitCode_Open_Peripheral = 251,
DX_ExitCode_OpenDeviceTwin = 250,
DX_ExitCode_AzureCloudToDeviceHandler = 249,
DX_ExitCode_InterCoreHandler = 248,
DX_ExitCode_ConsumeEventLoopTimeEvent = 247,
DX_ExitCode_Gpio_Read = 246,
DX_ExitCode_InterCoreReceiveFailed = 245,
DX_ExitCode_PnPModelJsonMemoryAllocationFailed = 244,
DX_ExitCode_PnPModelJsonFailed = 243,
DX_ExitCode_IsButtonPressed = 242,
DX_ExitCode_ButtonPressCheckHandler = 241,
DX_ExitCode_Led2OffHandler = 240,
DX_ExitCode_MissingRealTimeComponentId = 239,
DX_ExitCode_Validate_Hostname_Not_Defined = 238,
DX_ExitCode_Validate_ScopeId_Not_Defined = 237,
DX_ExitCode_Validate_Connection_Type_Not_Defined = 236,
DX_ExitCode_Gpio_Not_Initialized = 235,
DX_ExitCode_Gpio_Wrong_Direction = 234,
DX_ExitCode_Gpio_Open_Output_Failed = 233,
DX_ExitCode_Gpio_Open_Input_Failed = 232,
DX_ExitCode_Gpio_Open_Direction_Unknown = 231,
DX_ExitCode_UpdateCallback_UnexpectedEvent = 230,
DX_ExitCode_UpdateCallback_GetUpdateEvent = 229,
DX_ExitCode_UpdateCallback_DeferEvent = 228,
DX_ExitCode_UpdateCallback_FinalUpdate = 227,
DX_ExitCode_UpdateCallback_UnexpectedStatus = 226,
DX_ExitCode_SetUpSysEvent_RegisterEvent = 225,
DX_ExitCode_Init_IoTCTimer = 220,
DX_ExitCode_IoTCTimer_Consume = 219,
DX_ExitCode_Uart_Open_Failed = 215,
DX_ExitCode_Uart_Read_Failed = 214,
DX_ExitCode_Uart_Write_Failed = 213,
DX_ExitCode_UartHandler = 212
} ExitCode;
void dx_registerTerminationHandler(void);
void dx_terminationHandler(int signalNumber);
void dx_terminate(int exitCode);
bool dx_isTerminationRequired(void);
int dx_getTerminationExitCode(void);
static void LedOffToggleHandler(EventLoopTimer* eventLoopTimer) {
if (ConsumeEventLoopTimerEvent(eventLoopTimer) != 0) {
dx_terminate(DX_ExitCode_ConsumeEventLoopTimeEvent);
return;
}
dx_gpioOff(&led);
}
int main(void)
{
dx_registerTerminationHandler();
InitPeripheralsAndHandlers();
// Main loop
while (!dx_isTerminationRequired())
{
int result = EventLoop_Run(dx_timerGetEventLoop(), -1, true);
// Continue if interrupted by signal, e.g. due to breakpoint being set.
if (result == -1 && errno != EINTR)
{
dx_terminate(DX_ExitCode_Main_EventLoopFail);
}
}
ClosePeripheralsAndHandlers();
Log_Debug("Application exiting.\n");
return dx_getTerminationExitCode();
}
By convention, create application specific exit codes in a file named app_exit_codes.h in your project.
See avnet_send_message example.
/* Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. */
#pragma once
// Include the DevX exit codes
#include "dx_exit_codes.h"
/// <summary>
/// Exit codes for this application. Application exit codes
/// must be between 1 and 149, where 0 is reserved for successful
// termination. Exit codes 150 - 254 are reserved for the
// Exit_Code enumeration located in dx_exit_codes.h.
/// </summary>
typedef enum {
APP_ExitCode_Telemetry_Buffer_Too_Small = 1
} App_Exit_Code;
AzureSphereDevX Examples Wiki
- Home
- Build Tools
- Adding the DevX library
- Azure IoT Hub Messaging
- Azure IoT Hub Device Twins
- Azure IoT Hub Direct Methods
- Avnet IoT Connect messaging
- Handling multithreaded async events
- Working with GPIO
- Working with UARTS
- Working with PWM
- Working with Event Timers
- Intercore Messaging
- Application termination
- Deferring updates
- Utility functions
- Tools and scripts
- Hardware Definitions