XMMS2
src/xmms/xform_plugin.c
Go to the documentation of this file.
00001 /*  XMMS2 - X Music Multiplexer System
00002  *  Copyright (C) 2003-2011 XMMS2 Team
00003  *
00004  *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  */
00016 
00017 #include "xmmspriv/xmms_xform.h"
00018 #include "xmmspriv/xmms_xform_plugin.h"
00019 #include "xmms/xmms_log.h"
00020 
00021 struct xmms_xform_plugin_St {
00022     xmms_plugin_t plugin;
00023     xmms_xform_methods_t methods;
00024     GList *in_types;
00025 };
00026 
00027 static void
00028 destroy (xmms_object_t *obj)
00029 {
00030     xmms_xform_plugin_t *plugin = (xmms_xform_plugin_t *) obj;
00031 
00032     while (plugin->in_types) {
00033         xmms_object_unref (plugin->in_types->data);
00034 
00035         plugin->in_types = g_list_delete_link (plugin->in_types,
00036                                                plugin->in_types);
00037     }
00038 
00039     xmms_plugin_destroy ((xmms_plugin_t *) obj);
00040 }
00041 
00042 xmms_plugin_t *
00043 xmms_xform_plugin_new (void)
00044 {
00045     xmms_xform_plugin_t *res;
00046 
00047     res = xmms_object_new (xmms_xform_plugin_t, destroy);
00048 
00049     return (xmms_plugin_t *)res;
00050 }
00051 
00052 void
00053 xmms_xform_plugin_methods_set (xmms_xform_plugin_t *plugin,
00054                                xmms_xform_methods_t *methods)
00055 {
00056     g_return_if_fail (plugin);
00057     g_return_if_fail (plugin->plugin.type == XMMS_PLUGIN_TYPE_XFORM);
00058 
00059     XMMS_DBG ("Registering xform '%s'",
00060               xmms_plugin_shortname_get ((xmms_plugin_t *) plugin));
00061 
00062     memcpy (&plugin->methods, methods, sizeof (xmms_xform_methods_t));
00063 }
00064 
00065 gboolean
00066 xmms_xform_plugin_verify (xmms_plugin_t *_plugin)
00067 {
00068     xmms_xform_plugin_t *plugin = (xmms_xform_plugin_t *) _plugin;
00069 
00070     g_return_val_if_fail (plugin, FALSE);
00071     g_return_val_if_fail (plugin->plugin.type == XMMS_PLUGIN_TYPE_XFORM, FALSE);
00072 
00073     /* more checks */
00074 
00075     return TRUE;
00076 }
00077 
00078 void
00079 xmms_xform_plugin_indata_add (xmms_xform_plugin_t *plugin, ...)
00080 {
00081     xmms_stream_type_t *t;
00082     va_list ap;
00083     gchar *config_key, config_value[32];
00084     gint priority;
00085 
00086     va_start (ap, plugin);
00087     t = xmms_stream_type_parse (ap);
00088     va_end (ap);
00089 
00090     config_key = g_strconcat ("priority.",
00091                               xmms_stream_type_get_str (t, XMMS_STREAM_TYPE_NAME),
00092                               NULL);
00093     priority = xmms_stream_type_get_int (t, XMMS_STREAM_TYPE_PRIORITY);
00094     g_snprintf (config_value, sizeof (config_value), "%d", priority);
00095     xmms_xform_plugin_config_property_register (plugin, config_key,
00096                                                 config_value, NULL, NULL);
00097     g_free (config_key);
00098 
00099     plugin->in_types = g_list_prepend (plugin->in_types, t);
00100 }
00101 
00102 gboolean
00103 xmms_xform_plugin_supports (const xmms_xform_plugin_t *plugin, xmms_stream_type_t *st,
00104                             gint *priority)
00105 {
00106     GList *t;
00107 
00108     g_return_val_if_fail (st, FALSE);
00109     g_return_val_if_fail (plugin, FALSE);
00110     g_return_val_if_fail (priority, FALSE);
00111 
00112     for (t = plugin->in_types; t; t = g_list_next (t)) {
00113         xmms_config_property_t *config_priority;
00114         const gchar *type_name;
00115         gchar *config_key;
00116 
00117         if (!xmms_stream_type_match (t->data, st)) {
00118             continue;
00119         }
00120 
00121         type_name = xmms_stream_type_get_str (t->data, XMMS_STREAM_TYPE_NAME);
00122 
00123         config_key = g_strconcat ("priority.", type_name, NULL);
00124         config_priority = xmms_plugin_config_lookup ((xmms_plugin_t *) plugin,
00125                                                      config_key);
00126         g_free (config_key);
00127 
00128         if (config_priority) {
00129             *priority = xmms_config_property_get_int (config_priority);
00130         } else {
00131             *priority = XMMS_STREAM_TYPE_PRIORITY_DEFAULT;
00132         }
00133 
00134         return TRUE;
00135     }
00136 
00137     return FALSE;
00138 }
00139 
00140 xmms_config_property_t *
00141 xmms_xform_plugin_config_property_register (xmms_xform_plugin_t *xform_plugin,
00142                                             const gchar *name,
00143                                             const gchar *default_value,
00144                                             xmms_object_handler_t cb,
00145                                             gpointer userdata)
00146 {
00147     xmms_plugin_t *plugin = (xmms_plugin_t *) xform_plugin;
00148 
00149     return xmms_plugin_config_property_register (plugin, name,
00150                                                  default_value,
00151                                                  cb, userdata);
00152 }
00153 
00154 gboolean
00155 xmms_xform_plugin_can_init (const xmms_xform_plugin_t *plugin)
00156 {
00157     return !!plugin->methods.init;
00158 }
00159 
00160 gboolean
00161 xmms_xform_plugin_can_read (const xmms_xform_plugin_t *plugin)
00162 {
00163     return !!plugin->methods.read;
00164 }
00165 
00166 gboolean
00167 xmms_xform_plugin_can_seek (const xmms_xform_plugin_t *plugin)
00168 {
00169     return !!plugin->methods.seek;
00170 }
00171 
00172 gboolean
00173 xmms_xform_plugin_can_browse (const xmms_xform_plugin_t *plugin)
00174 {
00175     return !!plugin->methods.browse;
00176 }
00177 
00178 gboolean
00179 xmms_xform_plugin_can_destroy (const xmms_xform_plugin_t *plugin)
00180 {
00181     return !!plugin->methods.destroy;
00182 }
00183 
00184 gboolean
00185 xmms_xform_plugin_init (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform)
00186 {
00187     return plugin->methods.init (xform);
00188 }
00189 
00190 gint
00191 xmms_xform_plugin_read (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform,
00192                         xmms_sample_t *buf, gint length, xmms_error_t *error)
00193 {
00194     return plugin->methods.read (xform, buf, length, error);
00195 }
00196 
00197 gint64
00198 xmms_xform_plugin_seek (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform,
00199                         gint64 offset, xmms_xform_seek_mode_t whence,
00200                         xmms_error_t *err)
00201 {
00202     return plugin->methods.seek (xform, offset, whence, err);
00203 }
00204 
00205 
00206 gboolean
00207 xmms_xform_plugin_browse (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform,
00208                           const gchar *url, xmms_error_t *error)
00209 {
00210     return plugin->methods.browse (xform, url, error);
00211 }
00212 
00213 void
00214 xmms_xform_plugin_destroy (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform)
00215 {
00216     plugin->methods.destroy (xform);
00217 }
00218