mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-23 19:24:38 +00:00
2007-06-27 Tambet Ingo <tambet@ximian.com>
* libnm-glib/nm-object.[ch]: Add these to the SVN, oops. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2619 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
a61f78493d
commit
8c33f85a90
|
@ -1,3 +1,7 @@
|
|||
2007-06-27 Tambet Ingo <tambet@ximian.com>
|
||||
|
||||
* libnm-glib/nm-object.[ch]: Add these to the SVN, oops.
|
||||
|
||||
2007-06-22 Tambet Ingo <tambet@ximian.com>
|
||||
|
||||
* src/nm-device-802-11-wireless.c (merge_scanned_ap): Don't advertise constantly
|
||||
|
|
303
libnm-glib/nm-object.c
Normal file
303
libnm-glib/nm-object.c
Normal file
|
@ -0,0 +1,303 @@
|
|||
#include "nm-object.h"
|
||||
#include "NetworkManager.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (NMObject, nm_object, G_TYPE_OBJECT)
|
||||
|
||||
#define NM_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_OBJECT, NMObjectPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGConnection *connection;
|
||||
char *path;
|
||||
DBusGProxy *properties_proxy;
|
||||
|
||||
gboolean disposed;
|
||||
} NMObjectPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CONNECTION,
|
||||
PROP_PATH,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
static void
|
||||
nm_object_init (NMObject *object)
|
||||
{
|
||||
}
|
||||
|
||||
static GObject*
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
NMObjectPrivate *priv;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_object_parent_class)->constructor (type,
|
||||
n_construct_params,
|
||||
construct_params);
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
|
||||
if (priv->connection == NULL || priv->path == NULL) {
|
||||
g_warning ("Connection or path not received.");
|
||||
g_object_unref (object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
priv->properties_proxy = dbus_g_proxy_new_for_name (priv->connection,
|
||||
NM_DBUS_SERVICE,
|
||||
priv->path,
|
||||
"org.freedesktop.DBus.Properties");
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
|
||||
if (priv->disposed)
|
||||
return;
|
||||
|
||||
priv->disposed = TRUE;
|
||||
|
||||
g_object_unref (priv->properties_proxy);
|
||||
dbus_g_connection_unref (priv->connection);
|
||||
|
||||
G_OBJECT_CLASS (nm_object_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
|
||||
g_free (priv->path);
|
||||
|
||||
G_OBJECT_CLASS (nm_object_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CONNECTION:
|
||||
/* Construct only */
|
||||
priv->connection = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_PATH:
|
||||
/* Construct only */
|
||||
priv->path = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CONNECTION:
|
||||
g_value_set_boxed (value, priv->connection);
|
||||
break;
|
||||
case PROP_PATH:
|
||||
g_value_set_string (value, priv->path);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_object_class_init (NMObjectClass *nm_object_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (nm_object_class);
|
||||
|
||||
g_type_class_add_private (nm_object_class, sizeof (NMObjectPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
object_class->dispose = dispose;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
/* porperties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_CONNECTION,
|
||||
g_param_spec_boxed (NM_OBJECT_CONNECTION,
|
||||
"Connection",
|
||||
"Connection",
|
||||
DBUS_TYPE_G_CONNECTION,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_PATH,
|
||||
g_param_spec_string (NM_OBJECT_PATH,
|
||||
"Object Path",
|
||||
"DBus Object Path",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
DBusGConnection *
|
||||
nm_object_get_connection (NMObject *object)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
|
||||
|
||||
return NM_OBJECT_GET_PRIVATE (object)->connection;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_object_get_path (NMObject *object)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
|
||||
|
||||
return NM_OBJECT_GET_PRIVATE (object)->path;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
nm_object_get_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name,
|
||||
GValue *value)
|
||||
{
|
||||
GError *err = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_OBJECT (object), FALSE);
|
||||
g_return_val_if_fail (interface != NULL, FALSE);
|
||||
g_return_val_if_fail (prop_name != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
if (!dbus_g_proxy_call (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
|
||||
"Get", &err,
|
||||
G_TYPE_STRING, interface,
|
||||
G_TYPE_STRING, prop_name,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_VALUE, value,
|
||||
G_TYPE_INVALID)) {
|
||||
g_warning ("Error in get_property: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nm_object_set_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name,
|
||||
GValue *value)
|
||||
{
|
||||
g_return_if_fail (NM_IS_OBJECT (object));
|
||||
g_return_if_fail (interface != NULL);
|
||||
g_return_if_fail (prop_name != NULL);
|
||||
g_return_if_fail (G_IS_VALUE (value));
|
||||
|
||||
dbus_g_proxy_call_no_reply (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
|
||||
"Set",
|
||||
G_TYPE_STRING, interface,
|
||||
G_TYPE_STRING, prop_name,
|
||||
G_TYPE_VALUE, value,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
|
||||
char *
|
||||
nm_object_get_string_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name)
|
||||
{
|
||||
char *str = NULL;
|
||||
GValue value = {0,};
|
||||
|
||||
if (nm_object_get_property (object, interface, prop_name, &value))
|
||||
str = g_strdup (g_value_get_string (&value));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *
|
||||
nm_object_get_object_path_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name)
|
||||
{
|
||||
char *path = NULL;
|
||||
GValue value = {0,};
|
||||
|
||||
if (nm_object_get_property (object, interface, prop_name, &value))
|
||||
path = g_strdup (g_value_get_boxed (&value));
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
gint32
|
||||
nm_object_get_int_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name)
|
||||
{
|
||||
gint32 i = 0;
|
||||
GValue value = {0,};
|
||||
|
||||
if (nm_object_get_property (object, interface, prop_name, &value))
|
||||
i = g_value_get_int (&value);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_object_get_uint_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name)
|
||||
{
|
||||
guint32 i = 0;
|
||||
GValue value = {0,};
|
||||
|
||||
if (nm_object_get_property (object, interface, prop_name, &value))
|
||||
i = g_value_get_uint (&value);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_object_get_boolean_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name)
|
||||
{
|
||||
gboolean b;
|
||||
GValue value = {0,};
|
||||
|
||||
if (nm_object_get_property (object, interface, prop_name, &value))
|
||||
b = g_value_get_boolean (&value);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
gdouble
|
||||
nm_object_get_double_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name)
|
||||
{
|
||||
gdouble d;
|
||||
GValue value = {0,};
|
||||
|
||||
if (nm_object_get_property (object, interface, prop_name, &value))
|
||||
d = g_value_get_double (&value);
|
||||
|
||||
return d;
|
||||
}
|
68
libnm-glib/nm-object.h
Normal file
68
libnm-glib/nm-object.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef NM_OBJECT_H
|
||||
#define NM_OBJECT_H
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib-object.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#define NM_TYPE_OBJECT (nm_object_get_type ())
|
||||
#define NM_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_OBJECT, NMObject))
|
||||
#define NM_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_OBJECT, NMObjectClass))
|
||||
#define NM_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_OBJECT))
|
||||
#define NM_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_OBJECT))
|
||||
#define NM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OBJECT, NMObjectClass))
|
||||
|
||||
#define NM_OBJECT_CONNECTION "connection"
|
||||
#define NM_OBJECT_PATH "path"
|
||||
|
||||
typedef struct {
|
||||
GObject parent;
|
||||
} NMObject;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent;
|
||||
} NMObjectClass;
|
||||
|
||||
GType nm_object_get_type (void);
|
||||
|
||||
DBusGConnection *nm_object_get_connection (NMObject *object);
|
||||
const char *nm_object_get_path (NMObject *object);
|
||||
|
||||
/* DBus property accessors */
|
||||
|
||||
gboolean nm_object_get_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name,
|
||||
GValue *value);
|
||||
|
||||
void nm_object_set_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name,
|
||||
GValue *value);
|
||||
|
||||
char *nm_object_get_string_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name);
|
||||
|
||||
char *nm_object_get_object_path_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name);
|
||||
|
||||
gint32 nm_object_get_int_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name);
|
||||
|
||||
guint32 nm_object_get_uint_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name);
|
||||
|
||||
gboolean nm_object_get_boolean_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name);
|
||||
|
||||
gdouble nm_object_get_double_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name);
|
||||
|
||||
|
||||
#endif /* NM_OBJECT_H */
|
Loading…
Reference in a new issue