From 18f07b63782c7cdb61c0c704cfaaf82df28f7a39 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 6 Jul 2019 20:17:42 -0700 Subject: [PATCH] ircd::m::sync: Move definitions to module. ircd::m::sync: Give sync::data an instance_list. --- include/ircd/m/sync.h | 1 + ircd/m.cc | 135 ++++++++++++++++++++++------------------- modules/client/sync.cc | 40 ++++++------ modules/console.cc | 39 ++++++++++++ 4 files changed, 132 insertions(+), 83 deletions(-) diff --git a/include/ircd/m/sync.h b/include/ircd/m/sync.h index efa480bdf..440d626f8 100644 --- a/include/ircd/m/sync.h +++ b/include/ircd/m/sync.h @@ -73,6 +73,7 @@ struct ircd::m::sync::item }; struct ircd::m::sync::data +:instance_list { /// Range to synchronize. Starting index is inclusive, ending index is /// exclusive. Generally the starting index is a since token, and ending diff --git a/ircd/m.cc b/ircd/m.cc index 89ede1934..5f1482955 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -695,10 +695,22 @@ ircd::m::sync::stats_info }; template<> -decltype(ircd::m::sync::item::instance_multimap::map) -ircd::m::sync::item::instance_multimap::map +decltype(ircd::util::instance_multimap>::map) +ircd::util::instance_multimap>::map {}; +template<> +decltype(ircd::util::instance_list::allocator) +ircd::util::instance_list::allocator +{}; + +template<> +decltype(ircd::util::instance_list::list) +ircd::util::instance_list::list +{ + allocator +}; + bool ircd::m::sync::for_each(const item_closure_bool &closure) { @@ -819,67 +831,6 @@ ircd::m::sync::loghead(const data &data) }; } -// -// data -// - -ircd::m::sync::data::data -( - const m::user &user, - const m::events::range &range, - ircd::client *const &client, - json::stack *const &out, - sync::stats *const &stats, - const string_view &filter_id -) -:range -{ - range -} -,stats -{ - stats -} -,client -{ - client -} -,user -{ - user -} -,user_room -{ - user -} -,user_state -{ - user_room -} -,user_rooms -{ - user -} -,filter_buf -{ - m::filter::get(filter_id, user) -} -,filter -{ - json::object{filter_buf} -} -,out -{ - out -} -{ -} - -ircd::m::sync::data::~data() -noexcept -{ -} - // // item // @@ -1133,6 +1084,64 @@ const return this->instance_multimap::it->first; } +// +// data +// + +ircd::m::sync::data::data(const m::user &user, + const m::events::range &range, + ircd::client *const &client, + json::stack *const &out, + sync::stats *const &stats, + const string_view &filter_id) +:range +{ + range +} +,stats +{ + stats +} +,client +{ + client +} +,user +{ + user +} +,user_room +{ + user +} +,user_state +{ + user_room +} +,user_rooms +{ + user +} +,filter_buf +{ + m::filter::get(filter_id, user) +} +,filter +{ + json::object{filter_buf} +} +,out +{ + out +} +{ +} + +ircd::m::sync::data::~data() +noexcept +{ +} + /////////////////////////////////////////////////////////////////////////////// // // m/app.h diff --git a/modules/client/sync.cc b/modules/client/sync.cc index cf5c16c04..2f10440db 100644 --- a/modules/client/sync.cc +++ b/modules/client/sync.cc @@ -144,26 +144,6 @@ ircd::m::sync::args::timeout_default { "default", 90 * 1000L }, }; -// -// args::args -// - -ircd::m::sync::args::args(const resource::request &request) -try -:request -{ - request -} -{ -} -catch(const bad_lex_cast &e) -{ - throw m::BAD_REQUEST - { - "Since parameter invalid :%s", e.what() - }; -} - // // GET sync // @@ -837,3 +817,23 @@ ircd::m::sync::longpoll::handle(data &data, return true; } + +// +// args::args +// + +ircd::m::sync::args::args(const resource::request &request) +try +:request +{ + request +} +{ +} +catch(const bad_lex_cast &e) +{ + throw m::BAD_REQUEST + { + "Since parameter invalid :%s", e.what() + }; +} diff --git a/modules/console.cc b/modules/console.cc index 43eef8713..e8d76975f 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -5406,6 +5406,45 @@ console_cmd__client__spawn(opt &out, const string_view &line) return true; } +bool +console_cmd__client__sync(opt &out, const string_view &line) +{ + for(auto *const &data_p : m::sync::data::list) + { + const auto *const &client(data_p->client); + if(client) + out << client->loghead() << " < "; + + out << m::sync::loghead(*data_p) << " | "; + out << std::endl; + } + + return true; +} + +bool +console_cmd__client__sync__item(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "prefix" + }}; + + const auto prefix + { + param.at("prefix", ""_sv) + }; + + ircd::m::sync::for_each(prefix, [&out] + (const auto &item) + { + out << item.name() << std::endl; + return true; + }); + + return true; +} + // // resource //