[gstreamermm] Make exception handling code in classes accessible globally.



commit 6db5878e23e73c799fcf93e328a1b7f2de4e56db
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Sun Dec 20 21:44:48 2009 -0500

    	Make exception handling code in classes accessible globally.
    
    	* gstreamer/gstreamermm/filelist.am:
    	* gstreamer/gstreamermm/handle_error.cc:
    	* gstreamer/gstreamermm/handle_error.h (gstreamermm_handle_error):
    	Added this new function to report errors in gstreamermm either by
    	exception (if they are enabled) or to std::err (otherwise) so that it
    	can be used globally throughout gstreamermm.
    	* gstreamer/src/bin.ccg:
    	* gstreamer/src/bin.hg:
    	* gstreamer/src/element.ccg:
    	* gstreamer/src/element.hg:
    	* gstreamer/src/iterator.hg:
    	* gstreamer/src/ghostpad.hg:
    	* gstreamer/src/ghostpad.ccg: Modified to use the global error
    	handling function above and not a member class defined one.
    	(GhostPad):
    	* gstreamer/src/pipeline.ccg (Pipeline): Use proper casting in
    	_CONSTRUCT macros of these constructors.
    	* gstreamer/src/ringbuffer.hg:
    	* gstreamer/src/ringbuffer.ccg (RingBufferSpec): Use g_try_new() for
    	underlying C object allocation in the constructors and use the error
    	handling function above to report errors if any allocation errors
    	occur.
    	* gstreamer/src/format.ccg (get_format_details):
    	* gstreamer/src/query.ccg (get_details): Use "if(!...) return false;"
    	instead of g_return_val_if_fail().
    	* gstreamer/src/basesink.ccg:
    	* gstreamer/src/parse.ccg: Removed unneeded parenthesis.

 ChangeLog                             |   32 +++++++++++++++++++++
 gstreamer/gstreamermm/filelist.am     |    2 +
 gstreamer/gstreamermm/handle_error.cc |   34 +++++++++++++++++++++++
 gstreamer/gstreamermm/handle_error.h  |   38 +++++++++++++++++++++++++
 gstreamer/src/basesink.ccg            |    4 +-
 gstreamer/src/bin.ccg                 |   27 +++++-------------
 gstreamer/src/bin.hg                  |    3 --
 gstreamer/src/element.ccg             |   25 +++++------------
 gstreamer/src/element.hg              |    4 ---
 gstreamer/src/format.ccg              |    3 +-
 gstreamer/src/ghostpad.ccg            |   49 ++++++++++++---------------------
 gstreamer/src/ghostpad.hg             |    3 --
 gstreamer/src/iterator.hg             |   24 +++-------------
 gstreamer/src/parse.ccg               |    6 ++--
 gstreamer/src/pipeline.ccg            |    2 +-
 gstreamer/src/query.ccg               |    3 +-
 gstreamer/src/ringbuffer.ccg          |   31 +++++++++++++++++---
 gstreamer/src/ringbuffer.hg           |   14 ++++++++-
 18 files changed, 191 insertions(+), 113 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 329d712..4766d55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2009-12-20  José Alburquerque  <jaalburqu svn gnome org>
+
+	Make exception handling code in classes accessible globally.
+
+	* gstreamer/gstreamermm/filelist.am:
+	* gstreamer/gstreamermm/handle_error.cc:
+	* gstreamer/gstreamermm/handle_error.h (gstreamermm_handle_error):
+	Added this new function to report errors in gstreamermm either by
+	exception (if they are enabled) or to std::err (otherwise) so that it
+	can be used globally throughout gstreamermm.
+	* gstreamer/src/bin.ccg:
+	* gstreamer/src/bin.hg:
+	* gstreamer/src/element.ccg:
+	* gstreamer/src/element.hg:
+	* gstreamer/src/iterator.hg:
+	* gstreamer/src/ghostpad.hg:
+	* gstreamer/src/ghostpad.ccg: Modified to use the global error
+	handling function above and not a member class defined one.
+	(GhostPad):
+	* gstreamer/src/pipeline.ccg (Pipeline): Use proper casting in
+	_CONSTRUCT macros of these constructors.
+	* gstreamer/src/ringbuffer.hg:
+	* gstreamer/src/ringbuffer.ccg (RingBufferSpec): Use g_try_new() for
+	underlying C object allocation in the constructors and use the error
+	handling function above to report errors if any allocation errors
+	occur.
+	* gstreamer/src/format.ccg (get_format_details):
+	* gstreamer/src/query.ccg (get_details): Use "if(!...) return false;"
+	instead of g_return_val_if_fail().
+	* gstreamer/src/basesink.ccg:
+	* gstreamer/src/parse.ccg: Removed unneeded parenthesis.
+
 2009-12-18  José Alburquerque  <jaalburqu svn gnome org>
 
 	Plugin Generator: Generate convenience methods for action signals.
diff --git a/gstreamer/gstreamermm/filelist.am b/gstreamer/gstreamermm/filelist.am
index ca9812d..2e2de35 100644
--- a/gstreamer/gstreamermm/filelist.am
+++ b/gstreamer/gstreamermm/filelist.am
@@ -6,12 +6,14 @@ files_built_ph = $(patsubst %.hg,private/%_p.h,$(files_hg))
 files_extra_cc =                \
         init.cc                 \
         gst_wrap_init.cc        \
+        handle_error.cc         \
         miniobject.cc           \
         version.cc              \
         wrap.cc
 files_extra_h  =                \
         init.h                  \
         gst_wrap_init.h         \
+        handle_error.h          \
         miniobject.h            \
         version.h               \
         wrap.h                  \
diff --git a/gstreamer/gstreamermm/handle_error.cc b/gstreamer/gstreamermm/handle_error.cc
new file mode 100644
index 0000000..b4c8f05
--- /dev/null
+++ b/gstreamer/gstreamermm/handle_error.cc
@@ -0,0 +1,34 @@
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2009 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gstreamermm/handle_error.h>
+
+namespace Gst
+{
+
+void gstreamermm_handle_error(const Glib::ustring& message)
+{
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    throw std::runtime_error(message);
+#else
+      std::cerr << "gstreamermm: " << message << std::endl;
+#endif
+}
+
+}
diff --git a/gstreamer/gstreamermm/handle_error.h b/gstreamer/gstreamermm/handle_error.h
new file mode 100644
index 0000000..d240d8d
--- /dev/null
+++ b/gstreamer/gstreamermm/handle_error.h
@@ -0,0 +1,38 @@
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2009 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _GSTREAMERMM_HANDLE_ERROR_H
+#define _GSTREAMERMM_IHANDLE_ERRORH
+
+#include <glibmm/ustring.h>
+#include <stdexcept>
+#ifndef GLIBMM_EXCEPTIONS_ENABLED
+#include <iostream>
+#endif
+
+namespace Gst
+{
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+void gstreamermm_handle_error(const Glib::ustring& message);
+#endif //DOXYGEN_SHOULD_SKIP_THIS
+
+}
+
+#endif //_GSTREAMERMM_HANDLE_ERROR_H
diff --git a/gstreamer/src/basesink.ccg b/gstreamer/src/basesink.ccg
index c702fab..b4aa3a5 100644
--- a/gstreamer/src/basesink.ccg
+++ b/gstreamer/src/basesink.ccg
@@ -31,8 +31,8 @@ bool BaseSink::query_latency(bool& live, bool& upstream_live, ClockTime& min_lat
 
   const bool result =
     gst_base_sink_query_latency(const_cast<GstBaseSink*>(gobj()),
-    &gst_live, &gst_upstream_live, static_cast<GstClockTime*>(&(min_latency)),
-    static_cast<GstClockTime*>(&(max_latency)));
+    &gst_live, &gst_upstream_live, static_cast<GstClockTime*>(&min_latency),
+    static_cast<GstClockTime*>(&max_latency));
 
   live = gst_live;
   upstream_live = gst_upstream_live;
diff --git a/gstreamer/src/bin.ccg b/gstreamer/src/bin.ccg
index 6bfb6c4..9657a22 100644
--- a/gstreamer/src/bin.ccg
+++ b/gstreamer/src/bin.ccg
@@ -17,16 +17,12 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <stdexcept>
 #include <gst/gstbin.h>
 #include <gst/gstutils.h>
 #include <gstreamermm/pad.h>
 #include <gstreamermm/ghostpad.h>
 #include <gstreamermm/iterator.h>
-
-#ifndef GLIBMM_EXCEPTIONS_ENABLED
-#include <iostream>
-#endif
+#include <gstreamermm/handle_error.h>
 
 _PINCLUDE(glibmm/private/object_p.h)
 _PINCLUDE(gstreamermm/private/element_p.h)
@@ -35,13 +31,13 @@ namespace Gst
 {
 
 Bin::Bin()
-: _CONSTRUCT("name", 0)
+: _CONSTRUCT("name", static_cast<char*>(0))
 {}
 
 Glib::RefPtr<Gst::Bin> Bin::add(const Glib::RefPtr<Gst::Element>& element)
 {
   if(!element)
-    handle_error("Failed to add null element.");
+    gstreamermm_handle_error("Failed to add null element.");
 
   GstElement* celement = Glib::unwrap(element);
 
@@ -60,7 +56,8 @@ Glib::RefPtr<Gst::Bin> Bin::add(const Glib::RefPtr<Gst::Element>& element)
   // If addition successful, return RefPtr<..> to this bin, otherwise throw an
   // exception
   if(!result)
-    handle_error("Failed to add " + element->get_name() + " element.");
+    gstreamermm_handle_error("Failed to add " + element->get_name() +
+      " element.");
 
   return Glib::wrap(gobj(), true);
 }
@@ -68,7 +65,7 @@ Glib::RefPtr<Gst::Bin> Bin::add(const Glib::RefPtr<Gst::Element>& element)
 Glib::RefPtr<Gst::Bin> Bin::remove(const Glib::RefPtr<Gst::Element>& element)
 {
   if(!element)
-    handle_error("Failed to remove null element.");
+    gstreamermm_handle_error("Failed to remove null element.");
 
 
   const bool result = gst_bin_remove(gobj(), Glib::unwrap(element));
@@ -76,7 +73,8 @@ Glib::RefPtr<Gst::Bin> Bin::remove(const Glib::RefPtr<Gst::Element>& element)
   // If removal successful, return RefPtr<..> to this bin, otherwise throw an
   // exception
   if(!result)
-    handle_error("Failed to remove " + element->get_name() + " element.");
+    gstreamermm_handle_error("Failed to remove " + element->get_name() +
+      " element.");
 
   return Glib::wrap(gobj(), true);
 }
@@ -92,13 +90,4 @@ Glib::RefPtr<Gst::GhostPad> Bin::add_ghost_pad(const
   return ghost_pad;
 }
 
-void Bin::handle_error(const Glib::ustring& message)
-{
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-    throw std::runtime_error(message);
-#else
-      std::cerr << "gstreamermm: " << message << std::endl;
-#endif
-}
-
 } //namespace Gst
diff --git a/gstreamer/src/bin.hg b/gstreamer/src/bin.hg
index 5ba2f59..9297438 100644
--- a/gstreamer/src/bin.hg
+++ b/gstreamer/src/bin.hg
@@ -261,9 +261,6 @@ public:
   /** Method to handle a message from the children.
    */
   _WRAP_VFUNC(void handle_message(const Glib::RefPtr<Gst::Message>& message), "handle_message")
-
-private:
-  void handle_error(const Glib::ustring& message);
 };
 
 } //namespace Gst
diff --git a/gstreamer/src/element.ccg b/gstreamer/src/element.ccg
index fc1dc1e..8f82a90 100644
--- a/gstreamer/src/element.ccg
+++ b/gstreamer/src/element.ccg
@@ -17,7 +17,6 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <stdexcept>
 #include <gst/gstenumtypes.h>
 #include <gst/gstinterface.h>
 #include <gst/gstutils.h>
@@ -31,10 +30,7 @@
 #include <gstreamermm/query.h>
 #include <gstreamermm/taglist.h>
 #include <gstreamermm/iterator.h>
-
-#ifndef GLIBMM_EXCEPTIONS_ENABLED
-#include <iostream>
-#endif
+#include <gstreamermm/handle_error.h>
 
 _PINCLUDE(gstreamermm/private/object_p.h)
 
@@ -69,7 +65,7 @@ Glib::ustring get_name(StateChangeReturn s)
 Glib::RefPtr<Gst::Element> Element::link(const Glib::RefPtr<Gst::Element>& dest)
 {
   if(!dest)
-    handle_error("Failed to link null element.");
+    gstreamermm_handle_error("Failed to link null element.");
     
   const bool result = gst_element_link(gobj(), Glib::unwrap(dest));
 
@@ -77,7 +73,8 @@ Glib::RefPtr<Gst::Element> Element::link(const Glib::RefPtr<Gst::Element>& dest)
     return dest;
   else
   {
-    handle_error("failed to link: " + get_name() + "->" + dest->get_name());
+    gstreamermm_handle_error("failed to link: " + get_name() + "->" +
+      dest->get_name());
     return Glib::RefPtr<Gst::Element>();
   }
 }
@@ -85,7 +82,7 @@ Glib::RefPtr<Gst::Element> Element::link(const Glib::RefPtr<Gst::Element>& dest)
 Glib::RefPtr<Gst::Element> Element::link(const Glib::RefPtr<Gst::Element>& dest, const Glib::RefPtr<Gst::Caps>& filter)
 {
   if(!dest)
-    handle_error("Failed to link null element.");
+    gstreamermm_handle_error("Failed to link null element.");
     
   const bool result = gst_element_link_filtered(gobj(), Glib::unwrap(dest),
     Glib::unwrap(filter));
@@ -94,7 +91,8 @@ Glib::RefPtr<Gst::Element> Element::link(const Glib::RefPtr<Gst::Element>& dest,
     return dest;
   else
   {
-    handle_error("failed to link: " + get_name() + "->" + dest->get_name());
+    gstreamermm_handle_error("failed to link: " + get_name() + "->" +
+      dest->get_name());
     return Glib::RefPtr<Gst::Element>();
   }
 }
@@ -244,13 +242,4 @@ Glib::ArrayHandle<QueryType> Gst::Element::get_query_types_vfunc() const
 }
 #endif //GLIBMM_VFUNCS_ENABLED
 
-void Element::handle_error(const Glib::ustring& message)
-{
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-    throw std::runtime_error(message);
-#else
-    std::cerr << "gstreamermm: " << message << std::endl;
-#endif
-}
-
 } //namespace Gst
diff --git a/gstreamer/src/element.hg b/gstreamer/src/element.hg
index d10332d..7e6aeab 100644
--- a/gstreamer/src/element.hg
+++ b/gstreamer/src/element.hg
@@ -428,10 +428,6 @@ protected:
   static const GstQueryType* get_query_types_vfunc_callback(GstElement* self);
   _POP()
 #m4end
-
-private:
-  void handle_error(const Glib::ustring& message);
-  
 };
 
 /** Templated class used for casting Gst::Element to interfaces that its
diff --git a/gstreamer/src/format.ccg b/gstreamer/src/format.ccg
index 2f028e6..1302f7f 100644
--- a/gstreamer/src/format.ccg
+++ b/gstreamer/src/format.ccg
@@ -75,7 +75,8 @@ bool get_format_details(Format format, FormatDefinition& def)
 {
   const GstFormatDefinition* gstdef = gst_format_get_details(static_cast<GstFormat>(format));
 
-  g_return_val_if_fail(gstdef != 0, false);
+  if(!gstdef)
+    return false;
 
   def.value = Format(gstdef->value);
   def.nick = gstdef->nick;
diff --git a/gstreamer/src/ghostpad.ccg b/gstreamer/src/ghostpad.ccg
index 1ce915a..29d7bff 100644
--- a/gstreamer/src/ghostpad.ccg
+++ b/gstreamer/src/ghostpad.ccg
@@ -17,14 +17,10 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <stdexcept>
 #include <sstream>
 #include <gst/gstghostpad.h>
 #include <gstreamermm/padtemplate.h>
-
-#ifndef GLIBMM_EXCEPTIONS_ENABLED
-#include <iostream>
-#endif
+#include <gstreamermm/handle_error.h>
 
 _PINCLUDE(gstreamermm/private/pad_p.h)
 
@@ -33,19 +29,19 @@ namespace Gst
 
 GhostPad::GhostPad(const Glib::RefPtr<Gst::Pad>& target,
   const Glib::ustring& name)
-  : _CONSTRUCT("name", (name.empty() ? 0 : name.c_str()),
+  : _CONSTRUCT("name", (name.empty() ? static_cast<char*>(0) : name.c_str()),
     "direction",
-    ((target) ? ((GstPadDirection) target->get_direction()) : GST_PAD_UNKNOWN))
+    (target ? ((GstPadDirection) target->get_direction()) : GST_PAD_UNKNOWN))
 {
   if(!target)
-    handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
+    gstreamermm_handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
       " const Glib::RefPtr<Gst::Pad>&): "
       "Failed to construct ghost pad (name = " + name + ") from null target.");
 
   if(!gst_ghost_pad_construct(gobj()) ||
     !gst_ghost_pad_set_target(gobj(), target->gobj()))
   {
-    handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
+    gstreamermm_handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
       " const Glib::RefPtr<Gst::Pad>&): "
       "Unsuccessful construction of ghost pad (name = " + name +
       ", target = " + target->get_name() + ").");
@@ -53,15 +49,15 @@ GhostPad::GhostPad(const Glib::RefPtr<Gst::Pad>& target,
 }
 
 GhostPad::GhostPad( PadDirection direction, const Glib::ustring& name)
-  : _CONSTRUCT("name", (name.empty() ? 0 : name.c_str()),
-    "direction", (GstPadDirection) direction)
+  : _CONSTRUCT("name", (name.empty() ? static_cast<char*>(0) : name.c_str()),
+    "direction", static_cast<GstPadDirection>(direction))
 {
   if(!gst_ghost_pad_construct(gobj()))
   {
     std::stringstream int_conv_stream;
     int_conv_stream << direction;
 
-    handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&, "
+    gstreamermm_handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&, "
     "PadDirection): Unsuccessful construction of ghost pad (name = " +
     name + ", direction = " + int_conv_stream.str() + ").");
   }
@@ -70,13 +66,13 @@ GhostPad::GhostPad( PadDirection direction, const Glib::ustring& name)
 GhostPad::GhostPad( const Glib::RefPtr<Gst::Pad>& target,
   const Glib::RefPtr<Gst::PadTemplate>& templ,
   const Glib::ustring& name)
-  : _CONSTRUCT("name", (name.empty() ? 0 : name.c_str()),
+  : _CONSTRUCT("name", (name.empty() ? static_cast<char*>(0) : name.c_str()),
     "direction",
-    ((target) ? ((GstPadDirection) target->get_direction()) : GST_PAD_UNKNOWN),
-    "template", ((templ) ? templ->gobj() : 0))
+    (target ? static_cast<GstPadDirection>(target->get_direction()) : GST_PAD_UNKNOWN),
+    "template", (templ ? templ->gobj() : static_cast<GstPadTemplate*>(0)))
 {
   if(!target || !templ)
-    handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
+    gstreamermm_handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
       " const Glib::RefPtr<Gst::Pad>&, const Glib::RefPtr<Gst::PadTemplate>&):"
       " Failed to construct ghost pad (name = " + name + ") from null "
       "target or template.");
@@ -84,7 +80,7 @@ GhostPad::GhostPad( const Glib::RefPtr<Gst::Pad>& target,
   if(!gst_ghost_pad_construct(gobj()) ||
     !gst_ghost_pad_set_target(gobj(), target->gobj()))
   {
-    handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
+    gstreamermm_handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
       " const Glib::RefPtr<Gst::Pad>&, const Glib::RefPtr<Gst::PadTemplate>&):"
       " Unsuccessful construction of ghost pad (name = " + name +
       ", target = " + target->get_name() + ", templ = " +
@@ -94,32 +90,23 @@ GhostPad::GhostPad( const Glib::RefPtr<Gst::Pad>& target,
 
 GhostPad::GhostPad( const Glib::RefPtr<Gst::PadTemplate>& templ,
   const Glib::ustring& name)
-  : _CONSTRUCT("name", (name.empty() ? 0 : name.c_str()), "direction", 
-    ((templ) ? ((GstPadDirection) templ->get_direction()) : GST_PAD_UNKNOWN),
-    "template", ((templ) ? templ->gobj() : 0))
+  : _CONSTRUCT("name", (name.empty() ? static_cast<char*>(0) : name.c_str()),
+    "direction", (templ ? static_cast<GstPadDirection>(templ->get_direction()) : GST_PAD_UNKNOWN),
+    "template", (templ ? templ->gobj() : static_cast<GstPadTemplate*>(0)))
 {
   if(!templ)
-    handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
+    gstreamermm_handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
       " const Glib::RefPtr<Gst::PadTemplate>&): "
       "Failed to construct ghost pad (name = " + name +
       ") from null template.");
 
   if(!gst_ghost_pad_construct(gobj()))
   {
-    handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
+    gstreamermm_handle_error("Gst::GhostPad::GhostPad(const Glib::ustring&,"
       " const Glib::RefPtr<Gst::PadTemplate>&): "
       "Unsuccessful construction of ghost pad (name = " + name +
       ", templ = " + templ->get_name_template() + ").");
   }
 }
 
-void GhostPad::handle_error(const Glib::ustring& message)
-{
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-    throw std::runtime_error(message);
-#else
-      std::cerr << "gstreamermm: " << message << std::endl;
-#endif
-}
-
 } //namespace Gst
diff --git a/gstreamer/src/ghostpad.hg b/gstreamer/src/ghostpad.hg
index f706940..6753df9 100644
--- a/gstreamer/src/ghostpad.hg
+++ b/gstreamer/src/ghostpad.hg
@@ -135,9 +135,6 @@ public:
 
   _WRAP_METHOD(Glib::RefPtr<Gst::Pad> get_target(), gst_ghost_pad_get_target)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Pad> get_target() const, gst_ghost_pad_get_target, constversion)
-
-private:
-  void handle_error(const Glib::ustring& message);
 };
 
 } // namespace Gst
diff --git a/gstreamer/src/iterator.hg b/gstreamer/src/iterator.hg
index fecc778..b417c16 100644
--- a/gstreamer/src/iterator.hg
+++ b/gstreamer/src/iterator.hg
@@ -18,11 +18,7 @@
  */
 
 #include <gst/gstiterator.h>
-#include <stdexcept>
-
-#ifndef GLIBMM_EXCEPTIONS_ENABLED
-#include <iostream>
-#endif
+#include <gstreamermm/handle_error.h>
 
 _DEFS(gstreamermm,gst)
 
@@ -186,9 +182,6 @@ public:
    * concurrent update to the iterator occurs while it iterates).
    */
   IteratorBasic<CppType> operator++(int);
-
-private:
-  void handle_error(const Glib::ustring& message);
 };
 
 /**  Gst::Iterator - Class that retrieve multiple reference counted elements in
@@ -397,9 +390,10 @@ IteratorBasic<CppType>& IteratorBasic<CppType>::operator++()
   const IteratorResult result = this->next();
 
   if(result == Gst::ITERATOR_RESYNC)
-    handle_error("Concurrent update of iterator elements.  Please resync.");
+    gstreamermm_handle_error("Concurrent update of iterator elements.  "
+      "Please resync.");
   else if(result == Gst::ITERATOR_ERROR)
-    handle_error("Iterator error while incrementing.");
+    gstreamermm_handle_error("Iterator error while incrementing.");
 
   return *this;
 }
@@ -412,16 +406,6 @@ IteratorBasic<CppType> IteratorBasic<CppType>::operator++(int)
   return original;
 }
 
-template<class CppType>
-void IteratorBasic<CppType>::handle_error(const Glib::ustring& message)
-{
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-  throw std::runtime_error(message);
-#else
-  std::cerr << "gstreamermm: " << message << std::endl;
-#endif
-}
-
 /******************* Gst::Iterator<CppType> **************************/
 
 template <class CppType>
diff --git a/gstreamer/src/parse.ccg b/gstreamer/src/parse.ccg
index 5ea2796..24f764d 100644
--- a/gstreamer/src/parse.ccg
+++ b/gstreamer/src/parse.ccg
@@ -31,7 +31,7 @@ Glib::RefPtr<Gst::Element> Parse::launch(const Glib::ustring& pipeline_descripti
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  Glib::RefPtr<Gst::Element> retvalue = Glib::wrap(gst_parse_launch(pipeline_description.c_str(), &(gerror)));
+  Glib::RefPtr<Gst::Element> retvalue = Glib::wrap(gst_parse_launch(pipeline_description.c_str(), &gerror));
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
@@ -51,7 +51,7 @@ Glib::RefPtr<Gst::Element> Parse::launchv(const gchar *argv[], std::auto_ptr<Gli
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  Glib::RefPtr<Gst::Element> retvalue = Glib::wrap(gst_parse_launchv(argv, &(gerror)));
+  Glib::RefPtr<Gst::Element> retvalue = Glib::wrap(gst_parse_launchv(argv, &gerror));
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
@@ -71,7 +71,7 @@ Glib::RefPtr<Gst::Element> Parse::create_bin(const Glib::ustring& bin_descriptio
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  Glib::RefPtr<Gst::Element> retvalue = Glib::wrap(gst_parse_bin_from_description(bin_description.c_str(), ghost_unconnected_pads, &(gerror)));
+  Glib::RefPtr<Gst::Element> retvalue = Glib::wrap(gst_parse_bin_from_description(bin_description.c_str(), ghost_unconnected_pads, &gerror));
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
diff --git a/gstreamer/src/pipeline.ccg b/gstreamer/src/pipeline.ccg
index 47e7f69..d8c4a70 100644
--- a/gstreamer/src/pipeline.ccg
+++ b/gstreamer/src/pipeline.ccg
@@ -27,7 +27,7 @@ namespace Gst
 {
 
 Pipeline::Pipeline()
-: _CONSTRUCT("name", 0)
+: _CONSTRUCT("name", static_cast<char*>(0))
 {}
 
 } // namespace Gst
diff --git a/gstreamer/src/query.ccg b/gstreamer/src/query.ccg
index 1091707..abd0d64 100644
--- a/gstreamer/src/query.ccg
+++ b/gstreamer/src/query.ccg
@@ -66,7 +66,8 @@ bool get_details(QueryType type, QueryTypeDefinition &def)
 {
   const GstQueryTypeDefinition* gstdef = gst_query_type_get_details(GstQueryType(type));
 
-  g_return_val_if_fail(gstdef != 0, false);
+  if(!gstdef)
+    return false;
 
   def.value = static_cast<QueryType>(gstdef->value);
   def.nick = gstdef->nick;
diff --git a/gstreamer/src/ringbuffer.ccg b/gstreamer/src/ringbuffer.ccg
index 1cb6bcb..97df2d4 100644
--- a/gstreamer/src/ringbuffer.ccg
+++ b/gstreamer/src/ringbuffer.ccg
@@ -17,8 +17,8 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <cstring>
 #include <gst/audio/audio-enumtypes.h>
+#include <gstreamermm/handle_error.h>
 _PINCLUDE(gstreamermm/private/object_p.h)
 
 // This constant is obtained from the "silence_sample" member in the
@@ -59,19 +59,33 @@ namespace Gst
 {
 
 RingBufferSpec::RingBufferSpec()
-: m_spec(g_new(GstRingBufferSpec, 1)),
+: m_spec(g_try_new(GstRingBufferSpec, 1)),
   take_ownership(true)
-{}
+{
+  // Handle possible memory allocation failure.
+  if(!m_spec)
+  {
+    gstreamermm_handle_error("Failed to allocate a new Gst::RingBufferSpec.");
+    return;
+  }
+}
 
 RingBufferSpec::RingBufferSpec(const Glib::RefPtr<Gst::Caps>& caps,
   Gst::BufferFormatType type, Gst::BufferFormat format, bool sign,
   bool bigend, int width, int depth, int rate, int channels,
   guint64 latency_time, guint64 buffer_time, int segsize, int segtotal,
   int seglatency)
-: m_spec(g_new(GstRingBufferSpec, 1)),
+: m_spec(g_try_new(GstRingBufferSpec, 1)),
   take_ownership(true)
   
 {
+  // Handle possible memory allocation failure.
+  if(!m_spec)
+  {
+    gstreamermm_handle_error("Failed to allocate a new Gst::RingBufferSpec.");
+    return;
+  }
+
   GstRingBufferSpec* spec = gobj();
 
   spec->caps = Glib::unwrap(caps);
@@ -106,9 +120,16 @@ RingBufferSpec::RingBufferSpec(GstRingBufferSpec& castitem, bool take_ownership)
 }
 
 RingBufferSpec::RingBufferSpec(const RingBufferSpec& other)
-: m_spec(g_new(GstRingBufferSpec, 1)),
+: m_spec(g_try_new(GstRingBufferSpec, 1)),
   take_ownership(true)
 {
+  // Handle possible memory allocation failure.
+  if(!m_spec)
+  {
+    gstreamermm_handle_error("Failed to allocate a new Gst::RingBufferSpec.");
+    return;
+  }
+
   m_spec->caps = other.m_spec->caps;
 
   // Keep a copy of the caps (it will be unreferenced in the destructor).
diff --git a/gstreamer/src/ringbuffer.hg b/gstreamer/src/ringbuffer.hg
index 66655b0..0476389 100644
--- a/gstreamer/src/ringbuffer.hg
+++ b/gstreamer/src/ringbuffer.hg
@@ -45,7 +45,10 @@ class RingBufferSpec
 {
     _CLASS_GENERIC(RingBufferSpec, GstRingBufferSpec)
 public:
-  /// Default constructor.
+  /** Default constructor.
+   * @throw std::runtime_error if memory is unavailable for the new
+   * Gst::RingBufferSpec.
+   */
   RingBufferSpec();
 
   /** Fully construct a Gst::RingBufferSpec.  Only the "(in)" parameters are
@@ -66,6 +69,9 @@ public:
    * @param segtotal The total number of segments (in/out).
    * @param seglatency Number of segments queued in the lower level device,
    * defaults to @a segtotal in the C API (in/out).
+   *
+   * @throw std::runtime_error if memory is unavailable for the new
+   * Gst::RingBufferSpec.
    */
   RingBufferSpec(const Glib::RefPtr<Gst::Caps>& caps,
     Gst::BufferFormatType type = Gst::BUFTYPE_LINEAR,
@@ -77,7 +83,11 @@ public:
   /// Construct a Gst::RingBufferSpec from a GstRingBufferSpec.
   RingBufferSpec(GstRingBufferSpec& castitem, bool take_ownership = false);
 
-  /// Copy constructor.
+  /** Copy constructor.
+   *
+   * @throw std::runtime_error if memory is unavailable for the new
+   * Gst::RingBufferSpec.
+   */
   RingBufferSpec(const RingBufferSpec& other);
 
   /// Assignment operator.



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