fix doc build fix autogen
[platform/upstream/gstreamer.git] / gst / gstquery.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gstquery.c: GstQueryType registration
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library 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  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library 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
23 #include <string.h>
24
25 #include "gstlog.h"
26
27 #include "gstquery.h"
28
29 static GList *_gst_queries = NULL;
30 static GHashTable *_nick_to_query = NULL;
31 static GHashTable *_query_type_to_nick = NULL;
32 static gint  _n_values = 1; /* we start from 1 because 0 reserved for NONE */
33
34 static GstQueryTypeDefinition standard_definitions[] = {
35   { GST_QUERY_TOTAL,       "total",       "Total length" },
36   { GST_QUERY_POSITION,    "position",    "Current Position" },
37   { GST_QUERY_LATENCY,     "latency",     "Latency" }, 
38   { GST_QUERY_JITTER,      "jitter",      "Jitter" },
39   { GST_QUERY_START,       "start",       "Start position of stream" },
40   { GST_QUERY_SEGMENT_END, "segment_end", "End position of the stream" },
41   { GST_QUERY_RATE,        "rate",        "Configured rate 1000000 = 1" },
42   { 0, NULL, NULL }
43 };
44
45 void            
46 _gst_query_type_initialize (void)
47 {
48   GstQueryTypeDefinition *standards = standard_definitions;
49
50   if (_nick_to_query == NULL) {
51     _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
52     _query_type_to_nick = g_hash_table_new (NULL, NULL);
53   }
54   
55   while (standards->nick) {
56     g_hash_table_insert (_nick_to_query, standards->nick, standards);
57     g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (standards->value), standards);
58
59     _gst_queries = g_list_append (_gst_queries, standards);
60     standards++;
61     _n_values++;
62   }
63 }
64
65 /**
66  * gst_query_type_register:
67  * @nick: The nick of the new query
68  * @description: The description of the new query
69  *
70  * Create a new GstQueryType based on the nick or return an
71  * allrady registered query with that nick
72  *
73  * Returns: A new GstQueryType or an already registered query
74  * with the same nick.
75  */
76 GstQueryType
77 gst_query_type_register (const gchar *nick, const gchar *description)
78 {
79   GstQueryTypeDefinition *query;
80   GstQueryType lookup;
81   
82   g_return_val_if_fail (nick != NULL, 0);
83   g_return_val_if_fail (description != NULL, 0);
84
85   lookup = gst_query_type_get_by_nick (nick);
86   if (lookup != GST_QUERY_NONE)
87     return lookup;
88   
89   query = g_new0 (GstQueryTypeDefinition, 1);
90   query->value = _n_values;
91   query->nick = g_strdup (nick);
92   query->description = g_strdup (description);
93
94   g_hash_table_insert (_nick_to_query, query->nick, query);
95   g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value), query);
96   _gst_queries = g_list_append (_gst_queries, query);
97   _n_values++;
98   
99   return query->value;
100 }
101
102 /**
103  * gst_query_type_get_by_nick:
104  * @nick: The nick of the query
105  *
106  * Return the query registered with the given nick. 
107  *
108  * Returns: The query with @nick or GST_QUERY_NONE
109  * if the query was not registered.
110  */
111 GstQueryType
112 gst_query_type_get_by_nick (const gchar *nick)
113 {
114   GstQueryTypeDefinition *query;
115   
116   g_return_val_if_fail (nick != NULL, 0);
117
118   query = g_hash_table_lookup (_nick_to_query, nick);
119   
120   if (query != NULL)
121     return query->value;
122   else
123     return GST_QUERY_NONE;
124 }
125
126 /**
127  * gst_query_types_contains:
128  * @types: The query array to search
129  * @type: the querytype to find
130  *
131  * See if the given query is inside the query array.
132  *
133  * Returns: TRUE if the query is found inside the array
134  */
135 gboolean
136 gst_query_types_contains (const GstQueryType *types, GstQueryType type)
137 {
138   if (!types)
139     return FALSE;
140
141   while (*types) {
142     if (*types == type)
143       return TRUE;
144
145     types++;
146   }
147   return FALSE;
148 }
149
150
151 /**
152  * gst_query_type_get_details:
153  * @type: The query to get details of
154  *
155  * Get details about the given query.
156  *
157  * Returns: The #GstQueryTypeDefinition for @query or NULL on failure.
158  */
159 const GstQueryTypeDefinition*
160 gst_query_type_get_details (GstQueryType type)
161 {
162   return g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
163 }
164
165 /**
166  * gst_query_type_get_definitions:
167  *
168  * Get a list of all the registered query types.
169  *
170  * Returns: A GList of #GstQueryTypeDefinition.
171  */
172 const GList*
173 gst_query_type_get_definitions (void)
174 {
175   return _gst_queries;
176 }