feat(producer) add exception mechanism for send message
diff --git a/src/PythonWrapper.cpp b/src/PythonWrapper.cpp
index f54a46d..dec63ce 100644
--- a/src/PythonWrapper.cpp
+++ b/src/PythonWrapper.cpp
@@ -179,8 +179,17 @@
void PySendExceptionCallback(CMQException e, CMessage *msg, void *pyCallback){
PyThreadStateLock PyThreadLock; // ensure hold GIL, before call python callback
+ PyMQException exception;
PyCallback *callback = (PyCallback *)pyCallback;
- boost::python::call<void>(callback->exceptionCallback, (void *) msg, e);
+ exception.error = e.error;
+ exception.line = e.line;
+ strncpy(exception.file, e.file, MAX_EXEPTION_FILE_LENGTH - 1);
+ exception.file[MAX_EXEPTION_FILE_LENGTH - 1] = 0;
+ strncpy(exception.msg, e.msg, MAX_EXEPTION_MSG_LENGTH - 1);
+ exception.msg[MAX_EXEPTION_MSG_LENGTH - 1] = 0;
+ strncpy(exception.type, e.type, MAX_EXEPTION_TYPE_LENGTH - 1);
+ exception.type[MAX_EXEPTION_TYPE_LENGTH - 1] = 0;
+ boost::python::call<void>(callback->exceptionCallback, (void *) msg, exception);
delete pyCallback;
}
@@ -333,6 +342,13 @@
.def("GetMsgId", &PySendResult::GetMsgId);
class_<PyMessageExt>("CMessageExt");
+ class_<PyMQException>("MQException")
+ .def_readonly("error", &PyMQException::error, "error")
+ .def_readonly("line", &PyMQException::line, "line")
+ .def("GetFile", &PyMQException::GetFile)
+ .def("GetMsg", &PyMQException::GetMsg)
+ .def("GetType", &PyMQException::GetType);
+
//For Message
def("CreateMessage", PyCreateMessage, return_value_policy<return_opaque_pointer>());
def("DestroyMessage", PyDestroyMessage);
diff --git a/src/PythonWrapper.h b/src/PythonWrapper.h
index d978984..c5bc5b9 100644
--- a/src/PythonWrapper.h
+++ b/src/PythonWrapper.h
@@ -37,6 +37,25 @@
}
} PySendResult;
+typedef struct _PyMQException_ {
+ int error;
+ int line;
+ char file[MAX_EXEPTION_FILE_LENGTH];
+ char msg[MAX_EXEPTION_MSG_LENGTH];
+ char type[MAX_EXEPTION_TYPE_LENGTH];
+
+ const char *GetFile() {
+ return (const char *) file;
+ }
+ const char *GetMsg() {
+ return (const char *) msg;
+ }
+ const char *GetType() {
+ return (const char *) type;
+ }
+} PyMQException;
+
+
typedef struct _PyMessageExt_ {
CMessageExt *pMessageExt;
} PyMessageExt;