gnomemm r1381 - in gstreamermm/trunk: . gstreamer/src tests
- From: jaalburqu svn gnome org
- To: svn-commits-list gnome org
- Subject: gnomemm r1381 - in gstreamermm/trunk: . gstreamer/src tests
- Date: Mon, 3 Mar 2008 22:38:42 +0000 (GMT)
Author: jaalburqu
Date: Mon Mar 3 22:38:42 2008
New Revision: 1381
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1381&view=rev
Log:
2008-03-03 Josà Alburquerque <jaalburqu svn gnome org>
* gstreamer/src/element.hg: Added templated, Element derived
Gst::ElementInterfaced class which implements the template argument.
This class is used in the templated Gst::Interface::cast() method to
cast the element's RefPtr to a RefPtr of a Gst::ElementInterfaced that
implements the target interface
* gstreamer/src/interface.hg: Modified Gst::Interface::cast() method
to return a RefPtr to a Gst::ElementInterfaced class
* tests/test-create-element.cc: Modified to test casting from
Glib::RefPtr<Gst::Element> to Glib::RefPtr< Gst::ElementInterfaced<..>
>
Modified:
gstreamermm/trunk/ChangeLog
gstreamermm/trunk/gstreamer/src/element.hg
gstreamermm/trunk/gstreamer/src/interface.hg
gstreamermm/trunk/tests/test-create-element.cc
Modified: gstreamermm/trunk/gstreamer/src/element.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/element.hg (original)
+++ gstreamermm/trunk/gstreamer/src/element.hg Mon Mar 3 22:38:42 2008
@@ -35,6 +35,7 @@
class ElementFactory;
class Event;
class Index;
+class Interface;
class Message;
class Pad;
class PadTemplate;
@@ -82,6 +83,9 @@
{
_CLASS_GOBJECT(Element, GstElement, GST_ELEMENT, Gst::Object, GstObject)
+protected:
+ _CTOR_DEFAULT
+
public:
Glib::RefPtr<Element> link(const Glib::RefPtr<Element>& other_element);
_WRAP_METHOD(bool add_pad(const Glib::RefPtr<Pad>& pad), gst_element_add_pad)
@@ -170,5 +174,32 @@
_WRAP_SIGNAL(void pad_removed(const Glib::RefPtr<Pad>& old_pad), "pad-removed")
};
+template <class T_Interface>
+class ElementInterfaced
+: public Element,
+ public T_Interface
+{
+protected:
+ ElementInterfaced(const ElementInterfaced&);
+ ElementInterfaced& operator=(const ElementInterfaced&);
+
+protected:
+ ElementInterfaced(GstElement* castitem);
+
+private:
+ friend class Gst::Interface;
+};
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
+template <class T_Interface>
+ElementInterfaced<T_Interface>::ElementInterfaced(GstElement* castitem)
+{
+ gobject_ = (GObject*)castitem;
+ gst_object_ref(Element::gobj());
+}
+
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
} // namespace Gst
Modified: gstreamermm/trunk/gstreamer/src/interface.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/interface.hg (original)
+++ gstreamermm/trunk/gstreamer/src/interface.hg Mon Mar 3 22:38:42 2008
@@ -40,20 +40,19 @@
_WRAP_METHOD(static bool element_implements(const Glib::RefPtr<const Element>&element, GType iface_type), gst_element_implements_interface)
template <class T_CastTo> inline
- static Glib::RefPtr<T_CastTo> cast(const Glib::RefPtr<Element>& element);
+ static Glib::RefPtr< ElementInterfaced<T_CastTo> > cast(const Glib::RefPtr<Element>& element);
};
-} // namespace Gst
-
-
-namespace Gst
-{
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
template <class T_CastTo> inline
-Glib::RefPtr<T_CastTo> Interface::cast(const Glib::RefPtr<Element>& element)
+Glib::RefPtr< Gst::ElementInterfaced<T_CastTo> > Interface::cast(const Glib::RefPtr<Element>& element)
{
- gpointer result = gst_implements_interface_cast(element->gobj(), T_CastTo::get_type());
- return Glib::RefPtr<T_CastTo>( dynamic_cast<T_CastTo*> (Glib::wrap_auto_interface<T_CastTo> ((GObject*)(result), true)) );
+ gpointer result = gst_implements_interface_cast(element->gobj(), T_CastTo::get_type());
+ Gst::ElementInterfaced<T_CastTo>* element_interfaced = new ElementInterfaced<T_CastTo>((GstElement*) result);
+ return Glib::RefPtr< Gst::ElementInterfaced<T_CastTo> >(element_interfaced);
}
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
} //namespace Gst
Modified: gstreamermm/trunk/tests/test-create-element.cc
==============================================================================
--- gstreamermm/trunk/tests/test-create-element.cc (original)
+++ gstreamermm/trunk/tests/test-create-element.cc Mon Mar 3 22:38:42 2008
@@ -32,9 +32,17 @@
std::cout << "Successfully created gst element '" <<
element->get_name() << "'." << std::endl;
- if(Gst::Interface::element_implements(element, Gst::URIHandler::get_type())) {
- std::cout << "element '" << element->get_name() << "' implements URIHandler interface." << std::endl;
- Glib::RefPtr<Gst::URIHandler> handler = Gst::Interface::cast <Gst::URIHandler>(element);
- std::cout << "handler memory = '" << handler << "'." << std::endl;
+ if(Gst::Interface::element_implements(element, Gst::URIHandler::get_type()))
+ {
+ std::cout << "element '" << element->get_name() <<
+ "' implements URIHandler interface." << std::endl;
+
+ Glib::RefPtr< Gst::ElementInterfaced<Gst::URIHandler> > handler =
+ Gst::Interface::cast <Gst::URIHandler>(element);
+
+ handler->set_uri("file:///tmp/media.file");
+
+ std::cout << handler->get_name() << " uri = '" << handler->get_uri() <<
+ "'." << std::endl;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]