|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Toonz includes
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timage_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//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 |
|
|
Toshihiro Shimizu |
890ddd |
//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 |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
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 |
|
|
Toshihiro Shimizu |
890ddd |
namespace tipc
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Shared Memory Request
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
QString DefaultMessageParser<shmem_request>::header() const { return QString("$shmem_request"); }</shmem_request>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
void DefaultMessageParser<shmem_request>::operator()(Message &msg)</shmem_request>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int size;
|
|
Toshihiro Shimizu |
890ddd |
QString id;
|
|
Toshihiro Shimizu |
890ddd |
msg >> id >> size >> clr;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QSharedMemory *mem = new QSharedMemory(id);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ok = (tipc::create(*mem, size) > 0);
|
|
Toshihiro Shimizu |
890ddd |
if (!ok) {
|
|
Toshihiro Shimizu |
890ddd |
msg << QString("err");
|
|
Toshihiro Shimizu |
890ddd |
delete mem;
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
sharedMemories.insert(id, mem);
|
|
Toshihiro Shimizu |
890ddd |
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 <>
|
|
Toshihiro Shimizu |
890ddd |
QString DefaultMessageParser<shmem_release>::header() const { return QString("$shmem_release"); }</shmem_release>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
void DefaultMessageParser<shmem_release>::operator()(Message &msg)</shmem_release>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString id;
|
|
Toshihiro Shimizu |
890ddd |
msg >> id >> clr;
|
|
Toshihiro Shimizu |
890ddd |
QSharedMemory *mem = sharedMemories.take(id);
|
|
Toshihiro Shimizu |
890ddd |
if (mem)
|
|
Toshihiro Shimizu |
890ddd |
delete mem;
|
|
Toshihiro Shimizu |
890ddd |
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 <>
|
|
Toshihiro Shimizu |
890ddd |
QString DefaultMessageParser<tmpfile_request>::header() const { return QString("$tmpfile_request"); }</tmpfile_request>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
void DefaultMessageParser<tmpfile_request>::operator()(Message &msg)</tmpfile_request>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString id;
|
|
Toshihiro Shimizu |
890ddd |
msg >> id >> clr;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Build a temporary file with passed id group.
|
|
Toshihiro Shimizu |
890ddd |
//The created QTemporaryFile CANNOT be stored directly, as it internally
|
|
Toshihiro Shimizu |
890ddd |
//keeps the file open until the object is destroyed. Instead, we store its
|
|
Toshihiro Shimizu |
890ddd |
//filePath and manually remove it upon release.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QTemporaryFile tmp(QDir::temp().filePath(id));
|
|
Toshihiro Shimizu |
890ddd |
tmp.setAutoRemove(false);
|
|
Toshihiro Shimizu |
890ddd |
if (!tmp.open()) {
|
|
Toshihiro Shimizu |
890ddd |
msg << QString("err");
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
temporaryFiles.insert(id, tmp.fileName());
|
|
Toshihiro Shimizu |
890ddd |
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 <>
|
|
Toshihiro Shimizu |
890ddd |
QString DefaultMessageParser<tmpfile_release>::header() const { return QString("$tmpfile_release"); }</tmpfile_release>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
void DefaultMessageParser<tmpfile_release>::operator()(Message &msg)</tmpfile_release>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString id;
|
|
Toshihiro Shimizu |
890ddd |
msg >> id >> clr;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString tmpPath = temporaryFiles.take(id);
|
|
Toshihiro Shimizu |
890ddd |
if (!tmpPath.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
QFile file(tmpPath);
|
|
Toshihiro Shimizu |
890ddd |
file.remove();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
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 <>
|
|
Toshihiro Shimizu |
890ddd |
QString DefaultMessageParser<quit_on_error>::header() const { return QString("$quit_on_error"); }</quit_on_error>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Toshihiro Shimizu |
890ddd |
void DefaultMessageParser<quit_on_error>::operator()(Message &msg)</quit_on_error>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QObject::connect(socket(), SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit()));
|
|
Toshihiro Shimizu |
890ddd |
//In Qt 5.5 originating process's termination emits 'disconnected' instead of 'error'
|
|
Toshihiro Shimizu |
890ddd |
QObject::connect(socket(), SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
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 |
|
|
Toshihiro Shimizu |
890ddd |
} //namespace tipc
|