Lines Matching refs:context
113 static struct bt_queue *bt_q_get_head(struct btbridged_context *context) in bt_q_get_head() argument
115 return context ? context->bt_q : NULL; in bt_q_get_head()
118 static struct bt_queue *bt_q_get_seq(struct btbridged_context *context, uint8_t seq) in bt_q_get_seq() argument
122 assert(context); in bt_q_get_seq()
124 t = context->bt_q; in bt_q_get_seq()
132 static struct bt_queue *bt_q_get_msg(struct btbridged_context *context) in bt_q_get_msg() argument
136 assert(context); in bt_q_get_msg()
138 t = context->bt_q; in bt_q_get_msg()
146 static struct bt_queue *bt_q_enqueue(struct btbridged_context *context, uint8_t *bt_data) in bt_q_enqueue() argument
152 assert(context && bt_data); in bt_q_enqueue()
164 bt_q = context->bt_q; in bt_q_enqueue()
187 context->bt_q = n; in bt_q_enqueue()
213 static struct bt_queue *bt_q_drop(struct btbridged_context *context, struct bt_queue *element) in bt_q_drop() argument
217 assert(context); in bt_q_drop()
219 if (!element || !context || !context->bt_q) in bt_q_drop()
222 if (element == context->bt_q) { in bt_q_drop()
223 context->bt_q = context->bt_q->next; in bt_q_drop()
225 r = context->bt_q; in bt_q_drop()
238 return context->bt_q; in bt_q_drop()
241 static struct bt_queue *bt_q_dequeue(struct btbridged_context *context) in bt_q_dequeue() argument
246 assert(context); in bt_q_dequeue()
248 bt_q = context->bt_q; in bt_q_dequeue()
256 context->bt_q = r; in bt_q_dequeue()
283 struct btbridged_context *context; in method_send_message() local
294 context = (struct btbridged_context *)userdata; in method_send_message()
295 if (!context) { in method_send_message()
315 bt_msg = bt_q_get_seq(context, seq); in method_send_message()
334 context->fds[BT_FD].events |= POLLOUT; in method_send_message()
340 static int bt_host_write(struct btbridged_context *context, struct bt_queue *bt_msg) in bt_host_write() argument
347 assert(context); in bt_host_write()
352 head = bt_q_get_head(context); in bt_host_write()
367 r = timerfd_settime(context->fds[TIMER_FD].fd, TFD_TIMER_ABSTIME, &ts, NULL); in bt_host_write()
384 len = write(context->fds[BT_FD].fd, data, data[0] + 1); in bt_host_write()
418 if (sd_bus_send(context->bus, msg, NULL) < 0) in bt_host_write()
422 bt_q_drop(context, bt_msg); in bt_host_write()
427 if (!bt_q_get_msg(context)) { in bt_host_write()
429 context->fds[BT_FD].events = POLLIN; in bt_host_write()
435 static int dispatch_timer(struct btbridged_context *context) in dispatch_timer() argument
438 if (context->fds[TIMER_FD].revents & POLLIN) { in dispatch_timer()
444 r = read(context->fds[TIMER_FD].fd, &counter, sizeof(counter)); in dispatch_timer()
447 head = bt_q_get_head(context); in dispatch_timer()
458 if (sd_bus_send(context->bus, msg, NULL) < 0) in dispatch_timer()
479 context->fds[BT_FD].events |= POLLOUT; in dispatch_timer()
485 static int dispatch_sd_bus(struct btbridged_context *context) in dispatch_sd_bus() argument
488 if (context->fds[SD_BUS_FD].revents) { in dispatch_sd_bus()
489 r = sd_bus_process(context->bus, NULL); in dispatch_sd_bus()
497 static int dispatch_bt(struct btbridged_context *context) in dispatch_bt() argument
502 assert(context); in dispatch_bt()
504 if (context->fds[BT_FD].revents & POLLIN) { in dispatch_bt()
509 r = read(context->fds[BT_FD].fd, data, sizeof(data)); in dispatch_bt()
520 new = bt_q_enqueue(context, data); in dispatch_bt()
525 if (new == bt_q_get_head(context)) { in dispatch_bt()
535 r = timerfd_settime(context->fds[TIMER_FD].fd, 0, &ts, NULL); in dispatch_bt()
540 r = sd_bus_message_new_signal(context->bus, &msg, OBJ_NAME, DBUS_NAME, "ReceivedMessage"); in dispatch_bt()
576 r = sd_bus_send(context->bus, msg, NULL); in dispatch_bt()
588 if (context->fds[BT_FD].revents & POLLOUT) { in dispatch_bt()
590 bt_msg = bt_q_get_msg(context); in dispatch_bt()
597 r = bt_host_write(context, bt_msg); in dispatch_bt()
630 struct btbridged_context *context; in main() local
642 context = calloc(1, sizeof(*context)); in main()
672 r = sd_bus_default_system(&context->bus); in main()
679 r = sd_bus_add_object_vtable(context->bus, in main()
684 context); in main()
691 …r = sd_bus_request_name(context->bus, DBUS_NAME, SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE… in main()
698 context->fds[SD_BUS_FD].fd = sd_bus_get_fd(context->bus); in main()
699 if (context->fds[SD_BUS_FD].fd < 0) { in main()
706 context->fds[BT_FD].fd = open(BT_BMC_PATH, O_RDWR | O_NONBLOCK); in main()
707 if (context->fds[BT_FD].fd < 0) { in main()
714 context->fds[TIMER_FD].fd = timerfd_create(CLOCK_MONOTONIC, 0); in main()
715 if (context->fds[TIMER_FD].fd < 0) { in main()
720 context->fds[SD_BUS_FD].events = POLLIN; in main()
721 context->fds[BT_FD].events = POLLIN; in main()
722 context->fds[TIMER_FD].events = POLLIN; in main()
727 polled = poll(context->fds, TOTAL_FDS, 1000); in main()
735 r = dispatch_sd_bus(context); in main()
740 r = dispatch_bt(context); in main()
745 r = dispatch_timer(context); in main()
753 if (bt_q_get_head(context)) { in main()
755 while (bt_q_dequeue(context)); in main()
757 close(context->fds[BT_FD].fd); in main()
758 close(context->fds[TIMER_FD].fd); in main()
759 sd_bus_unref(context->bus); in main()
760 free(context); in main()