Mercurial > hg > orthanc-python
comparison Sources/ReceivedInstanceCallback.cpp @ 171:c8de83fe7faa
removed deprecation warnings
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Jun 2024 15:52:51 +0200 |
parents | 6fada29b6759 |
children | f8dc8dd2da76 |
comparison
equal
deleted
inserted
replaced
170:b49eeb36cd0d | 171:c8de83fe7faa |
---|---|
51 PythonObject result(lock, PyObject_CallObject(receivedInstanceCallback_, args.GetPyObject())); | 51 PythonObject result(lock, PyObject_CallObject(receivedInstanceCallback_, args.GetPyObject())); |
52 | 52 |
53 std::string traceback; | 53 std::string traceback; |
54 if (lock.HasErrorOccurred(traceback)) | 54 if (lock.HasErrorOccurred(traceback)) |
55 { | 55 { |
56 OrthancPlugins::LogError("Error in the Python received instance callback, traceback:\n" + traceback); | 56 ORTHANC_PLUGINS_LOG_ERROR("Error in the Python received instance callback, traceback:\n" + traceback); |
57 return OrthancPluginReceivedInstanceAction_KeepAsIs; | 57 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
58 } | 58 } |
59 else if (!PyTuple_Check(result.GetPyObject()) || PyTuple_Size(result.GetPyObject()) != 2) | 59 else if (!PyTuple_Check(result.GetPyObject()) || PyTuple_Size(result.GetPyObject()) != 2) |
60 { | 60 { |
61 OrthancPlugins::LogError("The Python received instance callback has not returned a tuple as expected"); | 61 ORTHANC_PLUGINS_LOG_ERROR("The Python received instance callback has not returned a tuple as expected"); |
62 return OrthancPluginReceivedInstanceAction_KeepAsIs; | 62 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
63 } | 63 } |
64 else | 64 else |
65 { | 65 { |
66 PyObject* returnCode = PyTuple_GET_ITEM(result.GetPyObject(), 0); | 66 PyObject* returnCode = PyTuple_GET_ITEM(result.GetPyObject(), 0); |
67 PyObject* modifiedDicom = PyTuple_GET_ITEM(result.GetPyObject(), 1); | 67 PyObject* modifiedDicom = PyTuple_GET_ITEM(result.GetPyObject(), 1); |
68 | 68 |
69 if (!PyLong_Check(returnCode)) | 69 if (!PyLong_Check(returnCode)) |
70 { | 70 { |
71 OrthancPlugins::LogError("The Python received instance callback has not returned an int as the first element of the return tuple"); | 71 ORTHANC_PLUGINS_LOG_ERROR("The Python received instance callback has not returned an int as the first element of the return tuple"); |
72 return OrthancPluginReceivedInstanceAction_KeepAsIs; | 72 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
73 } | 73 } |
74 | 74 |
75 OrthancPluginReceivedInstanceAction resultCode = static_cast<OrthancPluginReceivedInstanceAction>(PyLong_AsLong(returnCode)); | 75 OrthancPluginReceivedInstanceAction resultCode = static_cast<OrthancPluginReceivedInstanceAction>(PyLong_AsLong(returnCode)); |
76 | 76 |
83 { | 83 { |
84 char* pythonBuffer = NULL; | 84 char* pythonBuffer = NULL; |
85 Py_ssize_t pythonSize = 0; | 85 Py_ssize_t pythonSize = 0; |
86 if (PyBytes_AsStringAndSize(modifiedDicom, &pythonBuffer, &pythonSize) == 1) | 86 if (PyBytes_AsStringAndSize(modifiedDicom, &pythonBuffer, &pythonSize) == 1) |
87 { | 87 { |
88 OrthancPlugins::LogError("Cannot access the byte buffer returned by the Python received instance callback"); | 88 ORTHANC_PLUGINS_LOG_ERROR("Cannot access the byte buffer returned by the Python received instance callback"); |
89 return OrthancPluginReceivedInstanceAction_KeepAsIs; | 89 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
90 } | 90 } |
91 else | 91 else |
92 { | 92 { |
93 OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), modifiedDicomBuffer, pythonSize); | 93 OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), modifiedDicomBuffer, pythonSize); |
94 | 94 |
95 if (pythonSize != 0) | 95 if (pythonSize != 0) |
96 { | 96 { |
97 if (modifiedDicomBuffer->data == NULL) | 97 if (modifiedDicomBuffer->data == NULL) |
98 { | 98 { |
99 OrthancPlugins::LogError("Cannot allocate memory in the Python received instance callback"); | 99 ORTHANC_PLUGINS_LOG_ERROR("Cannot allocate memory in the Python received instance callback"); |
100 return OrthancPluginReceivedInstanceAction_KeepAsIs; | 100 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
101 } | 101 } |
102 else | 102 else |
103 { | 103 { |
104 memcpy(modifiedDicomBuffer->data, pythonBuffer, pythonSize); | 104 memcpy(modifiedDicomBuffer->data, pythonBuffer, pythonSize); |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 catch (OrthancPlugins::PluginException& e) | 113 catch (OrthancPlugins::PluginException& e) |
114 { | 114 { |
115 OrthancPlugins::LogError("Error in the Python received instance callback: " + | 115 ORTHANC_PLUGINS_LOG_ERROR("Error in the Python received instance callback: " + |
116 std::string(e.What(OrthancPlugins::GetGlobalContext()))); | 116 std::string(e.What(OrthancPlugins::GetGlobalContext()))); |
117 } | 117 } |
118 | 118 |
119 return OrthancPluginReceivedInstanceAction_KeepAsIs; | 119 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
120 } | 120 } |
121 | 121 |