~ken-vandine/unity/gdbus-ppa

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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
/*
 * Copyright (C) 2010 Canonical, Ltd.
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 3.0 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3.0 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 *
 */

/*
 * IMPLEMENTATION NOTE:
 * It may appear this code it is bit more bloated than it needs to be
 * (considering the pure number of classes and indirections), but this has
 * some good reasons.
 *
 * Firstly we want to hide away Vala's internal DBus marshalling which would
 * expose raw structs in the API. These structs are hidden away in _RendererInfo,
 * and _EntryInfo. We wrap these in handy GObjects with properties and what not.
 * In fact we want to hide all DBusisms, which is also why the DBus interfaces
 * are declared private.
 *
 * Secondly we want the generatedd C API to be nice and not too Vala-ish. We
 * must anticipate that place daemons consuming libunity will be written in
 * both Vala and C.
 *
 */

using Dee;
using DBus;

namespace Unity.Place {

  /**
   * UnityPlace_RendererInfo:
   *
   * Private helper struct used for marshalling a RendererInfo object over DBus
   */
  private struct _RendererInfo {
  	public string default_renderer;
  	public string groups_model;
  	public string results_model;
  	public HashTable<string,string> hints;
  }

  /**
   * SECTION:unity-place-renderer-info
   * @short_description: Encapsulates all place entry metadata the Unity shell needs in order to render this model
   * @include: unity.h
   *
   *
   */
  public class RendererInfo : GLib.Object {
    
    /* We use a pointer to the _RendererInfo to avoid Vala duping the struct
     * values. The actual struct pointed to is owned by the parent EntryInfo */
    private _RendererInfo* info;
    private Dee.Model _groups_model;
    private Dee.Model _results_model;

    /*
     * Properties
     */
    public string default_renderer {
      get { return info->default_renderer; }
      set { info->default_renderer = value; }
    }

    public Dee.Model groups_model {
      get { return _groups_model; }
      set {
        _groups_model = value;
        if (value is Dee.SharedModel)
        {
          Dee.SharedModel model = value as Dee.SharedModel;
          info->groups_model = model.get_swarm_name();
        }
        else
          info->groups_model = "__local__";
      }
    }

    public Dee.Model results_model {
      get { return _results_model; }
      set {
        _results_model = value;
        if (value is Dee.SharedModel)
        {
          Dee.SharedModel model = value as Dee.SharedModel;
          info->results_model = model.get_swarm_name();
        }
        else
          info->results_model = "__local__";
      }
    }

    /*
     * Constructors
     */

    internal RendererInfo (_RendererInfo* info)
    {
      this.info = info;
    }

    /*
     * Public API
     */

    public void set_hint (string hint, string val)
    {
      info->hints.insert (hint, val);
    }

    public string? get_hint (string hint)
    {
      return info->hints.lookup (hint);
    }

    public void clear_hint (string hint)
    {
      info->hints.remove (hint);
    }

    public void clear_hints ()
    {
      info->hints.remove_all ();
    }

    public uint num_hints ()
    {
      return info->hints.size ();
    }
    
    internal _RendererInfo get_raw ()
    {
      return *info;
    }
  }

  /**
   *
   */
  public class Search : InitiallyUnowned {

    private string search;
    private HashTable<string,string> hints;

    /*
     * Public API
     */

    public Search (string search, HashTable<string,string> hints)
    {
      GLib.Object();
      this.search = search;
      this.hints = hints;
    }

    public string get_search_string ()
    {
      return search;
    }

    public List<unowned string> get_hints ()
    {
      return hints.get_keys ();
    }

    public void set_hint (string hint, string val)
    {
      hints.insert (hint, val);
    }

    public string? get_hint (string hint)
    {
      return hints.lookup (hint);
    }

    public void clear_hint (string hint)
    {
      hints.remove (hint);
    }

    public void clear_hints ()
    {
      hints.remove_all ();
    }

    public uint num_hints ()
    {
      return hints.size ();
    }
    
    /* Returns true if search strings and all hints match */
    public bool equals (Search? other)
    {
      if (other == null)
        return false;
        
      if (get_search_string() != other.get_search_string ())
        return false;
      
      if (num_hints () != other.num_hints())
        return false;
        
      foreach (var hint in get_hints ())
      {
        if (other.get_hint (hint) != get_hint (hint))
          return false;
      }
      
      return true;
    }
  }

  /**
   * UnityPlace_EntryInfo:
   *
   * Private helper struct used for marshalling an EntryInfo object over DBus
   */
  private struct _EntryInfo {
  	public string   dbus_path;
    public string   display_name;
    public string   icon;
    public uint     position;
    public string[] mimetypes;
    public bool     sensitive;
    public string   sections_model;
    public HashTable<string,string> hints;
    public _RendererInfo entry_renderer_info;
    public _RendererInfo global_renderer_info;
  }

  /**
   * UnityPlace_EntryInfoData:
   *
   * Private helper struct used for marshalling the EntryInfo data without
   * the RenderingInfo data over the bus
   */
  private struct _EntryInfoData {
  	public string   dbus_path;
    public string   display_name;
    public string   icon;
    public uint     position;
    public string[] mimetypes;
    public bool     sensitive;
    public string   sections_model;
    public HashTable<string,string> hints;
  }

  public class EntryInfo : GLib.Object {

    /* The _EntryInfo needs to be set before we set properties, so it's
     * paramount we do it here */
    private _EntryInfo info = _EntryInfo();
    private RendererInfo _entry_renderer_info;
    private RendererInfo _global_renderer_info;
    private Dee.Model _sections_model;
    private bool _active = false;
    private uint _active_section = 0;

    /*
     * Properties
     */
    public RendererInfo entry_renderer_info {
      get { return _entry_renderer_info; }
    }

    public RendererInfo global_renderer_info {
      get { return _global_renderer_info; }
    }

    public string dbus_path {
      get { return info.dbus_path; }
      construct set { info.dbus_path = value; }
    }

    public string display_name {
      get { return info.display_name; }
      construct set { info.display_name = value; }
    }

    public string icon {
      get { return info.icon; }
      construct set { info.icon = value; }
    }

    public uint position {
      get { return info.position; }
      construct set { info.position = value; }
    }

    public string[] mimetypes {
      get { return info.mimetypes; }
      construct set { info.mimetypes = value; }
    }

    public bool sensitive {
      get { return info.sensitive; }
      construct set { info.sensitive = value; }
    }

    public Dee.Model sections_model {
      get { return _sections_model; }
      construct set {
        _sections_model = value;
        if (value is Dee.SharedModel)
        {
          Dee.SharedModel model = value as Dee.SharedModel;
          info.sections_model = model.get_swarm_name();
        }
        else
          info.sections_model = "__local__";
      }
    }

    public bool active {
      get { return _active; }
      set { _active = value; }
    }

    public uint active_section {
      get { return _active_section; }
      set { _active_section = value; }
    }

    public Search active_search { get; set; }
    public Search active_global_search { get; set; }

    /* The browser will automagically be exported/unexported on the bus
     * when this property is set or unset. Setting the browser also sets the
     * UnityPlaceBrowserPath and UnitySectionStyle hints accordingly. */
    private Browser? _browser = null;
    public Browser? browser {
      get { return _browser; }
      set {
        _browser = value;
        if (value != null)
          {
            set_hint ("UnityPlaceBrowserPath", value.dbus_path);
            set_hint ("UnitySectionStyle", "breadcrumb");
          }
        else
          {
            clear_hint ("UnityPlaceBrowserPath");
            clear_hint ("UnitySectionStyle");
          }
      }
    }

    /*
     * Constructors
     */

    construct {
      if (info.dbus_path == null)
        {
          critical ("""No DBus path set for EntryInfo.
'dbus-path' property in the UnityPlaceEntryInfo constructor""");
          info.dbus_path = "";
        }
      if (info.display_name == null)
        info.display_name = "";
      if (info.icon == null)
        info.icon = "";
      info.position = 0;
      if (info.mimetypes == null)
        info.mimetypes = new string[0];
      info.sensitive = true;
      if (info.sections_model == null)
        info.sections_model = "";
      info.hints = new HashTable<string,string>(str_hash, str_equal);

      info.entry_renderer_info.default_renderer = "";
      info.entry_renderer_info.groups_model = "";
      info.entry_renderer_info.results_model = "";
      info.entry_renderer_info.hints = new HashTable<string, string> (str_hash, str_equal);

      info.global_renderer_info.default_renderer = "";
      info.global_renderer_info.groups_model = "";
      info.global_renderer_info.results_model = "";
      info.global_renderer_info.hints = new HashTable<string, string> (str_hash, str_equal);

      /* Pass in the address of the _RendererInfos as they are embedded
       * by value inside the _EntryInfo struct. The RendererInfo will then
       * only access the pointer to the struct to avoid memory duping which
       * would give incorrect return values for our DBus methods */
      _entry_renderer_info = new RendererInfo (&(info.entry_renderer_info));
      _global_renderer_info = new RendererInfo (&(info.global_renderer_info));
    }

    public EntryInfo (string dbus_path) {
      /* We need the _empty hack here to avoid a bug in valac, otherwise
       * valac will set it to NULL somehow and cause a g_critical in
       * g_strv_length() */
      var _empty = new string[0];
      GLib.Object(dbus_path : dbus_path,
                  mimetypes : _empty);
    }

    /*
     * Public API
     */

    public void set_hint (string hint, string val)
    {
      info.hints.insert (hint, val);
    }

    public string? get_hint (string hint)
    {
      return info.hints.lookup (hint);
    }

    public void clear_hint (string hint)
    {
      info.hints.remove (hint);
    }

    public void clear_hints ()
    {
      info.hints.remove_all ();
    }

    public uint num_hints ()
    {
      return info.hints.size ();
    }

    /*
     * Internal API
     */
     internal _EntryInfo get_raw ()
     {
       return info;
     }
  }

  /**
   * UnityPlaceService:
   *
   * DBus interface exported by a place daemon
   */
  [DBus (name = "com.canonical.Unity.Place")]
  private interface Service : GLib.Object
  {
    public abstract _EntryInfo[] get_entries () throws DBus.Error;

    public signal void entry_added (_EntryInfo entry);

    public signal void entry_removed (string entry_dbus_path);
  }

  /**
   * UnityPlaceEntryService:
   *
   * DBus interface for a given place entry exported by a place daemon
   */
  [DBus (name = "com.canonical.Unity.PlaceEntry")]
  private interface EntryService : GLib.Object
  {
    public abstract void set_global_search (string search,
                                            HashTable<string,string> hints) throws DBus.Error;

    public abstract void set_search (string search,
                                     HashTable<string,string> hints) throws DBus.Error;
    
    public abstract void set_active (bool is_active) throws DBus.Error;

    public abstract void set_active_section (uint section_id) throws DBus.Error;

    public signal void entry_renderer_info_changed (_RendererInfo renderer_info);
    
    public signal void global_renderer_info_changed (_RendererInfo renderer_info);
    
    public signal void place_entry_info_changed (_EntryInfoData entry_info_data);
  }

  /**
   * UnityPlaceServiceImpl:
   *
   * Private helper class to shield of DBus details and ugly
   * internal structs used for marshalling
   */
  private class ServiceImpl : GLib.Object, Service, Activation
  {
    private string _dbus_path;
    private HashTable<string,EntryServiceImpl> entries;
    private bool _exported;

    /*
     * Properties
     */

    [Property(nick = "DBus object path", blurb = "The DBus path this object is exported under")]
    public string dbus_path {
      get { return _dbus_path; }
      construct { _dbus_path = value; }
    }

    public bool exported {
      get { return _exported; }
    }
    
    public Activation? activation { get; set; default = null; }

    /*
     * Constructors
     */

    construct {
      entries = new HashTable<string,EntryServiceImpl> (str_hash, str_equal);
    }

    public ServiceImpl (string dbus_path)
    {
      GLib.Object (dbus_path : dbus_path);
    }

    /*
     * DBus API
     */

    public _EntryInfo[] get_entries ()
    {
      _EntryInfo[] result = new _EntryInfo[entries.size ()];

      int i = 0;
      foreach (var entry in entries.get_values ())
      {
        result[i] = entry.entry_info.get_raw();
        i++;
      }

      return result;
    }

    /*
     * Internal API
     */

    public void add_entry (EntryInfo entry_info)
    {
      if (entries.lookup (entry_info.dbus_path) != null)
        return;

      var entry = new EntryServiceImpl(entry_info);
      entries.insert (entry_info.dbus_path, entry);
      if (_exported)
        {
          try {
            entry.export ();
          } catch (DBus.Error e) {
            critical ("Failed to export place entry '%s': %s",
                      entry_info.dbus_path, e.message);
          }
        }
      entry_added (entry_info.get_raw ());
    }

    public EntryInfo? get_entry (string dbus_path)
    {
      var entry = entries.lookup (dbus_path);
      if (entry != null)
        return entry.entry_info;
      else
        return null;
    }

    public EntryServiceImpl? get_entry_service (string dbus_path)
    {
      var entry = entries.lookup (dbus_path);
      if (entry != null)
        return entry;
      else
        return null;
    }

    public uint num_entries ()
    {
      return entries.size ();
    }

    public string[] get_entry_paths ()
    {
      string[] result = new string[entries.size ()];

      int i = 0;
      foreach (var entry in entries.get_values ())
      {
        result[i] = entry.entry_info.dbus_path;
        i++;
      }

      return result;
    }

    public void remove_entry (string dbus_path)
    {
      var entry = entries.lookup (dbus_path);

      if (entry == null)
        return;

      entry_removed (dbus_path);
      if (_exported)
        {
          try {
            entry.unexport ();
          } catch (DBus.Error e) {
            critical ("Failed to unexport place entry '%s': %s",
                      entry.entry_info.dbus_path, e.message);
          }
        }

      entries.remove (dbus_path);
    }

    public void export () throws DBus.Error
    {
      var conn = DBus.Bus.get (DBus.BusType. SESSION);
      conn.register_object (_dbus_path, this);

      foreach (var entry in entries.get_values ())
      {
        entry.export ();
      }

      _exported = true;
      notify_property("exported");
    }

    public void unexport () throws DBus.Error
    {
      foreach (var entry in entries.get_values ())
      {
        entry.unexport ();
      }
      var conn = DBus.Bus.get (DBus.BusType. SESSION);
      conn.unregister_object (this);

      _exported = false;
      notify_property("exported");
    }
    
    /* Default impl of the Unity.Place.Activation interface,
     * delegates to the installed Activation impl if there is one */
    public async uint32 activate (string uri)
    {
      if (activation == null )
        return ActivationStatus.NOT_ACTIVATED;
      
      try {
        uint32 activated = yield activation.activate (uri);
        return activated;
      } catch (DBus.Error e) {
        return ActivationStatus.NOT_ACTIVATED;
      }
    }
    
  } /* End: ServiceImpl */

  /**
   * UnityPlaceEntryServiceImpl:
   *
   * Private helper class to shield of DBus details and ugly
   * internal structs used for marshalling
   */
  private class EntryServiceImpl : GLib.Object, EntryService
  {
    private bool _exported = false;
    private EntryInfo _entry_info;
    
    /* Queue up change signals in order not to flood the bus on rapid changes */
    private uint place_entry_info_changed_signal_source = 0;
    
    /* Keep a ref to the previous browser to properly handle it leaving and
     * entering the bus */
    private Browser? _browser = null;

    /*
     * Properties
     */

    public EntryInfo entry_info {
      get { return _entry_info; }
      construct { _entry_info = value; }
    }

    public bool exported {
      get { return _exported; }
    }

    /*
     * Constructors
     */

    public EntryServiceImpl (EntryInfo entry_info)
    {
      GLib.Object(entry_info : entry_info);
      _browser = entry_info.browser;
      
      entry_info.notify["browser"].connect (on_browser_changed);
    }

    /*
     * DBus API
     */

    public void set_global_search (string search,
                                   HashTable<string,string> hints)
    {
      var s = new Search (search, hints);
      
      if (!s.equals (this._entry_info.active_global_search))
        this._entry_info.active_global_search = s;
    }

    public void set_search (string search,
                            HashTable<string,string> hints)
    {
      var s = new Search (search, hints);
      
      if (!s.equals (this._entry_info.active_search))
        this._entry_info.active_search = s;
    }

    public void set_active (bool is_active)
    {
      this._entry_info.active = is_active;
    }

    public void set_active_section (uint section_id)
    {
      this._entry_info.active_section = section_id;
    }

    /*
     * Internal API
     */

    public void export () throws DBus.Error
    {
      var conn = DBus.Bus.get (DBus.BusType. SESSION);
      conn.register_object (_entry_info.dbus_path, this);

      if (_entry_info.browser != null)
        {
          debug ("Exporting browser at '%s'", _entry_info.browser.dbus_path);
          conn.register_object (_entry_info.browser.dbus_path,
                                _entry_info.browser.get_service ());

        }
      else
        debug ("No browser to export");
      
      _exported = true;
      notify_property("exported");
    }

    public void unexport () throws DBus.Error
    {
      var conn = DBus.Bus.get (DBus.BusType. SESSION);
      conn.unregister_object (this);

      if (_entry_info.browser != null)
        {
          debug ("Unexporting browser '%s'", _entry_info.browser.dbus_path);
          conn.unregister_object (_entry_info.browser.get_service ());
        }

      _exported = false;
      notify_property("exported");
    }
    
    private void on_browser_changed (GLib.Object obj, ParamSpec pspec)
    {
      DBus.Connection conn;
      try {
        conn = DBus.Bus.get (DBus.BusType. SESSION);
      } catch (DBus.Error e) {
        warning ("Unable to connect to session bus: %s", e.message);
        return;
      }

      /* If nothing changed, don't do anything */
      if (_browser == entry_info.browser)
        return;

      /* clear previous browser if any */
      if (_browser != null && _exported)
        {
          debug ("Unexporting browser '%s'", _browser.dbus_path);
          conn.unregister_object (_browser.get_service ());
        }

      _browser = entry_info.browser;

      /* Export the new one if any */
      if (_browser != null && _exported)
        {
          debug ("Exporting browser '%s'", _browser.dbus_path);
          conn.register_object (_browser.dbus_path, _browser.get_service ());
        }
    }
    
    /* Prepare emission of a PlaceEntryInfoChanged signal in next idle call,
     * unless one is already scheduled */
    public void queue_place_entry_info_changed_signal ()
    {
      if (place_entry_info_changed_signal_source == 0)
        {
          place_entry_info_changed_signal_source =
                          Idle.add (emit_place_entry_info_changed_signal);
        }
    }
    
    /* Idle handler for emitting PlaceEntryInfoChanged on the bus */
    private bool emit_place_entry_info_changed_signal ()
    {
      var entry_data = _EntryInfoData();
      
      var _entry = _entry_info.get_raw ();
      entry_data.dbus_path = _entry.dbus_path;
      entry_data.display_name = _entry.display_name;
      entry_data.icon = _entry.icon;
      entry_data.position = _entry.position;
      entry_data.mimetypes = _entry.mimetypes;
      entry_data.sensitive = _entry.sensitive;  
      entry_data.sections_model = _entry.sections_model;
      entry_data.hints = _entry.hints;
      
      /* Emit the signal */
      place_entry_info_changed (entry_data);
      
      /* Clear the queue */
      place_entry_info_changed_signal_source = 0;
      
      return false;
    }
    
  } /* End: EntryServiceImpl */

  /*
   * Private helper struct used to keep track of the installed signal handlers
   * for an entry added to a Controller
   */
  internal struct _EntrySignals
  {
    ulong place_entry_info_changed_id;
    ulong entry_renderer_info_changed_id;
    ulong global_renderer_info_changed_id;
  }

  /**
   * UnityPlaceController:
   *
   * Main handle for controlling the place entries managed by a place daemon
   */
  public class Controller : GLib.Object
  {
    private ServiceImpl service;
    private string _dbus_path;
    private bool _exported = false;
    private HashTable<string, _EntrySignals?> entry_signals;
    private Gee.Set<string> ignore_remote_notify_props;

    /*
     * Properties
     */

    [Property(nick = "DBus object path", blurb = "The DBus path this object is exported under")]
    public string dbus_path {
      get { return _dbus_path; }
      construct { _dbus_path = value; }
    }

    /* Whether or not this controller exports its installed entries and
     * activation service on the bus */
    public bool exported {
      get { return _exported; }
    }
    
    /* Defer URI activation to this instance. If there is no activation set
     * for the controller it will always decline any request for activation */
    public Activation? activation {
      get { return service.activation; }
      set { service.activation = value; }
    }

    /*
     * Constructors
     */

    construct {
      service = new ServiceImpl (_dbus_path);
      entry_signals = new HashTable<string, _EntrySignals?>(str_hash, str_equal);
      
      ignore_remote_notify_props = new Gee.HashSet<string> ();
      ignore_remote_notify_props.add ("active-search");
      ignore_remote_notify_props.add ("active-global-search");
      ignore_remote_notify_props.add ("active");
      ignore_remote_notify_props.add ("active-section");
    }

    public Controller (string dbus_path)
    {
      GLib.Object (dbus_path : dbus_path);
    }

    /*
     * Public API
     */

    public void add_entry (EntryInfo entry)
    {
      service.add_entry (entry);
      
      var signals = _EntrySignals ();
      
      signals.place_entry_info_changed_id = entry.notify.connect (on_entry_changed);
      
      /* We use a closure here because we need to capture the entry in order
       * to look up the EntryServiceImpl */
      signals.entry_renderer_info_changed_id = entry.entry_renderer_info.notify.connect (
        (obj, pspec) => {
          var renderer_info = (obj as RendererInfo);
          var entry_service = service.get_entry_service (entry.dbus_path);
          if (entry_service == null)
            {
              warning ("Entry renderer info changed for unknown entry '%s'", entry.dbus_path);
            }
          else
            entry_service.entry_renderer_info_changed (renderer_info.get_raw ());
          
        }
      );
      
      /* We use a closure here because we need to capture the entry in order
       * to look up the EntryServiceImpl */
      signals.global_renderer_info_changed_id = entry.global_renderer_info.notify.connect (
        (obj, pspec) => {
          var renderer_info = (obj as RendererInfo);
          var entry_service = service.get_entry_service (entry.dbus_path);
          if (entry_service == null)
            {
              warning ("Global renderer info changed for unknown entry '%s'", entry.dbus_path);
            }
          else
            entry_service.global_renderer_info_changed (renderer_info.get_raw ());
          
        }
      );
      
      /* Store all signal handler ids so we can remove them later */
      entry_signals.insert (entry.dbus_path, signals);
    }

    public EntryInfo? get_entry (string dbus_path)
    {
      return service.get_entry (dbus_path);
    }

    public void remove_entry (string dbus_path)
    {
      /* Disconnect all signals on the entry before we remove
       * it from the ServiceImpl */
      var signals = entry_signals.lookup (dbus_path);
      if (signals == null)
        {
          warning ("No signals connected for unknown entry '%s'",
                   dbus_path);
          service.remove_entry (dbus_path);
          return;
        }
      
      var entry = service.get_entry (dbus_path);
      if (entry == null)
        {
          warning ("Can not disconnect signals for unknown entry '%s'",
                   dbus_path);
          entry_signals.remove (dbus_path);
          return;
        }
      
      entry.disconnect (signals.place_entry_info_changed_id);
      entry.entry_renderer_info.disconnect (signals.entry_renderer_info_changed_id);
      entry.global_renderer_info.disconnect (signals.global_renderer_info_changed_id);
      
      service.remove_entry (dbus_path);
    }

    public uint num_entries ()
    {
      return service.num_entries ();
    }

    public string[] get_entry_paths ()
    {
      return service.get_entry_paths ();
    }

    public EntryInfo[] get_entries ()
    {
      uint len = num_entries();
      var result = new EntryInfo[len];
      var entry_paths = get_entry_paths ();

      int i = 0;
      for (i = 0; i < len; i++)
        {
          result[i] = get_entry (entry_paths[i]);
        }

      return result;
    }

    public void export () throws DBus.Error
    {
      /* Export the Place and Activation insterfaces */
      service.export ();
      
      _exported = true;
      notify_property("exported");
    }

    public void unexport () throws DBus.Error
    {
      service.unexport ();
      _exported = false;
      notify_property("exported");
    }
    
    /* Callback for when an entry property changes */
    private void on_entry_changed (GLib.Object obj, ParamSpec pspec)
    {
      var entry = (obj as EntryInfo);
      var entry_service = service.get_entry_service (entry.dbus_path);
      
      if (entry_service == null)
        {
          warning ("Got change signal from unknown entry service '%s'",
                   entry.dbus_path);
          return;
        }
      
      /* Don't emit signals on the bus that are strictly local metadata */
      if (pspec.get_name () in ignore_remote_notify_props)
        return;
      
      entry_service.queue_place_entry_info_changed_signal ();
    }
    
  } /* End: Controller class */

} /* namespace */