Skip to content

Commit

Permalink
tidy: Convert exit code macros to enums.
Browse files Browse the repository at this point in the history
This requires tweaking the test code to explicitly convert the enum
values to "int" since the Qt metatype code doesn't recognize the enum.
This could be solved by using an "enum class" instead of a plain enum,
but that would cause churn as every reference would need to be
updated (à la RecStatus::Type).  A project for another day.
  • Loading branch information
linuxdude42 committed Jul 10, 2022
1 parent bf07314 commit a1f1fb4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
14 changes: 8 additions & 6 deletions mythplugins/mythzoneminder/mythzmserver/mythzmserver.cpp
Expand Up @@ -43,12 +43,14 @@ static constexpr const char* ZM_OVERRIDECONFIG { "/etc/zm/conf.d/01-system-paths
// Care should be taken to keep these in sync with the exit codes in
// libmythbase/exitcodes.h (which is not included here to keep this code
// separate from mythtv libraries).
#define EXIT_OK 0
#define EXIT_INVALID_CMDLINE 132
#define EXIT_OPENING_LOGFILE_ERROR 136 // mapped to _PERMISSIONS_ERROR
#define EXIT_DAEMONIZING_ERROR 145
#define EXIT_SOCKET_ERROR 135
#define EXIT_VERSION_ERROR 136
enum EXIT_CODES {
EXIT_OK = 0,
EXIT_INVALID_CMDLINE = 132,
EXIT_OPENING_LOGFILE_ERROR = 136, // mapped to _PERMISSIONS_ERROR
EXIT_DAEMONIZING_ERROR = 145,
EXIT_SOCKET_ERROR = 135,
EXIT_VERSION_ERROR = 136,
};

int main(int argc, char **argv)
{
Expand Down
56 changes: 29 additions & 27 deletions mythtv/libs/libmythbase/exitcodes.h
Expand Up @@ -7,32 +7,34 @@
// Additionally, the functionality of mythwelcome/welcomedialog.cpp depends on
// being able to use exit code as an 8-bit masked integer.

#define GENERIC_EXIT_OK 0 ///< Exited with no error
#define GENERIC_EXIT_NOT_OK 128 ///< Exited with error
#define GENERIC_EXIT_CMD_NOT_FOUND 129 ///< Command not found
#define GENERIC_EXIT_NO_MYTHCONTEXT 130 ///< No MythContext available
#define GENERIC_EXIT_NO_THEME 131 ///< No Theme available
#define GENERIC_EXIT_INVALID_CMDLINE 132 ///< Command line parse error
#define GENERIC_EXIT_DB_OUTOFDATE 133 ///< Database needs upgrade
#define GENERIC_EXIT_DB_ERROR 134 ///< Database error
#define GENERIC_EXIT_SOCKET_ERROR 135 ///< Socket error
#define GENERIC_EXIT_PERMISSIONS_ERROR 136 ///< File permissions error
#define GENERIC_EXIT_CONNECT_ERROR 137 ///< Can't connect to master backend
#define GENERIC_EXIT_SETUP_ERROR 138 ///< Incorrectly setup system
#define GENERIC_EXIT_INVALID_TIME 139 ///< Invalid time
#define GENERIC_EXIT_KILLED 140 ///< Process killed or stopped
#define GENERIC_EXIT_TIMEOUT 141 ///< Process timed out
#define GENERIC_EXIT_RUNNING 142 ///< Process is running
#define GENERIC_EXIT_PIPE_FAILURE 143 ///< Error creating I/O pipes
#define GENERIC_EXIT_NO_HANDLER 144 ///< No MythSystemLegacy Handler
#define GENERIC_EXIT_DAEMONIZING_ERROR 145 ///< Error daemonizing or execl
#define GENERIC_EXIT_NO_RECORDING_DATA 146 ///< No program/recording data
#define GENERIC_EXIT_REMOTE_FILE 147 ///< Can't transcode a remote file
#define GENERIC_EXIT_RESTART 148 ///< Need to restart transcoding
#define GENERIC_EXIT_WRITE_FRAME_ERROR 149 ///< Frame write error
#define GENERIC_EXIT_DEADLOCK 150 ///< Transcode deadlock detected
#define GENERIC_EXIT_IN_USE 151 ///< Recording in use, can't flag
#define GENERIC_EXIT_START 152 ///< MythSystemLegacy process starting
#define GENERIC_EXIT_DB_NOTIMEZONE 153 ///< Missing DB time zone support
enum EXIT_CODES {
GENERIC_EXIT_OK = 0, ///< Exited with no error
GENERIC_EXIT_NOT_OK = 128, ///< Exited with error
GENERIC_EXIT_CMD_NOT_FOUND = 129, ///< Command not found
GENERIC_EXIT_NO_MYTHCONTEXT = 130, ///< No MythContext available
GENERIC_EXIT_NO_THEME = 131, ///< No Theme available
GENERIC_EXIT_INVALID_CMDLINE = 132, ///< Command line parse error
GENERIC_EXIT_DB_OUTOFDATE = 133, ///< Database needs upgrade
GENERIC_EXIT_DB_ERROR = 134, ///< Database error
GENERIC_EXIT_SOCKET_ERROR = 135, ///< Socket error
GENERIC_EXIT_PERMISSIONS_ERROR = 136, ///< File permissions error
GENERIC_EXIT_CONNECT_ERROR = 137, ///< Can't connect to master backend
GENERIC_EXIT_SETUP_ERROR = 138, ///< Incorrectly setup system
GENERIC_EXIT_INVALID_TIME = 139, ///< Invalid time
GENERIC_EXIT_KILLED = 140, ///< Process killed or stopped
GENERIC_EXIT_TIMEOUT = 141, ///< Process timed out
GENERIC_EXIT_RUNNING = 142, ///< Process is running
GENERIC_EXIT_PIPE_FAILURE = 143, ///< Error creating I/O pipes
GENERIC_EXIT_NO_HANDLER = 144, ///< No MythSystemLegacy Handler
GENERIC_EXIT_DAEMONIZING_ERROR = 145, ///< Error daemonizing or execl
GENERIC_EXIT_NO_RECORDING_DATA = 146, ///< No program/recording data
GENERIC_EXIT_REMOTE_FILE = 147, ///< Can't transcode a remote file
GENERIC_EXIT_RESTART = 148, ///< Need to restart transcoding
GENERIC_EXIT_WRITE_FRAME_ERROR = 149, ///< Frame write error
GENERIC_EXIT_DEADLOCK = 150, ///< Transcode deadlock detected
GENERIC_EXIT_IN_USE = 151, ///< Recording in use, can't flag
GENERIC_EXIT_START = 152, ///< MythSystemLegacy process starting
GENERIC_EXIT_DB_NOTIMEZONE = 153, ///< Missing DB time zone support
};

#endif // MYTH_EXIT_CODES_H
22 changes: 11 additions & 11 deletions mythtv/libs/libmythbase/test/test_logging/test_logging.cpp
Expand Up @@ -103,12 +103,12 @@ void TestLogging::test_verboseArgParse_kwd_data (void)
QTest::addColumn<int>("expectedExit");
QTest::addColumn<QString>("expectedOutput");

QTest::newRow("empty") << "" << GENERIC_EXIT_OK << "";
QTest::newRow("nextarg") << "-x" << GENERIC_EXIT_INVALID_CMDLINE << "Invalid or missing";
QTest::newRow("help") << "help" << GENERIC_EXIT_INVALID_CMDLINE << "Verbose debug levels";
QTest::newRow("important") << "important" << GENERIC_EXIT_OK << R"("important" log mask)";
QTest::newRow("extra") << "extra" << GENERIC_EXIT_OK << R"("extra" log mask)";
QTest::newRow("random") << "random" << GENERIC_EXIT_INVALID_CMDLINE << "Unknown argument";
QTest::newRow("empty") << "" << (int)GENERIC_EXIT_OK << "";
QTest::newRow("nextarg") << "-x" << (int)GENERIC_EXIT_INVALID_CMDLINE << "Invalid or missing";
QTest::newRow("help") << "help" << (int)GENERIC_EXIT_INVALID_CMDLINE << "Verbose debug levels";
QTest::newRow("important") << "important" << (int)GENERIC_EXIT_OK << R"("important" log mask)";
QTest::newRow("extra") << "extra" << (int)GENERIC_EXIT_OK << R"("extra" log mask)";
QTest::newRow("random") << "random" << (int)GENERIC_EXIT_INVALID_CMDLINE << "Unknown argument";
}

void TestLogging::test_verboseArgParse_kwd (void)
Expand Down Expand Up @@ -145,8 +145,8 @@ void TestLogging::test_verboseArgParse_twice (void)
std::cerr.rdbuf(oldCoutBuffer);

// Check results
QCOMPARE(GENERIC_EXIT_OK, actualExit1);
QCOMPARE(GENERIC_EXIT_INVALID_CMDLINE, actualExit2);
QCOMPARE((int)GENERIC_EXIT_OK, actualExit1);
QCOMPARE((int)GENERIC_EXIT_INVALID_CMDLINE, actualExit2);
QString actualOutput = QString::fromStdString(buffer.str());
QVERIFY(actualOutput.contains("-v general,system,socket"));
}
Expand Down Expand Up @@ -191,7 +191,7 @@ void TestLogging::test_verboseArgParse_class (void)
std::cerr.rdbuf(oldCoutBuffer);

// Check results
QCOMPARE(GENERIC_EXIT_OK, actualExit);
QCOMPARE((int)GENERIC_EXIT_OK, actualExit);
QString actualOutput = QString::fromStdString(buffer.str());
QVERIFY(actualOutput.isEmpty());
QCOMPARE(verboseMask, expectedVMask);
Expand Down Expand Up @@ -254,7 +254,7 @@ void TestLogging::test_verboseArgParse_level (void)
std::cerr.rdbuf(oldCoutBuffer);

// Check results
QCOMPARE(GENERIC_EXIT_OK, actualExit);
QCOMPARE((int)GENERIC_EXIT_OK, actualExit);
QString actualOutput = QString::fromStdString(buffer.str());
QVERIFY(actualOutput.isEmpty());
QCOMPARE(verboseMask, expectedVMask);
Expand Down Expand Up @@ -336,7 +336,7 @@ void TestLogging::test_logPropagateCalc (void)
std::cerr.rdbuf(oldCoutBuffer);

// Check results
QCOMPARE(GENERIC_EXIT_OK, actualExit);
QCOMPARE((int)GENERIC_EXIT_OK, actualExit);
QString actualOutput = QString::fromStdString(buffer.str());
QVERIFY(actualOutput.isEmpty());

Expand Down

0 comments on commit a1f1fb4

Please sign in to comment.