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