[Pkg-telepathy-commits] [telepathy-glib] 54/111: TpPresenceStatusSpec: be a boxed type

Simon McVittie smcv at debian.org
Wed Mar 19 18:07:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian
in repository telepathy-glib.

commit c73bd6a29e23bdc7afa8a26be0fd6ade0065c03a
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Oct 28 14:54:53 2013 +0000

    TpPresenceStatusSpec: be a boxed type
    
    Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71048
    Reviewed-by: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
---
 docs/reference/telepathy-glib-sections.txt |   5 ++
 telepathy-glib/presence-mixin.c            | 100 +++++++++++++++++++++++++++++
 telepathy-glib/presence-mixin.h            |  19 +++++-
 3 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index c8cef3d..7844951 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -2305,6 +2305,9 @@ tp_presence_status_spec_can_set_on_self
 tp_presence_status_spec_get_name
 tp_presence_status_spec_get_presence_type
 tp_presence_status_spec_has_message
+tp_presence_status_spec_new
+tp_presence_status_spec_copy
+tp_presence_status_spec_free
 TpPresenceMixinStatusAvailableFunc
 TpPresenceMixinGetContactStatusesFunc
 TpPresenceMixinSetOwnStatusFunc
@@ -2333,9 +2336,11 @@ tp_presence_mixin_class_get_offset_quark
 tp_presence_mixin_get_offset_quark
 TpPresenceMixinPrivate
 TpPresenceMixinClassPrivate
+TpPresenceStatusSpecPrivate
 <SUBSECTION Standard>
 TP_PRESENCE_MIXIN_CLASS
 TP_PRESENCE_MIXIN
+tp_presence_status_spec_get_type
 </SECTION>
 
 <SECTION>
diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c
index f8d44b8..50a70b5 100644
--- a/telepathy-glib/presence-mixin.c
+++ b/telepathy-glib/presence-mixin.c
@@ -1581,6 +1581,13 @@ tp_presence_mixin_simple_presence_register_with_contacts_mixin (GObject *obj)
       tp_presence_mixin_simple_presence_fill_contact_attributes);
 }
 
+/* For now, self->priv is just self if heap-allocated, NULL if not. */
+static gboolean
+_tp_presence_status_spec_is_heap_allocated (const TpPresenceStatusSpec *self)
+{
+  return (self->priv == (TpPresenceStatusSpecPrivate *) self);
+}
+
 /**
  * tp_presence_status_spec_get_presence_type:
  * @self: a presence status specification
@@ -1666,3 +1673,96 @@ tp_presence_status_spec_has_message (const TpPresenceStatusSpec *self)
 
   return FALSE;
 }
+
+/**
+ * tp_presence_status_spec_new:
+ * @name: the name of the new presence status
+ * @type: the category into which this presence status falls
+ * @can_set_on_self: %TRUE if the user can set this presence status
+ *  on themselves
+ * @has_message: %TRUE if this presence status is accompanied by an
+ *  optional human-readable message
+ *
+ * <!-- -->
+ *
+ * Returns: (transfer full): a new #TpPresenceStatusSpec
+ * Since: 0.UNRELEASED
+ */
+TpPresenceStatusSpec *
+tp_presence_status_spec_new (const gchar *name,
+    TpConnectionPresenceType type,
+    gboolean can_set_on_self,
+    gboolean has_message)
+{
+  TpPresenceStatusSpec *ret;
+  static const TpPresenceStatusOptionalArgumentSpec yes_it_has_a_message[] = {
+        { "message", "s" },
+        { NULL }
+  };
+
+  g_return_val_if_fail (!tp_str_empty (name), NULL);
+  g_return_val_if_fail (type >= 0 && type < TP_NUM_CONNECTION_PRESENCE_TYPES,
+      NULL);
+
+  ret = g_slice_new0 (TpPresenceStatusSpec);
+
+  ret->name = g_strdup (name);
+  ret->presence_type = type;
+  ret->self = can_set_on_self;
+
+  if (has_message)
+    ret->optional_arguments = yes_it_has_a_message;
+  else
+    ret->optional_arguments = NULL;
+
+  /* dummy marker for "this is on the heap" rather than a real struct */
+  ret->priv = (TpPresenceStatusSpecPrivate *) ret;
+
+  return ret;
+}
+
+/**
+ * tp_presence_status_spec_copy:
+ * @self: a presence status specification
+ *
+ * Copy a presence status specification.
+ *
+ * If @self has optional arguments other than a string named "message",
+ * they are not copied. Optional arguments with other names or types
+ * are deprecated.
+ *
+ * Returns: (transfer full): a new #TpPresenceStatusSpec resembling @self
+ * Since: 0.UNRELEASED
+ */
+TpPresenceStatusSpec *
+tp_presence_status_spec_copy (const TpPresenceStatusSpec *self)
+{
+  g_return_val_if_fail (self != NULL, NULL);
+
+  return tp_presence_status_spec_new (self->name, self->presence_type,
+      self->self, tp_presence_status_spec_has_message (self));
+}
+
+/**
+ * tp_presence_status_spec_free:
+ * @self: (transfer full): a presence status specification
+ *
+ * Free a presence status specification produced by
+ * tp_presence_status_spec_new() or tp_presence_status_spec_copy().
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_presence_status_spec_free (TpPresenceStatusSpec *self)
+{
+  g_return_if_fail (_tp_presence_status_spec_is_heap_allocated (self));
+
+  /* This struct was designed to always be on the stack, so freeing this
+   * needs a non-const-correct cast */
+  g_free ((gchar *) self->name);
+
+  g_slice_free (TpPresenceStatusSpec, self);
+}
+
+G_DEFINE_BOXED_TYPE (TpPresenceStatusSpec, tp_presence_status_spec,
+    tp_presence_status_spec_copy, tp_presence_status_spec_free)
diff --git a/telepathy-glib/presence-mixin.h b/telepathy-glib/presence-mixin.h
index 6654c5b..d10d6b0 100644
--- a/telepathy-glib/presence-mixin.h
+++ b/telepathy-glib/presence-mixin.h
@@ -35,6 +35,7 @@ G_BEGIN_DECLS
 typedef struct _TpPresenceStatusOptionalArgumentSpec
     TpPresenceStatusOptionalArgumentSpec;
 typedef struct _TpPresenceStatusSpec TpPresenceStatusSpec;
+typedef struct _TpPresenceStatusSpecPrivate TpPresenceStatusSpecPrivate;
 
 struct _TpPresenceStatusOptionalArgumentSpec {
     const gchar *name;
@@ -53,7 +54,7 @@ struct _TpPresenceStatusSpec {
 
     /*<private>*/
     gpointer _future1;
-    gpointer _future2;
+    TpPresenceStatusSpecPrivate *priv;
 };
 
 _TP_AVAILABLE_IN_UNRELEASED
@@ -72,6 +73,22 @@ _TP_AVAILABLE_IN_UNRELEASED
 gboolean tp_presence_status_spec_has_message (
     const TpPresenceStatusSpec *self);
 
+_TP_AVAILABLE_IN_UNRELEASED
+GType tp_presence_status_spec_get_type (void);
+
+_TP_AVAILABLE_IN_UNRELEASED
+TpPresenceStatusSpec *tp_presence_status_spec_new (const gchar *name,
+    TpConnectionPresenceType type,
+    gboolean can_set_on_self,
+    gboolean has_message);
+
+_TP_AVAILABLE_IN_UNRELEASED
+TpPresenceStatusSpec *tp_presence_status_spec_copy (
+    const TpPresenceStatusSpec *self);
+
+_TP_AVAILABLE_IN_UNRELEASED
+void tp_presence_status_spec_free (TpPresenceStatusSpec *self);
+
 typedef struct _TpPresenceStatus TpPresenceStatus;
 
 struct _TpPresenceStatus {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-glib.git



More information about the Pkg-telepathy-commits mailing list