// ========================================================================== // DEACTIVATE // ========================================================================== std::vector<telnetpp::token> client_option::deactivate() { if (state_ == state::inactive) { return on_state_changed(state_); } if (state_ == state::active) { state_ = state::deactivating; auto response = on_state_changed(state_); response.insert( response.begin(), { telnetpp::element( telnetpp::negotiation(telnetpp::dont, option_) )}); return response; } else { return {}; } }
static void on_state_changed_notify (EosUpdater *proxy, GParamSpec *pspec, gpointer data) { EosUpdaterState state = eos_updater_get_state (proxy); on_state_changed (proxy, state); }
/* We want to poll once when the updater starts. To make sure that we * can quit ourselves gracefully, we wait until the main loop starts. */ static gboolean initial_poll_idle_func (gpointer pointer) { EosUpdater *proxy = (EosUpdater *) pointer; EosUpdaterState initial_state = eos_updater_get_state (proxy); /* Attempt to clear the error by pretending to be ready, which will * trigger a poll */ if (initial_state == EOS_UPDATER_STATE_ERROR) initial_state = EOS_UPDATER_STATE_READY; on_state_changed (proxy, initial_state); /* Disable this function after the first run */ return G_SOURCE_REMOVE; }
void view::on_state(state_t const& state) { state_ = state; on_state_changed(); // Задействован только в чарте }
// ========================================================================== // NEGOTIATE // ========================================================================== std::vector<telnetpp::token> client_option::negotiate(telnetpp::u8 request) { switch(state_) { case state::inactive : if (request == telnetpp::will && activatable_) { state_ = state::active; auto response = on_state_changed(state_); response.insert( response.begin(), { telnetpp::element( telnetpp::negotiation(telnetpp::do_, option_) )}); return response; } else { return { telnetpp::element( telnetpp::negotiation(telnetpp::dont, option_) )}; } case state::activating : if (request == telnetpp::will) { state_ = state::active; return on_state_changed(state_); } else { state_ = state::inactive; return on_state_changed(state_); } case state::active : if (request == telnetpp::will) { return { telnetpp::element( telnetpp::negotiation(telnetpp::do_, option_) )}; } else { state_ = state::inactive; auto response = on_state_changed(state_); response.insert( response.begin(), { telnetpp::element( telnetpp::negotiation(telnetpp::dont, option_) )}); return response; } case state::deactivating : if (request == telnetpp::will) { // NOTE: This is technically unspecified. No server would send // a WILL when we're already active, and they're not allowed to // send a WILL after receiving a DONT. But to be nice, we'll // re-activate. state_ = state::active; return on_state_changed(state_); } else if (request == telnetpp::wont) { state_ = state::inactive; return on_state_changed(state_); } } return {}; }