Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
memory-monitor: Add portal implementation for GMemoryMonitor
- Loading branch information
Showing
8 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?xml version="1.0"?> | ||
| <!-- | ||
| Copyright (C) 2016, 2019 Red Hat, Inc. | ||
| This library is free software; you can redistribute it and/or | ||
| modify it under the terms of the GNU Lesser General Public | ||
| License as published by the Free Software Foundation; either | ||
| version 2 of the License, or (at your option) any later version. | ||
| This library is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| Lesser General Public License for more details. | ||
| You should have received a copy of the GNU Lesser General Public | ||
| License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| Authors: Matthias Clasen <mclasen@redhat.com> | ||
| Bastien Nocera <hadess@hadess.net> | ||
| --> | ||
| <node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> | ||
| <!-- | ||
| org.freedesktop.portal.MemoryMonitor: | ||
| @short_description: Memory monitoring portal | ||
| The Memory Monitor interface provides information about low system | ||
| memory to sandboxed applications. It is not a portal in the strict | ||
| sense, since it does not involve user interaction. Applications are | ||
| expected to use this interface indirectly, via a library API | ||
| such as the GLib GMemoryMonitor interface. | ||
| This documentation describes version 1 of this interface. | ||
| --> | ||
| <interface name="org.freedesktop.portal.MemoryMonitor"> | ||
| <!-- | ||
| LowMemoryWarning: | ||
| @level: An integer representing the level of low memory warning. | ||
| Signal emitted when a particular low memory situation happens with 0 being the lowest | ||
| level of memory availability warning, and 255 being the highest. Those levels are defined | ||
| and documented in <ulink url="https://hadess.pages.freedesktop.org/low-memory-monitor/"> | ||
| Low Memory Monitor's documentation</ulink>. | ||
| --> | ||
| <signal name="LowMemoryWarning"> | ||
| <arg name="level" type="y"/> | ||
| </signal> | ||
|
|
||
| <property name="version" type="u" access="read"/> | ||
| </interface> | ||
| </node> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright © 2016, 2019 Red Hat, Inc | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * Authors: | ||
| * Matthias Clasen <mclasen@redhat.com> | ||
| * Bastien Nocera <hadess@hadess.net> | ||
| */ | ||
|
|
||
| #include "config.h" | ||
|
|
||
| #include <string.h> | ||
| #include <gio/gio.h> | ||
|
|
||
| #include "memory-monitor.h" | ||
| #include "request.h" | ||
| #include "xdp-dbus.h" | ||
| #include "xdp-utils.h" | ||
|
|
||
| typedef struct _MemoryMonitor MemoryMonitor; | ||
| typedef struct _MemoryMonitorClass MemoryMonitorClass; | ||
|
|
||
| struct _MemoryMonitor | ||
| { | ||
| XdpMemoryMonitorSkeleton parent_instance; | ||
|
|
||
| GMemoryMonitor *monitor; | ||
| }; | ||
|
|
||
| struct _MemoryMonitorClass | ||
| { | ||
| XdpMemoryMonitorSkeletonClass parent_class; | ||
| }; | ||
|
|
||
| static MemoryMonitor *memory_monitor; | ||
|
|
||
| GType memory_monitor_get_type (void) G_GNUC_CONST; | ||
| static void memory_monitor_iface_init (XdpMemoryMonitorIface *iface); | ||
|
|
||
| G_DEFINE_TYPE_WITH_CODE (MemoryMonitor, memory_monitor, XDP_TYPE_MEMORY_MONITOR_SKELETON, | ||
| G_IMPLEMENT_INTERFACE (XDP_TYPE_MEMORY_MONITOR, memory_monitor_iface_init)); | ||
|
|
||
| static void | ||
| memory_monitor_iface_init (XdpMemoryMonitorIface *iface) | ||
| { | ||
| } | ||
|
|
||
| static void | ||
| low_memory_warning_cb (GObject *object, | ||
| GMemoryMonitorWarningLevel level, | ||
| MemoryMonitor *mm) | ||
| { | ||
| xdp_memory_monitor_emit_low_memory_warning (XDP_MEMORY_MONITOR (mm), level); | ||
| } | ||
|
|
||
| static void | ||
| memory_monitor_init (MemoryMonitor *mm) | ||
| { | ||
| mm->monitor = g_memory_monitor_dup_default (); | ||
| g_signal_connect (mm->monitor, "low-memory-warning", G_CALLBACK (low_memory_warning_cb), mm); | ||
|
|
||
| xdp_memory_monitor_set_version (XDP_MEMORY_MONITOR (mm), 1); | ||
| } | ||
|
|
||
| static void | ||
| memory_monitor_finalize (GObject *object) | ||
| { | ||
| MemoryMonitor *mm = (MemoryMonitor *) object; | ||
|
|
||
| g_clear_object (&mm->monitor); | ||
|
|
||
| G_OBJECT_CLASS (memory_monitor_parent_class)->finalize (object); | ||
| } | ||
|
|
||
| static void | ||
| memory_monitor_class_init (MemoryMonitorClass *klass) | ||
| { | ||
| GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
|
|
||
| object_class->finalize = memory_monitor_finalize; | ||
| } | ||
|
|
||
| GDBusInterfaceSkeleton * | ||
| memory_monitor_create (GDBusConnection *connection) | ||
| { | ||
| memory_monitor = g_object_new (memory_monitor_get_type (), NULL); | ||
|
|
||
| return G_DBUS_INTERFACE_SKELETON (memory_monitor); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright © 2016, 2019 Red Hat, Inc | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * Authors: | ||
| * Matthias Clasen <mclasen@redhat.com> | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <gio/gio.h> | ||
|
|
||
| GDBusInterfaceSkeleton * memory_monitor_create (GDBusConnection *connection); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters