Response execute(const Request& req) { std::lock_guard<std::mutex> lock(m_single_request_mutex); try { auto res = m_client.CallMethod(Request::get_command(), req.to_json()); m_connection_error_observed_at = std::experimental::nullopt; return Response::from_json(res); } catch (const json_rpc::JsonRpcException& e) { if (json_rpc::common::ERROR_CLIENT_CONNECTOR == e.get_code()) { auto now = std::chrono::high_resolution_clock::now(); if (m_connection_error_observed_at) { auto broken_seconds = std::chrono::duration_cast<std::chrono::seconds>( now - m_connection_error_observed_at.value()).count(); log_error("rest", "Agent " << get_gami_id() << " has not responded for " << broken_seconds << " seconds."); if (broken_seconds >= JsonAgent::REMOVE_AGENT_AFTER_SECONDS) { clean_resource_for_agent(); unregister_agent(); } } else { m_connection_error_observed_at = now; } throw AgentUnreachable(get_gami_id()); } m_connection_error_observed_at = std::experimental::nullopt; throw; } }
static void neard_exit(void) { unregister_agent(); if (watch_id != 0) g_dbus_remove_watch(connection, watch_id); if (connection != NULL) dbus_connection_unref(connection); }