Fix:Core:Further cleanups
[navit-package] / navit / speech.c
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 #include <glib.h>
21 #include <string.h>
22 #include "debug.h"
23 #include "item.h"
24 #include "speech.h"
25 #include "plugin.h"
26
27 struct speech {
28         struct speech_priv *priv;
29         struct speech_methods meth;
30 };
31
32 struct speech *
33 speech_new(struct attr *parent, struct attr **attrs) 
34 {
35         struct speech *this_;
36         struct speech_priv *(*speech_new)(const char *data, struct speech_methods *meth);
37         struct attr *type;
38
39         type=attr_search(attrs, NULL, attr_type);
40         if (! type) {
41                 dbg(0,"type missing\n");
42                 return NULL;
43         }
44         dbg(1,"type='%s'\n", type->u.str);
45         speech_new=plugin_get_speech_type(type->u.str);
46         dbg(1,"new=%p\n", speech_new);
47         if (! speech_new) {
48                 dbg(0,"wrong type '%s'\n", type->u.str);
49                 return NULL;
50         }
51         this_=g_new0(struct speech, 1);
52         this_->priv=speech_new(attrs, &this_->meth);
53         dbg(1, "say=%p\n", this_->meth.say);
54         dbg(1,"priv=%p\n", this_->priv);
55         if (! this_->priv) {
56                 g_free(this_);
57                 return NULL;
58         }
59         dbg(1,"return %p\n", this_);
60         return this_;
61 }
62
63 int
64 speech_say(struct speech *this_, const char *text)
65 {
66         dbg(1, "this_=%p text='%s' calling %p\n", this_, text, this_->meth.say);
67         return (this_->meth.say)(this_->priv, text);
68 }