diff options
author | serxa <serxa@yandex-team.ru> | 2022-02-10 16:49:08 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:08 +0300 |
commit | e5d4696304c6689379ac7ce334512404d4b7836c (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/lwtrace/custom_action.h | |
parent | d6d7db348c2cc64e71243cab9940ee6778f4317d (diff) | |
download | ydb-e5d4696304c6689379ac7ce334512404d4b7836c.tar.gz |
Restoring authorship annotation for <serxa@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/lwtrace/custom_action.h')
-rw-r--r-- | library/cpp/lwtrace/custom_action.h | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/library/cpp/lwtrace/custom_action.h b/library/cpp/lwtrace/custom_action.h index 6d950a39e1..92a3c66b84 100644 --- a/library/cpp/lwtrace/custom_action.h +++ b/library/cpp/lwtrace/custom_action.h @@ -8,68 +8,68 @@ #include <functional> -namespace NLWTrace { - class TSession; +namespace NLWTrace { + class TSession; - // Custom action can save any stuff (derived from IResource) in TSession object - // IMPORTANT: Derived class will be used from multiple threads! (see example3) - class IResource: public TAtomicRefCount<IResource> { - public: - virtual ~IResource() { - } - }; - using TResourcePtr = TIntrusivePtr<IResource>; - - // Trace resources that is used to hold/get/create any stuff - class TTraceResources: public THashMap<TString, TResourcePtr> { - public: - template <class T> - T& Get(const TString& name) { - auto iter = find(name); - if (iter == end()) { - iter = insert(value_type(name, TResourcePtr(new T()))).first; - } - return *static_cast<T*>(iter->second.Get()); - } - - template <class T> - const T* GetOrNull(const TString& name) const { - auto iter = find(name); - if (iter == end()) { - return nullptr; - } - return *iter->second; - } - }; - - // Base class of all custom actions - class TCustomActionExecutor: public IExecutor { - protected: - TProbe* const Probe; - bool Destructive; - - public: - TCustomActionExecutor(TProbe* probe, bool destructive) - : IExecutor() - , Probe(probe) - , Destructive(destructive) - { - } - - bool IsDestructive() { - return Destructive; - } - }; + // Custom action can save any stuff (derived from IResource) in TSession object + // IMPORTANT: Derived class will be used from multiple threads! (see example3) + class IResource: public TAtomicRefCount<IResource> { + public: + virtual ~IResource() { + } + }; + using TResourcePtr = TIntrusivePtr<IResource>; - // Factory to produce custom action executors - class TCustomActionFactory { - public: - using TCallback = std::function<TCustomActionExecutor*(TProbe* probe, const TCustomAction& action, TSession* trace)>; - TCustomActionExecutor* Create(TProbe* probe, const TCustomAction& action, TSession* trace) const; - void Register(const TString& name, const TCallback& callback); - - private: - THashMap<TString, TCallback> Callbacks; - }; - -} + // Trace resources that is used to hold/get/create any stuff + class TTraceResources: public THashMap<TString, TResourcePtr> { + public: + template <class T> + T& Get(const TString& name) { + auto iter = find(name); + if (iter == end()) { + iter = insert(value_type(name, TResourcePtr(new T()))).first; + } + return *static_cast<T*>(iter->second.Get()); + } + + template <class T> + const T* GetOrNull(const TString& name) const { + auto iter = find(name); + if (iter == end()) { + return nullptr; + } + return *iter->second; + } + }; + + // Base class of all custom actions + class TCustomActionExecutor: public IExecutor { + protected: + TProbe* const Probe; + bool Destructive; + + public: + TCustomActionExecutor(TProbe* probe, bool destructive) + : IExecutor() + , Probe(probe) + , Destructive(destructive) + { + } + + bool IsDestructive() { + return Destructive; + } + }; + + // Factory to produce custom action executors + class TCustomActionFactory { + public: + using TCallback = std::function<TCustomActionExecutor*(TProbe* probe, const TCustomAction& action, TSession* trace)>; + TCustomActionExecutor* Create(TProbe* probe, const TCustomAction& action, TSession* trace) const; + void Register(const TString& name, const TCallback& callback); + + private: + THashMap<TString, TCallback> Callbacks; + }; + +} |