Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Various TFarm fixes (#1140)

Dave5a94754d3cdc
diff --git a/toonz/sources/common/tapptools/tcli.cpp b/toonz/sources/common/tapptools/tcli.cpp
index 3f5f2dac6..d3ee46df5 100644
--- a/toonz/sources/common/tapptools/tcli.cpp
+++ b/toonz/sources/common/tapptools/tcli.cpp
@@ -4,6 +4,9 @@
#include "tconvert.h"
#include <ctype.h>
+#include "tversion.h"
+using namespace TVER;
+
using namespace std;
using namespace TCli;
@@ -16,11 +19,17 @@ namespace {
//---------------------------------------------------------
-void printToonzRelease(ostream &out) { out << "Toonz 7.1" << endl; }
+void printToonzRelease(ostream &out) {
+ TVER::ToonzVersion tver;
+ out << tver.getAppVersionInfo("") << endl;
+}
//---------------------------------------------------------
-void printLibRelease(ostream &out) { out << "Tnzcore 1.0 - " __DATE__ << endl; }
+void printLibRelease(ostream &out) {
+ TVER::ToonzVersion tver;
+ out << tver.getAppVersionInfo("") << " - " __DATE__ << endl;
+}
//---------------------------------------------------------
} // namespace
@@ -50,6 +59,7 @@ static SpecialUsageElement bra("[");
static SpecialUsageElement ket("]");
static Switcher help("-help", "Print this help page");
static Switcher release("-release", "Print the current Toonz version");
+static Switcher version("-version", "Print the current Toonz version");
static Switcher libRelease("-librelease", "");
// hidden: print the lib version
@@ -261,7 +271,7 @@ UsageLine TCli::operator+(const UsageLine &a, const Optional &b) {
Optional::Optional(const UsageLine &ul) : UsageLine(ul.getCount() + 2) {
m_elements[0] = &bra;
m_elements[m_count - 1] = &ket;
- for (int i = 0; i < ul.getCount(); i++) m_elements[i + 1] = ul[i];
+ for (int i = 0; i < ul.getCount(); i++) m_elements[i + 1]= ul[i];
}
//=========================================================
@@ -329,6 +339,7 @@ UsageImp::UsageImp(string progName)
void UsageImp::addStandardUsages() {
add(help);
add(release);
+ add(version);
add(libRelease);
}
@@ -700,7 +711,7 @@ bool Usage::parse(int argc, char *argv[], std::ostream &err) {
print(err);
return false;
}
- if (release) {
+ if (release || version) {
printToonzRelease(err);
return false;
}
diff --git a/toonz/sources/include/tversion.h b/toonz/sources/include/tversion.h
new file mode 100644
index 000000000..5bf7205d2
--- /dev/null
+++ b/toonz/sources/include/tversion.h
@@ -0,0 +1,57 @@
+#pragma once
+
+#ifndef TVER_INCLUDED
+#define TVER_INCLUDED
+
+namespace TVER {
+
+class ToonzVersion {
+public:
+ std::string getAppName(void);
+ float getAppVersion(void);
+ float getAppRevision(void);
+ std::string getAppVersionString(void);
+ std::string getAppRevisionString(void);
+ std::string getAppVersionInfo(std::string msg);
+
+private:
+ const char *applicationName = "OpenToonz";
+ const float applicationVersion = 1.1;
+ const float applicationRevision = 3;
+};
+
+std::string ToonzVersion::getAppName(void) {
+ std::string appname = applicationName;
+ return appname;
+}
+float ToonzVersion::getAppVersion(void) {
+ float appver = applicationVersion;
+ return appver;
+}
+float ToonzVersion::getAppRevision(void) {
+ float apprev = applicationRevision;
+ return apprev;
+}
+std::string ToonzVersion::getAppVersionString(void) {
+ char buffer[50];
+ sprintf(buffer, "%.1f", applicationVersion);
+ std::string appver = std::string(buffer);
+ return appver;
+}
+std::string ToonzVersion::getAppRevisionString(void) {
+ char buffer[50];
+ sprintf(buffer, "%g", applicationRevision);
+ std::string apprev = std::string(buffer);
+ return apprev;
+}
+std::string ToonzVersion::getAppVersionInfo(std::string msg) {
+ std::string appinfo = std::string(applicationName);
+ appinfo += " " + msg + " v";
+ appinfo += getAppVersionString();
+ appinfo += "." + getAppRevisionString();
+ return appinfo;
+}
+
+} // namespace TVER
+
+#endif // TVER_INCLUDED
diff --git a/toonz/sources/tcomposer/tcomposer.cpp b/toonz/sources/tcomposer/tcomposer.cpp
index 1eb9d3201..581945306 100644
--- a/toonz/sources/tcomposer/tcomposer.cpp
+++ b/toonz/sources/tcomposer/tcomposer.cpp
@@ -85,7 +85,7 @@ typedef QualifierT<TFilePath> FilePathQualifier;
namespace {
double currentCameraSize = 12;
double getCurrentCameraSize() { return currentCameraSize; }
-}
+} // namespace
//========================================================================
//
@@ -223,7 +223,7 @@ void tcomposerRunOutOfContMemHandler(unsigned long size) {
TImageCache::instance()->clear(true);
exit(2);
}
-}
+} // namespace
//==============================================================================================
@@ -403,7 +403,7 @@ static std::pair<int, int> generateMovie(ToonzScene *scene, const TFilePath &fp,
r0 = r0 - 1;
r1 = r1 - 1;
- if (r0 < 0) r0 = 0;
+ if (r0 < 0) r0 = 0;
if (r1 < 0 || r1 >= scene->getFrameCount()) r1 = scene->getFrameCount() - 1;
string msg;
assert(r1 >= r0);
@@ -557,6 +557,9 @@ static std::pair<int, int> generateMovie(ToonzScene *scene, const TFilePath &fp,
// TODO: il main comincia a diventare troppo lungo. Forse val la pena
// separarlo in varie funzioni
// (tipo initToonzEnvironment(), parseCommandLine(), ecc)
+// TODO: the main starts getting too long. Perhaps it is worth
+// separated into various functions
+// (type initToonzEnvironment (), ParseCommandLine (), etc.)
DV_IMPORT_API void initStdFx();
DV_IMPORT_API void initColorFx();
@@ -658,8 +661,8 @@ int main(int argc, char *argv[]) {
TVectorBrushStyle::setRootDir(libraryFolder);
TPalette::setRootDir(libraryFolder);
TImageStyle::setLibraryDir(libraryFolder);
- TFilePath cacheRoot = ToonzFolder::getCacheRootFolder();
- if (cacheRoot.isEmpty()) cacheRoot = TEnv::getStuffDir() + "cache";
+ TFilePath cacheRoot = ToonzFolder::getCacheRootFolder();
+ if (cacheRoot.isEmpty()) cacheRoot= TEnv::getStuffDir() + "cache";
TImageCache::instance()->setRootDir(cacheRoot);
// #endif
@@ -944,8 +947,8 @@ int main(int argc, char *argv[]) {
DVGui::info(QString::fromStdString(msg));
TImageCache::instance()->clear(true);
} catch (TException &e) {
- msg = "Untrapped exception: " + ::to_string(e.getMessage()), cout << msg
- << endl;
+ msg = "Untrapped exception: " + ::to_string(e.getMessage()),
+ cout << msg << endl;
m_userLog->error(msg);
TImageCache::instance()->clear(true);
} catch (...) {
diff --git a/toonz/sources/tnzcore/CMakeLists.txt b/toonz/sources/tnzcore/CMakeLists.txt
index 8b605b787..76bf3891e 100644
--- a/toonz/sources/tnzcore/CMakeLists.txt
+++ b/toonz/sources/tnzcore/CMakeLists.txt
@@ -120,6 +120,7 @@ set(HEADERS ${MOC_HEADERS}
../include/tenv.h
../include/tmeshimage.h
../include/tgldisplaylistsmanager.h
+ ../include/tversion.h
)
set(SOURCES
diff --git a/toonz/sources/toonzfarm/tfarmcontroller/tfarmcontroller.cpp b/toonz/sources/toonzfarm/tfarmcontroller/tfarmcontroller.cpp
index 7efb069aa..a1c038a96 100644
--- a/toonz/sources/toonzfarm/tfarmcontroller/tfarmcontroller.cpp
+++ b/toonz/sources/toonzfarm/tfarmcontroller/tfarmcontroller.cpp
@@ -8,6 +8,8 @@
#include "tfilepath_io.h"
#include "service.h"
#include "tcli.h"
+#include "tversion.h"
+using namespace TVER;
#include "tthreadmessage.h"
#include "tthread.h"
@@ -54,16 +56,29 @@ int inline STRICMP(const char *a, const char *b) {
namespace {
TFilePath getGlobalRoot() {
+ TVER::ToonzVersion tver;
TFilePath rootDir;
#ifdef _WIN32
- TFilePath name(L"SOFTWARE\\OpenToonz\\OpenToonz\\1.0\\FARMROOT");
+ std::string regpath = "SOFTWARE\\" + tver.getAppName() + "\\" +
+ tver.getAppName() + "\\" + tver.getAppVersionString() +
+ "\\FARMROOT";
+ TFilePath name(regpath);
rootDir = TFilePath(TSystem::getSystemValue(name).toStdString());
#else
- // Leggo la globalRoot da File txt
- Tifstream is(
- TFilePath("./OpenToonz_1.0.app/Contents/Resources/configfarmroot.txt"));
+// Leggo la globalRoot da File txt
+#ifdef MACOSX
+ // If MACOSX, change to MACOSX path
+ std::string unixpath = "./" + tver.getAppName() + "_" +
+ tver.getAppVersionString() +
+ ".app/Contents/Resources/configfarmroot.txt";
+#else
+ // set path to something suitable for most linux (Unix?) systems
+ std::string unixpath = "/etc/" + tver.getAppName() + "/opentoonz.conf";
+#endif
+ TFilePath name(unixpath);
+ Tifstream is(name);
if (is) {
char line[1024];
is.getline(line, 80);
@@ -87,17 +102,29 @@ TFilePath getGlobalRoot() {
//--------------------------------------------------------------------
TFilePath getLocalRoot() {
+ TVER::ToonzVersion tver;
TFilePath lroot;
#ifdef _WIN32
- TFilePath name(L"SOFTWARE\\OpenToonz\\OpenToonz\\1.0\\TOONZROOT");
+std:
+ string regpath = "SOFTWARE\\" + tver.getAppName() + "\\" + tver.getAppName() +
+ "\\" + tver.getAppVersionString() + "\\FARMROOT";
+ TFilePath name(regpath);
lroot = TFilePath(TSystem::getSystemValue(name).toStdString()) +
TFilePath("toonzfarm");
#else
- // Leggo la localRoot da File txt
-
- Tifstream is(
- TFilePath("./OpenToonz_1.0.app/Contents/Resources/configfarmroot.txt"));
+// Leggo la localRoot da File txt
+#ifdef MACOSX
+ // If MACOSX, change to MACOSX path
+ std::string unixpath = "./" + tver.getAppName() + "_" +
+ tver.getAppVersionString() +
+ ".app/Contents/Resources/configfarmroot.txt";
+#else
+ // set path to something suitable for most linux (Unix?) systems
+ std::string unixpath = "/etc/" + tver.getAppName() + "/opentoonz.conf";
+#endif
+ TFilePath name(unixpath);
+ Tifstream is(name);
if (is) {
char line[1024];
is.getline(line, 80);
@@ -212,7 +239,7 @@ public:
TPersist *create() const override { return new CtrlFarmTask; }
} Declaration("tfarmtask");
-}
+} // namespace
//------------------------------------------------------------------------------
@@ -739,8 +766,8 @@ inline QString toString(const TFarmTask &task, int ver) {
ss += ",";
ss += QString::number(task.m_platform) + ",";
- int depCount = 0;
- if (task.m_dependencies) depCount = task.m_dependencies->getTaskCount();
+ int depCount = 0;
+ if (task.m_dependencies) depCount= task.m_dependencies->getTaskCount();
ss += QString::number(depCount);
@@ -1292,8 +1319,8 @@ bool FarmController::tryToStartTask(CtrlFarmTask *task) {
map<TaskId, CtrlFarmTask *>::iterator itSubTask =
m_tasks.find(TaskId(*itSubTaskId));
if (itSubTask != m_tasks.end()) {
- CtrlFarmTask *subTask = itSubTask->second;
- if (tryToStartTask(subTask)) started = true;
+ CtrlFarmTask *subTask = itSubTask->second;
+ if (tryToStartTask(subTask)) started= true;
}
}
@@ -1674,7 +1701,7 @@ void FarmController::queryTaskShortInfo(const QString &id, QString &parentId,
void FarmController::attachServer(const QString &name, const QString &addr,
int port) {
- FarmServerProxy *server = 0;
+ FarmServerProxy *server = 0;
map<QString, FarmServerProxy *>::iterator it = m_servers.begin();
for (; it != m_servers.end(); ++it) {
FarmServerProxy *s = it->second;
@@ -1833,8 +1860,8 @@ void FarmController::taskCompleted(const QString &taskId, int exitCode) {
} else {
switch (exitCode) {
case 0:
- task->m_status = Completed;
- if (isAScript(task)) task->m_successfullSteps = task->m_stepCount;
+ task->m_status = Completed;
+ if (isAScript(task)) task->m_successfullSteps= task->m_stepCount;
break;
case RENDER_LICENSE_NOT_FOUND:
task->m_status = Waiting;
@@ -2202,6 +2229,7 @@ public:
void ControllerService::onStart(int argc, char *argv[]) {
// Initialize thread components
TThread::init();
+ TVER::ToonzVersion tver;
if (isRunningAsConsoleApp()) {
// i messaggi verranno ridiretti sullo standard output
@@ -2212,7 +2240,8 @@ void ControllerService::onStart(int argc, char *argv[]) {
if (!lRootDirExists) {
QString errMsg("Unable to start the Controller");
errMsg += "\n";
- errMsg += "The directory specified as Local Root does not exist";
+ errMsg += "The directory " + lRootDir.getQString() +
+ " specified as Local Root does not exist";
errMsg += "\n";
addToMessageLog(errMsg);
@@ -2224,12 +2253,14 @@ void ControllerService::onStart(int argc, char *argv[]) {
TFilePath logFilePath = lRootDir + "controller.log";
m_userLog = new TUserLog(logFilePath);
}
-
- m_userLog->info("ToonzFarm Controller 1.0\n\n");
+std:
+ string appverinfo = tver.getAppVersionInfo("Farm Controller") + "\n\n";
+ m_userLog->info(appverinfo.c_str());
TFilePath globalRoot = getGlobalRoot();
if (globalRoot.isEmpty()) {
- QString errMsg("Unable to get FARMROOT environment variable\n");
+ QString errMsg("Unable to get FARMROOT environment variable (" +
+ globalRoot.getQString() + ")\n");
addToMessageLog(errMsg);
// exit the program
@@ -2242,8 +2273,8 @@ void ControllerService::onStart(int argc, char *argv[]) {
if (!fs.isDirectory()) globalRootExists = false;
if (!globalRootExists) {
- QString errMsg(
- "The directory specified as TFARMGLOBALROOT does not exist\n");
+ QString errMsg("The directory " + globalRoot.getQString() +
+ " specified as TFARMGLOBALROOT does not exist\n");
addToMessageLog(errMsg);
// exit the program
diff --git a/toonz/sources/toonzfarm/tfarmserver/tfarmserver.cpp b/toonz/sources/toonzfarm/tfarmserver/tfarmserver.cpp
index c05d0486a..0b4b62cbf 100644
--- a/toonz/sources/toonzfarm/tfarmserver/tfarmserver.cpp
+++ b/toonz/sources/toonzfarm/tfarmserver/tfarmserver.cpp
@@ -1,5 +1,4 @@
-
#include "tfarmserver.h"
#include "tfarmexecutor.h"
#include "tfarmcontroller.h"
@@ -11,6 +10,8 @@
#include "tlog.h"
#include "tfilepath_io.h"
#include "tcli.h"
+#include "tversion.h"
+using namespace TVER;
#include <string>
#include <map>
@@ -62,16 +63,28 @@ namespace {
//--------------------------------------------------------------------
TFilePath getGlobalRoot() {
+ TVER::ToonzVersion tver;
TFilePath rootDir;
#ifdef _WIN32
- TFilePath name(L"SOFTWARE\\OpenToonz\\OpenToonz\\1.0\\FARMROOT");
+ std::string regpath = "SOFTWARE\\" + tver.getAppName() + "\\" +
+ tver.getAppName() + "\\" + tver.getAppVersionString() +
+ "\\FARMROOT";
+ TFilePath name(regpath);
rootDir = TFilePath(TSystem::getSystemValue(name).toStdString());
#else
- // Leggo la localRoot da File txt
-
- Tifstream is(
- TFilePath("./OpenToonz_1.0.app/Contents/Resources/configfarmroot.txt"));
+// Leggo la localRoot da File txt
+#ifdef MACOSX
+ // If MACOSX, change to MACOSX path
+ std::string unixpath = "./" + tver.getAppName() + "_" +
+ tver.getAppVersionString() +
+ ".app/Contents/Resources/configfarmroot.txt";
+#else
+ // set path to something suitable for most linux (Unix?) systems
+ std::string unixpath = "/etc/" + tver.getAppName() + "/opentoonz.conf";
+#endif
+ TFilePath name(unixpath);
+ Tifstream is(name);
if (is) {
char line[1024];
is.getline(line, 80);
@@ -95,15 +108,28 @@ TFilePath getGlobalRoot() {
//--------------------------------------------------------------------
TFilePath getLocalRoot() {
+ TVER::ToonzVersion tver;
TFilePath lroot;
#ifdef _WIN32
- TFilePath name("SOFTWARE\\OpenToonz\\OpenToonz\\1.0\\TOONZROOT");
+ QString regpath = QString::fromStdString(
+ "SOFTWARE\\" + tver.getAppName() + "\\" + tver.getAppName() + "\\" +
+ tver.getAppVersionString() + "\\FARMROOT");
+ TFilePath name(regpath);
lroot = TFilePath(TSystem::getSystemValue(name).toStdString()) +
TFilePath("toonzfarm");
#else
- Tifstream is(
- TFilePath("./OpenToonz_1.0.app/Contents/Resources/configfarmroot.txt"));
+#ifdef MACOSX
+ // If MACOSX, change to MACOSX path
+ std::string unixpath = "./" + tver.getAppName() + "_" +
+ tver.getAppVersionString() +
+ ".app/Contents/Resources/configfarmroot.txt";
+#else
+ // set path to something suitable for most linux (Unix?) systems
+ std::string unixpath = "/etc/" + tver.getAppName() + "/opentoonz.conf";
+#endif
+ TFilePath name(unixpath);
+ Tifstream is(name);
if (is) {
char line[1024];
is.getline(line, 80);
@@ -723,6 +749,7 @@ static bool loadServerData(const QString &hostname, QString &addr, int &port) {
void FarmServerService::onStart(int argc, char *argv[]) {
// Initialize thread components
TThread::init();
+ TVER::ToonzVersion tver;
#ifdef _WIN32
// DebugBreak();
@@ -735,7 +762,8 @@ void FarmServerService::onStart(int argc, char *argv[]) {
if (!lRootDirExists) {
std::string errMsg("Unable to start the Server");
errMsg += "\n";
- errMsg += "The directory specified as Local Root does not exist";
+ errMsg += "The directory " + ::to_string(lRootDir) +
+ " specified as Local Root does not exist";
errMsg += "\n";
addToMessageLog(errMsg);
@@ -751,7 +779,8 @@ void FarmServerService::onStart(int argc, char *argv[]) {
TFilePath gRootDir = getGlobalRoot();
if (::to_string(gRootDir) == "") {
- std::string errMsg("Unable to get TFARMGLOBALROOT environment variable");
+ std::string errMsg("Unable to get TFARMGLOBALROOT environment variable (" +
+ ::to_string(gRootDir) + ")");
addToMessageLog(errMsg);
// DEBUG MAC SERVIZIO (DA TOGLIERE)
@@ -807,7 +836,9 @@ void FarmServerService::onStart(int argc, char *argv[]) {
m_userLog = new TUserLog(logFilePath);
}
- m_userLog->info("ToonzFarm Server 1.0");
+std:
+ string appverinfo = tver.getAppVersionInfo("Farm Server") + "\n\n";
+ m_userLog->info(appverinfo.c_str());
// legge dal file di configurazione dei server il numero di porta da
// utilizzare
@@ -819,7 +850,8 @@ void FarmServerService::onStart(int argc, char *argv[]) {
msg += TSystem::getHostName();
msg += " from the servers config file";
msg += "\n";
- msg += "Using the default port number 8002";
+ msg += "Using the default port number ";
+ msg += QString::number(m_port);
msg += "\n";
msg += "\n";