122
|
1 /**
|
|
2 * Python plugin for Orthanc
|
|
3 * Copyright (C) 2020-2022 Osimis S.A., Belgium
|
|
4 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
|
|
5 *
|
|
6 * This program is free software: you can redistribute it and/or
|
|
7 * modify it under the terms of the GNU Affero General Public License
|
|
8 * as published by the Free Software Foundation, either version 3 of
|
|
9 * the License, or (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * Affero General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU Affero General Public License
|
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 **/
|
|
19
|
|
20
|
|
21 #include "PythonBytes.h"
|
|
22
|
|
23 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
|
|
24
|
|
25
|
|
26 void PythonBytes::SanityCheck()
|
|
27 {
|
|
28 if (!bytes_->IsValid())
|
|
29 {
|
|
30 OrthancPlugins::LogError("Cannot create Python bytes");
|
|
31 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
|
|
32 }
|
|
33 }
|
|
34
|
|
35
|
|
36 PythonBytes::PythonBytes(PythonLock& lock,
|
|
37 const void* data,
|
|
38 size_t size)
|
|
39 {
|
|
40 if (data == NULL &&
|
|
41 size != 0)
|
|
42 {
|
|
43 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer);
|
|
44 }
|
|
45 else
|
|
46 {
|
|
47 PyObject* obj = PyBytes_FromStringAndSize(reinterpret_cast<const char*>(data), size);
|
|
48 bytes_.reset(new PythonObject(lock, obj));
|
|
49 SanityCheck();
|
|
50 }
|
|
51 }
|