0
|
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 } sdk_{{name}}_Object;
|
|
24
|
|
25
|
|
26 /**
|
|
27 * Static global structure => the fields that are beyond the last
|
|
28 * initialized field are set to zero.
|
|
29 * https://stackoverflow.com/a/11152199/881731
|
|
30 **/
|
|
31 static PyTypeObject sdk_{{name}}_Type = {
|
|
32 PyVarObject_HEAD_INIT(NULL, 0)
|
|
33 "orthanc.{{short_name}}", /* tp_name */
|
|
34 sizeof(sdk_{{name}}_Object), /* tp_basicsize */
|
|
35 };
|
|
36
|
|
37
|
|
38 void Register{{name}}Enumeration(PyObject* module)
|
|
39 {
|
|
40 sdk_{{name}}_Type.tp_new = PyType_GenericNew;
|
|
41 sdk_{{name}}_Type.tp_flags = Py_TPFLAGS_DEFAULT;
|
|
42 sdk_{{name}}_Type.tp_doc = "Generated from C enumeration OrthancPlugin{{name}}";
|
|
43
|
|
44 sdk_{{name}}_Type.tp_dict = PyDict_New();
|
|
45
|
|
46 if (PyType_Ready(&sdk_{{name}}_Type) < 0)
|
|
47 {
|
|
48 OrthancPlugins::LogError("Cannot register Python enumeration: {{name}}");
|
|
49 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
|
|
50 }
|
|
51
|
|
52 /**
|
|
53 * Declare constants here (static members = class attributes)
|
|
54 * https://stackoverflow.com/a/8017906/881731
|
|
55 *
|
|
56 * "Static and class methods can be defined in tp_methods by adding
|
|
57 * METH_STATIC or METH_CLASS to the ml_flags field of the
|
|
58 * PyMethodDef structure. This is equivalent to @staticmethod and
|
|
59 * @classmethod decorators."
|
|
60 *
|
|
61 * "Class attributes can be added by setting the tp_dict to a
|
|
62 * dictionary with these attributes before calling PyType_Ready()
|
|
63 * (in your module initialization function)."
|
|
64 **/
|
|
65
|
|
66 {{#values}}
|
|
67 PyDict_SetItemString(sdk_{{name}}_Type.tp_dict, "{{key}}", PyLong_FromLong({{value}}));
|
|
68 {{/values}}
|
|
69
|
|
70 Py_INCREF(&sdk_{{name}}_Type);
|
|
71 if (PyModule_AddObject(module, "{{short_name}}", (PyObject *)&sdk_{{name}}_Type) < 0)
|
|
72 {
|
|
73 OrthancPlugins::LogError("Cannot register Python enumeration: {{name}}");
|
|
74 Py_DECREF(&sdk_{{name}}_Type);
|
|
75 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
|
|
76 }
|
|
77 }
|