Mercurial > hg > orthanc-databases
comparison MySQL/Plugins/IndexPlugin.cpp @ 2:17bce6a07b2b
storage plugin skeletons
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Jul 2018 15:06:32 +0200 |
parents | 7cea966b6829 |
children | 17f849b2af34 |
comparison
equal
deleted
inserted
replaced
1:d17b2631bb67 | 2:17bce6a07b2b |
---|---|
23 #include "../../Framework/MySQL/MySQLDatabase.h" | 23 #include "../../Framework/MySQL/MySQLDatabase.h" |
24 | 24 |
25 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> | 25 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> |
26 #include <Core/Logging.h> | 26 #include <Core/Logging.h> |
27 | 27 |
28 static OrthancPluginContext* context_ = NULL; | |
29 static std::auto_ptr<OrthancDatabases::MySQLIndex> backend_; | 28 static std::auto_ptr<OrthancDatabases::MySQLIndex> backend_; |
30 | |
31 | 29 |
32 | 30 |
33 static bool DisplayPerformanceWarning() | 31 static bool DisplayPerformanceWarning() |
34 { | 32 { |
35 (void) DisplayPerformanceWarning; // Disable warning about unused function | 33 (void) DisplayPerformanceWarning; // Disable warning about unused function |
36 OrthancPluginLogWarning(context_, "Performance warning in MySQL index: " | 34 LOG(WARNING) << "Performance warning in MySQL index: " |
37 "Non-release build, runtime debug assertions are turned on"); | 35 << "Non-release build, runtime debug assertions are turned on"; |
38 return true; | 36 return true; |
39 } | 37 } |
40 | 38 |
41 | 39 |
42 extern "C" | 40 extern "C" |
43 { | 41 { |
44 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | 42 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) |
45 { | 43 { |
46 Orthanc::Logging::Initialize(context); | 44 Orthanc::Logging::Initialize(context); |
47 | 45 |
48 context_ = context; | |
49 assert(DisplayPerformanceWarning()); | 46 assert(DisplayPerformanceWarning()); |
50 | 47 |
51 /* Check the version of the Orthanc core */ | 48 /* Check the version of the Orthanc core */ |
52 if (OrthancPluginCheckVersion(context_) == 0) | 49 if (OrthancPluginCheckVersion(context) == 0) |
53 { | 50 { |
54 char info[1024]; | 51 char info[1024]; |
55 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | 52 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", |
56 context_->orthancVersion, | 53 context->orthancVersion, |
57 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | 54 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
58 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | 55 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
59 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | 56 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
60 OrthancPluginLogError(context_, info); | 57 OrthancPluginLogError(context, info); |
61 return -1; | 58 return -1; |
62 } | 59 } |
63 | 60 |
64 OrthancPluginSetDescription(context_, "Stores the Orthanc index into a MySQL database."); | 61 OrthancPluginSetDescription(context, "Stores the Orthanc index into a MySQL database."); |
65 | 62 |
66 OrthancPlugins::OrthancConfiguration configuration(context); | 63 OrthancPlugins::OrthancConfiguration configuration(context); |
67 | 64 |
68 if (!configuration.IsSection("MySQL")) | 65 if (!configuration.IsSection("MySQL")) |
69 { | 66 { |
89 | 86 |
90 /* Create the database back-end */ | 87 /* Create the database back-end */ |
91 backend_.reset(new OrthancDatabases::MySQLIndex(parameters)); | 88 backend_.reset(new OrthancDatabases::MySQLIndex(parameters)); |
92 | 89 |
93 /* Register the MySQL index into Orthanc */ | 90 /* Register the MySQL index into Orthanc */ |
94 OrthancPlugins::DatabaseBackendAdapter::Register(context_, *backend_); | 91 OrthancPlugins::DatabaseBackendAdapter::Register(context, *backend_); |
95 } | 92 } |
96 catch (std::runtime_error& e) | 93 catch (Orthanc::OrthancException& e) |
97 { | 94 { |
98 OrthancPluginLogError(context_, e.what()); | 95 LOG(ERROR) << e.What(); |
96 return -1; | |
97 } | |
98 catch (...) | |
99 { | |
100 LOG(ERROR) << "Native exception while initializing the plugin"; | |
99 return -1; | 101 return -1; |
100 } | 102 } |
101 | 103 |
102 return 0; | 104 return 0; |
103 } | 105 } |
104 | 106 |
105 | 107 |
106 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | 108 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
107 { | 109 { |
108 OrthancPluginLogWarning(context_, "MySQL index is finalizing"); | 110 LOG(WARNING) << "MySQL index is finalizing"; |
111 | |
109 backend_.reset(NULL); | 112 backend_.reset(NULL); |
110 | |
111 OrthancDatabases::MySQLDatabase::GlobalFinalization(); | 113 OrthancDatabases::MySQLDatabase::GlobalFinalization(); |
112 } | 114 } |
113 | 115 |
114 | 116 |
115 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | 117 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() |