1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
{{#args}}
{{python_type}} {{name}}{{initialization}};
{{/args}}
{{#has_args}}
if (!PyArg_ParseTuple(args, {{tuple_format}}))
{
PyErr_SetString(PyExc_TypeError, "Bad types for the arguments ({{count_args}} arguments expected)");
return NULL;
}
{{/has_args}}
{{#args}}{{#check_object_type}}
if ({{name}} != Py_None && Py_TYPE({{name}}) != Get{{check_object_type}}Type())
{
PyErr_SetString(PyExc_TypeError, "Invalid orthanc.{{check_object_type}} object");
return NULL;
}
{{/check_object_type}}{{/args}}
{{#return_long}}
long value;
{
PythonThreadsAllower allower;
value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
}
{{#args}}{{release}}{{/args}}
return PyLong_FromLong(value);
{{/return_long}}
{{#return_static_string}}
const char* s;
{
PythonThreadsAllower allower;
s = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
}
{{#args}}{{release}}{{/args}}
if (s == NULL)
{
Py_INCREF(Py_None);
return Py_None;
}
else
{
return PyUnicode_FromString(s);
}
{{/return_static_string}}
{{#return_dynamic_string}}
OrthancPlugins::OrthancString s;
{
PythonThreadsAllower allower;
s.Assign({{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}));
}
{{#args}}{{release}}{{/args}}
if (s.GetContent() == NULL)
{
PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
return NULL;
}
else
{
return PyUnicode_FromString(s.GetContent());
}
{{/return_dynamic_string}}
{{#return_void}}
{
PythonThreadsAllower allower;
{{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
}
{{#args}}{{release}}{{/args}}
Py_INCREF(Py_None);
return Py_None;
{{/return_void}}
{{#return_error}}
OrthancPluginErrorCode code;
{
PythonThreadsAllower allower;
code = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
}
{{#args}}{{release}}{{/args}}
if (code == OrthancPluginErrorCode_Success)
{
Py_INCREF(Py_None);
return Py_None;
}
else
{
PythonLock::RaiseException(code);
return NULL;
}
{{/return_error}}
{{#return_object}}
// This is the case of a constructor
{{return_object}}* obj;
{
PythonThreadsAllower allower;
obj = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
}
{{#args}}{{release}}{{/args}}
if (obj == NULL)
{
PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
return NULL;
}
else
{
PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */);
PyObject *python = PyObject_CallObject((PyObject *) &sdk_{{return_object}}_Type, argList);
Py_DECREF(argList);
return python;
}
{{/return_object}}
{{#return_bytes}}
OrthancPlugins::MemoryBuffer buffer;
OrthancPluginErrorCode code;
{
PythonThreadsAllower allower;
code = {{c_function}}(OrthancPlugins::GetGlobalContext(), *buffer{{self}}{{call_args}});
}
{{#args}}{{release}}{{/args}}
if (code == OrthancPluginErrorCode_Success)
{
return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize());
}
else
{
PythonLock::RaiseException(code);
return NULL;
}
{{/return_bytes}}
{{#return_enumeration}}
{{return_enumeration}} value;
{
PythonThreadsAllower allower;
value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
}
{{#args}}{{release}}{{/args}}
return PyLong_FromLong(value);
{{/return_enumeration}}
|