~ted/+junk/upstart-app-launch

« back to all changes in this revision

Viewing changes to lsapp.c

  • Committer: Ted Gould
  • Date: 2013-05-13 16:22:40 UTC
  • Revision ID: ted@gould.cx-20130513162240-vcjood5hp649p19h
Putting some boiler plate dbus in there

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
int
6
6
main (int argc, char * argv[])
7
7
{
8
 
 
 
8
        const gchar * upstart_addr = g_getenv("UPSTART_SESSION");
 
9
        if (upstart_addr == NULL) {
 
10
                g_print("Doesn't appear to be an upstart user session\n");
 
11
                return 1;
 
12
        }
 
13
 
 
14
        GError * error = NULL;
 
15
        GDBusConnection * upstart = g_dbus_connection_new_for_address_sync(upstart_addr,
 
16
                                                                           G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
 
17
                                                                           NULL, /* auth */
 
18
                                                                           NULL, /* cancel */
 
19
                                                                           &error);
 
20
 
 
21
        if (error != NULL) {
 
22
                g_error("Unable to connect to Upstart bus: %s", error->message);
 
23
                g_error_free(error);
 
24
                return 1;
 
25
        }
 
26
 
 
27
        GVariant * instances = g_dbus_connection_call_sync(upstart,
 
28
                                                           "com.ubuntu.Upstart",
 
29
                                                           "/com/ubuntu/Upstart/jobs/application",
 
30
                                                           "com.ubuntu.Upstart0_6.Job",
 
31
                                                           "GetAllInstances",
 
32
                                                           g_variant_new_tuple(NULL, 0),
 
33
                                                           G_VARIANT_TYPE("(ao)"),
 
34
                                                           G_DBUS_CALL_FLAGS_NONE,
 
35
                                                           -1,
 
36
                                                           NULL,
 
37
                                                           &error);
 
38
 
 
39
        if (error != NULL) {
 
40
                g_error("Unable to list instances: %s", error->message);
 
41
                g_error_free(error);
 
42
                return;
 
43
        }
 
44
 
 
45
        /* TODO: Do more */
 
46
        g_print("%s\n", g_variant_print(instances, TRUE));
 
47
        g_variant_unref(instances);
 
48
 
 
49
        g_object_unref(upstart);
9
50
 
10
51
        return 0;
11
52
}