| 92 | } |
| 93 | |
| 94 | std::pair<bool, bool> ToggleQueue::cancel(ObjectInstance* obj) { |
| 95 | debug("cancel", obj); |
| 96 | g_assert(owns_lock() && "Unsafe access to queue"); |
| 97 | bool had_toggle_down = false; |
| 98 | bool had_toggle_up = false; |
| 99 | |
| 100 | for (auto it = q.begin(); it != q.end();) { |
| 101 | if (it->object == obj) { |
| 102 | had_toggle_down |= (it->direction == Direction::DOWN); |
| 103 | had_toggle_up |= (it->direction == Direction::UP); |
| 104 | it = q.erase(it); |
| 105 | continue; |
| 106 | } |
| 107 | it++; |
| 108 | } |
| 109 | |
| 110 | gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "ToggleQueue: %p (%p) was %s", obj, |
| 111 | obj ? obj->ptr() : nullptr, |
| 112 | had_toggle_down && had_toggle_up |
| 113 | ? "queued to toggle BOTH" |
| 114 | : had_toggle_down ? "queued to toggle DOWN" |
| 115 | : had_toggle_up ? "queued to toggle UP" |
| 116 | : "not queued"); |
| 117 | return {had_toggle_down, had_toggle_up}; |
| 118 | } |
| 119 | |
| 120 | bool ToggleQueue::handle_toggle(Handler handler) { |
| 121 | g_assert(owns_lock() && "Unsafe access to queue"); |