root/flow/flow-event.c

Revision 451ac85e349fd41eb887efb26d737614597deb5b, 4.0 kB (checked in by Hans Petter Jansson <hpj@gong.site>, 3 years ago)

Document API for flow-emitter.c, flow-event.c, flow-file-connect-op.c.

  • Property mode set to 100644
Line 
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3 /* flow-event.c - An event that can be propagated along a pipeline.
4  *
5  * Copyright (C) 2006 Hans Petter Jansson
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * Authors: Hans Petter Jansson <hpj@copyleft.no>
23  */
24
25 #include "config.h"
26 #include "flow-gobject-util.h"
27 #include "flow-event.h"
28
29 /* --- FlowEvent private data --- */
30
31 typedef struct
32 {
33 }
34 FlowEventPrivate;
35
36 /* --- FlowEvent properties --- */
37
38 static FlowElement *
39 flow_event_get_source_element_internal (FlowEvent *event)
40 {
41   return event->source_element;
42 }
43
44 static void
45 flow_event_set_source_element_internal (FlowEvent *event, FlowElement *element)
46 {
47   if (event->source_element == element)
48     return;
49
50   if (event->source_element)
51     g_object_remove_weak_pointer ((GObject *) event->source_element, (gpointer) &event->source_element);
52
53   event->source_element = element;
54
55   if (element)
56     g_object_add_weak_pointer ((GObject *) element, (gpointer) &event->source_element);
57 }
58
59 FLOW_GOBJECT_PROPERTIES_BEGIN (flow_event)
60 FLOW_GOBJECT_PROPERTY         (G_TYPE_OBJECT, "source-element", "Source element",
61                                "Element that generated this event", G_PARAM_READWRITE,
62                                flow_event_get_source_element_internal,
63                                flow_event_set_source_element_internal,
64                                flow_element_get_type)
65 FLOW_GOBJECT_PROPERTIES_END   ()
66
67 /* --- FlowEvent definition --- */
68
69 FLOW_GOBJECT_MAKE_IMPL        (flow_event, FlowEvent, G_TYPE_OBJECT, G_TYPE_FLAG_ABSTRACT)
70
71 /* --- FlowEvent implementation --- */
72
73 static void
74 flow_event_type_init (GType type)
75 {
76 }
77
78 static void
79 flow_event_class_init (FlowEventClass *klass)
80 {
81 }
82
83 static void
84 flow_event_init (FlowEvent *event)
85 {
86 }
87
88 static void
89 flow_event_construct (FlowEvent *event)
90 {
91 }
92
93 static void
94 flow_event_dispose (FlowEvent *event)
95 {
96   if (event->source_element)
97   {
98     g_object_remove_weak_pointer ((GObject *) event->source_element, (gpointer) &event->source_element);
99     event->source_element = NULL;
100   }
101 }
102
103 static void
104 flow_event_finalize (FlowEvent *event)
105 {
106   g_free (event->description);
107   event->description = NULL;
108 }
109
110 /* --- FlowEvent public API --- */
111
112 /**
113  * flow_event_get_source_element:
114  * @event: A #FlowEvent.
115  *
116  * Returns a pointer to the #FlowElement that generated this event. The source
117  * element may be unset, in which case %NULL will be returned. The source
118  * element may be set multiple times.
119  *
120  * Return value: The #FlowElement that generated the event, or %NULL if unset.
121  **/
122 FlowElement *
123 flow_event_get_source_element (FlowEvent *event)
124 {
125   g_return_val_if_fail (FLOW_IS_EVENT (event), NULL);
126
127   return event->source_element;
128 }
129
130 /**
131  * flow_event_get_description:
132  * @event: A #FlowEvent.
133  *
134  * Causes @event to generate a human-readable description of itself and return
135  * a pointer to it. The string belongs to @event and must not be freed.
136  *
137  * Return value: A pointer to a human-readable description of the event.
138  **/
139 const gchar *
140 flow_event_get_description (FlowEvent *event)
141 {
142   FlowEventClass *klass;
143
144   g_return_val_if_fail (FLOW_IS_EVENT (event), NULL);
145
146   klass = FLOW_EVENT_GET_CLASS (event);
147   if (klass->update_description)
148     klass->update_description (event);
149
150   if (!event->description)
151     return G_OBJECT_CLASS_NAME (event);
152
153   return event->description;
154 }
Note: See TracBrowser for help on using the browser.