From f5ce518f1e6b08b8b1d957ee1c1c4e905c63fe63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rados=C5=82aw=20Zarzy=C5=84ski?= Date: Wed, 6 Apr 2022 13:32:43 +0200 Subject: [PATCH] crimson/osd: add registry of external handlers of tracking events MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This commit intentionally fails the build. It does that to verify the static assertion on per-op-type lookup of event registry. The concrete assertion is the one about `ClientRequest` as we already moved two of its blocker into the new op tracking infra. Signed-off-by: Radosław Zarzyński --- src/crimson/common/operation.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/crimson/common/operation.h b/src/crimson/common/operation.h index 31ed35ad59f..84387356ba7 100644 --- a/src/crimson/common/operation.h +++ b/src/crimson/common/operation.h @@ -158,6 +158,21 @@ private: virtual const char *get_type_name() const = 0; }; +// the main template. by default an operation has no extenral +// event handler (the empty tuple). specializing the template +// allows to define backends on per-operation-type manner. +// NOTE: basically this could be a function but C++ disallows +// differentiating return type among specializations. +template +struct EventBackendRegistry { + template static constexpr bool always_false = false; + + static std::tuple<> get_backends() { + static_assert(always_false, "Registry specialization not found"); + return {}; + } +}; + template struct Event { T* that() { @@ -172,6 +187,14 @@ struct Event { that()->internal_backend.handle(*that(), std::forward(op), std::forward(args)...); + // let's call `handle()` for concrete event type from each single + // of our backends. the order in the registry matters. + std::apply([&, //args=std::forward_as_tuple(std::forward(args)...), + this] (auto... backend) { + (..., backend.handle(*that(), + std::forward(op), + std::forward(args)...)); + }, EventBackendRegistry>::get_backends()); } }; -- 2.39.5