~ubuntu-branches/ubuntu/wily/upower/wily

« back to all changes in this revision

Viewing changes to src/linux/up-backend.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-03-19 19:19:51 UTC
  • mfrom: (17.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130319191951-2lmdpe40kitm2zbx
Tags: 0.9.20-1
* New upstream release.
* Bump libpolkit-gobject-1-dev build dependency as per upstream
  configure.ac.
* Build with --enable-deprecated, we are not ready yet to drop
  suspend/hibernate functionality.
* Bump Standards-Version to 3.9.4. No changes necessary.
* Add "build" autopkgtest to compile/link/run a simple program against
  libupower-glib.
* Drop unnecessary "needs-root" restriction from upstream-system
  autopkgtest.
* Add no_deprecation_define.patch: Do not require applications to define
  UPOWER_ENABLE_DEPRECATED to access suspend/resume functionality. We are
  not ready to do that yet in Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
#include "up-device-supply.h"
38
38
#include "up-device-csr.h"
39
 
#include "up-device-lg-unifying.h"
 
39
#include "up-device-unifying.h"
40
40
#include "up-device-wup.h"
41
41
#include "up-device-hid.h"
42
42
#include "up-input.h"
49
49
#include <dbus/dbus-glib.h>
50
50
#include <dbus/dbus-glib-lowlevel.h>
51
51
 
 
52
#ifdef ENABLE_DEPRECATED
52
53
#ifdef HAVE_SYSTEMD
53
54
#include <systemd/sd-daemon.h>
54
55
 
56
57
#define SD_SUSPEND_COMMAND      "gdbus call --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1 --method org.freedesktop.login1.Manager.Suspend 'true'"
57
58
 
58
59
#endif
 
60
#endif
59
61
 
60
62
static void     up_backend_class_init   (UpBackendClass *klass);
61
63
static void     up_backend_init (UpBackend              *backend);
77
79
enum {
78
80
        SIGNAL_DEVICE_ADDED,
79
81
        SIGNAL_DEVICE_REMOVED,
 
82
#ifdef ENABLE_DEPRECATED
80
83
        SIGNAL_RESUMING,
 
84
#endif
81
85
        SIGNAL_LAST
82
86
};
83
87
 
88
92
static gboolean up_backend_device_add (UpBackend *backend, GUdevDevice *native);
89
93
static void up_backend_device_remove (UpBackend *backend, GUdevDevice *native);
90
94
 
 
95
#ifdef ENABLE_DEPRECATED
91
96
#define UP_BACKEND_SUSPEND_COMMAND              "/usr/sbin/pm-suspend"
92
97
#define UP_BACKEND_HIBERNATE_COMMAND            "/usr/sbin/pm-hibernate"
93
98
#define UP_BACKEND_POWERSAVE_TRUE_COMMAND       "/usr/sbin/pm-powersave true"
94
99
#define UP_BACKEND_POWERSAVE_FALSE_COMMAND      "/usr/sbin/pm-powersave false"
 
100
#endif
95
101
 
96
102
/**
97
103
 * up_backend_device_new:
118
124
                /* no valid power supply object */
119
125
                device = NULL;
120
126
 
 
127
        } else if (g_strcmp0 (subsys, "hid") == 0) {
 
128
 
 
129
                /* see if this is a Unifying mouse or keyboard */
 
130
                device = UP_DEVICE (up_device_unifying_new ());
 
131
                ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native));
 
132
                if (ret)
 
133
                        goto out;
 
134
                g_object_unref (device);
 
135
 
 
136
                /* no valid power supply object */
 
137
                device = NULL;
 
138
 
121
139
        } else if (g_strcmp0 (subsys, "tty") == 0) {
122
140
 
123
141
                /* try to detect a Watts Up? Pro monitor */
176
194
 
177
195
                        /* no valid input object */
178
196
                        device = NULL;
179
 
                } else {
180
 
                        g_object_unref (input);
181
 
 
182
 
                        /* see if this is a Unifying mouse or keyboard */
183
 
                        device = UP_DEVICE (up_device_unifying_new ());
184
 
                        ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native));
185
 
                        if (!ret) {
186
 
                                g_object_unref (device);
187
 
                                /* no valid input object */
188
 
                                device = NULL;
189
 
                        }
190
197
                }
 
198
                g_object_unref (input);
191
199
        } else {
192
200
                native_path = g_udev_device_get_sysfs_path (native);
193
201
                g_warning ("native path %s (%s) ignoring", native_path, subsys);
328
336
        GList *l;
329
337
        guint i;
330
338
        gboolean ret;
331
 
        const gchar *subsystems[] = {"power_supply", "usb", "usbmisc", "tty", "input", NULL};
 
339
        const gchar *subsystems[] = {"power_supply", "usb", "usbmisc", "tty", "input", "hid", NULL};
332
340
 
333
341
        backend->priv->daemon = g_object_ref (daemon);
334
342
        backend->priv->device_list = up_daemon_get_device_list (daemon);
360
368
        return TRUE;
361
369
}
362
370
 
 
371
#ifdef ENABLE_DEPRECATED
363
372
/**
364
373
 * up_backend_supports_sleep_state:
365
374
 *
617
626
#endif
618
627
        return FALSE;
619
628
}
 
629
#endif
620
630
 
 
631
#ifdef ENABLE_DEPRECATED
621
632
/**
622
633
 * up_backend_get_powersave_command:
623
634
 **/
628
639
                return UP_BACKEND_POWERSAVE_TRUE_COMMAND;
629
640
        return UP_BACKEND_POWERSAVE_FALSE_COMMAND;
630
641
}
 
642
#endif
631
643
 
632
644
/**
633
645
 * up_backend_class_init:
651
663
                              G_STRUCT_OFFSET (UpBackendClass, device_removed),
652
664
                              NULL, NULL, up_marshal_VOID__POINTER_POINTER,
653
665
                              G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
 
666
#ifdef ENABLE_DEPRECATED
654
667
        signals [SIGNAL_RESUMING] =
655
668
                g_signal_new ("resuming",
656
669
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
657
670
                              G_STRUCT_OFFSET (UpBackendClass, resuming),
658
671
                              NULL, NULL, g_cclosure_marshal_VOID__VOID,
659
672
                              G_TYPE_NONE, 0);
 
673
#endif
660
674
 
661
675
        g_type_class_add_private (klass, sizeof (UpBackendPrivate));
662
676
}
663
677
 
 
678
#ifdef ENABLE_DEPRECATED
664
679
static DBusHandlerResult
665
680
message_filter (DBusConnection *connection,
666
681
                DBusMessage *message,
673
688
                g_signal_emit (backend, signals[SIGNAL_RESUMING], 0);
674
689
                return DBUS_HANDLER_RESULT_HANDLED;
675
690
        }
676
 
 
677
691
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
678
692
}
 
693
#endif
679
694
 
680
695
/**
681
696
 * up_backend_init:
689
704
        backend->priv->device_list = NULL;
690
705
        backend->priv->managed_devices = up_device_list_new ();
691
706
 
 
707
#ifdef ENABLE_DEPRECATED
692
708
#ifdef HAVE_SYSTEMD
693
709
        if (sd_booted ()) {
694
710
                DBusGConnection *bus;
697
713
                dbus_connection_add_filter (backend->priv->connection, message_filter, backend, NULL);
698
714
        }
699
715
#endif
 
716
#endif
700
717
}
701
718
 
702
719
/**
721
738
 
722
739
        g_object_unref (backend->priv->managed_devices);
723
740
 
 
741
#ifdef ENABLE_DEPRECATED
724
742
        if (backend->priv->connection)
725
743
                dbus_connection_remove_filter (backend->priv->connection, message_filter, backend);
 
744
#endif
726
745
 
727
746
        G_OBJECT_CLASS (up_backend_parent_class)->finalize (object);
728
747
}