MCPcopy Create free account
hub / github.com/emberian/evdev / sync_events

Function sync_events

src/sync_stream.rs:624–660  ·  view source on GitHub ↗
(
    range: &mut std::ops::Range<usize>,
    event_buf: &[input_event],
    mut handle_event: impl FnMut(InputEvent),
)

Source from the content-addressed store, hash-verified

622/// Err(true) means the device should sync the state with ioctl
623#[inline]
624fn sync_events(
625 range: &mut std::ops::Range<usize>,
626 event_buf: &[input_event],
627 mut handle_event: impl FnMut(InputEvent),
628) -> (Result<input_event, bool>, Option<usize>) {
629 let mut consumed_to = None;
630 let res = 'outer: loop {
631 if let Some(idx) = range.next() {
632 // we're going through and emitting the events of a block that we checked
633 break Ok(event_buf[idx]);
634 }
635 // find the range of this new block: look for a SYN_REPORT
636 let block_start = range.end;
637 let mut block_dropped = false;
638 for (i, ev) in event_buf.iter().enumerate().skip(block_start) {
639 let ev = InputEvent::from(*ev);
640 match ev.destructure() {
641 EventSummary::Synchronization(_, SynchronizationCode::SYN_DROPPED, _) => {
642 block_dropped = true;
643 }
644 EventSummary::Synchronization(_, SynchronizationCode::SYN_REPORT, _) => {
645 consumed_to = Some(i + 1);
646 if block_dropped {
647 *range = event_buf.len()..event_buf.len();
648 break 'outer Err(true);
649 } else {
650 *range = block_start..i + 1;
651 continue 'outer;
652 }
653 }
654 _ => handle_event(ev),
655 }
656 }
657 break Err(false);
658 };
659 (res, consumed_to)
660}
661
662impl fmt::Display for Device {
663 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

Callers 4

nextMethod · 0.85
poll_eventMethod · 0.85
result_events_iterFunction · 0.85
test_iter_consistencyFunction · 0.85

Calls 4

iterMethod · 0.80
lenMethod · 0.80
nextMethod · 0.45
destructureMethod · 0.45

Tested by 1

test_iter_consistencyFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…