Changeset 649:5e5d8152c229 in freeDiameter for extensions/dbg_interactive/messages.i
- Timestamp:
- Jan 5, 2011, 5:13:34 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/dbg_interactive/messages.i
r640 r649 55 55 } 56 56 57 SWIG_PYTHON_THREAD_BEGIN_BLOCK; 58 59 if (!msg || !*msg) { 60 PyMsg = Py_None; 61 } else { 62 PyMsg = SWIG_NewPointerObj((void *)*msg, SWIGTYPE_p_msg, 0 ); 63 } 64 65 result = PyEval_CallFunction(l->cb, "(OO)", PyMsg, l->data); 66 Py_XDECREF(l->cb); 67 Py_XDECREF(l->data); 68 free(l); 69 70 /* The callback is supposed to return a message or NULL */ 71 if (!SWIG_IsOK(SWIG_ConvertPtr(result, (void *)msg, SWIGTYPE_p_msg, SWIG_POINTER_DISOWN))) { 72 fd_log_debug("Error: Cannot convert the return value to message.\n"); 73 *msg = NULL; 74 } 75 76 Py_XDECREF(result); 77 78 SWIG_PYTHON_THREAD_END_BLOCK; 79 57 if (l->cb) { 58 59 SWIG_PYTHON_THREAD_BEGIN_BLOCK; 60 61 if (!msg || !*msg) { 62 PyMsg = Py_None; 63 } else { 64 PyMsg = SWIG_NewPointerObj((void *)*msg, SWIGTYPE_p_msg, 0 ); 65 } 66 67 result = PyEval_CallFunction(l->cb, "(OO)", PyMsg, l->data); 68 Py_XDECREF(l->cb); 69 Py_XDECREF(l->data); 70 free(l); 71 72 /* The callback is supposed to return a message or NULL */ 73 if (!SWIG_IsOK(SWIG_ConvertPtr(result, (void *)msg, SWIGTYPE_p_msg, SWIG_POINTER_DISOWN))) { 74 fd_log_debug("Error: Cannot convert the return value to message.\n"); 75 *msg = NULL; 76 } 77 78 Py_XDECREF(result); 79 80 SWIG_PYTHON_THREAD_END_BLOCK; 81 82 } 83 /* else */ 84 /* Only the timeout was specified, without a callback */ 85 /* in this case, just delete the message */ 86 /* it actually happens automatically when we do nothing. */ 80 87 } 81 88 %} … … 121 128 /* SEND THE MESSAGE */ 122 129 %delobject send; /* when this has been called, the msg must not be freed anymore */ 123 void send(PyObject * PyCb = NULL, PyObject * data = NULL ) {130 void send(PyObject * PyCb = NULL, PyObject * data = NULL, unsigned int timeout = 0) { 124 131 int ret; 125 132 struct msg * m = $self; 126 133 struct anscb_py_layer * l = NULL; 127 134 128 if (PyCb ) {135 if (PyCb || timeout) { 129 136 l = malloc(sizeof(struct anscb_py_layer)); 130 137 if (!l) { … … 139 146 } 140 147 141 ret = fd_msg_send(&m, PyCb ? anscb_python : NULL, l); 148 if (timeout) { 149 struct timespec ts; 150 (void) clock_gettime(CLOCK_REALTIME, &ts); 151 ts.tv_sec += timeout; 152 ret = fd_msg_send_timeout(&m, anscb_python, l, &ts); 153 } else { 154 ret = fd_msg_send(&m, PyCb ? anscb_python : NULL, l); 155 } 142 156 if (ret != 0) { 143 157 DI_ERROR(ret, NULL, NULL); … … 303 317 } 304 318 319 /* Is request? (shortcut) */ 320 PyObject * is_request() { 321 PyObject * r; 322 int ret; 323 struct msg_hdr * h; 324 325 ret = fd_msg_hdr($self, &h); 326 if (ret != 0) { 327 DI_ERROR(ret, NULL, NULL); 328 } 329 if (h->msg_flags & CMD_FLAG_REQUEST) 330 r = Py_True; 331 else 332 r = Py_False; 333 Py_XINCREF(r); 334 return r; 335 } 336 305 337 /* Get the source */ 306 338 char *source() {
Note: See TracChangeset
for help on using the changeset viewer.