Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfarmtask.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "toutputproperties.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// QT includes
Toshihiro Shimizu 890ddd
#include <qstringlist></qstringlist>
Toshihiro Shimizu 890ddd
#include <qsettings></qsettings>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// MACOSX includes
Shinya Kitaoka d4642c
#ifdef _WIN32
Shinya Kitaoka d4642c
#include <winsock.h></winsock.h>
Campbell Barton e4aac6
#elif defined(MACOSX)
Dave ba9da1
#include "tversion.h"
Dave ba9da1
using namespace TVER;
Dave ba9da1
#include <netdb.h>      // gethostbyname</netdb.h>
Dave ba9da1
#include <arpa inet.h="">  // inet_ntoa</arpa>
Shinya Kitaoka d4642c
#else
Dave ba9da1
// these were included for OSX, i'm not sure if they are required for linux or
Dave ba9da1
// not? leaving them in as linux was building sucessfully already. damies13 -
Dave ba9da1
// 2017-04-15.
Shinya Kitaoka 120a6e
#include <netdb.h>      // gethostbyname</netdb.h>
Shinya Kitaoka 120a6e
#include <arpa inet.h="">  // inet_ntoa</arpa>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************************
Toshihiro Shimizu 890ddd
//    TFarmTask::Dependencies  implementation
Toshihiro Shimizu 890ddd
//*************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TFarmTask::Dependencies::Data {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Data() : m_tasks() {}
Shinya Kitaoka 120a6e
  ~Data() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<tfarmtask::id> m_tasks;</tfarmtask::id>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFarmTask::Dependencies::Dependencies() : m_data(new Data) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTask::Dependencies::Dependencies(const Dependencies &rhs)
Shinya Kitaoka 120a6e
    : m_data(new Data) {
Shinya Kitaoka 120a6e
  m_data->m_tasks = rhs.m_data->m_tasks;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFarmTask::Dependencies::~Dependencies() { delete m_data; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTask::Dependencies &TFarmTask::Dependencies::operator=(
Shinya Kitaoka 120a6e
    const Dependencies &rhs) {
Shinya Kitaoka 120a6e
  if (this != &rhs) {
Shinya Kitaoka 120a6e
    m_data->m_tasks = rhs.m_data->m_tasks;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFarmTask::Dependencies::operator==(const Dependencies &rhs) {
Shinya Kitaoka 120a6e
  return m_data->m_tasks == rhs.m_data->m_tasks;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFarmTask::Dependencies::operator!=(const Dependencies &rhs) {
Shinya Kitaoka 120a6e
  return !operator==(rhs);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFarmTask::Dependencies::add(const TFarmTask::Id &id) {
Shinya Kitaoka 120a6e
  m_data->m_tasks.push_back(id);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFarmTask::Dependencies::remove(const TFarmTask::Id &id) {
Shinya Kitaoka 120a6e
  std::vector<tfarmtask::id>::iterator it =</tfarmtask::id>
Shinya Kitaoka 120a6e
      std::find(m_data->m_tasks.begin(), m_data->m_tasks.end(), id);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (it != m_data->m_tasks.end()) m_data->m_tasks.erase(it);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TFarmTask::Dependencies::getTaskCount() const {
Shinya Kitaoka 120a6e
  return m_data->m_tasks.size();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTask::Id TFarmTask::Dependencies::getTaskId(int i) const {
Shinya Kitaoka 120a6e
  if (i >= 0 && i < (int)m_data->m_tasks.size()) return m_data->m_tasks[i];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return "";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************************
Toshihiro Shimizu 890ddd
//    TFarmTask  implementation
Toshihiro Shimizu 890ddd
//*************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFarmTask::TFarmTask(const QString &name)
Shinya Kitaoka 120a6e
    : m_isComposerTask()
Shinya Kitaoka 120a6e
    , m_name(name)
Shinya Kitaoka 120a6e
    , m_priority()
Shinya Kitaoka 120a6e
    , m_status(Suspended)
Shinya Kitaoka 120a6e
    , m_successfullSteps()
Shinya Kitaoka 120a6e
    , m_failedSteps()
Shinya Kitaoka 120a6e
    , m_stepCount()
Shinya Kitaoka 120a6e
    , m_from(-1)
Shinya Kitaoka 120a6e
    , m_to(-1)
Shinya Kitaoka 120a6e
    , m_step(-1)
Shinya Kitaoka 120a6e
    , m_shrink(-1)
Shinya Kitaoka 120a6e
    , m_chunkSize(-1)
Shinya Kitaoka 120a6e
    , m_multimedia(0)        // Full render, no multimedia
Shinya Kitaoka 120a6e
    , m_threadsIndex(2)      // All threads
Shinya Kitaoka 120a6e
    , m_maxTileSizeIndex(0)  // No tiling
Shinya Kitaoka 120a6e
    , m_overwrite()
Shinya Kitaoka 120a6e
    , m_onlyVisible()
Shinya Kitaoka 120a6e
    , m_platform(NoPlatform)
Shinya Kitaoka 120a6e
    , m_dependencies() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TFarmTask::TFarmTask(const QString &id, const QString &name, bool composerTask,
Shinya Kitaoka 120a6e
                     const QString &user, const QString &host, int stepCount,
Shinya Kitaoka 120a6e
                     int priority, const TFilePath &taskFilePath,
Shinya Kitaoka 120a6e
                     const TFilePath &outputPath, int from, int to, int step,
Shinya Kitaoka 120a6e
                     int shrink, int multimedia, int chunksize,
Shinya Kitaoka 120a6e
                     int threadsIndex, int maxTileSizeIndex,
Shinya Kitaoka 120a6e
                     OverwriteBehavior overwrite, bool onlyvisible)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    : m_isComposerTask(composerTask)
Shinya Kitaoka 120a6e
    , m_id(id)
Shinya Kitaoka 120a6e
    , m_name(name)
Shinya Kitaoka 120a6e
    , m_user(user)
Shinya Kitaoka 120a6e
    , m_hostName(host)
Shinya Kitaoka 120a6e
    , m_priority(priority)
Shinya Kitaoka 120a6e
    , m_successfullSteps(0)
Shinya Kitaoka 120a6e
    , m_failedSteps(0)
Shinya Kitaoka 120a6e
    , m_stepCount(stepCount)
Shinya Kitaoka 120a6e
    , m_platform(NoPlatform)
Shinya Kitaoka 120a6e
    , m_dependencies(new Dependencies)
Shinya Kitaoka 120a6e
    , m_taskFilePath(taskFilePath)
Shinya Kitaoka 120a6e
    , m_outputPath(outputPath)
Shinya Kitaoka 120a6e
    , m_from(from)
Shinya Kitaoka 120a6e
    , m_to(to)
Shinya Kitaoka 120a6e
    , m_step(step)
Shinya Kitaoka 120a6e
    , m_shrink(shrink)
Shinya Kitaoka 120a6e
    , m_multimedia(multimedia)
Shinya Kitaoka 120a6e
    , m_threadsIndex(threadsIndex)
Shinya Kitaoka 120a6e
    , m_maxTileSizeIndex(maxTileSizeIndex)
Shinya Kitaoka 120a6e
    , m_chunkSize(chunksize)
Shinya Kitaoka 120a6e
    , m_overwrite(overwrite)
Shinya Kitaoka 120a6e
    , m_onlyVisible(onlyvisible)
Shinya Kitaoka 120a6e
    , m_status(Suspended)
Shinya Kitaoka 120a6e
    , m_callerMachineName() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TFarmTask::TFarmTask(const QString &id, const QString &name,
Shinya Kitaoka 120a6e
                     const QString &cmdline, const QString &user,
Shinya Kitaoka 120a6e
                     const QString &host, int stepCount, int priority)
Shinya Kitaoka 120a6e
    : m_id(id)
Shinya Kitaoka 120a6e
    , m_name(name)
Shinya Kitaoka 120a6e
    , m_user(user)
Shinya Kitaoka 120a6e
    , m_hostName(host)
Shinya Kitaoka 120a6e
    , m_priority(priority)
Shinya Kitaoka 120a6e
    , m_successfullSteps(0)
Shinya Kitaoka 120a6e
    , m_failedSteps(0)
Shinya Kitaoka 120a6e
    , m_stepCount(stepCount)
Shinya Kitaoka 120a6e
    , m_platform(NoPlatform)
Shinya Kitaoka 120a6e
    , m_dependencies(new Dependencies)
Shinya Kitaoka 120a6e
    , m_status(Suspended)
Shinya Kitaoka 120a6e
    , m_callerMachineName() {
Shinya Kitaoka 120a6e
  parseCommandLine(cmdline);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TFarmTask::TFarmTask(const TFarmTask &rhs) : m_dependencies() { *this = rhs; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TFarmTask &TFarmTask::operator=(const TFarmTask &rhs) {
Shinya Kitaoka 120a6e
  if (this != &rhs) {
Shinya Kitaoka 120a6e
    m_name             = rhs.m_name;
Shinya Kitaoka 120a6e
    m_priority         = rhs.m_priority;
Shinya Kitaoka 120a6e
    m_user             = rhs.m_user;
Shinya Kitaoka 120a6e
    m_hostName         = rhs.m_hostName;
Shinya Kitaoka 120a6e
    m_id               = rhs.m_id;
Shinya Kitaoka 120a6e
    m_parentId         = rhs.m_parentId;
Shinya Kitaoka 120a6e
    m_status           = rhs.m_status;
Shinya Kitaoka 120a6e
    m_server           = rhs.m_server;
Shinya Kitaoka 120a6e
    m_submissionDate   = rhs.m_submissionDate;
Shinya Kitaoka 120a6e
    m_startDate        = rhs.m_startDate;
Shinya Kitaoka 120a6e
    m_completionDate   = rhs.m_completionDate;
Shinya Kitaoka 120a6e
    m_successfullSteps = rhs.m_successfullSteps;
Shinya Kitaoka 120a6e
    m_failedSteps      = rhs.m_failedSteps;
Shinya Kitaoka 120a6e
    m_stepCount        = rhs.m_stepCount;
Shinya Kitaoka 120a6e
    m_from             = rhs.m_from;
Shinya Kitaoka 120a6e
    m_to               = rhs.m_to;
Shinya Kitaoka 120a6e
    m_step             = rhs.m_step;
Shinya Kitaoka 120a6e
    m_shrink           = rhs.m_shrink;
Shinya Kitaoka 120a6e
    m_onlyVisible      = rhs.m_onlyVisible;
Shinya Kitaoka 120a6e
    m_overwrite        = rhs.m_overwrite;
Shinya Kitaoka 120a6e
    m_multimedia       = rhs.m_multimedia;
Shinya Kitaoka 120a6e
    m_threadsIndex     = rhs.m_threadsIndex;
Shinya Kitaoka 120a6e
    m_maxTileSizeIndex = rhs.m_maxTileSizeIndex;
Shinya Kitaoka 120a6e
    m_chunkSize        = rhs.m_chunkSize;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    delete m_dependencies;
Shinya Kitaoka 120a6e
    m_dependencies = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (rhs.m_dependencies)
Shinya Kitaoka 120a6e
      m_dependencies = new Dependencies(*rhs.m_dependencies);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return *this;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool TFarmTask::operator==(const TFarmTask &task) {
Shinya Kitaoka 120a6e
  bool equalDependencies;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!task.m_dependencies && !m_dependencies)
Shinya Kitaoka 120a6e
    equalDependencies = true;
Shinya Kitaoka 120a6e
  else if (task.m_dependencies && !m_dependencies)
Shinya Kitaoka 120a6e
    equalDependencies = false;
Shinya Kitaoka 120a6e
  else if (!task.m_dependencies && m_dependencies)
Shinya Kitaoka 120a6e
    equalDependencies = false;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    equalDependencies = (task.m_dependencies == m_dependencies);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return (
Shinya Kitaoka 120a6e
      task.m_name == m_name && task.m_priority == m_priority &&
Shinya Kitaoka 120a6e
      task.m_user == m_user && task.m_hostName == m_hostName &&
Shinya Kitaoka 120a6e
      task.m_id == m_id && task.m_parentId == m_parentId &&
Shinya Kitaoka 120a6e
      task.m_status == m_status && task.m_server == m_server &&
Shinya Kitaoka 120a6e
      task.m_submissionDate == m_submissionDate &&
Shinya Kitaoka 120a6e
      task.m_startDate == m_startDate &&
Shinya Kitaoka 120a6e
      task.m_completionDate == m_completionDate &&
Shinya Kitaoka 120a6e
      task.m_successfullSteps == m_successfullSteps &&
Shinya Kitaoka 120a6e
      task.m_failedSteps == m_failedSteps && task.m_stepCount == m_stepCount &&
Shinya Kitaoka 120a6e
      task.m_from == m_from && task.m_to == m_to && task.m_step == m_step &&
Shinya Kitaoka 120a6e
      task.m_shrink == m_shrink && task.m_onlyVisible == m_onlyVisible &&
Shinya Kitaoka 120a6e
      task.m_overwrite == m_overwrite && task.m_multimedia == m_multimedia &&
Shinya Kitaoka 120a6e
      task.m_threadsIndex == m_threadsIndex &&
Shinya Kitaoka 120a6e
      task.m_maxTileSizeIndex == m_maxTileSizeIndex &&
Shinya Kitaoka 120a6e
      task.m_chunkSize == m_chunkSize && equalDependencies);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TFarmTask::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.matchTag(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "taskId") {
Shinya Kitaoka 120a6e
      is >> m_id;
Shinya Kitaoka 120a6e
    } else if (tagName == "parentId") {
Shinya Kitaoka 120a6e
      is >> m_parentId;
Shinya Kitaoka 120a6e
    } else if (tagName == "name") {
Shinya Kitaoka 120a6e
      is >> m_name;
Shinya Kitaoka 120a6e
    } else if (tagName == "cmdline") {
Shinya Kitaoka 120a6e
      QString commandLine;
Shinya Kitaoka 120a6e
      is >> commandLine;
Shinya Kitaoka 120a6e
      parseCommandLine(commandLine);
Shinya Kitaoka 120a6e
    } else if (tagName == "priority") {
Shinya Kitaoka 120a6e
      is >> m_priority;
Shinya Kitaoka 120a6e
    } else if (tagName == "submittedBy") {
Shinya Kitaoka 120a6e
      is >> m_user;
Shinya Kitaoka 120a6e
    } else if (tagName == "submittedOn") {
Shinya Kitaoka 120a6e
      is >> m_hostName;
Shinya Kitaoka 120a6e
    } else if (tagName == "submissionDate") {
Shinya Kitaoka 120a6e
      QString date;
Shinya Kitaoka 120a6e
      is >> date;
Shinya Kitaoka 120a6e
      m_submissionDate = QDateTime::fromString(date);
Shinya Kitaoka 120a6e
    } else if (tagName == "stepCount") {
Shinya Kitaoka 120a6e
      is >> m_stepCount;
Shinya Kitaoka 120a6e
    } else if (tagName == "chunkSize") {
Shinya Kitaoka 120a6e
      assert(dynamic_cast<tfarmtaskgroup *="">(this));</tfarmtaskgroup>
Shinya Kitaoka 120a6e
      is >> m_chunkSize;
Shinya Kitaoka 120a6e
    } else if (tagName == "threadsIndex") {
Shinya Kitaoka 120a6e
      assert(dynamic_cast<tfarmtaskgroup *="">(this));</tfarmtaskgroup>
Shinya Kitaoka 120a6e
      is >> m_threadsIndex;
Shinya Kitaoka 120a6e
    } else if (tagName == "maxTileSizeIndex") {
Shinya Kitaoka 120a6e
      assert(dynamic_cast<tfarmtaskgroup *="">(this));</tfarmtaskgroup>
Shinya Kitaoka 120a6e
      is >> m_maxTileSizeIndex;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    else if (tagName == "platform") {
Shinya Kitaoka 120a6e
      int val;
Shinya Kitaoka 120a6e
      is >> val;
Shinya Kitaoka 120a6e
      m_platform = (TFarmPlatform)val;
Shinya Kitaoka 120a6e
    } else if (tagName == "dependencies") {
Shinya Kitaoka 120a6e
      m_dependencies = new Dependencies();
Shinya Kitaoka 120a6e
      while (!is.eos()) {
Shinya Kitaoka 120a6e
        is.matchTag(tagName);
Shinya Kitaoka 120a6e
        if (tagName == "taskId") {
Shinya Kitaoka 120a6e
          QString dependsOn;
Shinya Kitaoka 120a6e
          is >> dependsOn;
Shinya Kitaoka 120a6e
          m_dependencies->add(dependsOn);
Shinya Kitaoka 120a6e
        } else
Shinya Kitaoka 120a6e
          throw TException(tagName + " : unexpected tag");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        if (!is.matchEndTag()) throw TException(tagName + " : missing end tag");
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      throw TException(tagName + " : unexpected tag");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!is.matchEndTag()) throw TException(tagName + " : missing end tag");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TFarmTask::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.child("taskId") << m_id;
Shinya Kitaoka 120a6e
  os.child("parentId") << m_parentId;
Shinya Kitaoka 120a6e
  os.child("name") << m_name;
Shinya Kitaoka 120a6e
  os.child("cmdline") << getCommandLine();
Shinya Kitaoka 120a6e
  os.child("priority") << m_priority;
Shinya Kitaoka 120a6e
  os.child("submittedBy") << m_user;
Shinya Kitaoka 120a6e
  os.child("submittedOn") << m_hostName;
Shinya Kitaoka 120a6e
  os.child("submissionDate") << m_submissionDate.toString();
Shinya Kitaoka 120a6e
  os.child("stepCount") << m_stepCount;
Shinya Kitaoka 120a6e
  if (dynamic_cast<tfarmtaskgroup *="">(this))</tfarmtaskgroup>
Shinya Kitaoka 120a6e
    os.child("chunkSize") << m_chunkSize;
Shinya Kitaoka 120a6e
  os.child("threadsIndex") << m_threadsIndex;
Shinya Kitaoka 120a6e
  os.child("maxTileSizeIndex") << m_maxTileSizeIndex;
Shinya Kitaoka 120a6e
  os.child("platform") << m_platform;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  os.openChild("dependencies");
Shinya Kitaoka 120a6e
  if (m_dependencies) {
Shinya Kitaoka 120a6e
    for (int i = 0; i < m_dependencies->getTaskCount(); ++i) {
Shinya Kitaoka 120a6e
      TFarmTask::Id id = m_dependencies->getTaskId(i);
Shinya Kitaoka 120a6e
      os.child("taskId") << id;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  os.closeChild();  // "dependencies"
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
namespace {
Campbell Barton e4aac6
static QString getExeName(bool isComposer) {
Shinya Kitaoka 120a6e
  QString name = isComposer ? "tcomposer" : "tcleanup";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#ifdef _WIN32
Shinya Kitaoka 120a6e
  return name + ".exe ";
Campbell Barton e4aac6
#elif defined(MACOSX)
Dave ba9da1
  TVER::ToonzVersion tver;
artisteacher 48cbb8
  return "\"./" + QString::fromStdString(tver.getAppName()) +
Dave ba9da1
         ".app/Contents/MacOS/" + name + "\" ";
Shinya Kitaoka 120a6e
#else
Dave ba9da1
  return name;
Shinya Kitaoka 120a6e
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString toString(int value, int w, char c = ' ') {
Dave ba9da1
  QString s = QString::number(value);
Campbell Barton e4aac6
  while (s.size() < w) s = c + s;
Shinya Kitaoka 120a6e
  return s;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Campbell Barton ccd505
static TFilePath getFilePath(const QStringList &l, int &i) {
Shinya Kitaoka 120a6e
  QString outStr = l.at(i++);
Shinya Kitaoka 120a6e
  if (outStr.startsWith('"')) {
Shinya Kitaoka 120a6e
    outStr = outStr.remove(0, 1);
Shinya Kitaoka 120a6e
    if (!outStr.endsWith('"')) {
Shinya Kitaoka 120a6e
      do
Shinya Kitaoka 120a6e
        outStr += " " + l.at(i);
Shinya Kitaoka 120a6e
      while (i < l.size() && !l.at(i++).endsWith('"'));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    outStr.chop(1);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return TFilePath(outStr.toStdString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFarmTask::parseCommandLine(QString commandLine) {
Shinya Kitaoka 120a6e
  QStringList l = commandLine.split(" ", QString::SkipEmptyParts);
Shinya Kitaoka 120a6e
  assert(l.size() >= 2);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // serve per skippare il path dell'eseguibile su mac che contiene spazi
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  while (i < l.size() &&
Shinya Kitaoka 120a6e
         (!l.at(i).contains("tcomposer") && !l.at(i).contains("tcleanup")))
Shinya Kitaoka 120a6e
    ++i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_isComposerTask = l.at(i++).contains("tcomposer");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (i < l.size() && !l.at(i).startsWith('-'))
Shinya Kitaoka 120a6e
    m_taskFilePath = getFilePath(l, i);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_step   = 1;
Shinya Kitaoka 120a6e
  m_shrink = 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (i < l.size()) {
Shinya Kitaoka 120a6e
    QString str = l.at(i);
Shinya Kitaoka 120a6e
    if (l.at(i) == "-o")
Shinya Kitaoka 120a6e
      m_outputPath = getFilePath(l, ++i);
Shinya Kitaoka 120a6e
    else if (l.at(i) == "-range") {
Shinya Kitaoka 120a6e
      m_from = (l.at(i + 1).toInt());
Shinya Kitaoka 120a6e
      m_to   = (l.at(i + 2).toInt());
Shinya Kitaoka 120a6e
      i += 3;
Shinya Kitaoka 120a6e
    } else if (l.at(i) == "-step") {
Shinya Kitaoka 120a6e
      m_step = (l.at(i + 1).toInt());
Shinya Kitaoka 120a6e
      i += 2;
Shinya Kitaoka 120a6e
    } else if (l.at(i) == "-shrink") {
Shinya Kitaoka 120a6e
      m_shrink = (l.at(i + 1).toInt());
Shinya Kitaoka 120a6e
      i += 2;
Shinya Kitaoka 120a6e
    } else if (l.at(i) == "-multimedia") {
Shinya Kitaoka 120a6e
      m_multimedia = (l.at(i + 1).toInt());
Shinya Kitaoka 120a6e
      i += 2;
Shinya Kitaoka 120a6e
    } else if (l.at(i) == "-nthreads") {
Shinya Kitaoka 120a6e
      QString str(l.at(i + 1));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      m_threadsIndex = (str == "single") ? 0 : (str == "half") ? 1 : 2;
Shinya Kitaoka 120a6e
      i += 2;
Shinya Kitaoka 120a6e
    } else if (l.at(i) == "-maxtilesize") {
Shinya Kitaoka 120a6e
      QString str(l.at(i + 1));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      const QString maxTileSizeIndexes[3] = {
Shinya Kitaoka 120a6e
          QString::number(TOutputProperties::LargeVal),
Shinya Kitaoka 120a6e
          QString::number(TOutputProperties::MediumVal),
Shinya Kitaoka 120a6e
          QString::number(TOutputProperties::SmallVal)};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      m_maxTileSizeIndex = (str == maxTileSizeIndexes[2])
Shinya Kitaoka 120a6e
                               ? 3
Shinya Kitaoka 120a6e
                               : (str == maxTileSizeIndexes[1])
Shinya Kitaoka 120a6e
                                     ? 2
Shinya Kitaoka 120a6e
                                     : (str == maxTileSizeIndexes[0]) ? 1 : 0;
Shinya Kitaoka 120a6e
      i += 2;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    else if (l.at(i) == "-overwriteAll")
Shinya Kitaoka 120a6e
      m_overwrite = Overwrite_All, i++;
Shinya Kitaoka 120a6e
    else if (l.at(i) == "-overwriteNoPaint")
Shinya Kitaoka 120a6e
      m_overwrite = Overwrite_NoPaint, i++;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    else if (l.at(i) == "-onlyvisible")
Shinya Kitaoka 120a6e
      m_onlyVisible = true, ++i;
Shinya Kitaoka 120a6e
    else if (l.at(i) == "-farm" || l.at(i) == "-id")
Shinya Kitaoka 120a6e
      i += 2;
Shinya Kitaoka 120a6e
    else if (l.at(i) == "-tmsg") {
Shinya Kitaoka 120a6e
      m_callerMachineName = l.at(i + 1);
Shinya Kitaoka 120a6e
      i += 2;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      assert(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
QString TFarmTask::getCommandLine(bool isFarmTask) const {
Shinya Kitaoka 120a6e
  QString cmdline = getExeName(m_isComposerTask);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_taskFilePath.isEmpty())
Dave ba9da1
    cmdline += " \"" +
Dave ba9da1
               QString::fromStdWString(
Dave ba9da1
                   TSystem::toUNC(m_taskFilePath).getWideString()) +
Shinya Kitaoka 120a6e
               "\"";
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_callerMachineName != "") {
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Shinya Kitaoka 120a6e
    struct hostent *he = gethostbyname(m_callerMachineName.toLatin1());
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    struct hostent *he = gethostbyname(m_callerMachineName.toAscii());
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    if (he) {
Shinya Kitaoka 120a6e
      char *ipAddress = inet_ntoa(*(struct in_addr *)*(he->h_addr_list));
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Shinya Kitaoka 120a6e
      cmdline += " -tmsg " + QString::fromUtf8(ipAddress);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
      cmdline += " -tmsg " + QString::fromAscii(ipAddress);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_isComposerTask) {
Shinya Kitaoka 120a6e
    if (m_overwrite == Overwrite_All)
Shinya Kitaoka 120a6e
      cmdline += " -overwriteAll ";
Shinya Kitaoka 120a6e
    else if (m_overwrite == Overwrite_NoPaint)
Shinya Kitaoka 120a6e
      cmdline += " -overwriteNoPaint ";
Shinya Kitaoka 120a6e
    if (m_onlyVisible) cmdline += " -onlyvisible ";
Shinya Kitaoka 120a6e
    return cmdline;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_outputPath.isEmpty()) {
Shinya Kitaoka 120a6e
    TFilePath outputPath;
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      outputPath = TSystem::toUNC(m_outputPath);
Shinya Kitaoka 120a6e
    } catch (TException &) {
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    cmdline +=
Shinya Kitaoka 120a6e
        " -o \"" + QString::fromStdWString(outputPath.getWideString()) + "\"";
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  cmdline += " -range " + QString::number(m_from) + " " + QString::number(m_to);
Shinya Kitaoka 120a6e
  cmdline += " -step " + QString::number(m_step);
Shinya Kitaoka 120a6e
  cmdline += " -shrink " + QString::number(m_shrink);
Shinya Kitaoka 120a6e
  cmdline += " -multimedia " + QString::number(m_multimedia);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const QString threadCounts[3] = {"single", "half", "all"};
Shinya Kitaoka 120a6e
  cmdline += " -nthreads " + threadCounts[m_threadsIndex];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const QString maxTileSizes[4] = {
Shinya Kitaoka 120a6e
      "none", QString::number(TOutputProperties::LargeVal),
Shinya Kitaoka 120a6e
      QString::number(TOutputProperties::MediumVal),
Shinya Kitaoka 120a6e
      QString::number(TOutputProperties::SmallVal)};
Shinya Kitaoka 120a6e
  cmdline += " -maxtilesize " + maxTileSizes[m_maxTileSizeIndex];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString appname = QSettings().applicationName();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return cmdline;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TFarmTaskDeclaration final : public TPersistDeclaration {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TFarmTaskDeclaration(const std::string &id) : TPersistDeclaration(id) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TPersist *create() const override { return new TFarmTask; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} FarmTaskDeclaration("ttask");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TPersistDeclaration *TFarmTask::getDeclaration() const {
Shinya Kitaoka 120a6e
  return &FarmTaskDeclaration;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFarmTask::operator!=(const TFarmTask &task) { return !operator==(task); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TFarmTaskGroup::Imp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Imp() {}
Shinya Kitaoka 120a6e
  ~Imp() {
Shinya Kitaoka 120a6e
    // clearPointerContainer(m_tasks);
Shinya Kitaoka 120a6e
    std::vector<tfarmtask *="">::iterator it = m_tasks.begin();</tfarmtask>
Shinya Kitaoka 120a6e
    for (; it != m_tasks.end(); ++it) delete *it;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::vector<tfarmtask *=""> m_tasks;</tfarmtask>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTaskGroup::TFarmTaskGroup() : m_imp(new Imp()) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTaskGroup::TFarmTaskGroup(const QString &id, const QString &name,
Shinya Kitaoka 120a6e
                               const QString &cmdline, const QString &user,
Shinya Kitaoka 120a6e
                               const QString &host, int stepCount, int priority)
Shinya Kitaoka 120a6e
    : TFarmTask(id, name, cmdline, user, host, stepCount, priority)
Shinya Kitaoka 120a6e
    , m_imp(new Imp()) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFarmTaskGroup::changeChunkSize(int chunksize) {
Shinya Kitaoka 120a6e
  m_chunkSize  = chunksize;
Shinya Kitaoka 120a6e
  int subCount = tceil((m_to - m_from + 1) / (double)m_chunkSize);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (subCount > 1) {
Shinya Kitaoka 120a6e
    int ra = m_from;
Shinya Kitaoka 120a6e
    for (int i = 1; i <= subCount; ++i) {
Shinya Kitaoka 120a6e
      int rb = std::min(ra + m_chunkSize - 1, m_to);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      try {
Shinya Kitaoka 120a6e
        QString subName =
Shinya Kitaoka 120a6e
            m_name + " " + toString(ra, 2, '0') + "-" + toString(rb, 2, '0');
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        TFarmTask *subTask = new TFarmTask(
Shinya Kitaoka 120a6e
            m_id + "." + toString(i, 2, '0'), subName, true, m_user, m_hostName,
Shinya Kitaoka 120a6e
            rb - ra + 1, m_priority, m_taskFilePath, m_outputPath, ra, rb,
Shinya Kitaoka 120a6e
            m_step, m_shrink, m_multimedia, m_chunkSize, m_threadsIndex,
Shinya Kitaoka 120a6e
            m_maxTileSizeIndex, Overwrite_Off, false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        subTask->m_parentId = m_id;
Shinya Kitaoka 120a6e
        addTask(subTask);
Shinya Kitaoka 120a6e
      } catch (TException &) {
Shinya Kitaoka 120a6e
        // TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      ra = rb + 1;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTaskGroup::TFarmTaskGroup(const QString &id, const QString &name,
Shinya Kitaoka 120a6e
                               const QString &user, const QString &host,
Shinya Kitaoka 120a6e
                               int stepCount, int priority,
Shinya Kitaoka 120a6e
                               const TFilePath &taskFilePath,
Shinya Kitaoka 120a6e
                               const TFilePath &outputPath, int from, int to,
Shinya Kitaoka 120a6e
                               int step, int shrink, int multimedia,
Shinya Kitaoka 120a6e
                               int chunksize, int threadsIndex,
Shinya Kitaoka 120a6e
                               int maxTileSizeIndex)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    : TFarmTask(id, name, true, user, host, stepCount, priority, taskFilePath,
Shinya Kitaoka 120a6e
                outputPath, from, to, step, shrink, multimedia, chunksize,
Shinya Kitaoka 120a6e
                threadsIndex, maxTileSizeIndex, Overwrite_Off, false)
Shinya Kitaoka 120a6e
    , m_imp(new Imp()) {
Dave ba9da1
  int subCount = 0;
Campbell Barton e4aac6
  if (chunksize > 0) subCount = tceil((to - from + 1) / (double)chunksize);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int ra = from;
Shinya Kitaoka 120a6e
  if (subCount > 1) {
Shinya Kitaoka 120a6e
    for (int i = 1; i <= subCount; ++i) {
Shinya Kitaoka 120a6e
      int rb = std::min(ra + chunksize - 1, to);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      try {
Shinya Kitaoka 120a6e
        QString subName =
Shinya Kitaoka 120a6e
            name + " " + toString(ra, 2, '0') + "-" + toString(rb, 2, '0');
Shinya Kitaoka 120a6e
        stepCount = rb - ra + 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        TFarmTask *subTask =
Shinya Kitaoka 120a6e
            new TFarmTask(id + "." + toString(i, 2, '0'), subName, true, user,
Shinya Kitaoka 120a6e
                          host, stepCount, priority, taskFilePath, outputPath,
Shinya Kitaoka 120a6e
                          ra, rb, step, shrink, multimedia, chunksize,
Shinya Kitaoka 120a6e
                          threadsIndex, maxTileSizeIndex, Overwrite_Off, false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        subTask->m_parentId = id;
Shinya Kitaoka 120a6e
        addTask(subTask);
Shinya Kitaoka 120a6e
      } catch (TException &) {
Shinya Kitaoka 120a6e
        // TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      ra = rb + 1;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTaskGroup::TFarmTaskGroup(const QString &id, const QString &name,
Shinya Kitaoka 120a6e
                               const QString &user, const QString &host,
Shinya Kitaoka 120a6e
                               int stepCount, int priority,
Shinya Kitaoka 120a6e
                               const TFilePath &taskFilePath,
Shinya Kitaoka 120a6e
                               OverwriteBehavior overwrite, bool onlyvisible)
Shinya Kitaoka 120a6e
    : TFarmTask(id, name, false, user, host, stepCount, priority, taskFilePath,
Shinya Kitaoka 120a6e
                TFilePath(), 0, 0, 0, 0, 0, 0, 0, 0, overwrite, onlyvisible)
Shinya Kitaoka 120a6e
    , m_imp(new Imp()) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFarmTaskGroup::TFarmTaskGroup(const TFarmTaskGroup &src)
Shinya Kitaoka 120a6e
    : TFarmTask(src), m_imp(new TFarmTaskGroup::Imp()) {
Shinya Kitaoka 120a6e
  int count = src.getTaskCount();
Shinya Kitaoka 120a6e
  for (int i = 0; i < count; ++i) {
Shinya Kitaoka 120a6e
    TFarmTaskGroup &ssrc = const_cast<tfarmtaskgroup &="">(src);</tfarmtaskgroup>
Shinya Kitaoka 120a6e
    addTask(new TFarmTask(*ssrc.getTask(i)));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTaskGroup::~TFarmTaskGroup() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFarmTaskGroup::addTask(TFarmTask *task) {
Shinya Kitaoka 120a6e
  m_imp->m_tasks.push_back(task);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFarmTaskGroup::removeTask(TFarmTask *task) {
Shinya Kitaoka 120a6e
  std::vector<tfarmtask *="">::iterator it =</tfarmtask>
Shinya Kitaoka 120a6e
      std::find(m_imp->m_tasks.begin(), m_imp->m_tasks.end(), task);
Shinya Kitaoka 120a6e
  if (it != m_imp->m_tasks.end()) m_imp->m_tasks.erase(it);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TFarmTaskGroup::getTaskCount() const { return m_imp->m_tasks.size(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmTask *TFarmTaskGroup::getTask(int index) {
Shinya Kitaoka 120a6e
  std::vector<tfarmtask *="">::iterator it = m_imp->m_tasks.begin();</tfarmtask>
Shinya Kitaoka 120a6e
  std::advance(it, index);
Shinya Kitaoka 120a6e
  return it != m_imp->m_tasks.end() ? *it : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFarmTaskGroup::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.matchTag(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "info") {
Shinya Kitaoka 120a6e
      TFarmTask::loadData(is);
Shinya Kitaoka 120a6e
    } else if (tagName == "tasks") {
Shinya Kitaoka 120a6e
      while (!is.eos()) {
Shinya Kitaoka 120a6e
        TPersist *p = 0;
Shinya Kitaoka 120a6e
        is >> p;
Shinya Kitaoka 120a6e
        TFarmTask *task = dynamic_cast<tfarmtask *="">(p);</tfarmtask>
Shinya Kitaoka 120a6e
        if (task) addTask(task);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      throw TException(tagName + " : unexpected tag");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!is.matchEndTag()) throw TException(tagName + " : missing end tag");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFarmTaskGroup::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.openChild("info");
Shinya Kitaoka 120a6e
  TFarmTask::saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  os.openChild("tasks");
Shinya Kitaoka 120a6e
  std::vector<tfarmtask *="">::iterator it = m_imp->m_tasks.begin();</tfarmtask>
Shinya Kitaoka 120a6e
  for (; it != m_imp->m_tasks.end(); ++it) os << *it;
Shinya Kitaoka 120a6e
  os.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TFarmTaskGroupDeclaration final : public TPersistDeclaration {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TFarmTaskGroupDeclaration(const std::string &id) : TPersistDeclaration(id) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TPersist *create() const override { return new TFarmTaskGroup; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} FarmTaskGroupDeclaration("ttaskgroup");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TPersistDeclaration *TFarmTaskGroup::getDeclaration() const {
Shinya Kitaoka 120a6e
  return &FarmTaskGroupDeclaration;
Toshihiro Shimizu 890ddd
}