GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
Event.h
1 
29 #pragma once
30 
31 #include <any>
32 #include <functional>
33 #include <optional>
34 
35 #include "core/GpgFrontendCore.h"
36 #include "core/model/DataObject.h"
37 
38 namespace GpgFrontend::Module {
39 
40 class Event;
41 
42 using EventRefrernce = std::shared_ptr<Event>;
43 using EventIdentifier = QString;
44 using Evnets = std::vector<Event>;
45 
46 class GPGFRONTEND_CORE_EXPORT Event {
47  public:
48  using ParameterValue = std::any;
49  using EventIdentifier = QString;
50  using ListenerIdentifier = QString;
51  using EventCallback =
52  std::function<void(EventIdentifier, ListenerIdentifier, DataObjectPtr)>;
54  QString key;
55  ParameterValue value;
56  };
57 
58  explicit Event(const QString&,
59  std::initializer_list<ParameterInitializer> = {},
60  EventCallback = nullptr);
61 
62  ~Event();
63 
64  auto operator[](const QString& key) const -> std::optional<ParameterValue>;
65 
66  auto operator==(const Event& other) const -> bool;
67 
68  auto operator!=(const Event& other) const -> bool;
69 
70  auto operator<(const Event& other) const -> bool;
71 
72  auto operator<=(const Event& other) const -> bool;
73 
74  explicit operator QString() const;
75 
76  auto GetIdentifier() -> EventIdentifier;
77 
78  void AddParameter(const QString& key, const ParameterValue& value);
79 
80  void ExecuteCallback(ListenerIdentifier, DataObjectPtr);
81 
82  private:
83  class Impl;
84  SecureUniquePtr<Impl> p_;
85 };
86 
87 template <typename... Args>
88 auto MakeEvent(const EventIdentifier& event_id, Args&&... args,
89  Event::EventCallback e_cb) -> EventRefrernce {
90  std::initializer_list<Event::ParameterInitializer> params = {
91  Event::ParameterInitializer{std::forward<Args>(args)}...};
92  return GpgFrontend::SecureCreateSharedObject<Event>(event_id, params, e_cb);
93 }
94 
95 } // namespace GpgFrontend::Module
Definition: Event.h:46
Definition: Event.cpp:31