aboutsummaryrefslogtreecommitdiff
path: root/service/service.c
blob: 7d2751cdf5ab81aa22be5a842438f052ca92e01f (plain)
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
/**
 * Copyright (C) 2013 Canonical, Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3, as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <gio/gio.h>
#include <unistd.h>
#include "service-iface.h"

static gboolean
on_handle_request_url_start (ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *object,
                             GDBusMethodInvocation *invocation,
                             const gchar *arg_username,
                             const gchar *arg_url)
{
    /* Simply pass the request on */
    service_iface_org_ayatana_desktop_greeter_broadcast_emit_start_url (object,
                                                                        arg_username,
                                                                        arg_url);
    service_iface_org_ayatana_desktop_greeter_broadcast_complete_request_url_start (object,
                                                                                    invocation);
    return TRUE;
}

static gboolean
on_handle_request_home_shown (ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *object,
                              GDBusMethodInvocation *invocation,
                              const gchar *arg_username)
{
    /* Simply pass the request on */
    service_iface_org_ayatana_desktop_greeter_broadcast_emit_show_home (object,
                                                                        arg_username);
    service_iface_org_ayatana_desktop_greeter_broadcast_complete_request_home_shown (object,
                                                                                     invocation);
    return TRUE;
}

static gboolean
on_handle_request_sound_play_pause (ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *object,
                                    GDBusMethodInvocation *invocation,
                                    const gchar *arg_username)
{
    /* Simply pass the request on */
    service_iface_org_ayatana_desktop_greeter_broadcast_emit_sound_play_pause (object,
                                                                               arg_username);
    service_iface_org_ayatana_desktop_greeter_broadcast_complete_request_sound_play_pause (object,
                                                                                           invocation);
    return TRUE;
}

static gboolean
on_handle_request_sound_next (ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *object,
                              GDBusMethodInvocation *invocation,
                              const gchar *arg_username)
{
    /* Simply pass the request on */
    service_iface_org_ayatana_desktop_greeter_broadcast_emit_sound_next (object,
                                                                         arg_username);
    service_iface_org_ayatana_desktop_greeter_broadcast_complete_request_sound_next (object,
                                                                                     invocation);
    return TRUE;
}

static gboolean
on_handle_request_sound_prev (ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *object,
                              GDBusMethodInvocation *invocation,
                              const gchar *arg_username)
{
    /* Simply pass the request on */
    service_iface_org_ayatana_desktop_greeter_broadcast_emit_sound_prev (object,
                                                                         arg_username);
    service_iface_org_ayatana_desktop_greeter_broadcast_complete_request_sound_prev (object,
                                                                                     invocation);
    return TRUE;
}

static void
on_bus_acquired (GDBusConnection *connection,
                 const gchar     *name,
                 gpointer         user_data)
{
    GError *error = NULL;
    ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *interface;

    interface = (ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *)user_data;

    if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (interface),
                                           connection,
                                           "/org/ayatana/Desktop/Greeter/Broadcast",
                                           &error))
    {
        g_error ("Unable to export interface: %s, exiting", error->message);
    }
}

static void
on_name_lost (GDBusConnection *connection,
              const gchar     *name,
              gpointer         user_data)
{
    g_error ("Lost bus name, exiting");
}

int
main (int argc, char * argv[])
{
    guint owner_id;
    GMainLoop *loop;
    ServiceIfaceOrgAyatanaDesktopGreeterBroadcast *interface;

    interface = service_iface_org_ayatana_desktop_greeter_broadcast_skeleton_new ();

    /* Application Launching */
    g_signal_connect (interface,
                      "handle-request-url-start",
                      G_CALLBACK (on_handle_request_url_start),
                      NULL);
    g_signal_connect (interface,
                      "handle-request-home-shown",
                      G_CALLBACK (on_handle_request_home_shown),
                      NULL);

    /* Sound stuff */
    g_signal_connect (interface,
                      "handle-request-sound-play-pause",
                      G_CALLBACK (on_handle_request_sound_play_pause),
                      NULL);
    g_signal_connect (interface,
                      "handle-request-sound-next",
                      G_CALLBACK (on_handle_request_sound_next),
                      NULL);
    g_signal_connect (interface,
                      "handle-request-sound-prev",
                      G_CALLBACK (on_handle_request_sound_prev),
                      NULL);

    owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
                               "org.ayatana.Desktop.Greeter.Broadcast",
                               G_BUS_NAME_OWNER_FLAGS_NONE,
                               on_bus_acquired,
                               NULL,
                               on_name_lost,
                               g_object_ref (interface),
                               g_object_unref);

    loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (loop);

    g_bus_unown_name (owner_id);
    g_object_unref (interface);
    g_object_unref (loop);

    return 0;
}