Fcitx
matchrule.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_UTILS_DBUS_MATCHRULE_H_
8 #define _FCITX_UTILS_DBUS_MATCHRULE_H_
9 
10 #include <cstddef>
11 #include <functional>
12 #include <memory>
13 #include <string>
14 #include <vector>
16 #include <fcitx-utils/fcitxutils_export.h>
17 #include <fcitx-utils/macros.h>
18 
19 /// \addtogroup FcitxUtils
20 /// \{
21 /// \file
22 /// \brief API for DBus matching rule.
23 
24 namespace fcitx::dbus {
25 
26 class MatchRulePrivate;
27 class Message;
28 
29 /**
30  * A dbus matching rule to be used with add match.
31  *
32  * Usually it is used to monitor certain signals on the bus.
33  *
34  * @see dbus::Bus::addMatch
35  */
36 struct FCITXUTILS_EXPORT MatchRule {
37 public:
38  explicit MatchRule(std::string service, std::string path = "",
39  std::string interface = "", std::string name = "",
40  std::vector<std::string> argumentMatch = {});
41  explicit MatchRule(MessageType type, std::string service,
42  std::string destination = "", std::string path = "",
43  std::string interface = "", std::string name = "",
44  std::vector<std::string> argumentMatch = {},
45  bool eavesdrop = false);
46 
47  FCITX_DECLARE_VIRTUAL_DTOR_COPY_AND_MOVE(MatchRule)
48 
49  MessageType messageType() const noexcept;
50 
51  const std::string &rule() const noexcept;
52 
53  const std::string &service() const noexcept;
54  const std::string &destination() const noexcept;
55  const std::string &path() const noexcept;
56  const std::string &interface() const noexcept;
57  const std::string &name() const noexcept;
58  const std::vector<std::string> &argumentMatch() const noexcept;
59  bool eavesdrop() const noexcept;
60 
61  bool check(Message &, const std::string &alterName = {}) const;
62 
63  bool operator==(const MatchRule &other) const {
64  return rule() == other.rule();
65  }
66 
67  bool operator!=(const MatchRule &other) const { return !(*this == other); }
68 
69  static const std::string nullArg;
70 
71 private:
72  std::unique_ptr<MatchRulePrivate> d_ptr;
73  FCITX_DECLARE_PRIVATE(MatchRule);
74 };
75 
76 } // namespace fcitx::dbus
77 
78 namespace std {
79 
80 template <>
81 struct hash<fcitx::dbus::MatchRule> {
82  size_t operator()(const fcitx::dbus::MatchRule &rule) const noexcept {
83  return std::hash<std::string>()(rule.rule());
84  }
85 };
86 } // namespace std
87 
88 #endif // _FCITX_UTILS_DBUS_MATCHRULE_H_
Basic DBus type of a DBus message.
Definition: message.h:224
A dbus matching rule to be used with add match.
Definition: matchrule.h:36
Definition: action.cpp:17
Definition: matchrule.h:78
API for DBus message.