128
128
if (cookie == the_invalid_cookie)
131
std::weak_ptr<DisplayStateLock> wp{shared_from_this()};
131
// We make sure that we keep ourselves alive to make sure
132
// that release requests are always correctly issued.
133
auto sp = shared_from_this();
133
135
auto current_cookie(cookie);
135
137
timeout.expires_from_now(timeout_for_release());
136
timeout.async_wait([wp, state, current_cookie](const boost::system::error_code& ec)
138
timeout.async_wait([sp, state, current_cookie](const boost::system::error_code& ec)
138
140
// We only return early from the timeout handler if the operation has been
139
141
// explicitly aborted before.
140
142
if (ec == boost::asio::error::operation_aborted)
143
if (auto sp = wp.lock())
145
sp->object->invoke_method_asynchronously_with_callback<com::canonical::Unity::Screen::removeDisplayOnRequest, void>(
146
[wp, state, current_cookie](const core::dbus::Result<void>& result)
145
sp->object->invoke_method_asynchronously_with_callback<com::canonical::Unity::Screen::removeDisplayOnRequest, void>(
146
[sp, state, current_cookie](const core::dbus::Result<void>& result)
148
if (result.is_error())
148
if (result.is_error())
150
std::cerr << result.error().print() << std::endl;
154
if (auto sp = wp.lock())
156
sp->signals.released(state);
158
// We might have issued a different request before and
159
// only call the display state done if the original cookie
160
// corresponds to the one we just gave up.
161
if (sp->cookie == current_cookie)
162
sp->cookie = the_invalid_cookie;
150
std::cerr << result.error().print() << std::endl;
154
sp->signals.released(state);
156
// We might have issued a different request before and
157
// only call the display state done if the original cookie
158
// corresponds to the one we just gave up.
159
if (sp->cookie == current_cookie)
160
sp->cookie = the_invalid_cookie;