Mercurial > hg > orthanc-webviewer
comparison Orthanc/Core/Toolbox.cpp @ 69:fe8dab5c051f
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Aug 2015 21:23:42 +0200 |
parents | 902dedf9882a |
children | f869ea124433 |
comparison
equal
deleted
inserted
replaced
68:45da32410346 | 69:fe8dab5c051f |
---|---|
32 | 32 |
33 #include "PrecompiledHeaders.h" | 33 #include "PrecompiledHeaders.h" |
34 #include "Toolbox.h" | 34 #include "Toolbox.h" |
35 | 35 |
36 #include "OrthancException.h" | 36 #include "OrthancException.h" |
37 #include "Logging.h" | |
37 | 38 |
38 #include <string> | 39 #include <string> |
39 #include <stdint.h> | 40 #include <stdint.h> |
40 #include <string.h> | 41 #include <string.h> |
41 #include <boost/filesystem.hpp> | 42 #include <boost/filesystem.hpp> |
51 | 52 |
52 #if BOOST_HAS_REGEX == 1 | 53 #if BOOST_HAS_REGEX == 1 |
53 #include <boost/regex.hpp> | 54 #include <boost/regex.hpp> |
54 #endif | 55 #endif |
55 | 56 |
56 #if HAVE_GOOGLE_LOG == 1 | |
57 #include <glog/logging.h> | |
58 #endif | |
59 | |
60 #if defined(_WIN32) | 57 #if defined(_WIN32) |
61 #include <windows.h> | 58 #include <windows.h> |
62 #include <process.h> // For "_spawnvp()" | 59 #include <process.h> // For "_spawnvp()" and "_getpid()" |
63 #else | 60 #else |
64 #include <unistd.h> // For "execvp()" | 61 #include <unistd.h> // For "execvp()" |
65 #include <sys/wait.h> // For "waitpid()" | 62 #include <sys/wait.h> // For "waitpid()" |
66 #endif | 63 #endif |
67 | 64 |
438 { | 435 { |
439 try | 436 try |
440 { | 437 { |
441 return static_cast<uint64_t>(boost::filesystem::file_size(path)); | 438 return static_cast<uint64_t>(boost::filesystem::file_size(path)); |
442 } | 439 } |
443 catch (boost::filesystem::filesystem_error) | 440 catch (boost::filesystem::filesystem_error&) |
444 { | 441 { |
445 throw OrthancException(ErrorCode_InexistentFile); | 442 throw OrthancException(ErrorCode_InexistentFile); |
446 } | 443 } |
447 } | 444 } |
448 | 445 |
1133 int pid = fork(); | 1130 int pid = fork(); |
1134 | 1131 |
1135 if (pid == -1) | 1132 if (pid == -1) |
1136 { | 1133 { |
1137 // Error in fork() | 1134 // Error in fork() |
1138 #if HAVE_GOOGLE_LOG == 1 | 1135 #if ORTHANC_ENABLE_LOGGING == 1 |
1139 LOG(ERROR) << "Cannot fork a child process"; | 1136 LOG(ERROR) << "Cannot fork a child process"; |
1140 #endif | 1137 #endif |
1141 | 1138 |
1142 throw OrthancException(ErrorCode_SystemCommand); | 1139 throw OrthancException(ErrorCode_SystemCommand); |
1143 } | 1140 } |
1156 } | 1153 } |
1157 #endif | 1154 #endif |
1158 | 1155 |
1159 if (status != 0) | 1156 if (status != 0) |
1160 { | 1157 { |
1161 #if HAVE_GOOGLE_LOG == 1 | 1158 #if ORTHANC_ENABLE_LOGGING == 1 |
1162 LOG(ERROR) << "System command failed with status code " << status; | 1159 LOG(ERROR) << "System command failed with status code " << status; |
1163 #endif | 1160 #endif |
1164 | 1161 |
1165 throw OrthancException(ErrorCode_SystemCommand); | 1162 throw OrthancException(ErrorCode_SystemCommand); |
1166 } | 1163 } |
1272 { | 1269 { |
1273 return str.compare(0, prefix.size(), prefix) == 0; | 1270 return str.compare(0, prefix.size(), prefix) == 0; |
1274 } | 1271 } |
1275 } | 1272 } |
1276 | 1273 |
1274 | |
1275 int Toolbox::GetProcessId() | |
1276 { | |
1277 #if defined(_WIN32) | |
1278 return static_cast<int>(_getpid()); | |
1279 #else | |
1280 return static_cast<int>(getpid()); | |
1281 #endif | |
1282 } | |
1277 } | 1283 } |
1278 | 1284 |