~stolowski/libunity/activate-result

« back to all changes in this revision

Viewing changes to src/unity-scope-dbus-connector.vala

  • Committer: Tarmac
  • Author(s): Michal Hruby
  • Date: 2013-03-28 16:38:05 UTC
  • mfrom: (351.1.3 libunity)
  • Revision ID: tarmac-20130328163805-0g7b96lniptwtkdh
Add support for quitting scopes after being idle for a while.

Approved by Pawel Stolowski, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
public class ScopeDBusConnector : Object
26
26
{
 
27
  private static int DAEMON_TIMEOUT_SEC = 45;
 
28
 
27
29
  public unowned AbstractScope scope { get; construct; }
28
30
 
29
31
  public ScopeDBusConnector (AbstractScope scope)
31
33
    Object (scope: scope);
32
34
  }
33
35
 
34
 
  private Internal.ScopeDBusImpl pimpl;
 
36
  ~ScopeDBusConnector ()
 
37
  {
 
38
    unexport ();
 
39
  }
 
40
 
 
41
  private Internal.DefaultScopeDBusImpl pimpl;
35
42
  private bool exported;
36
43
  private uint bus_name_own_handle;
37
44
 
 
45
  private static int proxy_usage_count = 0;
 
46
 
38
47
  public void export () throws Error
39
48
  {
40
49
    if (!exported) // && can_export ()
41
50
    {
42
51
      if (pimpl == null) pimpl = new Internal.DefaultScopeDBusImpl (scope);
 
52
      pimpl.timeout = DAEMON_TIMEOUT_SEC;
 
53
      pimpl.on_timeout_reached.connect (timeout_reached);
43
54
      own_name (); // this will also export the object
44
55
      exported = true;
 
56
 
 
57
      proxy_usage_count++;
45
58
    }
46
59
  }
47
60
 
52
65
      pimpl.unexport ();
53
66
      exported = false;
54
67
      unown_name ();
 
68
 
 
69
      proxy_usage_count--;
55
70
    }
56
71
  }
57
72
 
 
73
  private void timeout_reached ()
 
74
  {
 
75
    unown_name ();
 
76
    Timeout.add_seconds_full (Priority.DEFAULT_IDLE, 30, () =>
 
77
    {
 
78
      unexport ();
 
79
      if (proxy_usage_count == 0) quit ();
 
80
      return false;
 
81
    });
 
82
  }
 
83
 
58
84
  private void own_name () throws Error
59
85
  {
60
86
    var dbus_name = scope.get_group_name ();