static void qd_core_agent_create_handler(qdr_core_t *core, qd_message_t *msg, qd_router_entity_type_t entity_type, qd_router_operation_type_t operation_type, qd_field_iterator_t *name_iter) { // // Add the Body // qd_composed_field_t *out_body = qd_compose(QD_PERFORMATIVE_BODY_AMQP_VALUE, 0); // Set the callback function. qdr_manage_handler(core, qd_manage_response_handler); // Call local function that creates and returns a qd_management_context_t containing the values passed in. qd_management_context_t *ctx = qd_management_context(qd_message(), msg, out_body, 0, core, operation_type, 0); qd_field_iterator_t *body_iter = qd_message_field_iterator(msg, QD_FIELD_BODY); qd_parsed_field_t *in_body = qd_parse(body_iter); qdr_manage_create(core, ctx, entity_type, name_iter, in_body, out_body); qd_field_iterator_free(body_iter); }
static void qd_core_agent_query_handler(qdr_core_t *core, qd_router_entity_type_t entity_type, qd_router_operation_type_t operation_type, qd_message_t *msg, int *count, int *offset) { // // Add the Body. // qd_composed_field_t *field = qd_compose(QD_PERFORMATIVE_BODY_AMQP_VALUE, 0); // Start a map in the body. Look for the end map in the callback function, qd_manage_response_handler. qd_compose_start_map(field); //add a "attributeNames" key qd_compose_insert_string(field, ATTRIBUTE_NAMES); // Call local function that creates and returns a local qd_management_context_t object containing the values passed in. qd_management_context_t *ctx = qd_management_context(qd_message(), msg, field, 0, core, operation_type, (*count)); // Grab the attribute names from the incoming message body. The attribute names will be used later on in the response. qd_parsed_field_t *attribute_names_parsed_field = 0; qd_field_iterator_t *body_iter = qd_message_field_iterator(msg, QD_FIELD_BODY); qd_parsed_field_t *body = qd_parse(body_iter); if (body != 0 && qd_parse_is_map(body)) { attribute_names_parsed_field = qd_parse_value_by_key(body, ATTRIBUTE_NAMES); } // Set the callback function. qdr_manage_handler(core, qd_manage_response_handler); ctx->query = qdr_manage_query(core, ctx, entity_type, attribute_names_parsed_field, field); //Add the attribute names qdr_query_add_attribute_names(ctx->query); //this adds a list of attribute names like ["attribute1", "attribute2", "attribute3", "attribute4",] qd_compose_insert_string(field, results); //add a "results" key qd_compose_start_list(field); //start the list for results qdr_query_get_first(ctx->query, (*offset)); qd_field_iterator_free(body_iter); qd_parse_free(body); }
static void qd_core_agent_update_handler(qdr_core_t *core, qd_message_t *msg, qd_router_entity_type_t entity_type, qd_router_operation_type_t operation_type, qd_field_iterator_t *identity_iter, qd_field_iterator_t *name_iter) { qd_composed_field_t *out_body = qd_compose(QD_PERFORMATIVE_BODY_AMQP_VALUE, 0); // Set the callback function. qdr_manage_handler(core, qd_manage_response_handler); qd_management_context_t *ctx = qd_management_context(qd_message(), msg, out_body, 0, core, operation_type, 0); qd_field_iterator_t *iter = qd_message_field_iterator(msg, QD_FIELD_BODY); qd_parsed_field_t *in_body= qd_parse(iter); qd_field_iterator_free(iter); qdr_manage_update(core, ctx, entity_type, name_iter, identity_iter, in_body, out_body); }
static PyObject *qd_python_send(PyObject *self, PyObject *args) { qd_error_clear(); IoAdapter *ioa = (IoAdapter*) self; qd_composed_field_t *field = 0; PyObject *message = 0; int no_echo = 1; int control = 0; if (!PyArg_ParseTuple(args, "O|ii", &message, &no_echo, &control)) return 0; if (compose_python_message(&field, message, ioa->qd) == QD_ERROR_NONE) { qd_message_t *msg = qd_message(); qd_message_compose_2(msg, field); qd_composed_field_t *ingress = qd_compose_subfield(0); qd_compose_insert_string(ingress, qd_router_id(ioa->qd)); qd_composed_field_t *trace = qd_compose_subfield(0); qd_compose_start_list(trace); qd_compose_insert_string(trace, qd_router_id(ioa->qd)); qd_compose_end_list(trace); qd_message_set_ingress_annotation(msg, ingress); qd_message_set_trace_annotation(msg, trace); PyObject *address = PyObject_GetAttrString(message, "address"); if (address) { qdr_send_to2(ioa->core, msg, PyString_AsString(address), (bool) no_echo, (bool) control); Py_DECREF(address); } qd_compose_free(field); qd_message_free(msg); Py_RETURN_NONE; } if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError, qd_error_message()); return 0; }
qd_message_t *qd_message_receive(pn_delivery_t *delivery) { pn_link_t *link = pn_delivery_link(delivery); ssize_t rc; qd_buffer_t *buf; qd_message_pvt_t *msg = (qd_message_pvt_t*) pn_delivery_get_context(delivery); // // If there is no message associated with the delivery, this is the first time // we've received anything on this delivery. Allocate a message descriptor and // link it and the delivery together. // if (!msg) { msg = (qd_message_pvt_t*) qd_message(); pn_delivery_set_context(delivery, (void*) msg); } // // Get a reference to the tail buffer on the message. This is the buffer into which // we will store incoming message data. If there is no buffer in the message, allocate // an empty one and add it to the message. // buf = DEQ_TAIL(msg->content->buffers); if (!buf) { buf = qd_buffer(); DEQ_INSERT_TAIL(msg->content->buffers, buf); } while (1) { // // Try to receive enough data to fill the remaining space in the tail buffer. // rc = pn_link_recv(link, (char*) qd_buffer_cursor(buf), qd_buffer_capacity(buf)); // // If we receive PN_EOS, we have come to the end of the message. // if (rc == PN_EOS) { // // If the last buffer in the list is empty, remove it and free it. This // will only happen if the size of the message content is an exact multiple // of the buffer size. // if (qd_buffer_size(buf) == 0) { DEQ_REMOVE_TAIL(msg->content->buffers); qd_buffer_free(buf); } pn_delivery_set_context(delivery, 0); char repr[qd_message_repr_len()]; qd_log(log_source, QD_LOG_TRACE, "Received %s on link %s", qd_message_repr((qd_message_t*)msg, repr, sizeof(repr)), pn_link_name(link)); return (qd_message_t*) msg; } if (rc > 0) { // // We have received a positive number of bytes for the message. Advance // the cursor in the buffer. // qd_buffer_insert(buf, rc); // // If the buffer is full, allocate a new empty buffer and append it to the // tail of the message's list. // if (qd_buffer_capacity(buf) == 0) { buf = qd_buffer(); DEQ_INSERT_TAIL(msg->content->buffers, buf); } } else // // We received zero bytes, and no PN_EOS. This means that we've received // all of the data available up to this point, but it does not constitute // the entire message. We'll be back later to finish it up. // break; } return 0; }