~sethj/ubuntu/wily/unity/fix-for-1445595

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "test_service_panel.h"
#include "panel-service-private.h"

namespace unity
{
namespace service
{
namespace
{
static const char * panel_interface =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<node name=\"/\">\n"
"    <interface name=\"" UPS_IFACE "\">\n"
"\n"
"<!-- Begin of real methods/signals -->\n"
"    <method name='Sync'>"
"      <arg type='" ENTRY_ARRAY_SIGNATURE "' name='state' direction='out'/>"
"    </method>"
"\n"
"    <method name='GetIconPaths'>"
"      <arg type='as' name='paths' direction='out'/>"
"    </method>"
"\n"
"    <signal name='ReSync'>"
"     <arg type='s' name='indicator_id' />"
"    </signal>"
"\n"
"<!-- Begin of test only methods/signals -->\n"
"\n"
"    <method name='TriggerResync1' />"
"\n"
"    <method name='TriggerResync1Sent'>"
"      <arg type='b' name='sent' direction='out'/>"
"    </method>"
"\n"
"        </interface>\n"
"</node>\n"
;

void add_entry_id(GVariantBuilder *b, gint priority)
{
  g_variant_builder_add (b, ENTRY_SIGNATURE,
                         "test_indicator_id",
                         "test_entry_id",
                         "test_entry_name_hint",
                         0, /* parent window */
                         "test_entry_label",
                         TRUE, /* label sensitive */
                         TRUE, /* label visible */
                         0, /* image type */
                         "", /* image_data */
                         TRUE, /* image sensitive */
                         TRUE, /* image visible */
                         priority);
}

void add_entry_id_2(GVariantBuilder *b, gint priority)
{
  g_variant_builder_add (b, ENTRY_SIGNATURE,
                         "test_indicator_id",
                         "test_entry_id2",
                         "test_entry_name_hint2",
                         12345, /* parent window */
                         "test_entry_label2",
                         TRUE, /* label sensitive */
                         TRUE, /* label visible */
                         0, /* image type */
                         "", /* image_data */
                         TRUE, /* image sensitive */
                         TRUE, /* image visible */
                         priority);
}
}


Panel::Panel()
  : sync_return_mode_(0)
  , trigger_resync1_sent_(false)
{
  auto object = glib::DBusObjectBuilder::GetObjectsForIntrospection(panel_interface).front();
  object->SetMethodsCallsHandler(sigc::mem_fun(this, &Panel::OnMethodCall));

  server_.AddObject(object, UPS_PATH);
}

GVariant* Panel::OnMethodCall(std::string const& method, GVariant *parameters)
{
  if (method == "Sync")
  {
    GVariantBuilder b;

    g_variant_builder_init (&b, G_VARIANT_TYPE ("(" ENTRY_ARRAY_SIGNATURE ")"));
    g_variant_builder_open (&b, G_VARIANT_TYPE (ENTRY_ARRAY_SIGNATURE));

    if (sync_return_mode_ == 0)
    {
      add_entry_id(&b, 1);
      add_entry_id_2(&b, 2);
    }
    else if (sync_return_mode_ == 1)
    {
      add_entry_id_2(&b, 1);
      add_entry_id(&b, 2);
    }

    if (sync_return_mode_ == 1)
    {
      trigger_resync1_sent_ = true;
    }

    g_variant_builder_close (&b);
    return g_variant_builder_end (&b);
  }
  else if (method == "TriggerResync1")
  {
    sync_return_mode_ = 1;
    trigger_resync1_sent_ = false;

    server_.GetObjects().front()->EmitSignal("ReSync", g_variant_new("(s)", ""));
  }
  else if (method == "TriggerResync1Sent")
  {
    return g_variant_new("(b)", trigger_resync1_sent_ ? TRUE : FALSE);
  }
  else if (method == "GetIconPaths")
  {
    return g_variant_new("(as)", nullptr);
  }

  return nullptr;
}

}
}