Recreate the navit git/gerrit project that vanished
[profile/ivi/navit.git] / navit / speech / speech_dispatcher / speech_speech_dispatcher.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 <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <glib.h>
28 #include <stdarg.h>
29 #include "config.h"
30 #include <libspeechd.h>
31 #include "plugin.h"
32 #include "speech.h"
33
34 struct speech_priv {
35         SPDConnection *conn;
36 };
37
38 static int 
39 speechd_say(struct speech_priv *this, const char *text) {
40         int err;
41
42         err = spd_sayf(this->conn, SPD_MESSAGE, text);
43         if (err != 1)
44                 return 1;
45         return 0;
46 }
47
48 static void 
49 speechd_destroy(struct speech_priv *this) {
50         spd_close(this->conn);
51         g_free(this);
52 }
53
54 static struct speech_methods speechd_meth = {
55         speechd_destroy,
56         speechd_say,
57 };
58
59 static struct speech_priv *
60 speechd_new(struct speech_methods *meth, struct attr **attrs, struct attr *attr) {
61         struct speech_priv *this;
62         SPDConnection *conn;
63
64         conn = spd_open("navit","main",NULL,SPD_MODE_SINGLE);
65         if (! conn) 
66                 return NULL;
67         this=g_new(struct speech_priv,1);
68         if (this) {
69                 this->conn=conn;
70                 *meth=speechd_meth;
71                 spd_set_punctuation(conn, SPD_PUNCT_NONE);
72         }
73         return this;
74 }
75
76
77 void
78 plugin_init(void)
79 {
80         plugin_register_speech_type("speech_dispatcher", speechd_new);
81 }