-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added ProcessManager from the old QTablet code base.
- Now it's possible to start applications from the QLauncher - QLauncher will be hidden when the application is started.
- Loading branch information
Showing
6 changed files
with
264 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <processmanager.hh> | ||
#include <QProcess> | ||
#include <QDebug> | ||
|
||
namespace qtablet | ||
{ | ||
ProcessManager * ProcessManager::instance() | ||
{ | ||
static ProcessManager instance; | ||
return &instance; | ||
} | ||
|
||
|
||
void ProcessManager::exec( QString const & program ) | ||
{ | ||
if ( program.isEmpty() ) | ||
{ | ||
return; | ||
} | ||
|
||
QProcess *proc = new QProcess( this); | ||
|
||
|
||
connect( proc, SIGNAL( finished(int, QProcess::ExitStatus ) ), | ||
this, SLOT ( finished(int, QProcess::ExitStatus ) ) ); | ||
connect( proc, SIGNAL( error( QProcess::ProcessError ) ), | ||
this, SLOT ( error( QProcess::ProcessError ) ) ); | ||
connect( proc, SIGNAL( started() ), | ||
this, SLOT ( started() ) ); | ||
|
||
qDebug() << "ProcessManager:exec: " << program; | ||
proc->start( program ); | ||
m_processMap.insert( proc, ProcessData(0, program) ); | ||
} | ||
|
||
|
||
ProcessManager::ProcessManager() | ||
{ | ||
|
||
} | ||
|
||
ProcessManager::~ProcessManager() | ||
{ | ||
|
||
} | ||
|
||
void ProcessManager::finished( int exitCode, QProcess::ExitStatus exitStatus ) | ||
{ | ||
Q_UNUSED( exitCode ); | ||
|
||
// Remove the finished process from the map | ||
QProcess* proc = qobject_cast<QProcess*>( sender() ); | ||
ProcessData data = m_processMap.take( proc ); | ||
|
||
if ( QProcess::CrashExit == exitStatus ) | ||
{ | ||
// Notify the framework about the crashed process | ||
emit processCrashed( data.getPid(), data.getName() ); | ||
} | ||
|
||
qDebug() << "ProcessManager: process " << data.getName() << " with pid: " << data.getPid() << "finished."; | ||
|
||
// Let Qt handle process deletion | ||
proc->deleteLater(); | ||
|
||
// Let the world know what this process has finished | ||
emit processFinished( data ); | ||
} | ||
|
||
|
||
void ProcessManager::error( QProcess::ProcessError error ) | ||
{ | ||
// just forward the error. finished should handle process removal. | ||
emit processError( error ); | ||
} | ||
|
||
void ProcessManager::started() | ||
{ | ||
QProcess* proc = qobject_cast<QProcess*>( sender() ); | ||
|
||
// Get the ProcessData object from the map and set it's pid | ||
QMap<QProcess*, ProcessData>::iterator it = m_processMap.find( proc ); | ||
|
||
if ( it == m_processMap.end() ){ | ||
qCritical() << "ProcessManager: could not find the process from the processMap"; | ||
return; | ||
} | ||
|
||
// Now that we are sure that process is ok, let's store its pid | ||
it->setPid( proc->pid() ); | ||
|
||
// let the interested parties to know that some process has started | ||
emit processStarted( *it ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#ifndef PROCESS_MANAGER_HH | ||
#define PROCESS_MANAGER_HH | ||
|
||
#include <QObject> | ||
#include <QMap> | ||
#include <QProcess> | ||
|
||
|
||
|
||
|
||
namespace qtablet | ||
{ | ||
//! ProcessData stores is a class for additional data about the process. | ||
//! | ||
//! Class Process stores process' name or path and the pid. | ||
//! This data will be used e.g. on crash situations for informing the user | ||
//! about the application crash. | ||
//! | ||
class ProcessData | ||
{ | ||
public: | ||
|
||
//! Default CTor. | ||
ProcessData(): | ||
m_name(), | ||
m_pid() | ||
{ | ||
} | ||
|
||
//! Ctor. | ||
//! \param pid process id | ||
//! \name process name or path | ||
ProcessData( Q_PID const & pid, QString const & name ): | ||
m_name( name ), | ||
m_pid ( pid ) | ||
{ | ||
} | ||
|
||
//! Dtor. Does nothing. | ||
virtual ~ProcessData() | ||
{ | ||
} | ||
|
||
//! \return name of the process. | ||
QString const getName() const | ||
{ | ||
return m_name; | ||
} | ||
|
||
//! Set pid. | ||
//! \param pid process id. | ||
void setPid( Q_PID const & pid ) | ||
{ | ||
m_pid = pid; | ||
} | ||
//! \return the pid of the process. | ||
Q_PID getPid() const | ||
{ | ||
return m_pid; | ||
} | ||
|
||
//! Assign operator. | ||
//! \param other object to be assigned to this. | ||
ProcessData &operator=(ProcessData const & other) | ||
{ | ||
if ( this == &other ){ | ||
return *this; | ||
} | ||
m_name = other.m_name; | ||
m_pid = other.m_pid; | ||
return *this; | ||
} | ||
|
||
private: | ||
//! Process name | ||
QString m_name; | ||
|
||
//! Process id | ||
Q_PID m_pid; | ||
}; | ||
|
||
|
||
//! ProcessManager is a sigleton class for process management in theQTablet framework. | ||
|
||
//! | ||
//! | ||
//! $Author: zchydem $ | ||
//! $Date: 2008-04-13 23:34:11 +0300 (Sun, 13 Apr 2008) $ | ||
//! $Revision: 84 $ | ||
class ProcessManager: public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
//! Get the singleton instance of ProcessManager. | ||
//! \return instance of ProcessManager | ||
static ProcessManager * instance(); | ||
|
||
//! Execute program \p program and the arguments can be given in the same string | ||
//! \param program e.g. "/usb/bin/ls -la " | ||
void exec( QString const & program ); | ||
|
||
|
||
protected: | ||
//! CTor. Used internally | ||
ProcessManager(); | ||
|
||
//! Dtor. Does nothing. | ||
virtual ~ProcessManager(); | ||
|
||
protected slots: | ||
//! Callback which is called when one of the previously started processes finish. | ||
//! \param exitCode see Qt Documentation | ||
//! \param exitStatus see Qt Documentation | ||
void finished( int exitCode, QProcess::ExitStatus exitStatus ); | ||
|
||
//! Callback which is called on error. | ||
//! \param error see Qt Documentation | ||
void error( QProcess::ProcessError error ); | ||
|
||
//! Callback which is called when a process has started. After this slot | ||
//! is being called, the process is added to the process map. | ||
void started(); | ||
|
||
signals: | ||
//! Signal for indicating process crash. | ||
//! \param pid process id | ||
//! \param name process name | ||
void processCrashed( qint64 pid, QString const name ); | ||
|
||
//! Signal for indicating process error. | ||
//! \param error process error code. | ||
void processError( QProcess::ProcessError error ); | ||
|
||
//! Signal for indicating that a process has been started | ||
//! \param processData information about the process (pid, name) | ||
void processStarted( ProcessData const processData ); | ||
|
||
void processFinished( ProcessData const processData ); | ||
|
||
private: | ||
|
||
//! QMap for processes and their names | ||
QMap <QProcess*, ProcessData> m_processMap; | ||
}; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters