utils: add quark and mini-object boilerplate macros
authorRob Clark <rob@ti.com>
Wed, 13 Jun 2012 23:54:51 +0000 (18:54 -0500)
committerNikhil Devshatwar <a0132237@ti.com>
Wed, 15 May 2013 11:20:51 +0000 (16:50 +0530)
gst/gstutils.h

index a746913dd2dcf591aa70d154c3c486ce890fb9de..fef1f9d9c88e013896a54a1cf206de9dfaebde96 100644 (file)
@@ -96,6 +96,40 @@ GType gst_type_register_static_full (GType parent_type,
 /* Macros for defining classes.  Ideas taken from Bonobo, which took theirs
    from Nautilus and GOB. */
 
+#define GST_BOILERPLATE_QUARK(type, type_as_function)  \
+GQuark                                                 \
+type_as_function ## _get_type (void)                   \
+{                                                      \
+  static gsize quark_gonce = 0;                        \
+  if (g_once_init_enter (&quark_gonce)) {              \
+    gsize quark;                                       \
+    quark = (gsize) g_quark_from_static_string (#type);\
+    g_once_init_leave (&quark_gonce, quark);           \
+  }                                                    \
+  return (GQuark) quark_gonce;                         \
+}
+
+#define GST_BOILERPLATE_MINI_OBJECT(type, type_as_function)               \
+static void type_as_function ## _class_init    (type ## Class *g_class);  \
+GType                                                                     \
+type_as_function ## _get_type (void)                                      \
+{                                                                         \
+  static volatile gsize type_id = 0;                                      \
+  if (g_once_init_enter (&type_id)) {                                     \
+    GType new_type_id = g_type_register_static_simple (                   \
+        GST_TYPE_MINI_OBJECT,                                             \
+        g_intern_static_string (#type),                                   \
+        sizeof (type ## Class),                                           \
+        (GClassInitFunc) type_as_function ## _class_init,                 \
+        sizeof (type),                                                    \
+        NULL,                                                             \
+        (GTypeFlags) 0);                                                  \
+    g_once_init_leave (&type_id, new_type_id);                            \
+  }                                                                       \
+  return type_id;                                                         \
+}
+
+
 /**
  * GST_BOILERPLATE_FULL:
  * @type: the name of the type struct