Merge lp:~kay20/wingpanel-indicator-power/improved-on-trunk-branch into lp:~wingpanel-devs/wingpanel-indicator-power/trunk

Proposed by kay van der Zander
Status: Merged
Approved by: Danielle Foré
Approved revision: 211
Merged at revision: 208
Proposed branch: lp:~kay20/wingpanel-indicator-power/improved-on-trunk-branch
Merge into: lp:~wingpanel-devs/wingpanel-indicator-power/trunk
Diff against target: 1179 lines (+915/-41)
13 files modified
src/CMakeLists.txt (+5/-1)
src/Indicator.vala (+33/-10)
src/Services/Backlight/Backlight.vala (+48/-0)
src/Services/DBusInterfaces/Screen.vala (+31/-0)
src/Services/Device.vala (+5/-1)
src/Services/DeviceManager.vala (+14/-13)
src/Utils.vala (+4/-0)
src/Widgets/AppList.vala (+4/-0)
src/Widgets/DeviceList.vala (+7/-3)
src/Widgets/DisplayWidget.vala (+8/-11)
src/Widgets/PopoverWidget.vala (+24/-2)
src/Widgets/ScreenBrightness.vala (+90/-0)
vapi/libudev.vapi (+642/-0)
To merge this branch: bzr merge lp:~kay20/wingpanel-indicator-power/improved-on-trunk-branch
Reviewer Review Type Date Requested Status
Adam Bieńkowski (community) code Approve
Danielle Foré ux Approve
Review via email: mp+321781@code.launchpad.net

Commit message

Add a display brightness slider

To post a comment you must log in.
Revision history for this message
kay van der Zander (kay20) wrote :

this branch fixes bug #1503202

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Some diff comments, mostly I would to see all multiple get_default () calls be removed (see comments for more details). Other comments include some tips about the code style and small things, apart from that the code looks okay. Note that I didn't actually test it, it's only a code review for now.

review: Needs Fixing (code)
209. By kay van der Zander

incorporate review of Adam

Revision history for this message
Danielle Foré (danrabbit) wrote :

Added a couple small inline comments that will make the brightness icon center against the battery icon :)

Otherwise, I can confirm that it works as expected on a notebook.

210. By kay van der Zander

adjust margin on he brightness icon

Revision history for this message
Danielle Foré (danrabbit) wrote :

is get_symbolic_icon_name_for_backlight really necessary? Seems like you should just do display_widget.set_icon_name ("display-brightness-symbolic") and do all that in one place in one line :p

Revision history for this message
Danielle Foré (danrabbit) :
review: Approve (ux)
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Still couple of small things, but it is indeed better now. Look diff comments.

review: Needs Fixing (code)
211. By kay van der Zander

incorporated review of adam

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

LGTM.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2015-08-03 20:11:42 +0000
3+++ src/CMakeLists.txt 2017-04-09 18:23:30 +0000
4@@ -1,7 +1,7 @@
5 find_package (PkgConfig)
6
7 # Add all your dependencies to the list below
8-pkg_check_modules (DEPS REQUIRED gthread-2.0 gtk+-3.0 wingpanel-2.0 granite libgtop-2.0 libbamf3)
9+pkg_check_modules (DEPS REQUIRED gthread-2.0 gtk+-3.0 wingpanel-2.0 granite libgtop-2.0 libbamf3 libudev)
10
11 add_definitions (${DEPS_CFLAGS})
12 link_directories (${DEPS_LIBRARY_DIRS})
13@@ -19,6 +19,7 @@
14 Widgets/PopoverWidget.vala
15 Widgets/AppList.vala
16 Widgets/DeviceList.vala
17+ Widgets/ScreenBrightness.vala
18 Services/SettingsManager.vala
19 Services/DeviceManager.vala
20 Services/Device.vala
21@@ -26,8 +27,10 @@
22 Services/DBusInterfaces/Properties.vala
23 Services/DBusInterfaces/UPower.vala
24 Services/DBusInterfaces/Device.vala
25+ Services/DBusInterfaces/Screen.vala
26 Services/ProcessMonitor/Monitor.vala
27 Services/ProcessMonitor/Process.vala
28+ Services/Backlight/Backlight.vala
29 ${CMAKE_CURRENT_BINARY_DIR}/config.vala
30 PACKAGES
31 wingpanel-2.0
32@@ -36,6 +39,7 @@
33 posix
34 CUSTOM_VAPIS
35 ../vapi/libgtop-2.0.vapi
36+ ../vapi/libudev.vapi
37 OPTIONS
38 --thread
39 )
40
41=== modified file 'src/Indicator.vala'
42--- src/Indicator.vala 2016-12-09 21:42:13 +0000
43+++ src/Indicator.vala 2017-04-09 18:23:30 +0000
44@@ -47,12 +47,20 @@
45 popover_widget = new Widgets.PopoverWidget (is_in_session);
46 popover_widget.settings_shown.connect (() => this.close ());
47
48+ var dm = Services.DeviceManager.get_default ();
49+
50 /* No need to display the indicator when the device is completely in AC mode */
51- Services.DeviceManager.get_default ().notify["has-battery"].connect (update_visibility);
52- Services.DeviceManager.get_default ().notify["primary-battery"].connect (update_primary_battery);
53-
54- /* Start the device-search after connecting the signals */
55- Services.DeviceManager.get_default ().init ();
56+ if (dm.has_battery || dm.backlight.present) {
57+ update_visibility ();
58+ if (dm.primary_battery != null) {
59+ update_primary_battery ();
60+ /* No need to display the indicator when the device is completely in AC mode */
61+ dm.notify["has-battery"].connect (update_visibility);
62+ dm.notify["primary-battery"].connect (update_primary_battery);
63+ } else if (dm.backlight.present) {
64+ show_backlight_data ();
65+ }
66+ }
67 }
68
69 return popover_widget;
70@@ -60,6 +68,7 @@
71
72 public override void opened () {
73 Services.ProcessMonitor.Monitor.get_default ().update ();
74+ popover_widget.update_brightness_slider ();
75 }
76
77 public override void closed () {
78@@ -67,8 +76,11 @@
79 }
80
81 private void update_visibility () {
82- if (this.visible != Services.DeviceManager.get_default ().has_battery) {
83- this.visible = Services.DeviceManager.get_default ().has_battery;
84+ var dm = Services.DeviceManager.get_default ();
85+ if (dm.has_battery || dm.backlight.present) {
86+ visible = true;
87+ } else {
88+ visible = false;
89 }
90 }
91
92@@ -86,13 +98,24 @@
93 if (display_widget != null) {
94 var icon_name = Utils.get_symbolic_icon_name_for_battery (battery);
95
96- display_widget.icon_name = icon_name;
97+ display_widget.set_icon_name (icon_name);
98
99 /* Debug output for designers */
100 debug ("Icon changed to \"%s\"", icon_name);
101
102- display_widget.percent = (int)Math.round (battery.percentage);
103- }
104+ display_widget.set_percent ((int)Math.round (battery.percentage));
105+ }
106+ }
107+
108+ private void show_backlight_data () {
109+ if (display_widget != null) {
110+ var icon_name = Utils.get_symbolic_icon_name_for_backlight ();
111+
112+ display_widget.set_icon_name (icon_name);
113+
114+ /* Debug output for designers */
115+ debug ("Icon changed to \"%s\"", icon_name);
116+ }
117 }
118 }
119
120
121=== added directory 'src/Services/Backlight'
122=== added file 'src/Services/Backlight/Backlight.vala'
123--- src/Services/Backlight/Backlight.vala 1970-01-01 00:00:00 +0000
124+++ src/Services/Backlight/Backlight.vala 2017-04-09 18:23:30 +0000
125@@ -0,0 +1,48 @@
126+/*
127+ * Copyright (c) 2011-2015 Wingpanel Developers (http://launchpad.net/wingpanel)
128+ *
129+ * This program is free software; you can redistribute it and/or
130+ * modify it under the terms of the GNU General Public
131+ * License as published by the Free Software Foundation; either
132+ * version 2 of the License, or (at your option) any later version.
133+ *
134+ * This program is distributed in the hope that it will be useful,
135+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
136+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
137+ * General Public License for more details.
138+ *
139+ * You should have received a copy of the GNU General Public
140+ * License along with this program; if not, write to the
141+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
142+ * Boston, MA 02111-1307, USA.
143+ */
144+
145+public class Power.Services.Backlight : GLib.Object {
146+
147+ private const string BACKLIGHT_NAME = "backlight";
148+
149+ public bool present { get; construct set; }
150+
151+ construct {
152+ present = get_backlight_present ();
153+ debug ("backlight present: %s", present.to_string ());
154+ }
155+
156+ private static bool get_backlight_present () {
157+ var context = new UDev.Context ();
158+ var e = context.create_enumerate ();
159+ e.add_match_subsystem (BACKLIGHT_NAME);
160+ e.scan_devices ();
161+
162+ for (unowned UDev.List d = e.entries; d != null; d = d.next) {
163+ var path = d.name;
164+ var dev = context.open_syspath (path);
165+
166+ if (dev != null) {
167+ return true;
168+ }
169+ }
170+
171+ return false;
172+ }
173+}
174
175=== added file 'src/Services/DBusInterfaces/Screen.vala'
176--- src/Services/DBusInterfaces/Screen.vala 1970-01-01 00:00:00 +0000
177+++ src/Services/DBusInterfaces/Screen.vala 2017-04-09 18:23:30 +0000
178@@ -0,0 +1,31 @@
179+/*
180+ * Copyright (c) 2011-2016 Wingpanel Developers (http://launchpad.net/wingpanel)
181+ *
182+ * This program is free software; you can redistribute it and/or
183+ * modify it under the terms of the GNU General Public
184+ * License as published by the Free Software Foundation; either
185+ * version 2 of the License, or (at your option) any later version.
186+ *
187+ * This program is distributed in the hope that it will be useful,
188+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
189+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
190+ * General Public License for more details.
191+ *
192+ * You should have received a copy of the GNU General Public
193+ * License along with this program; if not, write to the
194+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
195+ * Boston, MA 02111-1307, USA.
196+ */
197+
198+namespace Power.Services.DBusInterfaces {
199+ [DBus (name = "org.gnome.SettingsDaemon.Power.Screen")]
200+ interface PowerSettings : GLib.Object {
201+ #if OLD_GSD
202+ public abstract uint get_percentage () throws IOError;
203+ public abstract uint set_percentage (uint percentage) throws IOError;
204+ #else
205+ // use the Brightness property after updateing g-s-d to 3.10 or above
206+ public abstract int brightness { get; set; }
207+ #endif
208+ }
209+}
210
211=== modified file 'src/Services/Device.vala'
212--- src/Services/Device.vala 2016-03-02 21:02:12 +0000
213+++ src/Services/Device.vala 2017-04-09 18:23:30 +0000
214@@ -105,7 +105,11 @@
215 }
216
217 private void update_properties () {
218- device.Refresh ();
219+ try {
220+ device.Refresh ();
221+ } catch (Error e) {
222+ critical ("Updating the upower device parameters failed: %s", e.message);
223+ }
224
225 has_history = device.has_history;
226 has_statistics = device.has_statistics;
227
228=== modified file 'src/Services/DeviceManager.vala'
229--- src/Services/DeviceManager.vala 2016-02-23 19:21:02 +0000
230+++ src/Services/DeviceManager.vala 2017-04-09 18:23:30 +0000
231@@ -26,26 +26,35 @@
232 private DBusInterfaces.UPower? upower = null;
233 private DBusInterfaces.Properties? upower_properties = null;
234
235+ public Services.Backlight backlight { get; construct; }
236 public Gee.HashMap<string, Device> devices { get; private set; }
237 public Gee.Iterator batteries { get; private set; }
238-
239 public Device primary_battery { get; private set; }
240-
241 public bool has_battery { get; private set; }
242-
243 public bool on_battery { get; private set; }
244 public bool on_low_battery { get; private set; }
245
246 public signal void battery_registered (string device_path, Device battery);
247 public signal void battery_deregistered (string device_path);
248
249- public void init () {
250+ construct {
251+ backlight = new Services.Backlight ();
252+
253 if (connect_to_bus ()) {
254 update_properties ();
255 read_devices ();
256 update_batteries ();
257 connect_signals ();
258+ }
259+ }
260+
261+ // singleton one class object in memory. use instance to get data.
262+ public static unowned DeviceManager get_default () {
263+ if (instance == null) {
264+ instance = new DeviceManager ();
265 }
266+
267+ return instance;
268 }
269
270 private bool connect_to_bus () {
271@@ -65,7 +74,7 @@
272 }
273 }
274
275- private void read_devices () {
276+ public void read_devices () {
277 try {
278 var devices = upower.EnumerateDevices ();
279
280@@ -175,12 +184,4 @@
281 battery_deregistered (device_path);
282 }
283 }
284-
285- public static DeviceManager get_default () {
286- if (instance == null) {
287- instance = new DeviceManager ();
288- }
289-
290- return instance;
291- }
292 }
293
294=== modified file 'src/Utils.vala'
295--- src/Utils.vala 2016-11-30 22:39:56 +0000
296+++ src/Utils.vala 2017-04-09 18:23:30 +0000
297@@ -30,6 +30,10 @@
298 return get_icon_name_for_battery (battery) + "-symbolic";
299 }
300
301+ public string get_symbolic_icon_name_for_backlight () {
302+ return "display-brightness-symbolic";
303+ }
304+
305 public string get_icon_name_for_battery (Services.Device battery) {
306 if (battery.percentage == 100 && is_charging (battery.state) == true) {
307 return "battery-full-charged";
308
309=== modified file 'src/Widgets/AppList.vala'
310--- src/Widgets/AppList.vala 2016-12-09 21:42:13 +0000
311+++ src/Widgets/AppList.vala 2017-04-09 18:23:30 +0000
312@@ -27,6 +27,10 @@
313 construct {
314 app_manager = Services.AppManager.get_default ();
315
316+ connect_signals ();
317+ }
318+
319+ private void connect_signals () {
320 Services.ProcessMonitor.Monitor.get_default ().updated.connect (() => {
321 /* Don't block the ui while updating the data */
322 Idle.add (() => {
323
324=== modified file 'src/Widgets/DeviceList.vala'
325--- src/Widgets/DeviceList.vala 2016-12-09 21:42:13 +0000
326+++ src/Widgets/DeviceList.vala 2017-04-09 18:23:30 +0000
327@@ -26,9 +26,13 @@
328
329 construct {
330 entries = new Gee.HashMap<string, Gtk.Grid> ();
331-
332- Services.DeviceManager.get_default ().battery_registered.connect (add_battery);
333- Services.DeviceManager.get_default ().battery_deregistered.connect (remove_battery);
334+ var dm = Services.DeviceManager.get_default ();
335+
336+ dm.battery_registered.connect (add_battery);
337+ dm.battery_deregistered.connect (remove_battery);
338+
339+ // load all battery information.
340+ dm.read_devices ();
341 }
342
343 private void update_icons (Services.Device battery, Gtk.Image device_image, Gtk.Image battery_image) {
344
345=== modified file 'src/Widgets/DisplayWidget.vala'
346--- src/Widgets/DisplayWidget.vala 2016-12-09 21:42:13 +0000
347+++ src/Widgets/DisplayWidget.vala 2017-04-09 18:23:30 +0000
348@@ -22,17 +22,6 @@
349 private Gtk.Revealer percent_revealer;
350 private Gtk.Label percent_label;
351
352- public string icon_name {
353- set {
354- image.icon_name = value;
355- }
356- }
357-
358- public int percent {
359- set {
360- percent_label.label = "%i%%".printf (value);
361- }
362- }
363
364 construct {
365 valign = Gtk.Align.CENTER;
366@@ -56,4 +45,12 @@
367 percent_revealer.set_reveal_child (Services.SettingsManager.get_default ().show_percentage);
368 });
369 }
370+
371+ public void set_icon_name (string icon_name) {
372+ image.icon_name = icon_name;
373+ }
374+
375+ public void set_percent (int percentage) {
376+ percent_label.set_label ("%i%%".printf (percentage));
377+ }
378 }
379
380=== modified file 'src/Widgets/PopoverWidget.vala'
381--- src/Widgets/PopoverWidget.vala 2016-12-09 20:49:16 +0000
382+++ src/Widgets/PopoverWidget.vala 2017-04-09 18:23:30 +0000
383@@ -21,6 +21,7 @@
384 public bool is_in_session { get; construct; default = false; }
385 private DeviceList device_list;
386 private AppList app_list;
387+ private ScreenBrightness screen_brightness;
388
389 private Wingpanel.Widgets.Switch show_percent_switch;
390 private Wingpanel.Widgets.Button show_settings_button;
391@@ -33,6 +34,19 @@
392
393 construct {
394 device_list = new DeviceList ();
395+ var dm = Services.DeviceManager.get_default ();
396+
397+ if (dm.has_battery) {
398+ debug ("show list of batteries");
399+ pack_start (device_list);
400+ pack_start (new Wingpanel.Widgets.Separator ());
401+ }
402+
403+ if (dm.backlight.present) {
404+ debug ("show brightness slider");
405+ screen_brightness = new ScreenBrightness ();
406+ pack_start (screen_brightness);
407+ }
408
409 show_percent_switch = new Wingpanel.Widgets.Switch (_("Show Percentage"), Services.SettingsManager.get_default ().show_percentage);
410 show_settings_button = new Wingpanel.Widgets.Button (_("Power Settings…"));
411@@ -43,9 +57,13 @@
412 app_list = new AppList ();
413 this.pack_start (app_list); /* The app-list contains an own separator that is displayed if necessary. */
414 this.pack_start (new Wingpanel.Widgets.Separator ());
415- this.pack_start (show_percent_switch);
416+
417+ if (dm.has_battery) {
418+ this.pack_start (show_percent_switch);
419+ }
420+
421 this.pack_start (show_settings_button);
422- } else {
423+ } else if (dm.has_battery) {
424 this.pack_start (new Wingpanel.Widgets.Separator ());
425 this.pack_start (show_percent_switch);
426 }
427@@ -61,6 +79,10 @@
428 }
429 }
430
431+ public void update_brightness_slider () {
432+ screen_brightness.update_slider ();
433+ }
434+
435 private void show_settings () {
436 var list = new List<string> ();
437 list.append ("power");
438
439=== added file 'src/Widgets/ScreenBrightness.vala'
440--- src/Widgets/ScreenBrightness.vala 1970-01-01 00:00:00 +0000
441+++ src/Widgets/ScreenBrightness.vala 2017-04-09 18:23:30 +0000
442@@ -0,0 +1,90 @@
443+/*
444+ * Copyright (c) 2011-2016 Wingpanel Developers (http://launchpad.net/wingpanel)
445+ *
446+ * This program is free software; you can redistribute it and/or
447+ * modify it under the terms of the GNU General Public
448+ * License as published by the Free Software Foundation; either
449+ * version 2 of the License, or (at your option) any later version.
450+ *
451+ * This program is distributed in the hope that it will be useful,
452+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
453+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
454+ * General Public License for more details.
455+ *
456+ * You should have received a copy of the GNU General Public
457+ * License along with this program; if not, write to the
458+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
459+ * Boston, MA 02111-1307, USA.
460+ */
461+
462+public class Power.Widgets.ScreenBrightness : Gtk.Grid {
463+ private const string DBUS_PATH = "/org/gnome/SettingsDaemon/Power";
464+ private const string DBUS_NAME = "org.gnome.SettingsDaemon";
465+
466+ private Gtk.Image image;
467+ private Gtk.Scale brightness_slider;
468+ private Services.DBusInterfaces.PowerSettings iscreen;
469+
470+ construct {
471+ orientation = Gtk.Orientation.HORIZONTAL;
472+ set_column_spacing (12);
473+ init_bus.begin ();
474+
475+ image = new Gtk.Image.from_icon_name ("brightness-display-symbolic", Gtk.IconSize.DIALOG);
476+ image.margin_start = 6;
477+ attach (image, 0, 0, 1, 1);
478+
479+ brightness_slider = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0, 100, 10);
480+ brightness_slider.margin_end = 12;
481+ brightness_slider.hexpand = true;
482+ brightness_slider.draw_value = false;
483+
484+ brightness_slider.value_changed.connect (() => {
485+ on_scale_value_changed.begin ();
486+ });
487+
488+ #if OLD_GSD
489+ brightness_slider.set_value (iscreen.get_percentage ());
490+ #else
491+ brightness_slider.set_value (iscreen.brightness);
492+ #endif
493+
494+ attach (brightness_slider, 1, 0, 1, 1);
495+ }
496+
497+ public void update_slider () {
498+ #if OLD_GSD
499+ brightness_slider.set_value (iscreen.get_percentage ());
500+ #else
501+ brightness_slider.set_value (iscreen.brightness);
502+ #endif
503+
504+ // this fixes the first slow response
505+ #if OLD_GSD
506+ iscreen.set_percentage (iscreen.get_percentage ());
507+ #else
508+ iscreen.brightness = iscreen.brightness;
509+ #endif
510+ }
511+
512+ private async void init_bus () {
513+ try {
514+ iscreen = Bus.get_proxy_sync (BusType.SESSION, DBUS_NAME, DBUS_PATH, DBusProxyFlags.GET_INVALIDATED_PROPERTIES);
515+ } catch (IOError e) {
516+ warning ("screen brightness error %s", e.message);
517+ }
518+ }
519+
520+ private async void on_scale_value_changed () {
521+ int val = (int) brightness_slider.get_value ();
522+ try {
523+ #if OLD_GSD
524+ iscreen.set_percentage (val);
525+ #else
526+ iscreen.brightness = val;
527+ #endif
528+ } catch (IOError e) {
529+ warning ("screen brightness error %s", e.message);
530+ }
531+ }
532+}
533
534=== added file 'vapi/libudev.vapi'
535--- vapi/libudev.vapi 1970-01-01 00:00:00 +0000
536+++ vapi/libudev.vapi 2017-04-09 18:23:30 +0000
537@@ -0,0 +1,642 @@
538+[CCode (cheader_filename = "libudev.h")]
539+namespace UDev {
540+ /**
541+ * Reads the udev config and system environment allows custom logging
542+ */
543+ [CCode (cname = "struct udev", ref_function = "udev_ref", unref_function = "udev_unref", has_type_id = false)]
544+ public class Context {
545+ /**
546+ * Create udev library context.
547+ *
548+ * This reads the udev configuration file, and fills in the default values.
549+ */
550+ [CCode (cname = "udev_new")]
551+ public Context ();
552+ /**
553+ * The device directory path.
554+ *
555+ * The default value is "/dev", the actual value may be overridden in the
556+ * udev configuration file.
557+ */
558+ [CCode (cname = "udev_get_dev_path")]
559+ public string dev_path {
560+ get;
561+ }
562+ public int log_priority {
563+ [CCode (cname = "udev_get_log_priority")]
564+ get;
565+ [CCode (cname = "udev_set_log_priority")]
566+ set;
567+ }
568+ /**
569+ * The udev runtime directory path.
570+ *
571+ * The default is "/run/udev".
572+ */
573+ [CCode (cname = "udev_get_run_path")]
574+ public string run_path {
575+ get;
576+ }
577+ /**
578+ * The sysfs mount point.
579+ *
580+ * The default is "/sys". For testing purposes, it can be overridden with
581+ * udev_sys= in the udev configuration file.
582+ */
583+ [CCode (cname = "udev_get_sys_path")]
584+ public string sys_path {
585+ get;
586+ }
587+ public void* user_data {
588+ [CCode (cname = "udev_get_userdata")]
589+ get;
590+ [CCode (cname = "udev_set_userdata")]
591+ set;
592+ }
593+ [CCode (cname = "udev_enumerate_new")]
594+ public Enumerate create_enumerate ();
595+ [CCode (cname = "udev_queue_new")]
596+ public Queue? create_queue ();
597+ /**
598+ * Create new udev monitor and connect to a specified event source. Valid
599+ * sources identifiers are "udev" and "kernel".
600+ *
601+ * Applications should usually not connect directly to the "kernel" events,
602+ * because the devices might not be useable at that time, before udev has
603+ * configured them, and created device nodes. Accessing devices at the same
604+ * time as udev, might result in unpredictable behavior. The "udev" events
605+ * are sent out after udev has finished its event processing, all rules
606+ * have been processed, and needed device nodes are created.
607+ */
608+ [CCode (cname = "udev_monitor_new_from_netlink")]
609+ public Monitor? monitor_from_netlink (string name = "udev");
610+ /**
611+ * Create new udev device, and fill in information from the current process
612+ * environment.
613+ *
614+ * This only works reliable if the process is called from a udev rule. It
615+ * is usually used for tools executed from IMPORT= rules.
616+ */
617+ [CCode (cname = "udev_device_new_from_environment")]
618+ public Device? new_from_environment ();
619+ /**
620+ * Create new udev device, and fill in information from the sys device and
621+ * the udev database entry by its major/minor number and type.
622+ *
623+ * Character and block device numbers are not unique across the two types.
624+ * @param type 'c' for character devices or 'b' for block devices.sudo
625+ */
626+ [CCode (cname = "udev_device_new_from_devnum")]
627+ public Device? open_devnum (char type, Posix.dev_t devnum);
628+ /**
629+ * Create new udev device, and fill in information from the sys device
630+ * and the udev database entry. The device is looked up by the subsystem
631+ * and name string of the device, like "mem" / "zero", or "block" / "sda".
632+ */
633+ [CCode (cname = "udev_device_new_from_subsystem_sysname")]
634+ public Device? open_subsystem_sysname (string subsystem, string sysname);
635+ /**
636+ * Create new udev device, and fill in information from the sys device and
637+ * the udev database entry.
638+ *
639+ * The syspath is the absolute path to the device, including the sys mount
640+ * point.
641+ */
642+ [CCode (cname = "udev_device_new_from_syspath")]
643+ public Device? open_syspath (string syspath);
644+ /**
645+ * Take a reference of the udev library context.
646+ */
647+ [CCode (cname = "udev_ref")]
648+ public void ref ();
649+ /**
650+ * The error logging function.
651+ *
652+ * The built-in logging writes to stderr. It can be overridden by a custom
653+ * function, to plug log messages into the users' logging functionality.
654+ */
655+ [CCode (cname = "udev_set_log_fn")]
656+ public void set_logger (Logger logger);
657+
658+ /**
659+ * Drop a reference of the udev library context.
660+ */
661+ [CCode (cname = "udev_unref")]
662+ public void unref ();
663+ }
664+
665+ /**
666+ * Kernel sys devices
667+ *
668+ * Representation of kernel sys devices. Devices are uniquely identified by
669+ * their syspath, every device has exactly one path in the kernel sys
670+ * filesystem. Devices usually belong to a kernel subsystem, and and have a
671+ * unique name inside that subsystem.
672+ */
673+ [CCode (cname = "struct udev_device", ref_function = "udev_device_ref", unref_function = "udev_device_unref", has_type_id = false)]
674+ public class Device {
675+ /**
676+ * The action if the device was received through a monitor.
677+ *
678+ * Devices read from sys do not have an action string. Usual actions are: add, remove, change, online, offline.
679+ */
680+ public string? action {
681+ [CCode (cname = "udev_device_get_action")]
682+ get;
683+ }
684+
685+ /**
686+ * An indexable collection of sys attrs
687+ */
688+ public SysAttr attr {
689+ [CCode (cname = "")]
690+ get;
691+ }
692+ /**
693+ * The udev library context with which the device was created.
694+ */
695+ public Context context {
696+ [CCode (cname = "udev_device_get_udev")]
697+ get;
698+ }
699+ /**
700+ * The list of device links pointing to the device file of the udev device.
701+ */
702+ public List? devlinks {
703+ [CCode (cname = "udev_device_get_devlinks_list_entry")]
704+ get;
705+ }
706+ /**
707+ * Retrieve the device node file name belonging to the udev device.
708+ *
709+ * The path is an absolute path, and starts with the device directory.
710+ */
711+ public string? devnode {
712+ [CCode (cname = "udev_device_get_devnode")]
713+ get;
714+ }
715+ /**
716+ * The the device major/minor number
717+ */
718+ public Posix.dev_t devnum {
719+ [CCode (cname = "udev_device_get_devnum")]
720+ get;
721+ }
722+ /**
723+ * Retrieve the kernel devpath value of the udev device.
724+ *
725+ * The path does not contain the sys mount point, and starts with a '/'.
726+ */
727+ public string devpath {
728+ [CCode (cname = "udev_device_get_devpath")]
729+ get;
730+ }
731+ /**
732+ * The devtype name of the device, if it can be determined.
733+ */
734+ public string? devtype {
735+ [CCode (cname = "udev_device_get_devtype")]
736+ get;
737+ }
738+ /**
739+ * Get the name of the driver, if one is attached.
740+ */
741+ public string? driver {
742+ [CCode (cname = "udev_device_get_driver")]
743+ get;
744+ }
745+ /**
746+ * Has already handled the device and has set up device node permissions
747+ * and context, or has renamed a network device?
748+ *
749+ * This is only implemented for devices with a device node or network
750+ * interfaces. All other devices return true.
751+ */
752+ public bool is_initialized {
753+ [CCode (cname = "udev_device_get_is_initialized")]
754+ get;
755+ }
756+ /**
757+ * Find the next parent device, and fill in information from the sys device
758+ * and the udev database entry.
759+ *
760+ * It is not necessarily just the upper level directory, empty or not
761+ * recognized sys directories are ignored.
762+ */
763+ public Device? parent {
764+ [CCode (cname = "udev_device_get_parent")]
765+ get;
766+ }
767+ /**
768+ * The list of key/value device properties of the udev device.
769+ */
770+ public List? properties {
771+ [CCode (cname = "udev_device_get_properties_list_entry")]
772+ get;
773+ }
774+ /**
775+ * The sequence number
776+ *
777+ * This is only valid if the device was received through a monitor. Devices read from sys do not have a sequence number.
778+ */
779+ public uint64 seqnum {
780+ [CCode (cname = "udev_device_get_seqnum")]
781+ get;
782+ }
783+ /**
784+ * The subsystem string of the device, if it can be determined.
785+ *
786+ * This string will not contain /.
787+ */
788+ public string? subsystem {
789+ [CCode (cname = "udev_device_get_subsystem")]
790+ get;
791+ }
792+ /**
793+ * The list of available sysattrs, with value being empty.
794+ *
795+ * This just return all available sysfs attributes for a particular device
796+ * without reading their values.
797+ */
798+ public List sysattr {
799+ [CCode (cname = "udev_device_get_sysattr_list_entry")]
800+ get;
801+ }
802+ /**
803+ * The sys name of the device device
804+ */
805+ public string sysname {
806+ [CCode (cname = "udev_device_get_sysname")]
807+ get;
808+ }
809+ /**
810+ * The trailing number of of the device name
811+ */
812+ public string sysnum {
813+ [CCode (cname = "udev_device_get_sysnum")]
814+ get;
815+ }
816+ /**
817+ * Retrieve the absolute sys path of the udev device starting with the sys mount point.
818+ */
819+ public string syspath {
820+ [CCode (cname = "udev_device_get_syspath")]
821+ get;
822+ }
823+ /**
824+ * The list of tags attached to the udev device
825+ */
826+ public List? tags {
827+ [CCode (cname = "udev_device_get_tags_list_entry")]
828+ get;
829+ }
830+ /**
831+ * The number of microseconds passed since udev set up the device for the
832+ * first time.
833+ *
834+ * This is only implemented for devices with need to store properties
835+ * in the udev database. All other devices are 0.
836+ */
837+ public uint64 usec_since_initialized {
838+ [CCode (cname = "udev_device_get_usec_since_initialized")]
839+ get;
840+ }
841+ /**
842+ * Get the value of a device property, if one exists.
843+ */
844+ [CCode (cname = "udev_device_get_property_value")]
845+ public unowned string? get (string key);
846+ /**
847+ * Find the next parent device, with a matching subsystem and devtype
848+ * value, and fill in information from the sys device and the udev database
849+ * entry.
850+ *
851+ * @param devtype the type of the device, or null to match any.
852+ */
853+ [CCode (cname = "udev_device_get_parent_with_subsystem_devtype")]
854+ public unowned Device? get_parent (string subsystem, string? devtype = null);
855+ [CCode (cname = "udev_device_has_tag")]
856+ public bool has_tag (string tag);
857+ /**
858+ * Take a reference of a udev device.
859+ */
860+ [CCode (cname = "udev_device_ref")]
861+ public void ref ();
862+ /**
863+ * Drop a reference of a udev device.
864+ */
865+ [CCode (cname = "udev_device_unref")]
866+ public void unref ();
867+ }
868+
869+ /**
870+ * Search sysfs for specific devices and provide a sorted list
871+ */
872+ [CCode (cname = "struct udev_enumerate", ref_function = "udev_enumerate_ref", unref_function = "udev_enumerate_unref", has_type_id = false)]
873+ public class Enumerate {
874+ /**
875+ * The udev library context.
876+ */
877+ public Context context {
878+ [CCode (cname = "udev_enumerate_get_udev")]
879+ get;
880+ }
881+ /**
882+ * The sorted list of device paths.
883+ */
884+ public List? entries {
885+ [CCode (cname = "udev_enumerate_get_list_entry")]
886+ get;
887+ }
888+ /**
889+ * Match only devices which udev has set up already.
890+ *
891+ * This makes sure, that the device node permissions and context are
892+ * properly set and that network devices are fully renamed.
893+ *
894+ * Usually, devices which are found in the kernel but not already handled
895+ * by udev, have still pending events. Services should subscribe to monitor
896+ * events and wait for these devices to become ready, instead of using
897+ * uninitialized devices.
898+ * @return false on success
899+ */
900+ [CCode (cname = "udev_enumerate_add_match_is_initialized")]
901+ public bool add_match_is_initialized ();
902+ /**
903+ * Return the devices on the subtree of one given device.
904+ *
905+ * The parent itself is included in the list.
906+ * @return false on success
907+ */
908+ [CCode (cname = "udev_enumerate_add_match_parent")]
909+ public bool add_match_parent (Device parent);
910+ /**
911+ * Filter for a property of the device to include in the list
912+ * @return false on success
913+ */
914+ [CCode (cname = "udev_enumerate_add_match_property")]
915+ public bool add_match_property (string property, string @value);
916+ /**
917+ * Filter for a subsystem of the device to include in the list
918+ * @return false on success
919+ */
920+ [CCode (cname = "udev_enumerate_add_match_subsystem")]
921+ public bool add_match_subsystem (string subsystem);
922+ /**
923+ * Filter for a sys attribute at the device to include in the list
924+ * @return false on success
925+ */
926+ [CCode (cname = "udev_enumerate_add_match_sysattr")]
927+ public bool add_match_sysattr (string sysattr, string @value);
928+ /**
929+ * Filter for the name of the device to include in the list
930+ * @return false on success
931+ */
932+ [CCode (cname = "udev_enumerate_add_match_sysname")]
933+ public bool add_match_sysname (string sysname);
934+ /**
935+ * Filter for a tag of the device to include in the list
936+ * @return false on success
937+ */
938+ [CCode (cname = "udev_enumerate_add_match_tag")]
939+ public bool add_match_tag (string tag);
940+ /**
941+ * Filter for a subsystem of the device to exclude from the list
942+ * @return false on success
943+ */
944+ [CCode (cname = "udev_enumerate_add_nomatch_subsystem")]
945+ public bool add_nomatch_subsystem (string subsystem);
946+ /**
947+ * Filter for a sys attribute at the device to exclude from the list
948+ * @return false on success
949+ */
950+ [CCode (cname = "udev_enumerate_add_nomatch_sysattr")]
951+ public bool add_nomatch_sysattr (string sysattr, string @value);
952+ /**
953+ * Add a device to the list of devices, to retrieve it back sorted in dependency order.
954+ * @return false on success
955+ */
956+ [CCode (cname = "udev_enumerate_add_syspath")]
957+ public bool add_syspath (string syspath);
958+ /**
959+ * Take a reference of a enumeration context.
960+ */
961+ [CCode (cname = "udev_enumerate_ref")]
962+ public void ref ();
963+ /**
964+ * Run enumeration with active filters
965+ * @return false on success
966+ */
967+ [CCode (cname = "udev_enumerate_scan_devices")]
968+ public bool scan_devices ();
969+ /**
970+ * Run enumeration with active filters
971+ * @return false on success
972+ */
973+ [CCode (cname = "udev_enumerate_scan_subsystems")]
974+ public bool scan_subsystems ();
975+ /**
976+ * Drop a reference of an enumeration context.
977+ */
978+ [CCode (cname = "udev_enumerate_unref")]
979+ public void unref ();
980+ }
981+
982+ [CCode (cname = "struct udev_list_entry", free_function = "")]
983+ [Compact]
984+ public class List {
985+ [CCode (cname = "udev_list_entry_get_by_name")]
986+ public List? get (string name);
987+ public string name {
988+ [CCode (cname = "udev_list_entry_get_name")]
989+ get;
990+ }
991+ public List? next {
992+ [CCode (cname = "udev_list_entry_get_next")]
993+ get;
994+ }
995+ public string @value {
996+ [CCode (cname = "udev_list_entry_get_value")]
997+ get;
998+ }
999+ }
1000+
1001+ /**
1002+ * Connection to a device event source.
1003+ */
1004+ [CCode (cname = "struct udev_monitor", ref_function = "udev_monitor_ref", unref_function = "udev_monitor_unref", has_type_id = false)]
1005+ public class Monitor {
1006+ /**
1007+ * The udev library context with which the monitor was created.
1008+ */
1009+ public Context context {
1010+ [CCode (cname = "udev_monitor_get_udev")]
1011+ get;
1012+ }
1013+
1014+ /**
1015+ * The socket file descriptor associated with the monitor.
1016+ */
1017+ public int fd {
1018+ [CCode (cname = "udev_monitor_get_fd")]
1019+ get;
1020+ }
1021+
1022+ /**
1023+ * This filter is efficiently executed inside the kernel, and libudev
1024+ * subscribers will usually not be woken up for devices which do not match.
1025+ *
1026+ * The filter must be installed before the monitor is switched to listening mode.
1027+ * @return false on success
1028+ */
1029+ [CCode (cname = "udev_monitor_filter_add_match_subsystem_devtype")]
1030+ public bool add_match_subsystem_devtype (string subsystem, string? devtype = null);
1031+ /**
1032+ * This filter is efficiently executed inside the kernel, and libudev
1033+ * subscribers will usually not be woken up for devices which do not match.
1034+ *
1035+ * The filter must be installed before the monitor is switched to listening mode.
1036+ * @return false on success
1037+ */
1038+ [CCode (cname = "udev_monitor_filter_add_match_tag")]
1039+ public bool add_match_tag (string tag);
1040+ /**
1041+ * Binds the monitor socket to the event source.
1042+ * @return false on success
1043+ */
1044+ [CCode (cname = "udev_monitor_enable_receiving")]
1045+ public bool enable_receiving ();
1046+ /**
1047+ * Receive data from the udev monitor socket, allocate a new udev device,
1048+ * fill in the received data, and return the device.
1049+ *
1050+ * Only socket connections with uid=0 are accepted.
1051+ * @return a new udev device, or null, in case of an error
1052+ */
1053+ [CCode (cname = "udev_monitor_receive_device")]
1054+ public Device? receive_device ();
1055+ /**
1056+ * Take a reference of a udev monitor.
1057+ */
1058+ [CCode (cname = "udev_monitor_ref")]
1059+ public void ref ();
1060+ /**
1061+ * Remove all filters from monitor.
1062+ * @return false on success
1063+ */
1064+ [CCode (cname = "udev_monitor_filter_remove")]
1065+ public bool remove_filter ();
1066+ /**
1067+ * Set the size of the kernel socket buffer.
1068+ *
1069+ * This call needs the appropriate privileges to succeed.
1070+ * @return false on success
1071+ */
1072+ [CCode (cname = "udev_monitor_set_receive_buffer_size")]
1073+ public bool set_receive_buffer_size (int size);
1074+ /**
1075+ * Drop a reference of a udev monitor.
1076+ */
1077+ [CCode (cname = "udev_monitor_unref")]
1078+ public void unref ();
1079+ /**
1080+ * Update the installed socket filter.
1081+ *
1082+ * This is only needed, if the filter was removed or changed.
1083+ * @return false on success
1084+ */
1085+ [CCode (cname = "udev_monitor_filter_update")]
1086+ public bool update_filter ();
1087+ }
1088+ /**
1089+ * Access to currently active events
1090+ *
1091+ * The udev daemon processes events asynchronously. All events which do not
1092+ * have interdependencies run in parallel. This exports the current state of
1093+ * the event processing queue, and the current event sequence numbers from
1094+ * the kernel and the udev daemon.
1095+ */
1096+ [CCode (cname = "struct udev_queue", ref_function = "udev_queue_ref", unref_function = "udev_queue_unref", has_type_id = false)]
1097+ public class Queue {
1098+ /**
1099+ * The udev library context with which the queue context was created.
1100+ */
1101+ public Context context {
1102+ [CCode (cname = "udev_queue_get_udev")]
1103+ get;
1104+ }
1105+ /**
1106+ * The list of queued events.
1107+ */
1108+ public List? events {
1109+ [CCode (cname = "udev_queue_get_queued_list_entry")]
1110+ get;
1111+ }
1112+ public bool is_active {
1113+ [CCode (cname = "udev_queue_get_udev_is_active")]
1114+ get;
1115+ }
1116+ public bool is_empty {
1117+ [CCode (cname = "udev_queue_get_queue_is_empty")]
1118+ get;
1119+ }
1120+ /**
1121+ * The current kernel event sequence number.
1122+ */
1123+ public uint64 kernel_seqnum {
1124+ [CCode (cname = "udev_queue_get_kernel_seqnum")]
1125+ get;
1126+ }
1127+ /**
1128+ * The last known udev event sequence number.
1129+ */
1130+ public uint64 udev_seqnum {
1131+ [CCode (cname = "udev_queue_get_udev_seqnum")]
1132+ get;
1133+ }
1134+ /**
1135+ * Indicates whether the given sequence number is currently active.
1136+ */
1137+ [CCode (cname = "udev_queue_get_seqnum_is_finished")]
1138+ public bool is_finished (uint64 seqnum);
1139+ /**
1140+ * Indicates if any of the sequence numbers in the given range is currently active.
1141+ */
1142+ [CCode (cname = "udev_queue_get_seqnum_sequence_is_finished")]
1143+ public bool is_sequence_finished (uint64 start, uint64 end);
1144+ /**
1145+ * Take a reference of a udev queue context.
1146+ */
1147+ [CCode (cname = "udev_queue_ref")]
1148+ public void ref ();
1149+ /**
1150+ * Drop a reference of a udev queue context.
1151+ */
1152+ [CCode (cname = "udev_queue_unref")]
1153+ public void unref ();
1154+ }
1155+ /**
1156+ * Internal class to make sysattrs easy to access
1157+ */
1158+ [CCode (cname = "struct udev_device", ref_function = "udev_device_ref", unref_function = "udev_device_unref", has_type_id = false)]
1159+ public class SysAttr {
1160+ /**
1161+ * The content of a sys attribute file, null if there is a sys attribute value.
1162+ *
1163+ * The retrieved value is cached in the device. Repeated calls will return the same
1164+ * value and not open the attribute again.
1165+ */
1166+ [CCode (cname = "udev_device_get_sysattr_value")]
1167+ public unowned string? get (string sysattr);
1168+ }
1169+
1170+ public delegate void Logger (Context udev, int priority, string file, int line, string fn, string format, va_list args);
1171+
1172+ /**
1173+ * Encode all potentially unsafe characters of a string to the corresponding 2 char hex value prefixed by '\x'.
1174+ * @param buffer the output buffer to store the string which might be four times the length of the input.
1175+ * @return true on error
1176+ */
1177+ [CCode (cname = "udev_util_encode_string")]
1178+ public bool encode_string (string str, char[] buffer);
1179+}

Subscribers

People subscribed via source and target branches