gnomemm r2087 - in gstreamermm/trunk: . gstreamer/src



Author: murrayc
Date: Tue Mar 10 21:44:09 2009
New Revision: 2087
URL: http://svn.gnome.org/viewvc/gnomemm?rev=2087&view=rev

Log:
2009-03-10  Murray Cumming  <murrayc murrayc com>

* gstreamer/src/bin.ccg: Add(): Throw an exception if the element is 
null, instead of crashing by dereferencing it. Maybe remove() should do 
the same. Constructor: Use 0 instead of NULL, because that is best 
in C++.

Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/gstreamer/src/bin.ccg

Modified: gstreamermm/trunk/gstreamer/src/bin.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/bin.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/bin.ccg	Tue Mar 10 21:44:09 2009
@@ -30,12 +30,17 @@
 {
 
 Bin::Bin()
-: _CONSTRUCT("name", NULL)
+: _CONSTRUCT("name", 0)
 {}
 
 
 Glib::RefPtr<Gst::Bin> Bin::add(const Glib::RefPtr<Gst::Element>& element)
 {
+  if(!element)
+    throw std::runtime_error("Failed to add null element.");
+
+  GstElement* celement = Glib::unwrap(element);
+
   // The following is needed because when adding an element to a bin, the bin
   // likes to have the last reference and then destroy it when the bin itself
   // is destroyed.  Without the extra reference, when the last Glib::RefPtr<>
@@ -43,22 +48,24 @@
   // bin and GStreamer complains about it.  The extra reference to the element
   // is removed when the bin is destroyed or when the element is removed from
   // the bin (see gst_bin_remove).
-  if (G_LIKELY(GST_OBJECT_IS_FLOATING(element->gobj())))
+  if (G_LIKELY(GST_OBJECT_IS_FLOATING(celement)))
     element->reference();
 
-  const bool result = gst_bin_add(gobj(), element->gobj());
+  const bool result = gst_bin_add(gobj(), celement);
 
   // If addition successful, return RefPtr<..> to this bin, otherwise return
   // NULL RefPtr<...>
   if(result)
     return Glib::wrap(gobj(), true);
   else
-    throw std::runtime_error("Failed to add " + element->get_name() + " element");
+    throw std::runtime_error("Failed to add " + element->get_name() + " element.");
 }
 
 Glib::RefPtr<Gst::Bin> Bin::remove(const Glib::RefPtr<Gst::Element>& element)
 {
-  const bool result = gst_bin_remove(gobj(), element->gobj());
+  //TODO: Throw an exception if element is null?
+
+  const bool result = gst_bin_remove(gobj(), Glib::unwrap(element));
 
   // If removal successful, return RefPtr<..> to this bin, otherwise return
   // NULL RefPtr<...>



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