1 #include <dbus/dbus-glib.h>
2 #include <glib/gprintf.h>
4 #include "tox-session.h"
6 typedef struct _ToxObjectPrivate
{
8 DBusGConnection
*connection
;
11 G_DEFINE_TYPE(ToxObject
, tox_object
, G_TYPE_OBJECT
)
13 gboolean
tox_create_session(ToxObject
*obj
, guint8 dir
, char **ret
, GError
**error
);
17 TOX_DBUS_CONNECTION
= 1,
20 static void tox_set_property(GObject
*obj
, guint property_id
, const GValue
*value
, GParamSpec
*pspec
);
21 static void tox_get_property(GObject
*obj
, guint property_id
, GValue
*value
, GParamSpec
*pspec
);
23 #include "tox-object-glue.h"
26 tox_object_init(ToxObject
*obj
)
28 obj
->priv
= g_new0(ToxObjectPrivate
, 1);
32 tox_object_class_init(ToxObjectClass
*klass
)
34 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
35 GParamSpec
*connection_param_spec
;
37 gobject_class
->set_property
= tox_set_property
;
38 gobject_class
->get_property
= tox_get_property
;
40 connection_param_spec
= g_param_spec_boxed("dbus-connection",
42 "Connection where new sessions are registered",
43 DBUS_TYPE_G_CONNECTION
,
44 G_PARAM_CONSTRUCT_ONLY
| G_PARAM_READWRITE
);
45 g_object_class_install_property(gobject_class
,
47 connection_param_spec
);
49 dbus_g_object_type_install_info(TOX_TYPE_OBJECT
, &dbus_glib_tox_object_info
);
54 tox_set_property(GObject
*obj
, guint property_id
, const GValue
*value
, GParamSpec
*pspec
)
56 ToxObject
*self
= (ToxObject
*)obj
;
59 case TOX_DBUS_CONNECTION
:
60 /* XXX: this should be a weak ref */
62 /* if (self->priv->connection) */
63 /* dbus_g_connection_unref(self->priv->connection); */
64 self
->priv
->connection
= (DBusGConnection
*)g_value_get_boxed(value
);
65 /* dbus_g_connection_ref(self->priv->connection); */
68 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, property_id
, pspec
);
73 tox_get_property(GObject
*obj
, guint property_id
, GValue
*value
, GParamSpec
*pspec
)
75 ToxObject
*self
= (ToxObject
*)obj
;
78 case TOX_DBUS_CONNECTION
:
79 g_value_set_boxed(value
, self
->priv
->connection
);
82 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, property_id
, pspec
);
87 tox_create_session(ToxObject
*obj
, guint8 dir
, char **ret
, GError
**error
)
89 guint session_number
= ++obj
->priv
->session_counter
;
90 DBusGConnection
*connection
= obj
->priv
->connection
;
93 if (dir
< 1 || dir
> 3) {
94 /* XXX: how to set the D-Bus error name? */
95 g_set_error(error
, DBUS_GERROR
,
96 DBUS_GERROR_REMOTE_EXCEPTION
,
97 "Direction out of range (was %u, should be 1 <= dir <= 3)",
102 session
= g_object_new(TOX_TYPE_SESSION
, "direction", dir
, NULL
);
104 *ret
= g_strdup_printf("/net/sourceforge/emacs_jabber/Tox/%u", session_number
);
105 dbus_g_connection_register_g_object(connection
, *ret
, G_OBJECT(session
));
107 g_debug("CreateSession called, returning %s\n", *ret
);