Lines Matching defs:attrib
143 GAttrib *g_attrib_ref(GAttrib *attrib)
145 if (!attrib)
148 g_atomic_int_inc(&attrib->refs);
150 return attrib;
170 static void attrib_destroy(GAttrib *attrib)
175 while ((c = g_queue_pop_head(attrib->queue)))
178 g_queue_free(attrib->queue);
179 attrib->queue = NULL;
181 for (l = attrib->events; l; l = l->next)
184 g_slist_free(attrib->events);
185 attrib->events = NULL;
187 if (attrib->timeout_watch > 0)
188 g_source_remove(attrib->timeout_watch);
190 if (attrib->write_watch > 0)
191 g_source_remove(attrib->write_watch);
193 if (attrib->read_watch > 0) {
194 g_source_remove(attrib->read_watch);
195 g_io_channel_unref(attrib->io);
198 g_free(attrib->buf);
200 if (attrib->destroy)
201 attrib->destroy(attrib->destroy_user_data);
203 g_free(attrib);
206 void g_attrib_unref(GAttrib *attrib)
208 if (!attrib)
211 if (g_atomic_int_dec_and_test(&attrib->refs) == FALSE)
214 attrib_destroy(attrib);
217 GIOChannel *g_attrib_get_channel(GAttrib *attrib)
219 if (!attrib)
222 return attrib->io;
225 gboolean g_attrib_set_disconnect_function(GAttrib *attrib,
228 if (attrib == NULL)
231 attrib->disconnect = disconnect;
232 attrib->disc_user_data = user_data;
237 gboolean g_attrib_set_destroy_function(GAttrib *attrib,
240 if (attrib == NULL)
243 attrib->destroy = destroy;
244 attrib->destroy_user_data = user_data;
251 struct _GAttrib *attrib = data;
253 attrib_destroy(attrib);
261 struct _GAttrib *attrib = data;
268 if (attrib->disconnect)
269 attrib->disconnect(attrib->disc_user_data);
274 cmd = g_queue_peek_head(attrib->queue);
284 g_queue_pop_head(attrib->queue);
292 if (attrib->timeout_watch == 0)
293 attrib->timeout_watch = g_timeout_add_seconds(GATT_TIMEOUT,
294 disconnect_timeout, attrib);
301 struct _GAttrib *attrib = data;
303 attrib->write_watch = 0;
306 static void wake_up_sender(struct _GAttrib *attrib)
308 if (attrib->write_watch == 0)
309 attrib->write_watch = g_io_add_watch_full(attrib->io,
311 attrib, destroy_sender);
316 struct _GAttrib *attrib = data;
324 if (attrib->timeout_watch > 0) {
325 g_source_remove(attrib->timeout_watch);
326 attrib->timeout_watch = 0;
330 attrib->read_watch = 0;
331 if (attrib->disconnect)
332 attrib->disconnect(attrib->disc_user_data);
345 for (l = attrib->events; l; l = l->next) {
356 cmd = g_queue_pop_head(attrib->queue);
359 return attrib->events != NULL;
375 qempty = attrib->queue == NULL || g_queue_is_empty(attrib->queue);
385 wake_up_sender(attrib);
392 struct _GAttrib *attrib;
398 attrib = g_try_new0(struct _GAttrib, 1);
399 if (attrib == NULL)
402 attrib->io = g_io_channel_ref(io);
403 attrib->queue = g_queue_new();
405 attrib->read_watch = g_io_add_watch(attrib->io,
407 received_data, attrib);
409 if (bt_io_get(attrib->io, BT_IO_L2CAP, NULL,
417 attrib->buf = g_malloc0(omtu);
418 attrib->buflen = omtu;
420 return g_attrib_ref(attrib);
423 guint g_attrib_send(GAttrib *attrib, guint id, guint8 opcode,
444 g_queue_push_head(attrib->queue, c);
446 c->id = ++attrib->next_cmd_id;
447 g_queue_push_tail(attrib->queue, c);
450 if (g_queue_get_length(attrib->queue) == 1)
451 wake_up_sender(attrib);
464 gboolean g_attrib_cancel(GAttrib *attrib, guint id)
469 if (attrib == NULL || attrib->queue == NULL)
472 l = g_queue_find_custom(attrib->queue, GUINT_TO_POINTER(id),
479 if (cmd == g_queue_peek_head(attrib->queue) && cmd->sent)
482 g_queue_remove(attrib->queue, cmd);
489 gboolean g_attrib_cancel_all(GAttrib *attrib)
494 if (attrib == NULL || attrib->queue == NULL)
497 while ((c = g_queue_pop_head(attrib->queue))) {
511 g_queue_push_head(attrib->queue, head);
517 gboolean g_attrib_set_debug(GAttrib *attrib,
523 uint8_t *g_attrib_get_buffer(GAttrib *attrib, int *len)
528 *len = attrib->buflen;
530 return attrib->buf;
533 gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu)
541 if (!bt_io_set(attrib->io, BT_IO_L2CAP, NULL,
546 attrib->buf = g_realloc(attrib->buf, mtu);
548 attrib->buflen = mtu;
553 guint g_attrib_register(GAttrib *attrib, guint8 opcode,
567 event->id = ++attrib->next_evt_id;
569 attrib->events = g_slist_append(attrib->events, event);
582 gboolean g_attrib_is_encrypted(GAttrib *attrib)
586 if (!bt_io_get(attrib->io, BT_IO_L2CAP, NULL,
594 gboolean g_attrib_unregister(GAttrib *attrib, guint id)
599 l = g_slist_find_custom(attrib->events, GUINT_TO_POINTER(id),
606 attrib->events = g_slist_remove(attrib->events, evt);
616 gboolean g_attrib_unregister_all(GAttrib *attrib)
620 if (attrib->events == NULL)
623 for (l = attrib->events; l; l = l->next) {
632 g_slist_free(attrib->events);
633 attrib->events = NULL;