|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Toonz includes
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timage_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qiodevice></qiodevice>
|
|
Toshihiro Shimizu |
890ddd |
#include <qsharedmemory></qsharedmemory>
|
|
Toshihiro Shimizu |
890ddd |
#include <qtemporaryfile></qtemporaryfile>
|
|
Toshihiro Shimizu |
890ddd |
#include <qdir></qdir>
|
|
Toshihiro Shimizu |
890ddd |
#include <qfile></qfile>
|
|
Toshihiro Shimizu |
890ddd |
#include <qcoreapplication></qcoreapplication>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// tipc includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tipc.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tipcmsg.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Local stuff
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
QHash<qstring, *="" qsharedmemory=""> sharedMemories;</qstring,>
|
|
Toshihiro Shimizu |
890ddd |
QHash<qstring, qstring=""> temporaryFiles;</qstring,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace tipc {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Shared Memory Request
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
QString DefaultMessageParser<shmem_request>::header() const {</shmem_request>
|
|
Shinya Kitaoka |
120a6e |
return QString("$shmem_request");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
void DefaultMessageParser<shmem_request>::operator()(Message &msg) {</shmem_request>
|
|
Shinya Kitaoka |
120a6e |
int size;
|
|
Shinya Kitaoka |
120a6e |
QString id;
|
|
Shinya Kitaoka |
120a6e |
msg >> id >> size >> clr;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QSharedMemory *mem = new QSharedMemory(id);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool ok = (tipc::create(*mem, size) > 0);
|
|
Shinya Kitaoka |
120a6e |
if (!ok) {
|
|
Shinya Kitaoka |
120a6e |
msg << QString("err");
|
|
Shinya Kitaoka |
120a6e |
delete mem;
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
sharedMemories.insert(id, mem);
|
|
Shinya Kitaoka |
120a6e |
msg << QString("ok");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Shared Memory Release
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
QString DefaultMessageParser<shmem_release>::header() const {</shmem_release>
|
|
Shinya Kitaoka |
120a6e |
return QString("$shmem_release");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
void DefaultMessageParser<shmem_release>::operator()(Message &msg) {</shmem_release>
|
|
Shinya Kitaoka |
120a6e |
QString id;
|
|
Shinya Kitaoka |
120a6e |
msg >> id >> clr;
|
|
Shinya Kitaoka |
120a6e |
QSharedMemory *mem = sharedMemories.take(id);
|
|
Shinya Kitaoka |
120a6e |
if (mem) delete mem;
|
|
Shinya Kitaoka |
120a6e |
msg << QString("ok");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Temporary File Request
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
QString DefaultMessageParser<tmpfile_request>::header() const {</tmpfile_request>
|
|
Shinya Kitaoka |
120a6e |
return QString("$tmpfile_request");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
void DefaultMessageParser<tmpfile_request>::operator()(Message &msg) {</tmpfile_request>
|
|
Shinya Kitaoka |
120a6e |
QString id;
|
|
Shinya Kitaoka |
120a6e |
msg >> id >> clr;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Build a temporary file with passed id group.
|
|
Shinya Kitaoka |
120a6e |
// The created QTemporaryFile CANNOT be stored directly, as it internally
|
|
Shinya Kitaoka |
120a6e |
// keeps the file open until the object is destroyed. Instead, we store its
|
|
Shinya Kitaoka |
120a6e |
// filePath and manually remove it upon release.
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QTemporaryFile tmp(QDir::temp().filePath(id));
|
|
Shinya Kitaoka |
120a6e |
tmp.setAutoRemove(false);
|
|
Shinya Kitaoka |
120a6e |
if (!tmp.open()) {
|
|
Shinya Kitaoka |
120a6e |
msg << QString("err");
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
temporaryFiles.insert(id, tmp.fileName());
|
|
Shinya Kitaoka |
120a6e |
msg << QString("ok") << tmp.fileName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Temporary File Release
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
QString DefaultMessageParser<tmpfile_release>::header() const {</tmpfile_release>
|
|
Shinya Kitaoka |
120a6e |
return QString("$tmpfile_release");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
void DefaultMessageParser<tmpfile_release>::operator()(Message &msg) {</tmpfile_release>
|
|
Shinya Kitaoka |
120a6e |
QString id;
|
|
Shinya Kitaoka |
120a6e |
msg >> id >> clr;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QString tmpPath = temporaryFiles.take(id);
|
|
Shinya Kitaoka |
120a6e |
if (!tmpPath.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
QFile file(tmpPath);
|
|
Shinya Kitaoka |
120a6e |
file.remove();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
msg << QString("ok");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Quit On Error
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
QString DefaultMessageParser<quit_on_error>::header() const {</quit_on_error>
|
|
Shinya Kitaoka |
120a6e |
return QString("$quit_on_error");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
void DefaultMessageParser<quit_on_error>::operator()(Message &msg) {</quit_on_error>
|
|
Shinya Kitaoka |
120a6e |
QObject::connect(socket(), SIGNAL(error(QLocalSocket::LocalSocketError)),
|
|
Shinya Kitaoka |
120a6e |
QCoreApplication::instance(), SLOT(quit()));
|
|
Shinya Kitaoka |
120a6e |
// In Qt 5.5 originating process's termination emits 'disconnected' instead of
|
|
Shinya Kitaoka |
120a6e |
// 'error'
|
|
Shinya Kitaoka |
120a6e |
QObject::connect(socket(), SIGNAL(disconnected()),
|
|
Shinya Kitaoka |
120a6e |
QCoreApplication::instance(), SLOT(quit()));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
msg << clr << QString("ok");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Explicit template instantiation for all basic datatypes
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------- Default Messages ---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template class DefaultMessageParser<shmem_request>;</shmem_request>
|
|
Toshihiro Shimizu |
890ddd |
template class DefaultMessageParser<shmem_release>;</shmem_release>
|
|
Toshihiro Shimizu |
890ddd |
template class DefaultMessageParser<tmpfile_request>;</tmpfile_request>
|
|
Toshihiro Shimizu |
890ddd |
template class DefaultMessageParser<tmpfile_release>;</tmpfile_release>
|
|
Toshihiro Shimizu |
890ddd |
template class DefaultMessageParser<quit_on_error>;</quit_on_error>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace tipc
|