annotate OrthancServer/Plugins/Samples/StorageArea/Plugin.cpp @ 4749:1a061bc2d6ca

Clicking on "Send to remote modality" displays the job information to monitor progress
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Jul 2021 14:57:21 +0200
parents 5b929e6b3c36
children 7053502fbf97
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
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 static OrthancPluginContext* context = NULL;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static std::string GetPath(const char* uuid)
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 return "plugin_" + std::string(uuid);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 }
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
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
38 static bool ReadFile(std::string& content,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
39 const std::string& path)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
40 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
41 FILE* fp = fopen(path.c_str(), "rb");
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
42 if (!fp)
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 return false;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
45 }
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 if (fseek(fp, 0, SEEK_END) < 0)
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 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
50 return false;
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
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
53 long size = ftell(fp);
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 if (fseek(fp, 0, SEEK_SET) < 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
56 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
57 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
58 return false;
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 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
61 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
62 content.resize(size);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
63
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
64 if (size != 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
65 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
66 bool success = (fread(&content[0], size, 1, fp) == 1);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
67 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
68 return success;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
69 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
70 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
71 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
72 fclose(fp);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
73 return true;
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 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
76 }
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
1627
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
79 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
80 const void* content,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
81 int64_t size,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
82 OrthancPluginContentType type)
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 std::string path = GetPath(uuid);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 FILE* fp = fopen(path.c_str(), "wb");
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 if (!fp)
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
89 return OrthancPluginErrorCode_StorageAreaPlugin;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 bool ok = fwrite(content, size, 1, fp) == 1;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 fclose(fp);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
95 return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_StorageAreaPlugin;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
99 #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
100 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
101 int64_t* size,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
102 const char* uuid,
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
103 OrthancPluginContentType type)
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
105 const std::string path = GetPath(uuid);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
106
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
107 std::string s;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
108 if (ReadFile(s, path))
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 *size = s.size();
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
112 if (s.size() == 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
113 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
114 *content = NULL;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
115 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
116 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
117 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
118 *content = malloc(s.size());
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
119 if (*content == NULL)
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 return OrthancPluginErrorCode_StorageAreaPlugin;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
122 }
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 if (!s.empty())
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 memcpy(*content, s.c_str(), s.size());
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
127 }
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
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
130 return OrthancPluginErrorCode_Success;
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 else
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
134 return OrthancPluginErrorCode_StorageAreaPlugin;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
136 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
138 #else
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
140 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
141 const char* uuid,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
142 OrthancPluginContentType type)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
143 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
144 const std::string path = GetPath(uuid);
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
146 std::string s;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
147 if (ReadFile(s, path))
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 if (OrthancPluginCreateMemoryBuffer64(context, target, s.size()) != OrthancPluginErrorCode_Success)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
150 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
151 return OrthancPluginErrorCode_NotEnoughMemory;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
152 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
154 if (!s.empty())
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
155 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
156 memcpy(target->data, s.c_str(), s.size());
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
157 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
159 return OrthancPluginErrorCode_Success;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 else
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
163 return OrthancPluginErrorCode_StorageAreaPlugin;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
164 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
165 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
166
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
167 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
168 const char* uuid,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
169 OrthancPluginContentType type,
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
170 uint64_t rangeStart)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
171 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
172 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
173 const std::string path = GetPath(uuid);
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 std::string s;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
176
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
177 if (rangeSize == 0)
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
178 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
179 return OrthancPluginErrorCode_Success;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
180 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
181 else if (ReadFile(s, path))
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
182 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
183 if (rangeStart + rangeSize > s.size())
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
185 return OrthancPluginErrorCode_BadRange;
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
187 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
188 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
189 memcpy(target->data, &s[rangeStart], rangeSize);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
190 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
192 return OrthancPluginErrorCode_Success;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
193 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
194 else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
195 {
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
196 return OrthancPluginErrorCode_StorageAreaPlugin;
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
197 }
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
198 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
200 #endif
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
1627
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
203 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
204 OrthancPluginContentType type)
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 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
207
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
208 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
209 {
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
210 return OrthancPluginErrorCode_Success;
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
211 }
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
212 else
da7854deb662 Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1425
diff changeset
213 {
1643
87c77b9b3679 provision for error codes in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1627
diff changeset
214 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
215 }
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 extern "C"
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 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 context = c;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 OrthancPluginLogWarning(context, "Storage plugin is initializing");
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 /* Check the version of the Orthanc core */
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 if (OrthancPluginCheckVersion(c) == 0)
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
229 char info[1024];
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 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
231 c->orthancVersion,
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 OrthancPluginLogError(context, info);
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 return -1;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
239 #if USE_LEGACY_API == 1
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageRead, StorageRemove);
4483
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
241 #else
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
242 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove);
a926f8995d0b sample for OrthancPluginRegisterStorageArea2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
243 #endif
1136
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 return 0;
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
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
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
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 OrthancPluginLogWarning(context, "Storage plugin is finalizing");
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
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
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
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 return "storage";
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
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
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
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 return "1.0";
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
208dc67b9bab sample custom storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }