Add:Core:speech_dbus
[navit-package] / navit / speech / dbus / speech_dbus.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 <stdlib.h>
21 #include <glib.h>
22 #include "config.h"
23 #include "item.h"
24 #include "plugin.h"
25 #include "navit.h"
26 #include "attr.h"
27 #include "callback.h"
28 #include "speech.h"
29
30 struct speech_priv {
31         struct navit *nav;
32 };
33
34 static int 
35 speech_dbus_say(struct speech_priv *this, const char *text)
36 {
37         struct attr attr1,attr2,cb,*attr_list[3];
38         int valid=0;
39         attr1.type=attr_type;
40         attr1.u.str="speech";
41         attr2.type=attr_data;
42         attr2.u.str=(char *)text;
43         attr_list[0]=&attr1;
44         attr_list[1]=&attr2;
45         attr_list[2]=NULL;
46         if (navit_get_attr(this->nav, attr_callback_list, &cb, NULL))
47                 callback_list_call_attr_4(cb.u.callback_list, attr_command, "dbus_send_signal", attr_list, NULL, &valid);
48         return 0;
49 }
50
51 static void 
52 speech_dbus_destroy(struct speech_priv *this) {
53         g_free(this);
54 }
55
56 static struct speech_methods speech_dbus_meth = {
57         speech_dbus_destroy,
58         speech_dbus_say,
59 };
60
61 static struct speech_priv *
62 speech_dbus_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) {
63         struct speech_priv *this;
64         if (!parent || parent->type != attr_navit)
65                 return NULL;
66         this=g_new(struct speech_priv,1);
67         this->nav=parent->u.navit;
68         *meth=speech_dbus_meth;
69         return this;
70 }
71
72
73 void
74 plugin_init(void)
75 {
76         plugin_register_speech_type("dbus", speech_dbus_new);
77 }