Commit 14dec45a authored by Christian Hergert's avatar Christian Hergert

deviced: add device provider backed by libdeviced

parent ac16163e
......@@ -26,6 +26,7 @@
"--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf",
"--system-talk-name=org.freedesktop.Avahi",
"--talk-name=org.freedesktop.FileManager1",
"--talk-name=org.gnome.SettingsDaemon.Color",
"--talk-name=org.freedesktop.PackageKit",
......@@ -712,6 +713,52 @@
}
]
},
{
"name" : "avahi",
"config-opts" : [
"--with-distro=none",
"--disable-qt3",
"--disable-qt4",
"--disable-gtk",
"--disable-gtk3",
"--disable-python",
"--disable-pygobject",
"--disable-python-dbus",
"--disable-mono",
"--disable-monodoc",
"--disable-autoipd",
"--disable-core-docs",
"--disable-manpages",
"--disable-xmltoman",
"--disable-tests",
"--disable-libdaemon",
"--disable-compat-libdns_sd",
"--disable-compat-howl"
],
"sources" : [
{
"type" : "git",
"url" : "https://github.com/lathiat/avahi.git"
}
]
},
{
"name" : "deviced",
"config-opts" : [
"--libdir=/app/lib",
"--buildtype=debugoptimized",
"-Ddaemon=false",
"-Dtools=false"
],
"buildsystem" : "meson",
"builddir" : true,
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.gnome.org/chergert/deviced.git"
}
]
},
{
"name" : "gnome-builder",
"buildsystem" : "meson",
......
......@@ -33,6 +33,7 @@ option('with_create_project', type: 'boolean')
option('with_ctags', type: 'boolean')
option('with_documentation_card', type: 'boolean')
option('with_devhelp', type: 'boolean')
option('with_deviced', type: 'boolean')
option('with_eslint', type: 'boolean')
option('with_file_search', type: 'boolean')
option('with_find_other_file', type: 'boolean')
......
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/builder/plugins">
<file>deviced.plugin</file>
</gresource>
<gresource prefix="/org/gnome/builder/plugins/deviced-plugin">
</gresource>
</gresources>
[Plugin]
Module=deviced-plugin
Name=Deviced
Description=Integration with deviced devices
Authors=Christian Hergert <christian@hergert.me>
Copyright=Copyright © 2017 Christian Hergert
Depends=editor;debugger;terminal;
Hidden=true
Builtin=true
Embedded=gbp_deviced_register_types
/* gbp-deviced-device-provider.c
*
* Copyright 2018 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "gbp-deviced-device-provider"
#include <libdeviced.h>
#include "gbp-deviced-device.h"
#include "gbp-deviced-device-provider.h"
struct _GbpDevicedDeviceProvider
{
IdeDeviceProvider parent_instance;
/*
* This is our browser for device nodes. As new nodes are discovered, we get
* a signal which we translate into the IdeDviceProvider::device-added or
* removed signals.
*/
DevdBrowser *browser;
};
G_DEFINE_TYPE (GbpDevicedDeviceProvider, gbp_deviced_device_provider, IDE_TYPE_DEVICE_PROVIDER)
static void
gbp_deviced_device_provider_device_added_cb (GbpDevicedDeviceProvider *self,
DevdDevice *device,
DevdBrowser *browser)
{
GbpDevicedDevice *wrapped;
IdeContext *context;
IDE_ENTRY;
g_assert (GBP_IS_DEVICED_DEVICE_PROVIDER (self));
g_assert (DEVD_IS_DEVICE (device));
g_assert (DEVD_IS_BROWSER (browser));
context = ide_object_get_context (IDE_OBJECT (self));
wrapped = gbp_deviced_device_new (context, device);
g_object_set_data (G_OBJECT (device), "GBP_DEVICED_DEVICE", wrapped);
ide_device_provider_emit_device_added (IDE_DEVICE_PROVIDER (self), IDE_DEVICE (wrapped));
IDE_EXIT;
}
static void
gbp_deviced_device_provider_device_removed_cb (GbpDevicedDeviceProvider *self,
DevdDevice *device,
DevdBrowser *browser)
{
IdeDevice *wrapped;
IDE_ENTRY;
g_assert (GBP_IS_DEVICED_DEVICE_PROVIDER (self));
g_assert (DEVD_IS_DEVICE (device));
g_assert (DEVD_IS_BROWSER (browser));
if ((wrapped = g_object_get_data (G_OBJECT (device), "GBP_DEVICED_DEVICE")))
ide_device_provider_emit_device_removed (IDE_DEVICE_PROVIDER (self), wrapped);
g_object_set_data (G_OBJECT (device), "GBP_DEVICED_DEVICE", NULL);
IDE_EXIT;
}
static void
gbp_deviced_device_provider_load_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
DevdBrowser *browser = (DevdBrowser *)object;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data;
IDE_ENTRY;
g_assert (DEVD_IS_BROWSER (browser));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
if (!devd_browser_load_finish (browser, result, &error))
g_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_boolean (task, TRUE);
IDE_EXIT;
}
static void
gbp_deviced_device_provider_load_async (IdeDeviceProvider *provider,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GbpDevicedDeviceProvider *self = (GbpDevicedDeviceProvider *)provider;
g_autoptr(GTask) task = NULL;
IDE_ENTRY;
g_assert (GBP_IS_DEVICED_DEVICE_PROVIDER (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gbp_deviced_device_provider_load_async);
devd_browser_load_async (self->browser,
cancellable,
gbp_deviced_device_provider_load_cb,
g_steal_pointer (&task));
IDE_EXIT;
}
static gboolean
gbp_deviced_device_provider_load_finish (IdeDeviceProvider *provider,
GAsyncResult *result,
GError **error)
{
gboolean ret;
IDE_ENTRY;
g_assert (GBP_IS_DEVICED_DEVICE_PROVIDER (provider));
g_assert (G_IS_TASK (result));
ret = g_task_propagate_boolean (G_TASK (result), error);
IDE_RETURN (ret);
}
static void
gbp_deviced_device_provider_finalize (GObject *object)
{
GbpDevicedDeviceProvider *self = (GbpDevicedDeviceProvider *)object;
g_clear_object (&self->browser);
G_OBJECT_CLASS (gbp_deviced_device_provider_parent_class)->finalize (object);
}
static void
gbp_deviced_device_provider_class_init (GbpDevicedDeviceProviderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
IdeDeviceProviderClass *provider_class = IDE_DEVICE_PROVIDER_CLASS (klass);
object_class->finalize = gbp_deviced_device_provider_finalize;
provider_class->load_async = gbp_deviced_device_provider_load_async;
provider_class->load_finish = gbp_deviced_device_provider_load_finish;
}
static void
gbp_deviced_device_provider_init (GbpDevicedDeviceProvider *self)
{
self->browser = devd_browser_new ();
g_signal_connect_object (self->browser,
"device-added",
G_CALLBACK (gbp_deviced_device_provider_device_added_cb),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (self->browser,
"device-removed",
G_CALLBACK (gbp_deviced_device_provider_device_removed_cb),
self,
G_CONNECT_SWAPPED);
}
/* gbp-deviced-device-provider.h
*
* Copyright 2018 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <ide.h>
G_BEGIN_DECLS
#define GBP_TYPE_DEVICED_DEVICE_PROVIDER (gbp_deviced_device_provider_get_type())
G_DECLARE_FINAL_TYPE (GbpDevicedDeviceProvider, gbp_deviced_device_provider, GBP, DEVICED_DEVICE_PROVIDER, IdeDeviceProvider)
G_END_DECLS
/* gbp-deviced-device.c
*
* Copyright 2018 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 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/>.
*/
#define G_LOG_DOMAIN "gbp-deviced-device"
#include "gbp-deviced-device.h"
struct _GbpDevicedDevice
{
IdeDevice parent_instance;
DevdDevice *device;
};
G_DEFINE_TYPE (GbpDevicedDevice, gbp_deviced_device, IDE_TYPE_DEVICE)
enum {
PROP_0,
PROP_DEVICE,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
static void
gbp_deviced_device_finalize (GObject *object)
{
GbpDevicedDevice *self = (GbpDevicedDevice *)object;
IDE_ENTRY;
g_clear_object (&self->device);
G_OBJECT_CLASS (gbp_deviced_device_parent_class)->finalize (object);
IDE_EXIT;
}
static void
gbp_deviced_device_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GbpDevicedDevice *self = GBP_DEVICED_DEVICE (object);
switch (prop_id)
{
case PROP_DEVICE:
g_value_set_object (value, self->device);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gbp_deviced_device_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GbpDevicedDevice *self = GBP_DEVICED_DEVICE (object);
switch (prop_id)
{
case PROP_DEVICE:
self->device = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gbp_deviced_device_class_init (GbpDevicedDeviceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gbp_deviced_device_finalize;
object_class->get_property = gbp_deviced_device_get_property;
object_class->set_property = gbp_deviced_device_set_property;
properties [PROP_DEVICE] =
g_param_spec_object ("device",
"Device",
"The underlying libdeviced device",
DEVD_TYPE_DEVICE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
gbp_deviced_device_init (GbpDevicedDevice *self)
{
}
GbpDevicedDevice *
gbp_deviced_device_new (IdeContext *context,
DevdDevice *device)
{
g_autofree gchar *id = NULL;
const gchar *name;
const gchar *icon_name;
g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
g_return_val_if_fail (DEVD_IS_DEVICE (device), NULL);
id = g_strdup_printf ("deviced:%s", devd_device_get_id (device));
name = devd_device_get_name (device);
icon_name = devd_device_get_icon_name (device);
return g_object_new (GBP_TYPE_DEVICED_DEVICE,
"id", id,
"context", context,
"device", device,
"display-name", name,
"icon-name", icon_name,
NULL);
}
/* gbp-deviced-device.h
*
* Copyright 2018 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 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/>.
*/
#pragma once
#include <ide.h>
#include <libdeviced.h>
G_BEGIN_DECLS
#define GBP_TYPE_DEVICED_DEVICE (gbp_deviced_device_get_type())
G_DECLARE_FINAL_TYPE (GbpDevicedDevice, gbp_deviced_device, GBP, DEVICED_DEVICE, IdeDevice)
GbpDevicedDevice *gbp_deviced_device_new (IdeContext *context,
DevdDevice *device);
G_END_DECLS
/* gbp-deviced-plugin.c
*
* Copyright 2018 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <ide.h>
#include <libpeas/peas.h>
#include "gbp-deviced-device-provider.h"
void
gbp_deviced_register_types (PeasObjectModule *module)
{
peas_object_module_register_extension_type (module, IDE_TYPE_DEVICE_PROVIDER, GBP_TYPE_DEVICED_DEVICE_PROVIDER);
}
if get_option('with_deviced')
deviced_resources = gnome.compile_resources(
'deviced-resources',
'deviced.gresource.xml',
c_name: 'gbp_deviced',
)
deviced_sources = [
'gbp-deviced-plugin.c',
'gbp-deviced-device.c',
'gbp-deviced-device-provider.c',
]
gnome_builder_plugins_deps += [
dependency('libdeviced', version: '>=3.27.4'),
]
gnome_builder_plugins_sources += files(deviced_sources)
gnome_builder_plugins_sources += deviced_resources[0]
endif
......@@ -25,6 +25,7 @@ subdir('create-project')
subdir('ctags')
subdir('documentation-card')
subdir('devhelp')
subdir('deviced')
subdir('eslint')
subdir('file-search')
subdir('find-other-file')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment