Mercurial > audlegacy-plugins
comparison src/paranormal/pn/pnactuatorfactory.c @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Visualization/paranormal/pn/pnactuatorfactory.c@13389e613d67 |
children |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 /* Paranormal - A highly customizable audio visualization library | |
2 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com> | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public | |
15 * License along with this library; if not, write to the Free | |
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <glib.h> | |
22 #include "pnactuatorfactory.h" | |
23 | |
24 static gboolean pn_actuator_factory_initialized = FALSE; | |
25 static GHashTable *actuator_hash; | |
26 | |
27 void | |
28 pn_actuator_factory_init (void) | |
29 { | |
30 if (pn_actuator_factory_initialized == TRUE) | |
31 return; | |
32 | |
33 /* FIXME: This should be done this way, but to avoid mixing glib version calls | |
34 * when linked to both versions, we need to use functions that are in both | |
35 * versions. | |
36 * | |
37 * uncomment this when glib-1.2 is no longer linked to by things like XMMS | |
38 */ | |
39 /* actuator_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); */ | |
40 actuator_hash = g_hash_table_new (g_str_hash, g_str_equal); | |
41 | |
42 pn_actuator_factory_initialized = TRUE; | |
43 } | |
44 | |
45 void | |
46 pn_actuator_factory_register_actuator (const gchar *name, GType type) | |
47 { | |
48 gchar *dup_name; | |
49 GType *dup_type; | |
50 | |
51 g_return_if_fail (pn_actuator_factory_initialized == TRUE); | |
52 g_return_if_fail (name != NULL); | |
53 g_return_if_fail (g_type_is_a (type, PN_TYPE_ACTUATOR)); | |
54 | |
55 /* if (pn_actuator_factory_is_registered (name)) */ | |
56 /* return; */ | |
57 | |
58 dup_name = g_strdup (name); | |
59 dup_type = g_new (GType, 1); | |
60 *dup_type = type; | |
61 | |
62 g_hash_table_insert (actuator_hash, dup_name, dup_type); | |
63 } | |
64 | |
65 void | |
66 pn_actuator_factory_unregister_actuator (const gchar *name) | |
67 { | |
68 g_return_if_fail (pn_actuator_factory_initialized == TRUE); | |
69 g_return_if_fail (name != NULL); | |
70 | |
71 g_hash_table_remove (actuator_hash, name); | |
72 } | |
73 | |
74 gboolean | |
75 pn_actuator_factory_is_registered (const gchar *name) | |
76 { | |
77 g_return_val_if_fail (pn_actuator_factory_initialized == TRUE, FALSE); | |
78 g_return_val_if_fail (name != NULL, FALSE); | |
79 | |
80 return (g_hash_table_lookup (actuator_hash, name) != NULL); | |
81 } | |
82 | |
83 PnActuator* | |
84 pn_actuator_factory_new_actuator (const gchar *name) | |
85 { | |
86 GType *type; | |
87 g_return_val_if_fail (pn_actuator_factory_initialized == TRUE, NULL); | |
88 g_return_val_if_fail (name != NULL, NULL); | |
89 | |
90 type = (GType *) g_hash_table_lookup (actuator_hash, name); | |
91 if (! type) | |
92 return NULL; | |
93 | |
94 return (PnActuator *) g_object_new (*type, NULL); | |
95 } | |
96 | |
97 PnActuator* | |
98 pn_actuator_factory_new_actuator_from_xml (xmlNodePtr node) | |
99 { | |
100 PnActuator *actuator; | |
101 | |
102 actuator = pn_actuator_factory_new_actuator ((gchar *)node->name); | |
103 if (! actuator) | |
104 return NULL; | |
105 | |
106 pn_user_object_load_thyself (PN_USER_OBJECT (actuator), node); | |
107 | |
108 return actuator; | |
109 } |