/*! * * Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file DeviceError.cpp * \author (last) Behrouz NematiPour * \date (last) 22-Oct-2023 * \author (original) Behrouz NematiPour * \date (original) 06-Jun-2021 * */ #include "DeviceError.h" // Linux // Qt #include #include // Project #include "DeviceGlobals.h" // namespace using namespace Device; const char *DeviceError::Scripts_Error_Text[] = { QT_TR_NOOP("The device script abnormal exit." ), // eDevice_Scripts_Error_Status QT_TR_NOOP("The device script file is not found." ), // eDevice_Scripts_Error_NotFound QT_TR_NOOP("The device script file is not executable." ), // eDevice_Scripts_Error_NotExecutable QT_TR_NOOP("The request is already in progress." ), // eDevice_Scripts_Error_IsRunning QT_TR_NOOP("The requested value length is incorrect." ), // eDevice_Scripts_Error_Incorrect_Rsp_Len QT_TR_NOOP("The requested value type is incorrect." ), // eDevice_Scripts_Error_Incorrect_Rsp_Type QT_TR_NOOP("The requested value range is incorrect." ), // eDevice_Scripts_Error_Incorrect_Rsp_Range QT_TR_NOOP("The response value length is incorrect." ), // eDevice_Scripts_Error_Incorrect_Rsp_Len QT_TR_NOOP("The response value type is incorrect." ), // eDevice_Scripts_Error_Incorrect_Rsp_Type QT_TR_NOOP("The response value range is incorrect." ), // eDevice_Scripts_Error_Incorrect_Rsp_Range QT_TR_NOOP("The watch file cannot be created." ), // eDevice_Watch_Error_NotCreate QT_TR_NOOP("The watch file is not found." ), // eDevice_Watch_Error_NotFound QT_TR_NOOP("The watch file cannot be added." ), // eDevice_Watch_Error_NotAdded QT_TR_NOOP("The Bluetooth cuff pair clear error." ), // eDevice_BCuff_Error_Reset QT_TR_NOOP("The Bluetooth cuff pair query error." ), // eDevice_BCuff_Error_Query QT_TR_NOOP("No paired Bluetooth cuff found." ), // eDevice_BCuff_Error_Query_Empty QT_TR_NOOP("The Bluetooth cuff pair invalid address." ), // eDevice_BCuff_Error_Query_Addr QT_TR_NOOP("The Encrypted Partition error." ), // eDevice_CryptSetup_Error QT_TR_NOOP("The Factory Reset failed." ), // eDevice_FactoryReset_Error QT_TR_NOOP("The Decommissioning failed." ), // eDevice_Decommission_Error QT_TR_NOOP("The Brightness failed." ), // eDevice_Brightness_Error QT_TR_NOOP("The WiFi scan failed." ), // eDevice_WifiList_Error QT_TR_NOOP("The WiFi info failed." ), // eDevice_WifiInfo_Error QT_TR_NOOP("The Connect WiFi failed." ), // eDevice_ConnectWifi_Error QT_TR_NOOP("The USB Mount failed." ), // eDevice_USBMount_Error }; /*! * \brief DeviceController::checkScript * \details Prepends the script folder path to the script name and checks if the script exists and is executable. * \param vScript : The script name with full path which will be set in this parameter passed argument. * \param vShellScript : The shell script name * \return true if succeeds and false otherwise */ DeviceError::Scripts_Error_Enum DeviceError::checkScript(QString &vScript, const QString &vShellScript) { DeviceError::Scripts_Error_Enum err = DeviceError::eDevice_OK; vScript = Storage::Scripts_Path_Name() + vShellScript; QFileInfo info(vScript); if ( ! info.exists () ) { err = DeviceError::eDevice_Scripts_Error_NotFound ; goto lOut; } if ( ! info.isExecutable() ) { err = DeviceError::eDevice_Scripts_Error_NotExecutable ; goto lOut; } lOut: return err; } QString DeviceError::deviceErrorText(DeviceError::Scripts_Error_Enum vError, int vExitCode) { QString message; int idx = vError - eDevice_Scripts_Error_Start - 1; const int l = (sizeof Scripts_Error_Text / sizeof Scripts_Error_Text[0]); const int i = eDevice_Error_End - eDevice_Scripts_Error_Start - 1; // DEBUG: qDebug() << l << i << idx; // if this error happens it means not all the Error IDs in the Scripts_Error_Enum are covered in the Scripts_Error_Text static_assert(l == i, "Device Error Scripts Error Text is incomplete."); if (idx >= l) { message = QObject::tr("Unknown device error %2 [%1]").arg(vExitCode).arg(vError) ; goto lOut; } if (eDevice_Scripts_Error_Start < vError && vError < eDevice_Error_End) { message = QObject::tr(Scripts_Error_Text[idx]) + (vExitCode ? QString(" [%1]").arg(vExitCode) : "") ; goto lOut; } message = QObject::tr("Device error [%1]").arg(vExitCode); lOut: return message; }