Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | #include "propsgs-client.h" |
| 2 | #include <iostream> |
| 3 | #include <signal.h> |
| 4 | #include <pthread.h> |
| 5 | |
| 6 | using namespace org::freedesktop::DBus; |
| 7 | |
| 8 | static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties"; |
| 9 | static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties"; |
| 10 | |
| 11 | PropsClient::PropsClient(DBus::Connection &connection, const char *path, const char *name) |
| 12 | : DBus::ObjectProxy(connection, path, name) |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | void PropsClient::MessageChanged(const std::string &message) |
| 17 | { |
| 18 | std::cout << "MessageChanged signal, new value: " << message << "\n"; |
| 19 | }; |
| 20 | |
| 21 | void PropsClient::DataChanged(const double &data) |
| 22 | { |
| 23 | std::cout << "DataChanged signal, new value:" << data << "\n"; |
| 24 | }; |
| 25 | |
| 26 | void *test_property_proxy(void *input) |
| 27 | { |
| 28 | PropsClient *client = static_cast<PropsClient *>(input); |
| 29 | |
| 30 | std::cout << "read property 'Version', value:" << client->Version() << "\n"; |
| 31 | |
| 32 | std::cout << "read property 'Message', value:" << client->Message() << "\n"; |
| 33 | |
| 34 | client->Message("message set by property access"); |
| 35 | std::cout << "wrote property 'Message'\n"; |
| 36 | |
| 37 | std::cout << "read property 'Message', value:" << client->Message() << "\n"; |
| 38 | |
| 39 | client->Data(1.1); |
| 40 | std::cout << "wrote property 'Data'\n"; |
| 41 | |
| 42 | return NULL; |
| 43 | } |
| 44 | |
| 45 | DBus::BusDispatcher dispatcher; |
| 46 | |
| 47 | void niam(int sig) |
| 48 | { |
| 49 | dispatcher.leave(); |
| 50 | pthread_exit(NULL); |
| 51 | } |
| 52 | |
| 53 | int main() |
| 54 | { |
| 55 | signal(SIGTERM, niam); |
| 56 | signal(SIGINT, niam); |
| 57 | |
| 58 | DBus::default_dispatcher = &dispatcher; |
| 59 | |
| 60 | DBus::_init_threading(); |
| 61 | |
| 62 | DBus::Connection conn = DBus::Connection::SessionBus(); |
| 63 | |
| 64 | PropsClient client(conn, PROPS_SERVER_PATH, PROPS_SERVER_NAME); |
| 65 | |
| 66 | pthread_t thread; |
| 67 | pthread_create(&thread, NULL, test_property_proxy, &client); |
| 68 | |
| 69 | dispatcher.enter(); |
| 70 | |
| 71 | return 0; |
| 72 | } |