Changeset 640:237cf6339546 in freeDiameter for extensions/dbg_interactive/routing.i
- Timestamp:
- Dec 20, 2010, 7:36:40 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/dbg_interactive/routing.i
r637 r640 77 77 } 78 78 79 80 79 81 %extend rtd_candidate { 80 82 void dump() { … … 86 88 } 87 89 90 91 %{ 92 /* call it (will be called from a different thread than the interpreter, when message arrives) */ 93 static int call_the_python_rt_fwd_callback(void * pycb, struct msg **msg) { 94 PyObject *PyMsg; 95 PyObject *cb, *result = NULL; 96 int ret = 0; 97 98 if (!pycb) { 99 fd_log_debug("Internal error: missing the callback!\n"); 100 return ENOTSUP; 101 } 102 cb = pycb; 103 104 SWIG_PYTHON_THREAD_BEGIN_BLOCK; 105 /* Convert the arguments */ 106 PyMsg = SWIG_NewPointerObj((void *)*msg, SWIGTYPE_p_msg, 0 ); 107 108 /* Call the function */ 109 result = PyEval_CallFunction(cb, "(O)", PyMsg); 110 111 /* The result is supposedly composed of: [ ret, *msg ] */ 112 if ((result == NULL) || (!PyList_Check(result)) || (PyList_Size(result) != 2)) { 113 fd_log_debug("Error: The Python callback did not return [ ret, msg ].\n"); 114 ret = EINVAL; 115 goto out; 116 } 117 118 /* Convert the return values */ 119 if (!SWIG_IsOK(SWIG_AsVal_int(PyList_GetItem(result, 0), &ret))) { 120 fd_log_debug("Error: Cannot convert the first return value to integer.\n"); 121 ret = EINVAL; 122 goto out; 123 } 124 if (ret) { 125 TRACE_DEBUG(INFO, "The Python callback returned the error code %d (%s)\n", ret, strerror(ret)); 126 goto out; 127 } 128 129 if (!SWIG_IsOK(SWIG_ConvertPtr(PyList_GetItem(result, 1), (void *)msg, SWIGTYPE_p_msg, SWIG_POINTER_DISOWN))) { 130 fd_log_debug("Error: Cannot convert the second return value to message.\n"); 131 ret = EINVAL; 132 goto out; 133 } 134 135 out: 136 Py_XDECREF(result); 137 138 SWIG_PYTHON_THREAD_END_BLOCK; 139 return ret; 140 } 141 %} 142 143 144 struct fd_rt_fwd_hdl { 145 }; 146 147 %extend fd_rt_fwd_hdl{ 148 fd_rt_fwd_hdl(PyObject * PyCb, enum fd_rt_fwd_dir dir) { 149 struct fd_rt_fwd_hdl * r = NULL; 150 int ret; 151 152 Py_XINCREF(PyCb); 153 154 ret = fd_rt_fwd_register( call_the_python_rt_fwd_callback, PyCb, dir, &r ); 155 if (ret != 0) { 156 DI_ERROR(ret, NULL, NULL); 157 return NULL; 158 } 159 return r; 160 } 161 162 ~fd_rt_fwd_hdl() { 163 PyObject * func; 164 int ret = fd_rt_fwd_unregister ( $self, (void *) &func ); 165 if (ret != 0) { 166 DI_ERROR(ret, NULL, NULL); 167 return; 168 } 169 Py_XDECREF(func); 170 return; 171 } 172 } 173 174 175 %{ 176 /* call it (will be called from a different thread than the interpreter, when message arrives) */ 177 static int call_the_python_rt_out_callback(void * pycb, struct msg *msg, struct fd_list * candidates) { 178 PyObject *PyMsg, *PyCands; 179 PyObject *cb, *result = NULL; 180 int ret = 0; 181 182 if (!pycb) { 183 fd_log_debug("Internal error: missing the callback!\n"); 184 return ENOTSUP; 185 } 186 cb = pycb; 187 188 SWIG_PYTHON_THREAD_BEGIN_BLOCK; 189 /* Convert the arguments */ 190 PyMsg = SWIG_NewPointerObj((void *)msg, SWIGTYPE_p_msg, 0 ); 191 PyCands = SWIG_NewPointerObj((void *)candidates, SWIGTYPE_p_fd_list, 0 ); 192 193 /* Call the function */ 194 result = PyEval_CallFunction(cb, "(OO)", PyMsg, PyCands); 195 196 /* The result is supposedly composed of: [ ret, *msg ] */ 197 if (result == NULL){ 198 fd_log_debug("Error: The Python callback raised an exception.\n"); 199 ret = EINVAL; 200 goto out; 201 } 202 203 /* Convert the return values */ 204 if (!SWIG_IsOK(SWIG_AsVal_int(result, &ret))) { 205 fd_log_debug("Error: Cannot convert the return value to integer.\n"); 206 ret = EINVAL; 207 goto out; 208 } 209 out: 210 Py_XDECREF(result); 211 212 SWIG_PYTHON_THREAD_END_BLOCK; 213 return ret; 214 } 215 %} 216 217 218 struct fd_rt_out_hdl { 219 }; 220 221 %extend fd_rt_out_hdl{ 222 fd_rt_out_hdl(PyObject * PyCb, int priority = 0) { 223 struct fd_rt_out_hdl * r = NULL; 224 int ret; 225 226 Py_XINCREF(PyCb); 227 228 ret = fd_rt_out_register( call_the_python_rt_out_callback, PyCb, priority, &r ); 229 if (ret != 0) { 230 DI_ERROR(ret, NULL, NULL); 231 return NULL; 232 } 233 return r; 234 } 235 236 ~fd_rt_out_hdl() { 237 PyObject * func; 238 int ret = fd_rt_out_unregister ( $self, (void *) &func ); 239 if (ret != 0) { 240 DI_ERROR(ret, NULL, NULL); 241 return; 242 } 243 Py_XDECREF(func); 244 return; 245 } 246 } 247
Note: See TracChangeset
for help on using the changeset viewer.