[gstreamermm] wrapped some virtual methods in urihandler interface



commit aa160d4e1945ce66a088a251c07bc7f43ff4cb20
Author: Marcin Kolny <marcin kolny flytronic pl>
Date:   Fri May 16 15:03:04 2014 +0200

    wrapped some virtual methods in urihandler interface

 .gitignore                   |    1 +
 gstreamer/src/urihandler.ccg |  112 ++++++++++++++++++++++++++++++++++++++++++
 gstreamer/src/urihandler.hg  |   25 +++++++--
 tests/Makefile.am            |    3 +-
 tests/test-urihandler.cc     |   74 +++++++++++++++++++++++++++
 5 files changed, 208 insertions(+), 7 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 6aecca8..23c30db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -482,6 +482,7 @@ tests/test-pad
 tests/test-query
 tests/test-structure
 tests/test-taglist
+tests/test-urihandler
 
 test-plugin-appsink
 test-plugin-appsrc
diff --git a/gstreamer/src/urihandler.ccg b/gstreamer/src/urihandler.ccg
index e11ef06..b5285a4 100644
--- a/gstreamer/src/urihandler.ccg
+++ b/gstreamer/src/urihandler.ccg
@@ -19,3 +19,115 @@
 
 #include <gst/gst.h>
 #include <gstreamermm/element.h>
+
+namespace Gst
+{
+
+URIType URIHandler::get_type_vfunc()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+    g_type_interface_peek_parent(
+      g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type())
+      )  );
+
+  if(base && base->get_type)
+  {
+    return static_cast<URIType>((*base->get_type)(CppObjectType::get_type()));
+  }
+
+  return URIType();
+}
+
+GstURIType URIHandler_Class::get_type_vfunc_callback(GType type)
+{
+  gpointer self = g_object_new(type, NULL);
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj)
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        return static_cast<GstURIType>(obj->get_type_vfunc());
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+
+  BaseClassType *const base = static_cast<BaseClassType*>(
+    g_type_interface_peek_parent(
+      g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type())
+      )  );
+
+  if(base && base->get_type)
+  {
+    return (*base->get_type)(type);
+  }
+
+  return GstURIType();
+}
+
+const gchar * const * URIHandler::get_protocols_vfunc() const
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+    g_type_interface_peek_parent(
+      g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type())
+      )  );
+
+  if(base && base->get_protocols)
+  {
+    return (*base->get_protocols)(CppObjectType::get_type());
+  }
+  static const gchar* protocols[] = {NULL};
+  return protocols;
+}
+
+const gchar * const * URIHandler_Class::get_protocols_vfunc_callback(GType type)
+{
+  gpointer self = g_object_new(type, NULL);
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj)
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        return obj->get_protocols_vfunc();
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+
+  BaseClassType *const base = static_cast<BaseClassType*>(
+    g_type_interface_peek_parent(
+      g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type())
+      )  );
+
+  if(base && base->get_protocols)
+  {
+    return (*base->get_protocols)(type);
+  }
+  static const gchar *protocols[] = { NULL };
+  return protocols;
+}
+}
diff --git a/gstreamer/src/urihandler.hg b/gstreamer/src/urihandler.hg
index 70cf420..6105acd 100644
--- a/gstreamer/src/urihandler.hg
+++ b/gstreamer/src/urihandler.hg
@@ -21,7 +21,7 @@
 #include <glibmm/interface.h>
 #include <gstreamermm/enums.h>
 #include <glibmm/arrayhandle.h>
-
+#include <cstdio>
 _DEFS(gstreamermm,gst)
 
 namespace Gst
@@ -80,11 +80,24 @@ public:
    */
   _WRAP_VFUNC(bool set_uri(const Glib::ustring& uri, GError** error), "set_uri)
 
-  //TODO: The GstURIHandler vfuncs get_type(), get_protocols(), get_type_full()
-  //and get_protocols_full() don't have a GstURIHandler as an argument declared
-  //in the Interface structure so those seem impossible to wrap because the C++
-  //callback would have no way of knowing which object's virtual function
-  //should be called.
+  /**
+   * Method to return the list of protocols handled by the element.
+   */
+  virtual const gchar * const * get_protocols_vfunc() const;
+
+  virtual URIType get_type_vfunc();
+
+
+protected:
+#m4begin
+  _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
+  klass->get_type = &get_type_vfunc_callback;
+  klass->get_protocols = &get_protocols_vfunc_callback;
+  _SECTION(SECTION_PH_VFUNCS)
+  static GstURIType get_type_vfunc_callback(GType type);
+  static const gchar * const * get_protocols_vfunc_callback(GType type);
+_POP()
+#m4end
 };
 
 } // namespace Gst
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 55f620b..98e90b9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,7 +21,7 @@ AM_CXXFLAGS = $(GSTREAMERMM_WXXFLAGS) -g
 LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm) -lgtest
 
 check_PROGRAMS = test-caps test-buffer test-bus test-caps test-pad \
-                 test-ghostpad \
+                 test-urihandler test-ghostpad \
                  test-query test-structure test-taglist test-plugin-appsink \
                  test-plugin-appsrc test-plugin-register test-plugin-pushsrc \ 
                  test-regression-bininpipeline test-regression-binplugin \
@@ -41,6 +41,7 @@ test_pad_SOURCES                      = test-pad.cc $(TEST_MAIN_SOURCE)
 test_query_SOURCES                     = test-query.cc $(TEST_MAIN_SOURCE)
 test_structure_SOURCES         = test-structure.cc $(TEST_MAIN_SOURCE)
 test_taglist_SOURCES           = test-taglist.cc $(TEST_MAIN_SOURCE)
+test_urihandler_SOURCES                = test-urihandler.cc $(TEST_MAIN_SOURCE)
 
 test_plugin_appsink_SOURCES                    = plugins/test-plugin-appsink.cc $(TEST_MAIN_SOURCE)
 test_plugin_appsrc_SOURCES                     = plugins/test-plugin-appsrc.cc $(TEST_MAIN_SOURCE)
diff --git a/tests/test-urihandler.cc b/tests/test-urihandler.cc
new file mode 100644
index 0000000..0023f6b
--- /dev/null
+++ b/tests/test-urihandler.cc
@@ -0,0 +1,74 @@
+/*
+ * test-urihandler.cc
+ *
+ *  Created on: May 16, 2014
+ *      Author: m.kolny
+ */
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <gstreamermm/private/element_p.h>
+
+using namespace Gst;
+
+class UriTestElement: public URIHandler, public Gst::Element {
+public:
+       typedef Gst::Element::BaseClassType BaseClassType;
+       typedef Gst::Element::BaseObjectType BaseObjectType;
+       typedef Gst::Element::CppClassType CppClassType;
+
+public:
+       static GType get_base_type() G_GNUC_CONST
+       {
+               return Element::get_base_type();
+       }
+
+       static void base_init(Gst::ElementClass<UriTestElement> *klass)
+       {
+               klass->set_metadata("uri_longname", "uri_classification",
+                               "uri_detail_description", "uri_detail_author");
+       }
+
+       explicit UriTestElement(GstElement *gobj) :
+                       Glib::ObjectBase(typeid(UriTestElement)),
+                       Gst::Element(gobj)
+       {
+       }
+
+       bool set_uri_vfunc(const Glib::ustring& uri, GError** error)
+       {
+               return true;
+       }
+
+       const gchar * const * get_protocols_vfunc() const
+       {
+               static const gchar* vect[] = { "dummyprotocol", NULL };
+
+               return vect;
+       }
+
+       URIType get_type_vfunc() override
+       {
+               return URI_SINK;
+       }
+
+       static bool register_uritestelement(Glib::RefPtr<Gst::Plugin> plugin)
+       {
+               auto t = Gst::register_mm_type<UriTestElement>("uritestelement");
+               add_interface(t);
+
+               return Gst::ElementFactory::register_element(plugin, "uritestelement",
+                               10, t);
+       }
+};
+
+TEST(URIHandlerTest, CheckURIType)
+{
+       Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "uritestelement", "uritestelement is 
example of C++ element",
+                       sigc::ptr_fun(&UriTestElement::register_uritestelement), "0.123", "LGPL", "source?", 
"package?",
+                       "http://example.com";);
+
+       Glib::ustring factory_name =
+                       URIHandler::make_element_from_uri(URI_SINK, "dummyprotocol:some/path", 
"dummy_name")->get_factory()->get_name();
+
+       ASSERT_STREQ("uritestelement", factory_name.c_str());
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]