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