~townsend/unity/fix-lp1301394-trusty

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
#include "test_service_panel.h"

namespace unity
{
namespace service
{
namespace
{
static const char * panel_interface =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<node name=\"/\">\n"
"    <interface name=\"com.canonical.Unity.Panel.Service\">\n"
"\n"
"<!-- Begin of real methods/signals -->\n"
"    <method name='Sync'>"
"      <arg type='a(ssssbbusbbi)' name='state' 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)
{
  g_variant_builder_add (b, "(ssssbbusbbi)",
                         "test_indicator_id",
                         "test_entry_id",
                         "test_entry_name_hint",
                         "test_entry_label",
                         TRUE, /* label sensitive */
                         TRUE, /* label visible */
                         0, /* image type */
                         "", /* image_data */
                         TRUE, /* image sensitive */
                         TRUE, /* image visible */
                         1 /* priority  */);
}

void add_entry_id_2(GVariantBuilder *b)
{
  g_variant_builder_add (b, "(ssssbbusbbi)",
                         "test_indicator_id",
                         "test_entry_id2",
                         "test_entry_name_hint2",
                         "test_entry_label2",
                         TRUE, /* label sensitive */
                         TRUE, /* label visible */
                         0, /* image type */
                         "", /* image_data */
                         TRUE, /* image sensitive */
                         TRUE, /* image visible */
                         1 /* 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, "/com/canonical/Unity/Panel/Service");
}

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

    g_variant_builder_init (&b, G_VARIANT_TYPE ("(a(ssssbbusbbi))"));
    g_variant_builder_open (&b, G_VARIANT_TYPE ("a(ssssbbusbbi)"));

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

    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);
  }

  return nullptr;
}

}
}