Some small improvements to IPC handling.

This commit is contained in:
LoRd_MuldeR 2014-01-29 16:23:55 +01:00
parent 014a9bee57
commit 9848d78beb
4 changed files with 46 additions and 27 deletions

View File

@ -112,7 +112,7 @@ void IPCReceiveThread::receiveLoop(void)
{
QStringList args;
int command;
if(m_ipc->popCommand(command, args))
if(m_ipc->popCommand(command, args, &m_stopped))
{
if((command >= 0) && (command < IPC::IPC_OPCODE_MAX))
{
@ -255,7 +255,7 @@ bool IPC::pushCommand(const int &command, const QStringList *args)
return success;
}
bool IPC::popCommand(int &command, QStringList &args)
bool IPC::popCommand(int &command, QStringList &args, volatile bool *abortFlag)
{
command = -1;
args.clear();
@ -297,7 +297,10 @@ bool IPC::popCommand(int &command, QStringList &args)
}
else
{
qWarning("IPC: Shared memory is empty -> cannot pop string!");
if(!abortFlag)
{
qWarning("IPC: Shared memory is empty -> cannot pop string!");
}
success = false;
}
}

View File

@ -48,6 +48,7 @@ public:
bool sendAsync(const int &command, const QStringList &args, const int timeout = 5000);
inline bool isInitialized(void) { return (m_initialized >= 0); }
inline bool isListening(void);
public slots:
bool startListening(void);
@ -57,7 +58,7 @@ signals:
void receivedCommand(const int &command, const QStringList &args);
protected:
bool popCommand(int &command, QStringList &args);
bool popCommand(int &command, QStringList &args, volatile bool *abortFlag);
bool pushCommand(const int &command, const QStringList *args);
int m_initialized;
@ -111,3 +112,12 @@ private:
volatile bool m_stopped;
IPC *const m_ipc;
};
///////////////////////////////////////////////////////////////////////////////
// Inline Functions
///////////////////////////////////////////////////////////////////////////////
inline bool IPC::isListening(void)
{
return (m_recvThread && m_recvThread->isRunning());
}

View File

@ -26,10 +26,10 @@
#define VER_X264_MAJOR 2
#define VER_X264_MINOR 3
#define VER_X264_PATCH 0
#define VER_X264_BUILD 733
#define VER_X264_BUILD 734
#define VER_X264_MINIMUM_REV 2363
#define VER_X264_CURRENT_API 140
#define VER_X264_MINIMUM_REV 2380
#define VER_X264_CURRENT_API 142
#define VER_X264_AVS2YUV_VER 242
#define VER_X264_PORTABLE_EDITION (0)

View File

@ -62,10 +62,8 @@ const char *tpl_last = "<LAST_USED>";
#define SET_FONT_BOLD(WIDGET,BOLD) do { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } while(0)
#define SET_TEXT_COLOR(WIDGET,COLOR) do { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); } while(0)
#define LINK(URL) "<a href=\"" URL "\">" URL "</a>"
#define ENSURE_APP_IS_IDLE() do { if(m_status != STATUS_IDLE) { qWarning("Cannot perfrom this action at this time!"); return; } } while(0)
#define INIT_ERROR_EXIT() do { m_status = STATUS_EXITTING; close(); qApp->exit(-1); return; } while(0)
#define ENSURE_APP_IS_IDLE() do { if(m_status != STATUS_IDLE) return; } while(0)
//static int exceptionFilter(_EXCEPTION_RECORD *dst, _EXCEPTION_POINTERS *src) { memcpy(dst, src->ExceptionRecord, sizeof(_EXCEPTION_RECORD)); return EXCEPTION_EXECUTE_HANDLER; }
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
@ -198,6 +196,7 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc)
*/
MainWindow::~MainWindow(void)
{
m_status = STATUS_EXITTING;
OptionsModel::saveTemplate(m_options, QString::fromLatin1(tpl_last));
X264_DELETE(m_jobList);
@ -211,17 +210,10 @@ MainWindow::~MainWindow(void)
X264_DELETE(temp);
}
/*
if(m_ipcThread->isRunning())
if(m_ipc->isListening())
{
m_ipcThread->setAbort();
if(!m_ipcThread->wait(5000))
{
m_ipcThread->terminate();
m_ipcThread->wait();
}
m_ipc->stopListening();
}
*/
X264_DELETE(m_preferences);
X264_DELETE(m_recentlyUsed);
@ -339,6 +331,8 @@ void MainWindow::browseButtonPressed(void)
*/
void MainWindow::pauseButtonPressed(bool checked)
{
ENSURE_APP_IS_IDLE();
if(checked)
{
m_jobList->pauseJob(ui->jobsView->currentIndex());
@ -570,6 +564,8 @@ void MainWindow::showAbout(void)
*/
void MainWindow::showWebLink(void)
{
ENSURE_APP_IS_IDLE();
if(QObject::sender() == ui->actionWebMulder) QDesktopServices::openUrl(QUrl(home_url));
if(QObject::sender() == ui->actionWebX264) QDesktopServices::openUrl(QUrl("http://www.x264.com/"));
if(QObject::sender() == ui->actionWebKomisar) QDesktopServices::openUrl(QUrl("http://komisar.gin.by/"));
@ -675,12 +671,21 @@ void MainWindow::shutdownComputer(void)
{
qDebug("shutdownComputer(void)");
if((m_status != STATUS_IDLE) && (m_status != STATUS_EXITTING))
{
qWarning("Cannot shutdown computer at this time!");
return;
}
if(countPendingJobs() > 0)
{
qDebug("Still have pending jobs, won't shutdown yet!");
return;
}
const x264_status_t previousStatus = m_status;
m_status = STATUS_BLOCKED;
const int iTimeout = 30;
const Qt::WindowFlags flags = Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowSystemMenuHint;
const QString text = QString("%1%2%1").arg(QString().fill(' ', 18), tr("Warning: Computer will shutdown in %1 seconds..."));
@ -717,6 +722,7 @@ void MainWindow::shutdownComputer(void)
if(progressDialog.wasCanceled())
{
progressDialog.close();
m_status = previousStatus;
return;
}
progressDialog.setValue(i+1);
@ -727,11 +733,13 @@ void MainWindow::shutdownComputer(void)
}
qWarning("Shutting down !!!");
m_status = previousStatus;
if(x264_shutdown_computer("Simple x264 Launcher: All jobs completed, shutting down!", 10, true))
{
qApp->closeAllWindows();
}
}
/*
@ -1016,7 +1024,7 @@ void MainWindow::handleCommand(const int &command, const QStringList &args)
if(m_status != STATUS_AWAITING)
{
m_status = STATUS_AWAITING;
QTimer::singleShot(3333, this, SLOT(handlePendingFiles()));
QTimer::singleShot(5000, this, SLOT(handlePendingFiles()));
}
}
else
@ -1154,6 +1162,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
}
}
m_status = STATUS_EXITTING;
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
QMainWindow::closeEvent(e);
}
@ -1507,12 +1516,9 @@ bool MainWindow::parseCommandLineArgs(void)
bCommandAccepted = true;
if(args.size() >= 3)
{
QStringList lst;
for(int i = 0; i < 3; i++)
{
lst << args.takeFirst();
}
handleCommand(IPC::IPC_OPCODE_ADD_JOB, lst);
const QStringList list = args.mid(0, 3);
handleCommand(IPC::IPC_OPCODE_ADD_JOB, list);
args.erase(args.begin(), args.begin() + 3);
}
else
{