xref: /openbmc/boost-dbus/include/dbus/match.hpp (revision a83e5951)
1 // Copyright (c) Benjamin Kietzman (github.com/bkietz)
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef DBUS_MATCH_HPP
7 #define DBUS_MATCH_HPP
8 
9 #include <string>
10 #include <boost/asio.hpp>
11 
12 #include <dbus/error.hpp>
13 #include <dbus/connection.hpp>
14 
15 namespace dbus {
16 
17 /// Simple placeholder object for a match rule.
18 /**
19  * A match rule determines what messages will be received by this application.
20  *
21  * Each rule will be represented by an instance of match. To remove that rule,
22  * dispose of the object.
23  */
24 //TODO use noncopyable
25 class match
26 {
27   connection& connection_;
28   std::string expression_;
29 
30 public:
31   match(connection& c,
32       BOOST_ASIO_MOVE_ARG(std::string) e)
33     : connection_(c),
34       expression_(BOOST_ASIO_MOVE_CAST(std::string)(e))
35   {
36     connection_.new_match(*this);
37   }
38 
39   ~match()
40   {
41     connection_.delete_match(*this);
42   }
43 
44   const std::string& get_expression() const { return expression_; }
45 };
46 
47 //TODO move this to dbus::impl stat
48 void connection_service::new_match(implementation_type& impl,
49     match& m)
50 {
51   error e;
52   dbus_bus_add_match(impl, m.get_expression().c_str(), e);
53   e.throw_if_set();
54   // eventually, for complete asynchronicity, this should connect to
55   // org.freedesktop.DBus and call AddMatch
56 }
57 
58 void connection_service::delete_match(implementation_type& impl,
59     match& m)
60 {
61   error e;
62   dbus_bus_remove_match(impl, m.get_expression().c_str(), e);
63   e.throw_if_set();
64 }
65 
66 } // namespace dbus
67 
68 #endif // DBUS_MATCH_HPP
69