Skip to content
Permalink
Browse files

memory-monitor: Add portal implementation for GMemoryMonitor

  • Loading branch information
hadess committed Sep 19, 2019
1 parent 74ffe77 commit 78cea78b84cb5825bcdf4ac623d9f4b0e81a08f9
@@ -7,6 +7,7 @@ dist_introspection_DATA = \
data/org.freedesktop.portal.Trash.xml \
data/org.freedesktop.portal.OpenURI.xml \
data/org.freedesktop.portal.Print.xml \
data/org.freedesktop.portal.MemoryMonitor.xml \
data/org.freedesktop.portal.NetworkMonitor.xml \
data/org.freedesktop.portal.ProxyResolver.xml \
data/org.freedesktop.portal.Screenshot.xml \
@@ -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>
@@ -26,6 +26,7 @@ portal_files = \
$(top_srcdir)/data/org.freedesktop.portal.GameMode.xml \
$(top_srcdir)/data/org.freedesktop.portal.Camera.xml \
$(top_srcdir)/data/org.freedesktop.portal.Wallpaper.xml \
$(top_srcdir)/data/org.freedesktop.portal.MemoryMonitor.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.Request.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.Session.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.FileChooser.xml \
@@ -71,6 +72,7 @@ xml_files = \
portal-org.freedesktop.portal.Background.xml \
portal-org.freedesktop.portal.GameMode.xml \
portal-org.freedesktop.portal.Camera.xml \
portal-org.freedesktop.portal.MemoryMonitor.xml \
portal-org.freedesktop.impl.portal.Background.xml \
portal-org.freedesktop.impl.portal.Request.xml \
portal-org.freedesktop.impl.portal.Session.xml \
@@ -112,6 +112,7 @@
<xi:include href="portal-org.freedesktop.portal.Camera.xml"/>
<xi:include href="portal-org.freedesktop.portal.Documents.xml"/>
<xi:include href="portal-org.freedesktop.portal.Wallpaper.xml"/>
<xi:include href="portal-org.freedesktop.portal.MemoryMonitor.xml"/>
<xi:include href="portal-org.freedesktop.portal.Flatpak.xml"/>
<xi:include href="portal-org.freedesktop.portal.Flatpak.UpdateMonitor.xml"/>
</reference>
@@ -23,6 +23,7 @@ PORTAL_IFACE_FILES =\
data/org.freedesktop.portal.Trash.xml \
data/org.freedesktop.portal.OpenURI.xml \
data/org.freedesktop.portal.Print.xml \
data/org.freedesktop.portal.MemoryMonitor.xml \
data/org.freedesktop.portal.NetworkMonitor.xml \
data/org.freedesktop.portal.ProxyResolver.xml \
data/org.freedesktop.portal.Screenshot.xml \
@@ -121,6 +122,8 @@ xdg_desktop_portal_SOURCES = \
src/open-uri.h \
src/print.c \
src/print.h \
src/memory-monitor.c \
src/memory-monitor.h \
src/network-monitor.c \
src/network-monitor.h \
src/proxy-resolver.c \
@@ -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);
}
@@ -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);
@@ -38,6 +38,7 @@
#include "file-chooser.h"
#include "open-uri.h"
#include "print.h"
#include "memory-monitor.h"
#include "network-monitor.h"
#include "proxy-resolver.h"
#include "screenshot.h"
@@ -225,6 +226,7 @@ on_bus_acquired (GDBusConnection *connection,
else
lockdown = xdp_impl_lockdown_skeleton_new ();

export_portal_implementation (connection, memory_monitor_create (connection));
export_portal_implementation (connection, network_monitor_create (connection));
export_portal_implementation (connection, proxy_resolver_create (connection));
export_portal_implementation (connection, trash_create (connection));

0 comments on commit 78cea78

Please sign in to comment.
You can’t perform that action at this time.