comparison OrthancServer/Sources/main.cpp @ 5833:58c549b881ae find-refactoring-clean

merged find-refactoring -> find-refactoring-clean
author Alain Mazy <am@orthanc.team>
date Wed, 09 Oct 2024 11:01:11 +0200
parents 272b0d0eef38
children
comparison
equal deleted inserted replaced
5754:f75596b224e0 5833:58c549b881ae
823 PrintErrorCode(ErrorCode_DatabaseCannotSerialize, "Database could not serialize access due to concurrent update, the transaction should be retried"); 823 PrintErrorCode(ErrorCode_DatabaseCannotSerialize, "Database could not serialize access due to concurrent update, the transaction should be retried");
824 PrintErrorCode(ErrorCode_Revision, "A bad revision number was provided, which might indicate conflict between multiple writers"); 824 PrintErrorCode(ErrorCode_Revision, "A bad revision number was provided, which might indicate conflict between multiple writers");
825 PrintErrorCode(ErrorCode_MainDicomTagsMultiplyDefined, "A main DICOM Tag has been defined multiple times for the same resource level"); 825 PrintErrorCode(ErrorCode_MainDicomTagsMultiplyDefined, "A main DICOM Tag has been defined multiple times for the same resource level");
826 PrintErrorCode(ErrorCode_ForbiddenAccess, "Access to a resource is forbidden"); 826 PrintErrorCode(ErrorCode_ForbiddenAccess, "Access to a resource is forbidden");
827 PrintErrorCode(ErrorCode_DuplicateResource, "Duplicate resource"); 827 PrintErrorCode(ErrorCode_DuplicateResource, "Duplicate resource");
828 PrintErrorCode(ErrorCode_IncompatibleConfigurations, "Your configuration file contains configuration that are mutually incompatible");
828 PrintErrorCode(ErrorCode_SQLiteNotOpened, "SQLite: The database is not opened"); 829 PrintErrorCode(ErrorCode_SQLiteNotOpened, "SQLite: The database is not opened");
829 PrintErrorCode(ErrorCode_SQLiteAlreadyOpened, "SQLite: Connection is already open"); 830 PrintErrorCode(ErrorCode_SQLiteAlreadyOpened, "SQLite: Connection is already open");
830 PrintErrorCode(ErrorCode_SQLiteCannotOpen, "SQLite: Unable to open the database"); 831 PrintErrorCode(ErrorCode_SQLiteCannotOpen, "SQLite: Unable to open the database");
831 PrintErrorCode(ErrorCode_SQLiteStatementAlreadyUsed, "SQLite: This cached statement is already being referred to"); 832 PrintErrorCode(ErrorCode_SQLiteStatementAlreadyUsed, "SQLite: This cached statement is already being referred to");
832 PrintErrorCode(ErrorCode_SQLiteExecute, "SQLite: Cannot execute a command"); 833 PrintErrorCode(ErrorCode_SQLiteExecute, "SQLite: Cannot execute a command");
834 PrintErrorCode(ErrorCode_SQLiteCommitWithoutTransaction, "SQLite: Committing a nonexistent transaction"); 835 PrintErrorCode(ErrorCode_SQLiteCommitWithoutTransaction, "SQLite: Committing a nonexistent transaction");
835 PrintErrorCode(ErrorCode_SQLiteRegisterFunction, "SQLite: Unable to register a function"); 836 PrintErrorCode(ErrorCode_SQLiteRegisterFunction, "SQLite: Unable to register a function");
836 PrintErrorCode(ErrorCode_SQLiteFlush, "SQLite: Unable to flush the database"); 837 PrintErrorCode(ErrorCode_SQLiteFlush, "SQLite: Unable to flush the database");
837 PrintErrorCode(ErrorCode_SQLiteCannotRun, "SQLite: Cannot run a cached statement"); 838 PrintErrorCode(ErrorCode_SQLiteCannotRun, "SQLite: Cannot run a cached statement");
838 PrintErrorCode(ErrorCode_SQLiteCannotStep, "SQLite: Cannot step over a cached statement"); 839 PrintErrorCode(ErrorCode_SQLiteCannotStep, "SQLite: Cannot step over a cached statement");
839 PrintErrorCode(ErrorCode_SQLiteBindOutOfRange, "SQLite: Bing a value while out of range (serious error)"); 840 PrintErrorCode(ErrorCode_SQLiteBindOutOfRange, "SQLite: Bind a value while out of range (serious error)");
840 PrintErrorCode(ErrorCode_SQLitePrepareStatement, "SQLite: Cannot prepare a cached statement"); 841 PrintErrorCode(ErrorCode_SQLitePrepareStatement, "SQLite: Cannot prepare a cached statement");
841 PrintErrorCode(ErrorCode_SQLiteTransactionAlreadyStarted, "SQLite: Beginning the same transaction twice"); 842 PrintErrorCode(ErrorCode_SQLiteTransactionAlreadyStarted, "SQLite: Beginning the same transaction twice");
842 PrintErrorCode(ErrorCode_SQLiteTransactionCommit, "SQLite: Failure when committing the transaction"); 843 PrintErrorCode(ErrorCode_SQLiteTransactionCommit, "SQLite: Failure when committing the transaction");
843 PrintErrorCode(ErrorCode_SQLiteTransactionBegin, "SQLite: Cannot start a transaction"); 844 PrintErrorCode(ErrorCode_SQLiteTransactionBegin, "SQLite: Cannot start a transaction");
844 PrintErrorCode(ErrorCode_DirectoryOverFile, "The directory to be created is already occupied by a regular file"); 845 PrintErrorCode(ErrorCode_DirectoryOverFile, "The directory to be created is already occupied by a regular file");
1515 IStorageArea& storageArea, 1516 IStorageArea& storageArea,
1516 OrthancPlugins *plugins, 1517 OrthancPlugins *plugins,
1517 bool loadJobsFromDatabase) 1518 bool loadJobsFromDatabase)
1518 { 1519 {
1519 size_t maxCompletedJobs; 1520 size_t maxCompletedJobs;
1521 bool readOnly;
1520 1522
1521 { 1523 {
1522 OrthancConfiguration::ReaderLock lock; 1524 OrthancConfiguration::ReaderLock lock;
1523 1525
1524 // These configuration options must be set before creating the 1526 // These configuration options must be set before creating the
1542 if (maxCompletedJobs == 0) 1544 if (maxCompletedJobs == 0)
1543 { 1545 {
1544 LOG(WARNING) << "Setting option \"JobsHistorySize\" to zero is not recommended"; 1546 LOG(WARNING) << "Setting option \"JobsHistorySize\" to zero is not recommended";
1545 } 1547 }
1546 1548
1549 // New option in Orthanc 1.12.5
1550 readOnly = lock.GetConfiguration().GetBooleanParameter("ReadOnly", false);
1551
1547 // Configuration of DICOM TLS for Orthanc SCU (since Orthanc 1.9.0) 1552 // Configuration of DICOM TLS for Orthanc SCU (since Orthanc 1.9.0)
1548 DicomAssociationParameters::SetDefaultOwnCertificatePath( 1553 DicomAssociationParameters::SetDefaultOwnCertificatePath(
1549 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""), 1554 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""),
1550 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, "")); 1555 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, ""));
1551 DicomAssociationParameters::SetDefaultTrustedCertificatesPath( 1556 DicomAssociationParameters::SetDefaultTrustedCertificatesPath(
1556 // New option in Orthanc 1.9.3 1561 // New option in Orthanc 1.9.3
1557 DicomAssociationParameters::SetDefaultRemoteCertificateRequired( 1562 DicomAssociationParameters::SetDefaultRemoteCertificateRequired(
1558 lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_REMOTE_CERTIFICATE_REQUIRED, true)); 1563 lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_REMOTE_CERTIFICATE_REQUIRED, true));
1559 } 1564 }
1560 1565
1561 ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs); 1566 ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs, readOnly);
1562 1567
1563 { 1568 {
1564 OrthancConfiguration::ReaderLock lock; 1569 OrthancConfiguration::ReaderLock lock;
1565 1570
1566 context.SetCompressionEnabled(lock.GetConfiguration().GetBooleanParameter("StorageCompression", false)); 1571 if (context.IsReadOnly())
1567 context.SetStoreMD5ForAttachments(lock.GetConfiguration().GetBooleanParameter("StoreMD5ForAttachments", true)); 1572 {
1568 1573 LOG(WARNING) << "READ-ONLY SYSTEM: ignoring these configurations: StorageCompression, StoreMD5ForAttachments, OverwriteInstances, MaximumPatientCount, MaximumStorageSize, MaximumStorageMode, SaveJobs";
1569 // New option in Orthanc 1.4.2 1574 }
1570 context.SetOverwriteInstances(lock.GetConfiguration().GetBooleanParameter("OverwriteInstances", false)); 1575 else
1571 1576 {
1572 try 1577 context.SetCompressionEnabled(lock.GetConfiguration().GetBooleanParameter("StorageCompression", false));
1573 { 1578 context.SetStoreMD5ForAttachments(lock.GetConfiguration().GetBooleanParameter("StoreMD5ForAttachments", true));
1574 context.GetIndex().SetMaximumPatientCount(lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumPatientCount", 0)); 1579
1575 } 1580 // New option in Orthanc 1.4.2
1576 catch (...) 1581 context.SetOverwriteInstances(lock.GetConfiguration().GetBooleanParameter("OverwriteInstances", false));
1577 { 1582
1578 context.GetIndex().SetMaximumPatientCount(0); 1583 try
1579 } 1584 {
1580 1585 context.GetIndex().SetMaximumPatientCount(lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumPatientCount", 0));
1581 try 1586 }
1582 { 1587 catch (...)
1583 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageSize", 0); 1588 {
1584 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024); 1589 context.GetIndex().SetMaximumPatientCount(0);
1585 } 1590 }
1586 catch (...) 1591
1587 { 1592 try
1588 context.GetIndex().SetMaximumStorageSize(0); 1593 {
1589 } 1594 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageSize", 0);
1590 1595 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024);
1591 try 1596 }
1592 { 1597 catch (...)
1593 std::string mode = lock.GetConfiguration().GetStringParameter("MaximumStorageMode", "Recycle"); 1598 {
1594 context.GetIndex().SetMaximumStorageMode(StringToMaxStorageMode(mode)); 1599 context.GetIndex().SetMaximumStorageSize(0);
1595 } 1600 }
1596 catch (...) 1601
1597 { 1602 try
1598 context.GetIndex().SetMaximumStorageMode(MaxStorageMode_Recycle); 1603 {
1599 } 1604 std::string mode = lock.GetConfiguration().GetStringParameter("MaximumStorageMode", "Recycle");
1600 1605 context.GetIndex().SetMaximumStorageMode(StringToMaxStorageMode(mode));
1606 }
1607 catch (...)
1608 {
1609 context.GetIndex().SetMaximumStorageMode(MaxStorageMode_Recycle);
1610 }
1611 }
1612
1613 // note: this config is valid in ReadOnlyMode
1601 try 1614 try
1602 { 1615 {
1603 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageCacheSize", 128); 1616 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageCacheSize", 128);
1604 context.SetMaximumStorageCacheSize(size * 1024 * 1024); 1617 context.SetMaximumStorageCacheSize(size * 1024 * 1024);
1605 } 1618 }
1953 1966
1954 { 1967 {
1955 SQLiteDatabaseWrapper inMemoryDatabase; 1968 SQLiteDatabaseWrapper inMemoryDatabase;
1956 inMemoryDatabase.Open(); 1969 inMemoryDatabase.Open();
1957 MemoryStorageArea inMemoryStorage; 1970 MemoryStorageArea inMemoryStorage;
1958 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */); 1971 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
1959 OrthancRestApi restApi(context, false /* no Orthanc Explorer */); 1972 OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
1960 restApi.GenerateOpenApiDocumentation(openapi); 1973 restApi.GenerateOpenApiDocumentation(openapi);
1961 context.Stop(); 1974 context.Stop();
1962 } 1975 }
1963 1976
2004 2017
2005 { 2018 {
2006 SQLiteDatabaseWrapper inMemoryDatabase; 2019 SQLiteDatabaseWrapper inMemoryDatabase;
2007 inMemoryDatabase.Open(); 2020 inMemoryDatabase.Open();
2008 MemoryStorageArea inMemoryStorage; 2021 MemoryStorageArea inMemoryStorage;
2009 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */); 2022 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
2010 OrthancRestApi restApi(context, false /* no Orthanc Explorer */); 2023 OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
2011 restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html"); 2024 restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html");
2012 context.Stop(); 2025 context.Stop();
2013 } 2026 }
2014 2027