Mercurial > hg > orthanc-python
annotate CodeAnalysis/FunctionBody.mustache @ 151:566df919b286 cmove2
new more detailed C-Move SCP callbacks
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 27 Feb 2024 16:13:08 +0100 |
parents | e7ff5efb100d |
children | 8382c7dea471 |
rev | line source |
---|---|
0 | 1 {{#args}} |
2 {{python_type}} {{name}}{{initialization}}; | |
3 {{/args}} | |
4 | |
5 {{#has_args}} | |
6 if (!PyArg_ParseTuple(args, {{tuple_format}})) | |
7 { | |
8 PyErr_SetString(PyExc_TypeError, "Bad types for the arguments ({{count_args}} arguments expected)"); | |
9 return NULL; | |
10 } | |
11 {{/has_args}} | |
12 {{#return_long}} | |
13 long value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
14 {{#args}}{{release}}{{/args}} | |
15 return PyLong_FromLong(value); | |
16 {{/return_long}} | |
17 {{#return_static_string}} | |
18 const char* s = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
19 {{#args}}{{release}}{{/args}} | |
20 if (s == NULL) | |
21 { | |
22 Py_INCREF(Py_None); | |
23 return Py_None; | |
24 } | |
25 else | |
26 { | |
27 return PyUnicode_FromString(s); | |
28 } | |
29 {{/return_static_string}} | |
30 {{#return_dynamic_string}} | |
31 OrthancPlugins::OrthancString s; | |
32 s.Assign({{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}})); | |
33 {{#args}}{{release}}{{/args}} | |
34 if (s.GetContent() == NULL) | |
35 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
36 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
0 | 37 return NULL; |
38 } | |
39 else | |
40 { | |
41 return PyUnicode_FromString(s.GetContent()); | |
42 } | |
43 {{/return_dynamic_string}} | |
44 {{#return_void}} | |
45 {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
46 {{#args}}{{release}}{{/args}} | |
47 | |
48 Py_INCREF(Py_None); | |
49 return Py_None; | |
50 {{/return_void}} | |
51 {{#return_error}} | |
52 OrthancPluginErrorCode code = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
53 {{#args}}{{release}}{{/args}} | |
54 | |
55 if (code == OrthancPluginErrorCode_Success) | |
56 { | |
57 Py_INCREF(Py_None); | |
58 return Py_None; | |
59 } | |
60 else | |
61 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
62 PythonLock::RaiseException(code); |
0 | 63 return NULL; |
64 } | |
65 {{/return_error}} | |
66 {{#return_object}} | |
67 // This is the case of a constructor | |
68 {{return_object}}* obj = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
69 {{#args}}{{release}}{{/args}} | |
70 if (obj == NULL) | |
71 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
72 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
0 | 73 return NULL; |
74 } | |
75 else | |
76 { | |
77 PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); | |
78 PyObject *python = PyObject_CallObject((PyObject *) &sdk_{{return_object}}_Type, argList); | |
79 Py_DECREF(argList); | |
80 return python; | |
81 } | |
82 {{/return_object}} | |
83 {{#return_bytes}} | |
84 OrthancPlugins::MemoryBuffer buffer; | |
85 OrthancPluginErrorCode code = {{c_function}}(OrthancPlugins::GetGlobalContext(), *buffer{{self}}{{call_args}}); | |
86 {{#args}}{{release}}{{/args}} | |
87 if (code == OrthancPluginErrorCode_Success) | |
88 { | |
89 return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); | |
90 } | |
91 else | |
92 { | |
77
e7ff5efb100d
Custom exception "orthanc.OrthancException" is raised instead of "ValueError"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
93 PythonLock::RaiseException(code); |
0 | 94 return NULL; |
95 } | |
96 {{/return_bytes}} | |
97 {{#return_enumeration}} | |
98 {{return_enumeration}} value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
99 {{#args}}{{release}}{{/args}} | |
100 return PyLong_FromLong(value); | |
101 {{/return_enumeration}} |