gst/: We now have debugging in gst-python ;) gst.[log|debug|info|warning|error]()
authorEdward Hervey <bilboed@bilboed.com>
Thu, 4 Aug 2005 10:44:16 +0000 (10:44 +0000)
committerEdward Hervey <bilboed@bilboed.com>
Thu, 4 Aug 2005 10:44:16 +0000 (10:44 +0000)
Original commit message from CVS:
* gst/gst.defs:
* gst/gst.override:
* gst/gstmodule.c:
We now have debugging in gst-python ;)
gst.[log|debug|info|warning|error]()

ChangeLog
gst/gst.defs
gst/gst.override
gst/gstmodule.c

index 15a206a..4177d18 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-08-04  Edward Hervey  <edward@fluendo.com>
+
+       * gst/gst.defs:
+       * gst/gst.override:
+       * gst/gstmodule.c:
+       We now have debugging in gst-python ;)
+       gst.[log|debug|info|warning|error]()
+
 2005-08-03  Edward Hervey  <edward@fluendo.com>
 
        * configure.ac:
index 30642a6..232c6d3 100644 (file)
   )
 )
 
+;; DEBUGGING FUNCTIONS FROM PYTHON
+;; The c functions don't actually exist
 
+(define-function log
+  (c-name "gst_log")
+  (return-type "none")
+  (parameters
+   '("gchar *" "msg")
+   )
+)
+
+(define-function debug
+  (c-name "gst_debug")
+  (return-type "none")
+  (parameters
+   '("gchar *" "msg")
+   )
+)
+
+(define-function info
+  (c-name "gst_info")
+  (return-type "none")
+  (parameters
+   '("gchar *" "msg")
+   )
+)
+
+(define-function warning
+  (c-name "gst_warning")
+  (return-type "none")
+  (parameters
+   '("gchar *" "msg")
+   )
+)
+
+(define-function error
+  (c-name "gst_error")
+  (return-type "none")
+  (parameters
+   '("gchar *" "msg")
+   )
+)
 
 ;; From ../gstreamer/gst/gstinterface.h
 
index 57ee103..4d270e5 100644 (file)
@@ -53,6 +53,9 @@ headers
 
 PyObject *PyGstExc_LinkError = NULL;
 
+GST_DEBUG_CATEGORY_EXTERN (gst_python);
+#define GST_CAT_DEFAULT gst_python
+
 GSList *mainloops = NULL;
 void
 _pygst_main_quit(void)
@@ -217,6 +220,30 @@ _pygst_element_init (gpointer gclass, PyTypeObject *pyclass)
 }
 #endif
 
+static PyObject *
+pygst_debug_log (PyObject *whatever, PyObject *string, GstDebugLevel level)
+{
+    gchar      *str;
+    gchar      *function;
+    gchar      *filename;
+    gchar      lineno;
+    PyFrameObject      *frame;
+
+    if (!PyArg_ParseTuple(string, "s:gst.debug_log", &str)) {
+       PyErr_SetString(PyExc_TypeError, "Need a string!");
+       return NULL;
+    }
+
+    frame = PyEval_GetFrame();
+    function = PyString_AsString(frame->f_code->co_name);
+    filename = PyString_AsString(frame->f_code->co_filename);
+    lineno = frame->f_code->co_firstlineno;
+    /* gst_debug_log : category, level, file, function, line, object, format, va_list */
+    gst_debug_log (GST_CAT_DEFAULT, level, filename, function, lineno, NULL, str);
+    Py_INCREF (Py_None);
+    return Py_None;    
+}
+
 %%
 include
   gstbin.override
@@ -959,3 +986,38 @@ _wrap_gst_flow_get_name(PyObject *self, PyObject *args, PyObject *kwargs)
     Py_INCREF(Py_None);
     return Py_None;
 }
+%%
+override gst_log args
+static PyObject *
+_wrap_gst_log (PyObject *whatever, PyObject *string)
+{
+    return pygst_debug_log (whatever, string, GST_LEVEL_LOG);
+}
+%%
+override gst_debug args
+static PyObject *
+_wrap_gst_debug (PyObject *whatever, PyObject *string)
+{
+    return pygst_debug_log (whatever, string, GST_LEVEL_DEBUG);
+}
+%%
+override gst_info args
+static PyObject *
+_wrap_gst_info (PyObject *whatever, PyObject *string)
+{
+    return pygst_debug_log (whatever, string, GST_LEVEL_INFO);
+}
+%%
+override gst_warning
+static PyObject *
+_wrap_gst_warning (PyObject *whatever, PyObject *string)
+{
+    return pygst_debug_log (whatever, string, GST_LEVEL_WARNING);
+}
+%%
+override gst_error
+static PyObject *
+_wrap_gst_error (PyObject *whatever, PyObject *string)
+{
+    return pygst_debug_log (whatever, string, GST_LEVEL_ERROR);
+}
index a6699f6..da9bb40 100644 (file)
@@ -42,6 +42,7 @@ extern GSList *mainloops;
 extern void _pygst_main_quit(void);
 extern PyObject *PyGstExc_LinkError;
 
+GST_DEBUG_CATEGORY (gst_python);
 
 /* This is a timeout that gets added to the mainloop to handle SIGINT (Ctrl-C)
  * Other signals get handled at some other point where transition from
@@ -168,6 +169,8 @@ init_gst (void)
      pygst_register_classes (d);
      pygst_add_constants (m, "GST_");
 
+     /* Initialize debugging category */
+     GST_DEBUG_CATEGORY_INIT (gst_python, "gst-python", 0, "GStreamer python bindings");
 
      g_timeout_add_full (0, 100, python_do_pending_calls, NULL, NULL);