comparison Sources/Autogenerated/sdk_OrthancPluginJob.impl.h @ 1:fef9a239df5c

adding auto-generated files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Mar 2020 18:50:10 +0100
parents
children b2bbb516056e
comparison
equal deleted inserted replaced
0:7ed502b17b8f 1:fef9a239df5c
1 /**
2 * Python plugin for Orthanc
3 * Copyright (C) 2017-2020 Osimis S.A., Belgium
4 *
5 * This program is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License
7 * as published by the Free Software Foundation, either version 3 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **/
18
19
20 typedef struct
21 {
22 PyObject_HEAD
23
24 /* Type-specific fields go here. */
25 OrthancPluginJob* object_;
26 bool borrowed_;
27 } sdk_OrthancPluginJob_Object;
28
29
30
31 // Forward declaration of the methods
32 static PyObject *sdk_OrthancPluginJob_OrthancPluginSubmitJob(
33 sdk_OrthancPluginJob_Object* self, PyObject *args);
34
35
36 static PyMethodDef sdk_OrthancPluginJob_Methods[] = {
37 { "SubmitJob",
38 (PyCFunction) sdk_OrthancPluginJob_OrthancPluginSubmitJob, METH_VARARGS,
39 "Generated from C function OrthancPluginSubmitJob()" },
40 { NULL } /* Sentinel */
41 };
42
43
44 static int sdk_OrthancPluginJob_Constructor(
45 sdk_OrthancPluginJob_Object *self, PyObject *args, PyObject *kwds)
46 {
47 OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginJob");
48
49 self->object_ = NULL;
50 self->borrowed_ = false;
51
52 long long object = 0;
53 unsigned char borrowed = false;
54
55 if (PyArg_ParseTuple(args, "Lb", &object, &borrowed))
56 {
57 self->object_ = reinterpret_cast<OrthancPluginJob*>(static_cast<intptr_t>(object));
58 self->borrowed_ = borrowed;
59 return 0;
60 }
61 else
62 {
63 PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor");
64 return -1;
65 }
66 }
67
68
69 /**
70 * Static global structure => the fields that are beyond the last
71 * initialized field are set to zero.
72 * https://stackoverflow.com/a/11152199/881731
73 **/
74 static PyTypeObject sdk_OrthancPluginJob_Type = {
75 PyVarObject_HEAD_INIT(NULL, 0)
76 "orthanc.Job", /* tp_name */
77 sizeof(sdk_OrthancPluginJob_Object), /* tp_basicsize */
78 };
79
80
81 static void sdk_OrthancPluginJob_Destructor(PyObject *self)
82 {
83 OrthancPlugins::LogInfo("Destroying Python object of class OrthancPluginJob");
84
85 sdk_OrthancPluginJob_Object& tmp = *((sdk_OrthancPluginJob_Object*) self);
86
87 if (tmp.object_ != NULL &&
88 !tmp.borrowed_)
89 {
90 OrthancPluginFreeJob(OrthancPlugins::GetGlobalContext(), tmp.object_);
91 tmp.object_ = NULL;
92 }
93
94 Py_TYPE(self)->tp_free((PyObject *)self);
95 }
96
97
98 // Actual implementation of the methods
99 static PyObject *sdk_OrthancPluginJob_OrthancPluginSubmitJob(
100 sdk_OrthancPluginJob_Object* self, PyObject *args)
101 {
102 OrthancPlugins::LogInfo("Calling method OrthancPluginSubmitJob() on object of class OrthancPluginJob");
103
104 if (self->object_ == NULL)
105 {
106 // TODO: RAISE
107 //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer);
108 PyErr_SetString(PyExc_ValueError, "Invalid object");
109 return NULL;
110 }
111
112 int arg0 = 0;
113
114 if (!PyArg_ParseTuple(args, "i", &arg0))
115 {
116 // TODO => RAISE : https://stackoverflow.com/questions/60832317
117 PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)");
118 return NULL;
119 }
120 OrthancPlugins::OrthancString s;
121 s.Assign(OrthancPluginSubmitJob(OrthancPlugins::GetGlobalContext(), self->object_, arg0));
122
123 if (s.GetContent() == NULL)
124 {
125 // TODO => RAISE : https://stackoverflow.com/questions/60832317
126 //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError);
127 PyErr_SetString(PyExc_ValueError, "Internal error");
128 return NULL;
129 }
130 else
131 {
132 return PyUnicode_FromString(s.GetContent());
133 }
134 }
135
136
137
138 static void RegisterOrthancPluginJobClass(PyObject* module)
139 {
140 sdk_OrthancPluginJob_Type.tp_new = PyType_GenericNew;
141 sdk_OrthancPluginJob_Type.tp_flags = Py_TPFLAGS_DEFAULT;
142 sdk_OrthancPluginJob_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginJob";
143 sdk_OrthancPluginJob_Type.tp_methods = sdk_OrthancPluginJob_Methods;
144 sdk_OrthancPluginJob_Type.tp_init = (initproc) sdk_OrthancPluginJob_Constructor;
145
146 /**
147 * "tp_dealloc is called when the reference count of the object goes
148 * down to zero. This is where you destroy the object and its
149 * members. It should then free the memory occupied by the object by
150 * calling tp_free."
151 * https://stackoverflow.com/a/24863227/881731
152 **/
153 sdk_OrthancPluginJob_Type.tp_dealloc = sdk_OrthancPluginJob_Destructor;
154
155 if (PyType_Ready(&sdk_OrthancPluginJob_Type) < 0)
156 {
157 OrthancPlugins::LogError("Cannot register Python class: OrthancPluginJob");
158 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
159 }
160
161 Py_INCREF(&sdk_OrthancPluginJob_Type);
162 if (PyModule_AddObject(module, "Job", (PyObject *)&sdk_OrthancPluginJob_Type) < 0)
163 {
164 OrthancPlugins::LogError("Cannot register Python class: OrthancPluginJob");
165 Py_DECREF(&sdk_OrthancPluginJob_Type);
166 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
167 }
168 }
169
170
171 PyObject* GetOrthancPluginJobType()
172 {
173 return (PyObject*) &sdk_OrthancPluginJob_Type;
174 }