Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Formatting and allowed reloading of plug-ins.

  • Loading branch information...
commit db1b3c5db7722e9414cbe30ad0d801c5fe12cd08 1 parent 1ec3699
@jalcine authored
View
5 src/logging.cpp
@@ -33,7 +33,8 @@
using namespace std;
using std::string;
-using namespace Wintermute;
+
+WINTER_USE_NAMESPACE
Logging* Logging::s_inst = new Logging;
@@ -83,7 +84,7 @@ void Logging::catchQDebugMessage (QtMsgType p_messageType, const char* p_message
QString uuid = Core::arguments().value (WINTER_COMMAND_LINE_IPC_PLUGIN).toString();
if (Factory::currentPlugin() == 0) {
- str += "**loading**";
+ str += "??";
}
else {
if (Factory::obtainPlugin (uuid)) {
View
8 src/logging.hpp
@@ -30,9 +30,10 @@
#include <QObject>
#include <QDebug>
#include <QTime>
+#include <global.hpp>
+
+WINTER_BEGIN_NAMESPACE
-namespace Wintermute
-{
class Logging;
/// @todo Allow triggering the saving of such logs to disc.
@@ -58,7 +59,8 @@ class Logging : public QObject
Logging();
static Logging* s_inst;
};
-} // namespace
+
+WINTER_END_NAMESPACE
#endif
// kate: indent-mode cstyle; indent-width 4; replace-tabs on;
View
37 src/pluginhandle.cpp
@@ -31,11 +31,12 @@
#include "factory.hpp"
#include "pluginhandle.hpp"
#include "pluginhandleprivate.hpp"
+#include "shellplugin.hpp"
WINTER_USE_NAMESPACE
PluginHandlePrivate::PluginHandlePrivate (PluginHandle* p_qPtr) : q_ptr (p_qPtr),
- uuid(), process (0), settings (0)
+ uuid(), process (0), settings (0), watcher(new QFileSystemWatcher(p_qPtr))
{
}
@@ -59,6 +60,7 @@ PluginHandle::PluginHandle (const QString& p_uuid, QSettings* p_settings) : QObj
QObject::connect (this, SIGNAL (crashed (QString)), Factory::instance(), SLOT (doPluginCrash (QString)));
QObject::connect (this, SIGNAL (started (QString)), Factory::instance(), SLOT (doPluginLoad (QString)));
QObject::connect (this, SIGNAL (stopped (QString)), Factory::instance(), SLOT (doPluginUnload (QString)));
+ QObject::connect(d->watcher,SIGNAL(fileChanged(QString)),this,SLOT(on_watcher_fileChanged(QString)));
start();
}
@@ -74,6 +76,7 @@ void PluginHandle::stop()
if (d->process) {
d->process->terminate();
d->process->close();
+ d->process->deleteLater();
}
}
@@ -96,11 +99,16 @@ void PluginHandle::start()
d->process->setProcessChannelMode (QProcess::SeparateChannels);
if (d->process->startDetached (QApplication::applicationFilePath(), args)) {
- qDebug() << "(core) [PluginPluginHandle] Forked process for plug-in" << d->uuid;
+ qDebug() << "(core) [PluginHandle] Forked process for plug-in" << d->uuid;
}
+
+ const QString library = d->settings->value ("Version/Library").toString();
+ const QString libraryPth = QString (WINTER_PLUGIN_PATH) + "/lib" + library + ".so";
+ qDebug() << "[PluginHandle] Watching library file" << libraryPth << "...";
+ d->watcher->addPath(libraryPth);
}
else
- qDebug() << "(core) [PluginPluginHandle] Plug-in" << name() << "has already started in pid" << d->process->pid();
+ qDebug() << "(core) [PluginHandle] Plug-in" << name() << "has already started in pid" << d->process->pid();
}
void PluginHandle::on_process_readyReadStdErr()
@@ -146,7 +154,7 @@ void PluginHandle::catchExit (int p_exitCode, const QProcess::ExitStatus& p_exit
case QProcess::NormalExit:
if (p_exitCode == 0) {
- qDebug() << "(core) [PluginPluginHandle] Plug-in" << name() << "has exitted normally with code" << p_exitCode << ".";
+ qDebug() << "(core) [PluginHandle] Plug-in" << name() << "has exitted normally with code" << p_exitCode << ".";
emit stopped();
}
else
@@ -157,7 +165,7 @@ void PluginHandle::catchExit (int p_exitCode, const QProcess::ExitStatus& p_exit
case QProcess::CrashExit:
if (p_exitCode != 0) {
- qDebug() << "(core) [PluginPluginHandle] Plug-in" << name() << "has exitted abnormally with code" << p_exitCode << ".";
+ qDebug() << "(core) [PluginHandle] Plug-in" << name() << "has exitted abnormally with code" << p_exitCode << ".";
emit crashed();
}
else catchExit (p_exitCode, QProcess::NormalExit);
@@ -172,7 +180,7 @@ void PluginHandle::catchExit (int p_exitCode, const QProcess::ExitStatus& p_exit
void PluginHandle::catchStart()
{
- qDebug() << "(core) [PluginPluginHandle] Plug-in" << name() << "running.";
+ qDebug() << "(core) [PluginHandle] Plug-in" << name() << "running.";
emit started();
}
@@ -185,12 +193,12 @@ void PluginHandle::catchError (const QProcess::ProcessError& p_err) const
case QProcess::Crashed:
if (d->process->exitCode() != 0)
- qDebug() << "(core) [PluginPluginHandle] Plug-in" << name() << "has crashed.";
+ qDebug() << "(core) [PluginHandle] Plug-in" << name() << "has crashed.";
break;
case QProcess::FailedToStart:
- qDebug() << "(core) [PluginPluginHandle] Plug-in" << name() << "has failed to start.";
+ qDebug() << "[PluginHandle] Plug-in" << name() << "has failed to start.";
break;
default:
@@ -199,6 +207,19 @@ void PluginHandle::catchError (const QProcess::ProcessError& p_err) const
}
}
+void PluginHandle::on_watcher_fileChanged (const QString& p_path)
+{
+ Q_D (const PluginHandle);
+ const QString library = d->settings->value ("Version/Library").toString();
+ const QString libraryPth = QString (WINTER_PLUGIN_PATH) + "/lib" + library + ".so";
+
+ if (p_path == libraryPth){
+ qDebug() << "[PluginHandle] Library update. Forcing reloading of plug-in.";
+ stop();
+ start();
+ }
+}
+
#include "pluginhandle.moc"
// kate: indent-mode cstyle; indent-width 4; replace-tabs on;
View
1  src/pluginhandle.hpp
@@ -70,6 +70,7 @@ class PluginHandle : public QObject
public slots:
void stop();
void start();
+ void on_watcher_fileChanged (const QString& p_path);
private slots:
void on_process_readyReadStdOut();
View
3  src/pluginhandleprivate.hpp
@@ -25,6 +25,7 @@
*/
#include <global.hpp>
+#include <QFileSystemWatcher>
WINTER_FORWARD_DECLARE_CLASS(PluginHandle)
@@ -38,7 +39,7 @@ struct PluginHandlePrivate {
QString uuid;
QProcess* process;
QSettings* settings;
-
+ QFileSystemWatcher* watcher;
};
WINTER_END_NAMESPACE
Please sign in to comment.
Something went wrong with that request. Please try again.