annotate OrthancServer/Plugins/Samples/StorageArea/Plugin.cpp @ 4483:a926f8995d0b

sample for OrthancPluginRegisterStorageArea2()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 28 Jan 2021 16:59:40 +0100
parents d9473bd5ed43
children 5b929e6b3c36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1136
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
1375
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
7 * This program is free software: you can redistribute it and/or
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
8 * modify it under the terms of the GNU General Public License as
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
10 * License, or (at your option) any later version.
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
11 *
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
12 * This program is distributed in the hope that it will be useful, but
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
15 * General Public License for more details.
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
1375
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
17 * You should have received a copy of the GNU General Public License
3d76e26b3865 fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
1425
97268448bdfc refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1375
diff changeset
22 #include <orthanc/OrthancCPlugin.h>
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <string.h>
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <stdio.h>
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <string>
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
28
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
29 #define USE_LEGACY_API 0
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
30
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
31
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static OrthancPluginContext* context = NULL;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static std::string GetPath(const char* uuid)
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 return "plugin_" + std::string(uuid);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
41 static bool ReadFile(std::string& content,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
42 const std::string& path)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
43 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
44 FILE* fp = fopen(path.c_str(), "rb");
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
45 if (!fp)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
46 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
47 return false;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
48 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
49
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
50 if (fseek(fp, 0, SEEK_END) < 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
51 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
52 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
53 return false;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
54 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
55
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
56 long size = ftell(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
57
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
58 if (fseek(fp, 0, SEEK_SET) < 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
59 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
60 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
61 return false;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
62 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
63 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
64 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
65 content.resize(size);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
66
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
67 if (size != 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
68 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
69 bool success = (fread(&content[0], size, 1, fp) == 1);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
70 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
71 return success;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
72 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
73 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
74 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
75 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
76 return true;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
77 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
78 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
79 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
80
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
81
1627
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
82 static OrthancPluginErrorCode StorageCreate(const char* uuid,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
83 const void* content,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
84 int64_t size,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
85 OrthancPluginContentType type)
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 std::string path = GetPath(uuid);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 FILE* fp = fopen(path.c_str(), "wb");
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 if (!fp)
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
92 return OrthancPluginErrorCode_StorageAreaPlugin;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 bool ok = fwrite(content, size, 1, fp) == 1;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 fclose(fp);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
98 return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_StorageAreaPlugin;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
102 #if USE_LEGACY_API == 1
1627
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
103 static OrthancPluginErrorCode StorageRead(void** content,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
104 int64_t* size,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
105 const char* uuid,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
106 OrthancPluginContentType type)
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
108 const std::string path = GetPath(uuid);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
109
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
110 std::string s;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
111 if (ReadFile(s, path))
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
112 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
113 *size = s.size();
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
115 if (s.size() == 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
116 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
117 *content = NULL;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
118 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
119 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
120 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
121 *content = malloc(s.size());
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
122 if (*content == NULL)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
123 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
124 return OrthancPluginErrorCode_StorageAreaPlugin;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
125 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
126
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
127 if (!s.empty())
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
128 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
129 memcpy(*content, s.c_str(), s.size());
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
130 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
131 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
132
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
133 return OrthancPluginErrorCode_Success;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
134 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
135 else
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
137 return OrthancPluginErrorCode_StorageAreaPlugin;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
139 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
141 #else
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
143 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
144 const char* uuid,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
145 OrthancPluginContentType type)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
146 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
147 const std::string path = GetPath(uuid);
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
149 std::string s;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
150 if (ReadFile(s, path))
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
152 if (OrthancPluginCreateMemoryBuffer64(context, target, s.size()) != OrthancPluginErrorCode_Success)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
153 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
154 return OrthancPluginErrorCode_NotEnoughMemory;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
155 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
157 if (!s.empty())
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
158 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
159 memcpy(target->data, s.c_str(), s.size());
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
160 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
162 return OrthancPluginErrorCode_Success;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 else
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
166 return OrthancPluginErrorCode_StorageAreaPlugin;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
167 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
168 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
169
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
170 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
171 const char* uuid,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
172 OrthancPluginContentType type,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
173 uint64_t rangeStart)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
174 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
175 const size_t rangeSize = target->size; // The buffer is allocated by Orthanc
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
176 const std::string path = GetPath(uuid);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
177
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
178 std::string s;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
179
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
180 if (rangeSize == 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
181 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
182 return OrthancPluginErrorCode_Success;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
183 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
184 else if (ReadFile(s, path))
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
185 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
186 if (rangeStart + rangeSize > s.size())
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
188 return OrthancPluginErrorCode_BadRange;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
190 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
191 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
192 memcpy(target->data, &s[rangeStart], rangeSize);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
193 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
195 return OrthancPluginErrorCode_Success;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
196 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
197 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
198 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
199 return OrthancPluginErrorCode_StorageAreaPlugin;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
200 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
201 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
203 #endif
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
1627
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
206 static OrthancPluginErrorCode StorageRemove(const char* uuid,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
207 OrthancPluginContentType type)
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 std::string path = GetPath(uuid);
1627
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
210
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
211 if (remove(path.c_str()) == 0)
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
212 {
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
213 return OrthancPluginErrorCode_Success;
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
214 }
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
215 else
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
216 {
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
217 return OrthancPluginErrorCode_StorageAreaPlugin;
1627
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
218 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 extern "C"
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 context = c;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 OrthancPluginLogWarning(context, "Storage plugin is initializing");
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 /* Check the version of the Orthanc core */
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (OrthancPluginCheckVersion(c) == 0)
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
232 char info[1024];
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 c->orthancVersion,
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 OrthancPluginLogError(context, info);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 return -1;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
242 #if USE_LEGACY_API == 1
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageRead, StorageRemove);
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
244 #else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
245 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
246 #endif
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 return 0;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 OrthancPluginLogWarning(context, "Storage plugin is finalizing");
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 return "storage";
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 return "1.0";
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }