1
#include "test_service_gdbus_wrapper.h"
9
const char * gdbus_wrapper_interface =
10
"<?xml version='1.0' encoding='UTF-8'?>\n"
12
" <interface name='com.canonical.gdbus_wrapper'>\n"
13
"<!-- Properties -->\n"
16
"<!-- Functions -->\n"
17
" <method name='TestMethod'>\n"
19
" <arg type='s' name='query' direction='in' />\n"
21
" <arg type='s' name='target' direction='out' />\n"
24
" <method name='SetReadOnlyProperty'>\n"
25
" <arg type='i' name='value' direction='in' />\n"
28
" <method name='GetWriteOnlyProperty'>\n"
29
" <arg type='i' name='value' direction='out' />\n"
33
" <signal name='TestSignal'>\n"
34
" <arg type='s' name='target' />\n"
37
"<!-- Properties -->\n"
38
" <property name='ReadOnlyProperty' type='i' access='read'/>\n"
39
" <property name='WriteOnlyProperty' type='i' access='write'/>\n"
40
" <property name='ReadWriteProperty' type='i' access='readwrite'/>\n"
42
"<!-- End of interesting stuff -->\n"
54
auto object = glib::DBusObjectBuilder::GetObjectsForIntrospection(gdbus_wrapper_interface).front();
55
object->SetMethodsCallsHandler([this, object] (std::string const& method, GVariant *parameters) -> GVariant* {
56
if (method == "TestMethod")
59
g_variant_get(parameters, "(s)", &query);
61
object->EmitSignal("TestSignal", g_variant_new("(s)", query.Value()));
62
return g_variant_new("(s)", query.Value());
64
else if (method == "SetReadOnlyProperty")
67
g_variant_get(parameters, "(i)", &new_value);
69
if (new_value != ro_property_)
71
ro_property_ = new_value;
72
object->EmitPropertyChanged("ReadOnlyProperty");
75
else if (method == "GetWriteOnlyProperty")
77
return g_variant_new("(i)", wo_property_);
83
object->SetPropertyGetter([this] (std::string const& property) -> GVariant* {
84
if (property == "ReadOnlyProperty")
85
return g_variant_new_int32(ro_property_);
86
else if (property == "ReadWriteProperty")
87
return g_variant_new_int32(rw_property_);
92
object->SetPropertySetter([this] (std::string const& property, GVariant* value) -> bool {
93
if (property == "ReadWriteProperty")
95
g_variant_get(value, "i", &rw_property_);
98
else if (property == "WriteOnlyProperty")
100
g_variant_get(value, "i", &wo_property_);
107
server_.AddObject(object, "/com/canonical/gdbus_wrapper");