guint g_attrib_send(GAttrib *attrib, guint id, guint8 opcode, const guint8 *pdu, guint16 len, GAttribResultFunc func, gpointer user_data, GDestroyNotify notify) { struct command *c; c = g_try_new0(struct command, 1); if (c == NULL) return 0; c->opcode = opcode; c->expected = opcode2expected(opcode); c->pdu = g_malloc(len); memcpy(c->pdu, pdu, len); c->len = len; c->func = func; c->user_data = user_data; c->notify = notify; if (id) { c->id = id; g_queue_push_head(attrib->queue, c); } else { c->id = ++attrib->next_cmd_id; g_queue_push_tail(attrib->queue, c); } if (g_queue_get_length(attrib->queue) == 1) wake_up_sender(attrib); return c->id; }
guint g_attrib_send(GAttrib *attrib, guint id, const guint8 *pdu, guint16 len, GAttribResultFunc func, gpointer user_data, GDestroyNotify notify) { struct command *c; GQueue *queue; uint8_t opcode; if (attrib->stale) return 0; c = g_try_new0(struct command, 1); if (c == NULL) return 0; opcode = pdu[0]; c->opcode = opcode; c->expected = opcode2expected(opcode); c->pdu = g_malloc(len); memcpy(c->pdu, pdu, len); c->len = len; c->func = func; c->user_data = user_data; c->notify = notify; if (is_response(opcode)) queue = attrib->responses; else queue = attrib->requests; if (id) { c->id = id; if (!is_response(opcode)) g_queue_push_head(queue, c); else /* Don't re-order responses even if an ID is given */ g_queue_push_tail(queue, c); } else { c->id = ++attrib->next_cmd_id; g_queue_push_tail(queue, c); } /* * If a command was added to the queue and it was empty before, wake up * the sender. If the sender was already woken up by the second queue, * wake_up_sender will just return. */ if (g_queue_get_length(queue) == 1) wake_up_sender(attrib); return c->id; }