Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | #include "propsgs-server.h" |
| 2 | #include <iostream> |
| 3 | #include <signal.h> |
| 4 | |
| 5 | static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties"; |
| 6 | static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties"; |
| 7 | |
| 8 | PropsServer::PropsServer(DBus::Connection &connection) |
| 9 | : DBus::ObjectAdaptor(connection, PROPS_SERVER_PATH) |
| 10 | { |
| 11 | Version = 1; |
| 12 | Message = "default message"; |
| 13 | } |
| 14 | |
| 15 | void PropsServer::on_set_property |
| 16 | (DBus::InterfaceAdaptor &interface, const std::string &property, const DBus::Variant &value) |
| 17 | { |
| 18 | if (property == "Message") |
| 19 | { |
| 20 | std::cout << "'Message' has been changed\n"; |
| 21 | |
| 22 | std::string msg = value; |
| 23 | this->MessageChanged(msg); |
| 24 | } |
| 25 | if (property == "Data") |
| 26 | { |
| 27 | std::cout << "'Data' has been changed\n"; |
| 28 | |
| 29 | double data = value; |
| 30 | this->DataChanged(data); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | DBus::BusDispatcher dispatcher; |
| 35 | |
| 36 | void niam(int sig) |
| 37 | { |
| 38 | dispatcher.leave(); |
| 39 | } |
| 40 | |
| 41 | int main() |
| 42 | { |
| 43 | signal(SIGTERM, niam); |
| 44 | signal(SIGINT, niam); |
| 45 | |
| 46 | DBus::default_dispatcher = &dispatcher; |
| 47 | |
| 48 | DBus::Connection conn = DBus::Connection::SessionBus(); |
| 49 | conn.request_name(PROPS_SERVER_NAME); |
| 50 | |
| 51 | PropsServer server(conn); |
| 52 | |
| 53 | dispatcher.enter(); |
| 54 | |
| 55 | return 0; |
| 56 | } |