summaryrefslogtreecommitdiff
path: root/examples/properties/propsgs-client.cpp
blob: d4b51f4bd258afdacd966b613456ad4e8b572599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "propsgs-client.h"
#include <iostream>
#include <signal.h>
#include <pthread.h>

using namespace org::freedesktop::DBus;

static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties";
static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties";

PropsClient::PropsClient(DBus::Connection &connection, const char *path, const char *name)
: DBus::ObjectProxy(connection, path, name)
{
}

void PropsClient::MessageChanged(const std::string& message)
{
	std::cout << "MessageChanged signal, new value: " << message << "\n";
};

void PropsClient::DataChanged(const double& data)
{
	std::cout << "DataChanged signal, new value:" << data << "\n";
};

void *test_property_proxy(void * input)
{
	PropsClient *client = static_cast<PropsClient*>(input);

	std::cout << "read property 'Version', value:" << client->Version() << "\n";

	std::cout << "read property 'Message', value:" << client->Message() << "\n";
	
	client->Message("message set by property access");
	std::cout << "wrote property 'Message'\n";
	
	std::cout << "read property 'Message', value:" << client->Message() << "\n";
	
	client->Data(1.1);
	std::cout << "wrote property 'Data'\n";

	return NULL;
}

DBus::BusDispatcher dispatcher;

void niam(int sig)
{
	dispatcher.leave();
	pthread_exit(NULL);
}

int main()
{
	signal(SIGTERM, niam);
	signal(SIGINT, niam);

	DBus::default_dispatcher = &dispatcher;

	DBus::_init_threading();

	DBus::Connection conn = DBus::Connection::SessionBus();

	PropsClient client (conn, PROPS_SERVER_PATH, PROPS_SERVER_NAME);

	pthread_t thread;
	pthread_create(&thread, NULL, test_property_proxy, &client);

	dispatcher.enter();

	return 0;
}