~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/test_service_gdbus_wrapper.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "test_service_gdbus_wrapper.h"
2
 
 
3
 
namespace unity
4
 
{
5
 
namespace service
6
 
{
7
 
namespace
8
 
{
9
 
const char * gdbus_wrapper_interface =
10
 
"<?xml version='1.0' encoding='UTF-8'?>\n"
11
 
"<node name='/'>\n"
12
 
"        <interface name='com.canonical.gdbus_wrapper'>\n"
13
 
"<!-- Properties -->\n"
14
 
"                <!-- None -->\n"
15
 
"\n"
16
 
"<!-- Functions -->\n"
17
 
"                <method name='TestMethod'>\n"
18
 
"                        <!-- in -->\n"
19
 
"                        <arg type='s' name='query' direction='in' />\n"
20
 
"                        <!-- out -->\n"
21
 
"                        <arg type='s' name='target' direction='out' />\n"
22
 
"                </method>\n"
23
 
"\n"
24
 
"                <method name='SetReadOnlyProperty'>\n"
25
 
"                        <arg type='i' name='value' direction='in' />\n"
26
 
"                </method>\n"
27
 
"\n"
28
 
"                <method name='GetWriteOnlyProperty'>\n"
29
 
"                        <arg type='i' name='value' direction='out' />\n"
30
 
"                </method>\n"
31
 
"\n"
32
 
"<!-- Signals -->\n"
33
 
"                <signal name='TestSignal'>\n"
34
 
"                        <arg type='s' name='target' />\n"
35
 
"                </signal>\n"
36
 
"\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"
41
 
"\n"
42
 
"<!-- End of interesting stuff -->\n"
43
 
"\n"
44
 
"        </interface>\n"
45
 
"</node>\n"
46
 
;
47
 
}
48
 
 
49
 
GDBus::GDBus()
50
 
  : ro_property_(0)
51
 
  , rw_property_(0)
52
 
  , wo_property_(0)
53
 
{
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")
57
 
    {
58
 
      glib::String query;
59
 
      g_variant_get(parameters, "(s)", &query);
60
 
 
61
 
      object->EmitSignal("TestSignal", g_variant_new("(s)", query.Value()));
62
 
      return g_variant_new("(s)", query.Value());
63
 
    }
64
 
    else if (method == "SetReadOnlyProperty")
65
 
    {
66
 
      int new_value = 0;
67
 
      g_variant_get(parameters, "(i)", &new_value);
68
 
 
69
 
      if (new_value != ro_property_)
70
 
      {
71
 
        ro_property_ = new_value;
72
 
        object->EmitPropertyChanged("ReadOnlyProperty");
73
 
      }
74
 
    }
75
 
    else if (method == "GetWriteOnlyProperty")
76
 
    {
77
 
      return g_variant_new("(i)", wo_property_);
78
 
    }
79
 
 
80
 
    return nullptr;
81
 
  });
82
 
 
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_);
88
 
 
89
 
    return nullptr;
90
 
  });
91
 
 
92
 
  object->SetPropertySetter([this] (std::string const& property, GVariant* value) -> bool {
93
 
    if (property == "ReadWriteProperty")
94
 
    {
95
 
      g_variant_get(value, "i", &rw_property_);
96
 
      return true;
97
 
    }
98
 
    else if (property == "WriteOnlyProperty")
99
 
    {
100
 
      g_variant_get(value, "i", &wo_property_);
101
 
      return true;
102
 
    }
103
 
 
104
 
    return false;
105
 
  });
106
 
 
107
 
  server_.AddObject(object, "/com/canonical/gdbus_wrapper");
108
 
}
109
 
 
110
 
}
111
 
}