aboutsummaryrefslogtreecommitdiff
path: root/src/session-dbus.c
blob: cc12311b85ea9872185d44f145ffee3410c70f04 (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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "session-dbus.h"

static gboolean _session_dbus_server_get_icon (SessionDbus * service, gchar ** icon, GError ** error);

#include "session-dbus-server.h"

typedef struct _SessionDbusPrivate SessionDbusPrivate;
struct _SessionDbusPrivate {
	gchar * name;
};

#define SESSION_DBUS_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), SESSION_DBUS_TYPE, SessionDbusPrivate))

static void session_dbus_class_init (SessionDbusClass *klass);
static void session_dbus_init       (SessionDbus *self);
static void session_dbus_dispose    (GObject *object);
static void session_dbus_finalize   (GObject *object);

G_DEFINE_TYPE (SessionDbus, session_dbus, G_TYPE_OBJECT);

static void
session_dbus_class_init (SessionDbusClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	g_type_class_add_private (klass, sizeof (SessionDbusPrivate));

	object_class->dispose = session_dbus_dispose;
	object_class->finalize = session_dbus_finalize;

	dbus_g_object_type_install_info(SESSION_DBUS_TYPE, &dbus_glib__session_dbus_server_object_info);

	return;
}

static void
session_dbus_init (SessionDbus *self)
{
	DBusGConnection * session = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
	dbus_g_connection_register_g_object(session, "/bob", G_OBJECT(self));

	SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(self);

	priv->name = g_strdup("icon");

	return;
}

static void
session_dbus_dispose (GObject *object)
{

	G_OBJECT_CLASS (session_dbus_parent_class)->dispose (object);
	return;
}

static void
session_dbus_finalize (GObject *object)
{
	SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(object);

	if (priv->name != NULL) {
		g_free(priv->name);
		priv->name = NULL;
	}

	G_OBJECT_CLASS (session_dbus_parent_class)->finalize (object);
	return;
}

static gboolean
_session_dbus_server_get_icon (SessionDbus * service, gchar ** icon, GError ** error)
{
	SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(service);
	*icon = g_strdup(priv->name);
	return TRUE;
}

void
session_dbus_set_name (SessionDbus * session, const gchar * name)
{
	SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session);
	if (priv->name != NULL) {
		g_free(priv->name);
		priv->name = NULL;
	}
	priv->name = g_strdup(name);
	return;
}