comparison Framework/Plugins/DatabaseBackendAdapterV2.cpp @ 222:c8e06b41feec

refactoring registration/finalization of index backend
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Apr 2021 11:16:13 +0200
parents 73cc85f3d9c1
children 61c309e06797
comparison
equal deleted inserted replaced
221:73cc85f3d9c1 222:c8e06b41feec
1435 { 1435 {
1436 return new Output(context_, database_); 1436 return new Output(context_, database_);
1437 } 1437 }
1438 1438
1439 1439
1440 void DatabaseBackendAdapterV2::Register(IDatabaseBackend& backend) 1440 static std::unique_ptr<IDatabaseBackend> backend_;
1441 { 1441
1442 void DatabaseBackendAdapterV2::Register(IDatabaseBackend* backend)
1443 {
1444 if (backend == NULL)
1445 {
1446 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
1447 }
1448
1449 if (backend_.get() != NULL)
1450 {
1451 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
1452 }
1453
1454 backend_.reset(backend);
1455
1442 OrthancPluginDatabaseBackend params; 1456 OrthancPluginDatabaseBackend params;
1443 memset(&params, 0, sizeof(params)); 1457 memset(&params, 0, sizeof(params));
1444 1458
1445 OrthancPluginDatabaseExtensions extensions; 1459 OrthancPluginDatabaseExtensions extensions;
1446 memset(&extensions, 0, sizeof(extensions)); 1460 memset(&extensions, 0, sizeof(extensions));
1513 extensions.setResourcesContent = SetResourcesContent; // Fast setting tags/metadata 1527 extensions.setResourcesContent = SetResourcesContent; // Fast setting tags/metadata
1514 extensions.getChildrenMetadata = GetChildrenMetadata; 1528 extensions.getChildrenMetadata = GetChildrenMetadata;
1515 extensions.getLastChangeIndex = GetLastChangeIndex; 1529 extensions.getLastChangeIndex = GetLastChangeIndex;
1516 extensions.tagMostRecentPatient = TagMostRecentPatient; 1530 extensions.tagMostRecentPatient = TagMostRecentPatient;
1517 1531
1518 if (backend.HasCreateInstance()) 1532 if (backend_->HasCreateInstance())
1519 { 1533 {
1520 extensions.createInstance = CreateInstance; // Fast creation of resources 1534 extensions.createInstance = CreateInstance; // Fast creation of resources
1521 } 1535 }
1522 #endif 1536 #endif
1523 1537
1528 extensions.getAllMetadata = GetAllMetadata; 1542 extensions.getAllMetadata = GetAllMetadata;
1529 performanceWarning = false; 1543 performanceWarning = false;
1530 # endif 1544 # endif
1531 #endif 1545 #endif
1532 1546
1533 OrthancPluginContext* context = backend.GetContext(); 1547 OrthancPluginContext* context = backend_->GetContext();
1534 1548
1535 if (performanceWarning) 1549 if (performanceWarning)
1536 { 1550 {
1537 char info[1024]; 1551 char info[1024];
1538 sprintf(info, 1552 sprintf(info,
1548 1562
1549 OrthancPluginLogWarning(context, info); 1563 OrthancPluginLogWarning(context, info);
1550 } 1564 }
1551 1565
1552 OrthancPluginDatabaseContext* database = 1566 OrthancPluginDatabaseContext* database =
1553 OrthancPluginRegisterDatabaseBackendV2(context, &params, &extensions, &backend); 1567 OrthancPluginRegisterDatabaseBackendV2(context, &params, &extensions, backend_.get());
1554 if (database == NULL) 1568 if (database == NULL)
1555 { 1569 {
1556 throw std::runtime_error("Unable to register the database backend"); 1570 throw std::runtime_error("Unable to register the database backend");
1557 } 1571 }
1558 1572
1559 backend.SetOutputFactory(new Factory(context, database)); 1573 backend_->SetOutputFactory(new Factory(context, database));
1574 }
1575
1576
1577 void DatabaseBackendAdapterV2::Finalize()
1578 {
1579 backend_.reset(NULL);
1560 } 1580 }
1561 } 1581 }