changeset 6827:0aadb5a23a78

created Constants.h
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 21 May 2026 08:44:24 +0200
parents 65060f296783
children 13f0f6dda96d
files OrthancFramework/Sources/Constants.h OrthancFramework/UnitTestsSources/ToolboxTests.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp OrthancServer/Sources/ServerJobs/ArchiveJob.cpp OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp OrthancServer/Sources/main.cpp
diffstat 7 files changed, 66 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Sources/Constants.h	Thu May 21 08:44:24 2026 +0200
@@ -0,0 +1,35 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2023 Osimis S.A., Belgium
+ * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+ * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include <stdint.h>
+
+
+namespace Orthanc
+{
+  static const uint64_t KILOBYTE = 1024ull;
+  static const uint64_t MEGABYTE = 1024ull * 1024ull;
+  static const uint64_t GIGABYTE = 1024ull * 1024ull * 1024ull;
+}
--- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Tue May 19 15:12:28 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Thu May 21 08:44:24 2026 +0200
@@ -30,6 +30,7 @@
 #include <gtest/gtest.h>
 
 #include "../Sources/Compatibility.h"
+#include "../Sources/Constants.h"
 #include "../Sources/IDynamicObject.h"
 #include "../Sources/OrthancException.h"
 #include "../Sources/Toolbox.h"
@@ -477,3 +478,10 @@
     throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
   }
 }
+
+TEST(Toolbox, Constants)
+{
+  // Make sure that "16 * GIGABYTE" is not casted to a size_t on 32bit architectures
+  ASSERT_EQ(static_cast<int16_t>(16) * GIGABYTE, 16ull * 1024ull * 1024ull * 1024ull);
+  ASSERT_EQ(8, sizeof(static_cast<int16_t>(16) * GIGABYTE));
+}
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue May 19 15:12:28 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Thu May 21 08:44:24 2026 +0200
@@ -26,7 +26,9 @@
 
 #include "OrthancRestApi.h"
 
+#include "../../../OrthancFramework/Sources/CompatibilityMath.h"
 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h"
+#include "../../../OrthancFramework/Sources/Constants.h"
 #include "../../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
@@ -38,7 +40,6 @@
 #include "../../../OrthancFramework/Sources/Logging.h"
 #include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h"
 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
-#include "../../../OrthancFramework/Sources/CompatibilityMath.h"
 
 #include "../OrthancConfiguration.h"
 #include "../Search/DatabaseLookup.h"
@@ -1683,8 +1684,6 @@
       return;
     }
 
-    static const uint64_t MEGA_BYTES = 1024ull * 1024ull;
-
     std::string publicId = call.GetUriComponent("id", "");
 
     ResourceType type;
@@ -1696,14 +1695,14 @@
 
     Json::Value result = Json::objectValue;
     result["DiskSize"] = boost::lexical_cast<std::string>(diskSize);
-    result["DiskSizeMB"] = static_cast<unsigned int>(diskSize / MEGA_BYTES);
+    result["DiskSizeMB"] = static_cast<unsigned int>(diskSize / MEGABYTE);
     result["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize);
-    result["UncompressedSizeMB"] = static_cast<unsigned int>(uncompressedSize / MEGA_BYTES);
+    result["UncompressedSizeMB"] = static_cast<unsigned int>(uncompressedSize / MEGABYTE);
 
     result["DicomDiskSize"] = boost::lexical_cast<std::string>(dicomDiskSize);
-    result["DicomDiskSizeMB"] = static_cast<unsigned int>(dicomDiskSize / MEGA_BYTES);
+    result["DicomDiskSizeMB"] = static_cast<unsigned int>(dicomDiskSize / MEGABYTE);
     result["DicomUncompressedSize"] = boost::lexical_cast<std::string>(dicomUncompressedSize);
-    result["DicomUncompressedSizeMB"] = static_cast<unsigned int>(dicomUncompressedSize / MEGA_BYTES);
+    result["DicomUncompressedSizeMB"] = static_cast<unsigned int>(dicomUncompressedSize / MEGABYTE);
 
     switch (type)
     {
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Tue May 19 15:12:28 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Thu May 21 08:44:24 2026 +0200
@@ -24,6 +24,7 @@
 #include "../PrecompiledHeadersServer.h"
 #include "OrthancRestApi.h"
 
+#include "../../../OrthancFramework/Sources/Constants.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../../OrthancFramework/Sources/MetricsRegistry.h"
 #include "../../Plugins/Engine/OrthancPlugins.h"
@@ -241,8 +242,6 @@
       return;
     }
 
-    static const uint64_t MEGA_BYTES = 1024ull * 1024ull;
-
     uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances;
     OrthancRestApi::GetIndex(call).GetGlobalStatistics(diskSize, uncompressedSize, countPatients, 
                                                        countStudies, countSeries, countInstances);
@@ -250,8 +249,8 @@
     Json::Value result = Json::objectValue;
     result["TotalDiskSize"] = boost::lexical_cast<std::string>(diskSize);
     result["TotalUncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize);
-    result["TotalDiskSizeMB"] = static_cast<unsigned int>(diskSize / MEGA_BYTES);
-    result["TotalUncompressedSizeMB"] = static_cast<unsigned int>(uncompressedSize / MEGA_BYTES);
+    result["TotalDiskSizeMB"] = static_cast<unsigned int>(diskSize / MEGABYTE);
+    result["TotalUncompressedSizeMB"] = static_cast<unsigned int>(uncompressedSize / MEGABYTE);
     result["CountPatients"] = static_cast<unsigned int>(countPatients);
     result["CountStudies"] = static_cast<unsigned int>(countStudies);
     result["CountSeries"] = static_cast<unsigned int>(countSeries);
@@ -978,8 +977,6 @@
     OrthancRestApi::GetContext(call).GetPlugins().RefreshMetrics();
 #endif
 
-    static const float MEGA_BYTES = 1024 * 1024;
-
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances;
@@ -994,8 +991,8 @@
     context.GetIndex().GetLastChange(lastChange);
 
     MetricsRegistry& registry = context.GetMetricsRegistry();
-    registry.SetFloatValue("orthanc_disk_size_mb", static_cast<float>(diskSize) / MEGA_BYTES);
-    registry.SetFloatValue("orthanc_uncompressed_size_mb", static_cast<float>(diskSize) / MEGA_BYTES);
+    registry.SetFloatValue("orthanc_disk_size_mb", static_cast<float>(diskSize) / MEGABYTE);
+    registry.SetFloatValue("orthanc_uncompressed_size_mb", static_cast<float>(diskSize) / MEGABYTE);
     registry.SetIntegerValue("orthanc_count_patients", static_cast<int64_t>(countPatients));
     registry.SetIntegerValue("orthanc_count_studies", static_cast<int64_t>(countStudies));
     registry.SetIntegerValue("orthanc_count_series", static_cast<int64_t>(countSeries));
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Tue May 19 15:12:28 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Thu May 21 08:44:24 2026 +0200
@@ -26,12 +26,13 @@
 
 #include "../../../OrthancFramework/Sources/Cache/SharedArchive.h"
 #include "../../../OrthancFramework/Sources/Compression/HierarchicalZipWriter.h"
+#include "../../../OrthancFramework/Sources/Constants.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/DicomDirWriter.h"
 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../../OrthancFramework/Sources/Logging.h"
-#include "../../../OrthancFramework/Sources/OrthancException.h"
+#include "../../../OrthancFramework/Sources/MultiThreading/BlockingSharedMessageQueue.h"
 #include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h"
-#include "../../../OrthancFramework/Sources/MultiThreading/BlockingSharedMessageQueue.h"
+#include "../../../OrthancFramework/Sources/OrthancException.h"
 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
 #include "../OrthancConfiguration.h"
 #include "../ServerContext.h"
@@ -45,9 +46,6 @@
 #define snprintf _snprintf
 #endif
 
-static const uint64_t MEGA_BYTES = 1024ull * 1024;
-static const uint64_t GIGA_BYTES = 1024ull * 1024 * 1024;
-
 static const char* const MEDIA_IMAGES_FOLDER = "IMAGES"; 
 static const char* const KEY_DESCRIPTION = "Description";
 static const char* const KEY_INSTANCES_COUNT = "InstancesCount";
@@ -64,7 +62,7 @@
   static bool IsZip64Required(uint64_t uncompressedSize,
                               unsigned int countInstances)
   {
-    static const uint64_t      SAFETY_MARGIN = 64 * MEGA_BYTES;  // Should be large enough to hold DICOMDIR
+    static const uint64_t      SAFETY_MARGIN = 64 * MEGABYTE;  // Should be large enough to hold DICOMDIR
     static const unsigned int  FILES_MARGIN = 10;
 
     /**
@@ -74,7 +72,7 @@
      * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64
      **/
 
-    const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN ||
+    const bool isZip64 = (uncompressedSize >= 2 * GIGABYTE - SAFETY_MARGIN ||
                           countInstances >= 65535 - FILES_MARGIN);
 
     LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size "
@@ -1353,10 +1351,8 @@
     value = Json::objectValue;
     value[KEY_DESCRIPTION] = description_;
     value[KEY_INSTANCES_COUNT] = instancesCount_;
-    value[KEY_UNCOMPRESSED_SIZE_MB] =
-      static_cast<unsigned int>(uncompressedSize_ / MEGA_BYTES);
-    value[KEY_ARCHIVE_SIZE_MB] =
-      static_cast<unsigned int>(archiveSize_ / MEGA_BYTES);
+    value[KEY_UNCOMPRESSED_SIZE_MB] = static_cast<unsigned int>(uncompressedSize_ / MEGABYTE);
+    value[KEY_ARCHIVE_SIZE_MB] = static_cast<unsigned int>(archiveSize_ / MEGABYTE);
 
     // New in Orthanc 1.9.4
     value[KEY_ARCHIVE_SIZE] = boost::lexical_cast<std::string>(archiveSize_);
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Tue May 19 15:12:28 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Thu May 21 08:44:24 2026 +0200
@@ -25,6 +25,7 @@
 #include "OrthancPeerStoreJob.h"
 
 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h"
+#include "../../../OrthancFramework/Sources/Constants.h"
 #include "../../../OrthancFramework/Sources/Logging.h"
 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
 #include "../ServerContext.h"
@@ -241,9 +242,8 @@
       value["Transcode"] = GetTransferSyntaxUid(transferSyntax_);
     }
 
-    static const uint64_t MEGA_BYTES = 1024ull * 1024ull;
     value["Size"] = boost::lexical_cast<std::string>(size_);
-    value["SizeMB"] = static_cast<unsigned int>(size_ / MEGA_BYTES);
+    value["SizeMB"] = static_cast<unsigned int>(size_ / MEGABYTE);
   }
 
 
--- a/OrthancServer/Sources/main.cpp	Tue May 19 15:12:28 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Thu May 21 08:44:24 2026 +0200
@@ -27,6 +27,7 @@
 #include "../../OrthancFramework/Sources/Compatibility.h"
 #include "../../OrthancFramework/Sources/Compression/GzipCompressor.h"
 #include "../../OrthancFramework/Sources/Compression/ZipReader.h"
+#include "../../OrthancFramework/Sources/Constants.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
 #include "../../OrthancFramework/Sources/DicomNetworking/DicomAssociationParameters.h"
 #include "../../OrthancFramework/Sources/DicomNetworking/DicomServer.h"
@@ -1128,11 +1129,10 @@
       httpServer.SetRequestTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpRequestTimeout", 30));
 
       // New in Orthanc 1.12.11
-      static const uint64_t MEGABYTE = 1024ull * 1024ull;
       const unsigned int maxBodySize = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumRequestBodySizeMB", 8192);
       if (maxBodySize != 0)
       {
-        const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(static_cast<uint64_t>(maxBodySize) * MEGABYTE);
+        const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(maxBodySize * MEGABYTE);
         LOG(WARNING) << "Limiting the maximum body size in HTTP requests to " << (size / MEGABYTE) << "MB";
         httpServer.SetMaxBodySize(size);
       }
@@ -1144,7 +1144,7 @@
       const unsigned int maxSizeInArchive = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumFileSizeInArchiveMB", 4096);
       if (maxSizeInArchive != 0)
       {
-        const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(static_cast<uint64_t>(maxSizeInArchive) * MEGABYTE);
+        const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(maxSizeInArchive * MEGABYTE);
         LOG(WARNING) << "Limiting on the maximum file size uncompressed from ZIP/gzip archives to " << (size / MEGABYTE) << "MB";
         ZipReader::SetMaximumUncompressedFileSize(size);
         GzipCompressor::SetMaximumUncompressedFileSize(size);