tracer: pass the instance to the vmethod
[platform/upstream/gstreamer.git] / plugins / tracers / gstlog.c
1 /* GStreamer
2  * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
3  *
4  * gstlog.c: tracing module that logs events
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #endif
25
26 #include "gstlog.h"
27
28 GST_DEBUG_CATEGORY_STATIC (gst_log_debug);
29 #define GST_CAT_DEFAULT gst_log_debug
30
31 #define _do_init \
32     GST_DEBUG_CATEGORY_INIT (gst_log_debug, "log", 0, "log tracer");
33 #define gst_log_tracer_parent_class parent_class
34 G_DEFINE_TYPE_WITH_CODE (GstLogTracer, gst_log_tracer, GST_TYPE_TRACER,
35     _do_init);
36
37 static void gst_log_tracer_invoke (GstTracer * self, GstTracerHookId id,
38     GstStructure * s);
39
40 static void
41 gst_log_tracer_class_init (GstLogTracerClass * klass)
42 {
43   GstTracerClass *gst_tracer_class = GST_TRACER_CLASS (klass);
44
45   gst_tracer_class->invoke = gst_log_tracer_invoke;
46 }
47
48 static void
49 gst_log_tracer_init (GstLogTracer * self)
50 {
51   g_object_set (self, "mask", GST_TRACER_HOOK_ALL, NULL);
52 }
53
54 static void
55 gst_log_tracer_invoke (GstTracer * self, GstTracerHookId id, GstStructure * s)
56 {
57   gchar *str = gst_structure_to_string (s);
58   /* TODO(ensonic): log to different categories depending on 'id'
59    * GST_TRACER_HOOK_ID_BUFFERS  -> GST_CAT_BUFFER
60    * GST_TRACER_HOOK_ID_EVENTS   -> GST_CAT_EVENT
61    * GST_TRACER_HOOK_ID_MESSAGES -> GST_CAT_MESSAGE
62    * GST_TRACER_HOOK_ID_QUERIES  -> ?
63    * GST_TRACER_HOOK_ID_TOPLOGY  -> ?
64    */
65   GST_TRACE ("%s", str);
66   g_free (str);
67 }