//------------------------------------------------------------------------------------------------- static const char* GetUpdateType ( void ) //-------------------------------------------------------------------------------------------------- { le_avc_UpdateType_t type; le_result_t res = le_avc_GetUpdateType(&type); if (res != LE_OK) { LE_CRIT("Unable to get update type (%s)", LE_RESULT_TXT(res)); return "UNKNOWN"; } else { switch (type) { case LE_AVC_FIRMWARE_UPDATE: return "FIRMWARE"; case LE_AVC_APPLICATION_UPDATE: return "APPLICATION"; case LE_AVC_FRAMEWORK_UPDATE: return "FRAMEWORK"; case LE_AVC_UNKNOWN_UPDATE: return "UNKNOWN"; } LE_CRIT("Unexpected update type %d", type); return "UNKNOWN"; } }
//-------------------------------------------------------------------------------------------------- static void SimpleDownloadAndDeferInstall ( le_avc_Status_t updateStatus ) { // Use a count instead of a bool flag, so we could defer multiple times, if we want static int count=0; le_avc_UpdateType_t updateType; switch ( updateStatus ) { case LE_AVC_NO_UPDATE: LE_WARN("No action"); break; case LE_AVC_DOWNLOAD_PENDING: if ( le_avc_GetUpdateType(&updateType) == LE_OK ) { LE_INFO("Update type is %i", updateType); } else { LE_INFO("Update type is not available"); } LE_WARN("Accept download"); LE_ASSERT( le_avc_AcceptDownload() == LE_OK ); break; case LE_AVC_INSTALL_PENDING: if ( count < 1 ) { LE_WARN("Defer install"); LE_ASSERT( le_avc_DeferInstall(1) == LE_OK ); count++; } else { LE_WARN("Accept install"); LE_ASSERT( le_avc_AcceptInstall() == LE_OK ); } break; case LE_AVC_UNINSTALL_PENDING: LE_WARN("Accept uninstall"); LE_ASSERT( le_avc_AcceptUninstall() == LE_OK ); break; default: LE_WARN("Update status %i not handled", updateStatus); } }
//-------------------------------------------------------------------------------------------------- static void SimpleDownloadAndInstall ( le_avc_Status_t updateStatus ) { le_avc_UpdateType_t updateType; switch ( updateStatus ) { case LE_AVC_NO_UPDATE: LE_WARN("No action"); break; case LE_AVC_DOWNLOAD_PENDING: if ( le_avc_GetUpdateType(&updateType) == LE_OK ) { LE_INFO("Update type is %i", updateType); } else { LE_INFO("Update type is not available"); } LE_WARN("Accept download"); LE_ASSERT( le_avc_AcceptDownload() == LE_OK ); break; case LE_AVC_INSTALL_PENDING: LE_WARN("Accept install"); LE_ASSERT( le_avc_AcceptInstall() == LE_OK ); break; case LE_AVC_UNINSTALL_PENDING: LE_WARN("Accept uninstall"); LE_ASSERT( le_avc_AcceptUninstall() == LE_OK ); break; default: LE_WARN("Update status %i not handled", updateStatus); } }
//-------------------------------------------------------------------------------------------------- static void DownloadAndInstall ( le_avc_Status_t updateStatus, int32_t totalNumBytes, int32_t progress ) { le_avc_UpdateType_t updateType; switch ( updateStatus ) { case LE_AVC_NO_UPDATE: // In the wrong state, so this should be an error LE_ASSERT( le_avc_AcceptDownload() == LE_FAULT ); // In the wrong state, so this should be an error LE_ASSERT( le_avc_GetUpdateType(&updateType) == LE_FAULT ); break; case LE_AVC_DOWNLOAD_PENDING: LE_INFO("Total number of bytes to download = %d", totalNumBytes); LE_INFO("Download progress = %d%%", progress); // In the wrong state, so this should be an error LE_ASSERT( le_avc_AcceptInstall() == LE_FAULT ); LE_WARN("Accept download"); LE_ASSERT( le_avc_AcceptDownload() == LE_OK ); // Verify update type LE_ASSERT( le_avc_GetUpdateType(&updateType) == LE_OK ); //LE_ASSERT( updateType == LE_AVC_FIRMWARE_UPDATE ); // In the wrong state, so this should be an error LE_ASSERT( le_avc_DeferDownload(3) == LE_FAULT ); break; case LE_AVC_DOWNLOAD_IN_PROGRESS: LE_INFO("Download in Progress"); LE_INFO("Total number of bytes to download = %d", totalNumBytes); LE_INFO("Download progress = %d%%", progress); break; case LE_AVC_DOWNLOAD_COMPLETE: LE_INFO("Download completed"); LE_INFO("Total number of bytes to download = %d", totalNumBytes); LE_INFO("Download progress = %d%%", progress); break; case LE_AVC_INSTALL_PENDING: // In the wrong state, so this should be an error LE_ASSERT( le_avc_AcceptDownload() == LE_FAULT ); LE_WARN("Accept install"); LE_ASSERT( le_avc_AcceptInstall() == LE_OK ); // In the wrong state, so this should be an error LE_ASSERT( le_avc_DeferInstall(3) == LE_FAULT ); break; default: LE_WARN("Update status %i not handled", updateStatus); } }