static void qd_io_rx_handler(void *context, qd_message_t *msg, int link_id) { IoAdapter *self = (IoAdapter*) context; // // Parse the message through the body and exit if the message is not well formed. // if (!qd_message_check(msg, QD_DEPTH_BODY)) return; // This is called from non-python threads so we need to acquire the GIL to use python APIS. qd_python_lock_state_t lock_state = qd_python_lock(); PyObject *py_msg = PyObject_CallFunction(message_type, NULL); if (!py_msg) { qd_error_py(); qd_python_unlock(lock_state); return; } iter_to_py_attr(qd_message_field_iterator(msg, QD_FIELD_TO), py_iter_copy, py_msg, "address"); iter_to_py_attr(qd_message_field_iterator(msg, QD_FIELD_REPLY_TO), py_iter_copy, py_msg, "reply_to"); // Note: correlation ID requires _typed() iter_to_py_attr(qd_message_field_iterator_typed(msg, QD_FIELD_CORRELATION_ID), py_iter_parse, py_msg, "correlation_id"); iter_to_py_attr(qd_message_field_iterator(msg, QD_FIELD_APPLICATION_PROPERTIES), py_iter_parse, py_msg, "properties"); iter_to_py_attr(qd_message_field_iterator(msg, QD_FIELD_BODY), py_iter_parse, py_msg, "body"); PyObject *value = PyObject_CallFunction(self->handler, "Ol", py_msg, link_id); Py_DECREF(py_msg); Py_XDECREF(value); qd_error_py(); qd_python_unlock(lock_state); }
static void qd_set_properties(qd_message_t *msg, qd_field_iterator_t **reply_to, qd_composed_field_t **fld) { qd_field_iterator_t *correlation_id = qd_message_field_iterator_typed(msg, QD_FIELD_CORRELATION_ID); // Grab the reply_to field from the incoming message. This is the address we will send the response to. *reply_to = qd_message_field_iterator(msg, QD_FIELD_REPLY_TO); *fld = qd_compose(QD_PERFORMATIVE_PROPERTIES, 0); qd_compose_start_list(*fld); qd_compose_insert_null(*fld); // message-id qd_compose_insert_null(*fld); // user-id qd_compose_insert_string_iterator(*fld, *reply_to); // to qd_compose_insert_null(*fld); // subject qd_compose_insert_null(*fld); qd_compose_insert_typed_iterator(*fld, correlation_id); qd_compose_end_list(*fld); qd_field_iterator_free(correlation_id); }