about summary refs log tree commit diff
path: root/src/devices/nm-device-factory.c
blob: fc4d1c248ada84a878f4c6fc6f6d57674e71c161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager
 *
 * 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 2 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, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Copyright (C) 2014 Red Hat, Inc.
 */

#include "nm-device-factory.h"

enum {
	DEVICE_ADDED,
	COMPONENT_ADDED,
	LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };

gboolean
nm_device_factory_emit_component_added (NMDeviceFactory *factory, GObject *component)
{
	gboolean consumed = FALSE;

	g_signal_emit (factory, signals[COMPONENT_ADDED], 0, component, &consumed);
	return consumed;
}

static void
interface_init (gpointer g_iface)
{
	GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
	static gboolean initialized = FALSE;

	if (G_LIKELY (initialized))
		return;

	/* Signals */
	signals[DEVICE_ADDED] = g_signal_new (NM_DEVICE_FACTORY_DEVICE_ADDED,
	                                      iface_type,
	                                      G_SIGNAL_RUN_FIRST,
	                                      G_STRUCT_OFFSET (NMDeviceFactory, device_added),
	                                      NULL, NULL, NULL,
	                                      G_TYPE_NONE, 1, NM_TYPE_DEVICE);

	signals[COMPONENT_ADDED] = g_signal_new (NM_DEVICE_FACTORY_COMPONENT_ADDED,
	                                         iface_type,
	                                         G_SIGNAL_RUN_LAST,
	                                         G_STRUCT_OFFSET (NMDeviceFactory, component_added),
	                                         g_signal_accumulator_true_handled, NULL, NULL,
	                                         G_TYPE_BOOLEAN, 1, G_TYPE_OBJECT);

	initialized = TRUE;
}

GType
nm_device_factory_get_type (void)
{
	static GType device_factory_type = 0;

	if (!device_factory_type) {
		const GTypeInfo device_factory_info = {
			sizeof (NMDeviceFactory), /* class_size */
			interface_init,           /* base_init */
			NULL,                     /* base_finalize */
			NULL,
			NULL,                     /* class_finalize */
			NULL,                     /* class_data */
			0,
			0,                        /* n_preallocs */
			NULL
		};

		device_factory_type = g_type_register_static (G_TYPE_INTERFACE,
		                                              "NMDeviceFactory",
		                                              &device_factory_info,
		                                              0);
		g_type_interface_add_prerequisite (device_factory_type, G_TYPE_OBJECT);
	}

	return device_factory_type;
}

NMDevice *
nm_device_factory_new_link (NMDeviceFactory *factory,
                            NMPlatformLink *plink,
                            GError **error)
{
	g_return_val_if_fail (factory != NULL, NULL);
	g_return_val_if_fail (plink != NULL, NULL);

	if (NM_DEVICE_FACTORY_GET_INTERFACE (factory)->new_link)
		return NM_DEVICE_FACTORY_GET_INTERFACE (factory)->new_link (factory, plink, error);
	return NULL;
}