Mercurial > hg > orthanc-python
annotate CodeAnalysis/Class.mustache @ 213:f8dc8dd2da76
documented orthanc.RegisterIncomingCStoreInstanceFilter() and orthanc.RegisterReceivedInstanceCallback()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Jul 2024 14:56:51 +0200 |
parents | 66cd20e970d8 |
children | 3678a028f1f6 |
rev | line source |
---|---|
0 | 1 /** |
2 * Python plugin for Orthanc | |
166
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium |
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
155
71d305c29cfa
updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
186
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
22 // WARNING: Auto-generated file. Do not modify it by hand. |
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
23 |
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
24 |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
25 // Forward declaration of the autogenerated methods |
0 | 26 {{#methods}} |
27 static PyObject *sdk_{{class_name}}_{{c_function}}( | |
28 sdk_{{class_name}}_Object* self, PyObject *args); | |
29 {{/methods}} | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
30 // End of forward declarations |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
31 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
32 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
33 // Forward declaration of the custom methods |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
34 {{#custom_methods}} |
193
66cd20e970d8
simplification for custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
35 extern PyObject *{{implementation}}(sdk_{{class_name}}_Object* self, PyObject *args); |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
36 {{/custom_methods}} |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
37 // End of forward declarations |
0 | 38 |
39 | |
40 static PyMethodDef sdk_{{class_name}}_Methods[] = { | |
41 {{#methods}} | |
42 { "{{short_name}}", | |
43 (PyCFunction) sdk_{{class_name}}_{{c_function}}, METH_VARARGS, | |
44 "Generated from C function {{c_function}}()" }, | |
45 {{/methods}} | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
46 {{#custom_methods}} |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
47 { "{{short_name}}", |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
48 (PyCFunction) {{implementation}}, METH_VARARGS, |
193
66cd20e970d8
simplification for custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
49 "Implemented in C++ function {{implementation}}()" }, |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
50 {{/custom_methods}} |
0 | 51 { NULL } /* Sentinel */ |
52 }; | |
53 | |
54 | |
55 static int sdk_{{class_name}}_Constructor( | |
56 sdk_{{class_name}}_Object *self, PyObject *args, PyObject *kwds) | |
57 { | |
28
b2bbb516056e
The "Calling Python..." info logs are disabled if "PythonVerbose" is "false"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
58 PythonLock::LogCall("Creating Python object of class {{class_name}}"); |
0 | 59 |
60 self->object_ = NULL; | |
61 self->borrowed_ = false; | |
62 | |
63 long long object = 0; | |
64 unsigned char borrowed = false; | |
65 | |
66 if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) | |
67 { | |
68 self->object_ = reinterpret_cast<{{class_name}}*>(static_cast<intptr_t>(object)); | |
69 self->borrowed_ = borrowed; | |
70 return 0; | |
71 } | |
72 else | |
73 { | |
74 PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); | |
75 return -1; | |
76 } | |
77 } | |
78 | |
79 | |
80 /** | |
81 * Static global structure => the fields that are beyond the last | |
82 * initialized field are set to zero. | |
83 * https://stackoverflow.com/a/11152199/881731 | |
84 **/ | |
85 static PyTypeObject sdk_{{class_name}}_Type = { | |
86 PyVarObject_HEAD_INIT(NULL, 0) | |
87 "orthanc.{{short_name}}", /* tp_name */ | |
88 sizeof(sdk_{{class_name}}_Object), /* tp_basicsize */ | |
89 }; | |
90 | |
91 | |
92 {{#destructor}} | |
93 static void sdk_{{class_name}}_Destructor(PyObject *self) | |
94 { | |
28
b2bbb516056e
The "Calling Python..." info logs are disabled if "PythonVerbose" is "false"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
95 PythonLock::LogCall("Destroying Python object of class {{class_name}}"); |
0 | 96 |
97 sdk_{{class_name}}_Object& tmp = *((sdk_{{class_name}}_Object*) self); | |
98 | |
99 if (tmp.object_ != NULL && | |
100 !tmp.borrowed_) | |
101 { | |
102 {{destructor}}(OrthancPlugins::GetGlobalContext(), tmp.object_); | |
103 tmp.object_ = NULL; | |
104 } | |
105 | |
106 Py_TYPE(self)->tp_free((PyObject *)self); | |
107 } | |
108 {{/destructor}} | |
109 | |
110 | |
111 static void Register{{class_name}}Class(PyObject* module) | |
112 { | |
113 sdk_{{class_name}}_Type.tp_new = PyType_GenericNew; | |
114 sdk_{{class_name}}_Type.tp_flags = Py_TPFLAGS_DEFAULT; | |
115 sdk_{{class_name}}_Type.tp_doc = "Generated from Orthanc C class: {{class_name}}"; | |
116 sdk_{{class_name}}_Type.tp_methods = sdk_{{class_name}}_Methods; | |
117 sdk_{{class_name}}_Type.tp_init = (initproc) sdk_{{class_name}}_Constructor; | |
118 | |
119 {{#destructor}} | |
120 /** | |
121 * "tp_dealloc is called when the reference count of the object goes | |
122 * down to zero. This is where you destroy the object and its | |
123 * members. It should then free the memory occupied by the object by | |
124 * calling tp_free." | |
125 * https://stackoverflow.com/a/24863227/881731 | |
126 **/ | |
127 sdk_{{class_name}}_Type.tp_dealloc = sdk_{{class_name}}_Destructor; | |
128 {{/destructor}} | |
129 | |
130 if (PyType_Ready(&sdk_{{class_name}}_Type) < 0) | |
131 { | |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
132 ORTHANC_PLUGINS_LOG_ERROR("Cannot register Python class: {{class_name}}"); |
0 | 133 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
134 } | |
135 | |
136 Py_INCREF(&sdk_{{class_name}}_Type); | |
137 if (PyModule_AddObject(module, "{{short_name}}", (PyObject *)&sdk_{{class_name}}_Type) < 0) | |
138 { | |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
139 ORTHANC_PLUGINS_LOG_ERROR("Cannot register Python class: {{class_name}}"); |
0 | 140 Py_DECREF(&sdk_{{class_name}}_Type); |
141 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
142 } | |
143 } | |
144 | |
145 | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
146 PyTypeObject* Get{{class_name}}Type() |
0 | 147 { |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
148 return &sdk_{{class_name}}_Type; |
0 | 149 } |