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 #include "module/sdk/GFSDKModule.h"
38 
39 namespace GpgFrontend::Module {
40 
41 class Event;
42 
43 using EventReference = std::shared_ptr<Event>;
44 using EventIdentifier = QString;
45 using EventTriggerIdentifier = QString;
46 using Evnets = std::vector<Event>;
47 
48 class GPGFRONTEND_CORE_EXPORT Event {
49  public:
50  using ParameterValue = std::any;
51  using EventIdentifier = QString;
52  using ListenerIdentifier = QString;
53  using EventCallback =
54  std::function<void(EventIdentifier, ListenerIdentifier, DataObjectPtr)>;
56  QString key;
57  QString value;
58  };
59 
60  explicit Event(const QString&,
61  std::initializer_list<ParameterInitializer> = {},
62  EventCallback = nullptr);
63 
64  ~Event();
65 
66  auto operator[](const QString& key) const -> std::optional<ParameterValue>;
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  auto operator<=(const Event& other) const -> bool;
75 
76  explicit operator QString() const;
77 
78  auto GetIdentifier() -> EventIdentifier;
79 
80  auto GetTriggerIdentifier() -> EventTriggerIdentifier;
81 
82  void AddParameter(const QString& key, const QString& value);
83 
84  void ExecuteCallback(ListenerIdentifier, DataObjectPtr);
85 
86  auto ToModuleEvent() -> GFModuleEvent*;
87 
88  private:
89  class Impl;
90  SecureUniquePtr<Impl> p_;
91 };
92 
93 template <typename... Args>
94 auto MakeEvent(const EventIdentifier& event_id, Args&&... args,
95  Event::EventCallback e_cb) -> EventReference {
96  std::initializer_list<Event::ParameterInitializer> params = {
97  Event::ParameterInitializer{std::forward<Args>(args)}...};
98  return GpgFrontend::SecureCreateSharedObject<Event>(event_id, params, e_cb);
99 }
100 
101 } // namespace GpgFrontend::Module
Definition: Event.h:48
Definition: Event.cpp:33
Definition: GFSDKModule.h:49