All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Add TTY (hearing impaired) support
@ 2010-11-18 11:26 Lucas De Marchi
  2010-11-18 11:26 ` [PATCH 2/3] phonesim: implement TTY interface Lucas De Marchi
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Lucas De Marchi @ 2010-11-18 11:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 15942 bytes --]

---
 Makefile.am                |    5 +-
 doc/text-telephony-api.txt |   38 +++++
 include/dbus.h             |    1 +
 include/text-telephony.h   |   71 ++++++++++
 src/modem.c                |    1 +
 src/ofono.h                |    2 +
 src/text-telephony.c       |  333 ++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 449 insertions(+), 2 deletions(-)
 create mode 100644 doc/text-telephony-api.txt
 create mode 100644 include/text-telephony.h
 create mode 100644 src/text-telephony.c

diff --git a/Makefile.am b/Makefile.am
index f841b4c..ee1313d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,8 @@ include_HEADERS = include/log.h include/plugin.h include/history.h \
 			include/cbs.h include/call-volume.h \
 			include/gprs.h include/gprs-context.h \
 			include/radio-settings.h include/stk.h \
-			include/audio-settings.h include/nettime.h
+			include/audio-settings.h include/nettime.h \
+			include/text-telephony.h
 
 nodist_include_HEADERS = include/version.h
 
@@ -318,7 +319,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
 			src/radio-settings.c src/stkutil.h src/stkutil.c \
 			src/nettime.c src/stkagent.c src/stkagent.h \
 			src/simfs.c src/simfs.h src/audio-settings.c \
-			src/smsagent.c src/smsagent.h
+			src/smsagent.c src/smsagent.h src/text-telephony.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/doc/text-telephony-api.txt b/doc/text-telephony-api.txt
new file mode 100644
index 0000000..8623d5f
--- /dev/null
+++ b/doc/text-telephony-api.txt
@@ -0,0 +1,38 @@
+Text Telephony hierarchy
+========================
+
+Service		org.ofono
+Interface	org.ofono.TextTelephony
+Object path	[variable prefix]/{modem0,modem1,...}
+
+Methods		dict GetProperties()
+
+			Returns all Text Telephony properties. See the
+			properties section for available properties.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void SetProperty(string name, variant value)
+
+			Changes the value of the specified property. Only
+			properties that are listed as read-write are
+			changeable. On success a PropertyChanged signal
+			will be emitted.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.DoesNotExist
+					 [service].Error.InProgress
+
+Signals		PropertyChanged(string property, variant value)
+
+			This signal indicates a changed value of the given
+			property.
+
+Properties	boolean	Powered [readwrite]
+
+			This property will enable or disable the text
+			telephony feature in the modem.
+
+			Text telephony (TTY), also known as TDD, is a feature
+			present in some modems that allow them to be used by
+			hearing impaired people.
diff --git a/include/dbus.h b/include/dbus.h
index 59b2aae..9e29afb 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -48,6 +48,7 @@ extern "C" {
 #define OFONO_PHONEBOOK_INTERFACE "org.ofono.Phonebook"
 #define OFONO_RADIO_SETTINGS_INTERFACE "org.ofono.RadioSettings"
 #define OFONO_AUDIO_SETTINGS_INTERFACE "org.ofono.AudioSettings"
+#define OFONO_TEXT_TELEPHONY_INTERFACE "org.ofono.TextTelephony"
 #define OFONO_SIM_MANAGER_INTERFACE "org.ofono.SimManager"
 #define OFONO_VOICECALL_INTERFACE "org.ofono.VoiceCall"
 #define OFONO_VOICECALL_MANAGER_INTERFACE "org.ofono.VoiceCallManager"
diff --git a/include/text-telephony.h b/include/text-telephony.h
new file mode 100644
index 0000000..fafa7dd
--- /dev/null
+++ b/include/text-telephony.h
@@ -0,0 +1,71 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __OFONO_TEXT_TELEPHONY_H
+#define __OFONO_TEXT_TELEPHONY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ofono/types.h>
+
+struct ofono_text_telephony;
+
+typedef void (*ofono_text_telephony_set_cb_t)(const struct ofono_error *error,
+						void *data);
+typedef void (*ofono_text_telephony_query_cb_t)(const struct ofono_error *error,
+						ofono_bool_t enable, void *data);
+
+struct ofono_text_telephony_driver {
+	const char *name;
+	int (*probe)(struct ofono_text_telephony *tt, unsigned int vendor,
+			void *data);
+	void (*remove)(struct ofono_text_telephony *tt);
+	void (*query_tty)(struct ofono_text_telephony *tt,
+				ofono_text_telephony_query_cb_t cb,
+				void *data);
+	void (*set_tty)(struct ofono_text_telephony *tt,
+				int enable,
+				ofono_text_telephony_set_cb_t cb,
+				void *data);
+};
+
+int ofono_text_telephony_driver_register(const struct ofono_text_telephony_driver *d);
+void ofono_text_telephony_driver_unregister(const struct ofono_text_telephony_driver *d);
+
+struct ofono_text_telephony *ofono_text_telephony_create(struct ofono_modem *modem,
+								unsigned int vendor,
+								const char *driver,
+								void *data);
+
+void ofono_text_telephony_register(struct ofono_text_telephony *tt);
+void ofono_text_telephony_remove(struct ofono_text_telephony *tt);
+
+void ofono_text_telephony_set_data(struct ofono_text_telephony *tt, void *data);
+void *ofono_text_telephony_get_data(struct ofono_text_telephony *tt);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_TEXT_TELEPHONY_H */
diff --git a/src/modem.c b/src/modem.c
index 3776461..6f1db7c 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -857,6 +857,7 @@ static const struct {
 	{ OFONO_SIM_MANAGER_INTERFACE,			"sim"	},
 	{ OFONO_STK_INTERFACE,				"stk"	},
 	{ OFONO_CONNECTION_MANAGER_INTERFACE,		"gprs"	},
+	{ OFONO_TEXT_TELEPHONY_INTERFACE,		"tty"	},
 	{ },
 };
 
diff --git a/src/ofono.h b/src/ofono.h
index 4d76d20..5218f42 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -124,6 +124,7 @@ enum ofono_atom_type {
 	OFONO_ATOM_TYPE_AUDIO_SETTINGS = 19,
 	OFONO_ATOM_TYPE_STK = 20,
 	OFONO_ATOM_TYPE_NETTIME = 21,
+	OFONO_ATOM_TYPE_TEXT_TELEPHONY = 22
 };
 
 enum ofono_atom_watch_condition {
@@ -197,6 +198,7 @@ gboolean __ofono_call_settings_is_busy(struct ofono_call_settings *cs);
 #include <ofono/gprs-context.h>
 #include <ofono/radio-settings.h>
 #include <ofono/audio-settings.h>
+#include <ofono/text-telephony.h>
 
 #include <ofono/voicecall.h>
 
diff --git a/src/text-telephony.c b/src/text-telephony.c
new file mode 100644
index 0000000..4640bd8
--- /dev/null
+++ b/src/text-telephony.c
@@ -0,0 +1,333 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "ofono.h"
+#include "common.h"
+
+static GSList *g_drivers = NULL;
+
+struct ofono_text_telephony {
+	DBusMessage *pending;
+	ofono_bool_t powered;
+	ofono_bool_t powered_pending;
+	const struct ofono_text_telephony_driver *driver;
+	void *driver_data;
+	struct ofono_atom *atom;
+};
+
+static DBusMessage *tt_get_properties_reply(DBusMessage *msg,
+						struct ofono_text_telephony *tt)
+{
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	dbus_bool_t value;
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+	value = tt->powered;
+	ofono_dbus_dict_append(&dict, "Powered", DBUS_TYPE_BOOLEAN, &value);
+	dbus_message_iter_close_container(&iter, &dict);
+
+	return reply;
+}
+
+static void tt_set_powered(struct ofono_text_telephony *tt,
+					ofono_bool_t enable)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	const char *path = __ofono_atom_get_path(tt->atom);
+	dbus_bool_t value = enable;
+
+	if (tt->powered == enable)
+		return;
+
+	ofono_dbus_signal_property_changed(conn, path,
+						OFONO_TEXT_TELEPHONY_INTERFACE,
+						"Powered",
+						DBUS_TYPE_BOOLEAN, &value);
+	tt->powered = enable;
+}
+
+static void tt_set_powered_callback(const struct ofono_error *error,
+						void *data)
+{
+	struct ofono_text_telephony *tt = data;
+	DBusMessage *reply;
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		DBG("Error setting powered property");
+
+		tt->powered_pending = tt->powered;
+
+		reply = __ofono_error_failed(tt->pending);
+		__ofono_dbus_pending_reply(&tt->pending, reply);
+
+		return;
+	}
+
+	reply = dbus_message_new_method_return(tt->pending);
+	__ofono_dbus_pending_reply(&tt->pending, reply);
+
+	tt_set_powered(tt, tt->powered_pending);
+}
+
+static void tt_send_properties_reply(struct ofono_text_telephony *tt)
+{
+	DBusMessage *reply;
+
+	reply = tt_get_properties_reply(tt->pending, tt);
+	__ofono_dbus_pending_reply(&tt->pending, reply);
+}
+
+static void tt_query_powered_callback(const struct ofono_error *error,
+						ofono_bool_t enable, void *data)
+{
+	struct ofono_text_telephony *tt = data;
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		DBusMessage *reply;
+
+		ofono_debug("Error during powered query");
+
+		reply = __ofono_error_failed(tt->pending);
+		__ofono_dbus_pending_reply(&tt->pending, reply);
+
+		return;
+	}
+
+	tt_set_powered(tt, enable);
+	tt_send_properties_reply(tt);
+}
+
+static DBusMessage *tt_get_properties(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	struct ofono_text_telephony *tt = data;
+
+	if (tt->pending)
+		return __ofono_error_busy(msg);
+
+	tt->pending = dbus_message_ref(msg);
+	tt->driver->query_tty(tt, tt_query_powered_callback, tt);
+
+	return NULL;
+}
+
+static DBusMessage *tt_set_property(DBusConnection *conn, DBusMessage *msg,
+					void *data)
+{
+	struct ofono_text_telephony *tt = data;
+	DBusMessageIter iter;
+	DBusMessageIter var;
+	const char *property;
+
+	if (tt->pending)
+		return __ofono_error_busy(msg);
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return __ofono_error_invalid_args(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __ofono_error_invalid_args(msg);
+
+	dbus_message_iter_get_basic(&iter, &property);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return __ofono_error_invalid_args(msg);
+
+	dbus_message_iter_recurse(&iter, &var);
+
+	if (g_strcmp0(property, "Powered") == 0) {
+		dbus_bool_t value;
+		int target;
+
+		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
+			return __ofono_error_invalid_args(msg);
+
+		dbus_message_iter_get_basic(&var, &value);
+		target = value;
+
+		if (tt->powered == target)
+			return dbus_message_new_method_return(msg);
+
+		tt->pending = dbus_message_ref(msg);
+		tt->powered_pending = target;
+
+		tt->driver->set_tty(tt, target,
+					tt_set_powered_callback, tt);
+		return NULL;
+	}
+
+	return __ofono_error_invalid_args(msg);
+}
+
+static GDBusMethodTable tt_methods[] = {
+	{ "GetProperties",  "",    "a{sv}",  tt_get_properties,
+						G_DBUS_METHOD_FLAG_ASYNC },
+	{ "SetProperty",    "sv",  "",       tt_set_property,
+						G_DBUS_METHOD_FLAG_ASYNC },
+	{ }
+};
+
+static GDBusSignalTable tt_signals[] = {
+	{ "PropertyChanged",	"sv" },
+	{ }
+};
+
+int ofono_text_telephony_driver_register(const struct ofono_text_telephony_driver *d)
+{
+	DBG("driver: %p, name: %s", d, d->name);
+
+	if (!d || !d->probe)
+		return -EINVAL;
+
+	g_drivers = g_slist_prepend(g_drivers, (void *)d);
+
+	return 0;
+}
+
+void ofono_text_telephony_driver_unregister(const struct ofono_text_telephony_driver *d)
+{
+	DBG("driver: %p, name: %s", d, d->name);
+
+	if (!d)
+		return;
+
+	g_drivers = g_slist_remove(g_drivers, (void *)d);
+}
+
+static void text_telephony_unregister(struct ofono_atom *atom)
+{
+	struct ofono_text_telephony *tt = __ofono_atom_get_data(atom);
+	const char *path = __ofono_atom_get_path(tt->atom);
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_modem *modem = __ofono_atom_get_modem(tt->atom);
+
+	ofono_modem_remove_interface(modem, OFONO_TEXT_TELEPHONY_INTERFACE);
+	g_dbus_unregister_interface(conn, path, OFONO_TEXT_TELEPHONY_INTERFACE);
+}
+
+static void text_telephony_remove(struct ofono_atom *atom)
+{
+	struct ofono_text_telephony *tt = __ofono_atom_get_data(atom);
+
+	DBG("atom: %p", atom);
+
+	if (!tt)
+		return;
+
+	if (tt->driver && tt->driver->remove)
+		tt->driver->remove(tt);
+
+	g_free(tt);
+}
+
+struct ofono_text_telephony *ofono_text_telephony_create(struct ofono_modem *modem,
+							unsigned int vendor,
+							const char *driver,
+							void *data)
+{
+	struct ofono_text_telephony *tt;
+	GSList *l;
+	if (!driver)
+		return NULL;
+
+	tt = g_try_new0(struct ofono_text_telephony, 1);
+	if (!tt)
+		return NULL;
+
+	tt->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_TEXT_TELEPHONY,
+						text_telephony_remove, tt);
+
+	tt->powered = -1;
+
+	for (l = g_drivers; l; l = l->next) {
+		const struct ofono_text_telephony_driver *drv = l->data;
+
+		if (g_strcmp0(drv->name, driver) != 0)
+			continue;
+
+		if (drv->probe(tt, vendor, data) < 0)
+			continue;
+
+		tt->driver = drv;
+		break;
+	}
+
+	return tt;
+}
+
+void ofono_text_telephony_register(struct ofono_text_telephony *tt)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_modem *modem = __ofono_atom_get_modem(tt->atom);
+	const char *path = __ofono_atom_get_path(tt->atom);
+
+	if (!g_dbus_register_interface(conn, path,
+					OFONO_TEXT_TELEPHONY_INTERFACE,
+						tt_methods, tt_signals,
+					NULL, tt, NULL)) {
+		ofono_error("Could not create %s interface",
+				OFONO_TEXT_TELEPHONY_INTERFACE);
+
+		return;
+	}
+
+	ofono_modem_add_interface(modem, OFONO_TEXT_TELEPHONY_INTERFACE);
+	__ofono_atom_register(tt->atom, text_telephony_unregister);
+}
+
+void ofono_text_telephony_remove(struct ofono_text_telephony *tt)
+{
+	__ofono_atom_free(tt->atom);
+}
+
+void ofono_text_telephony_set_data(struct ofono_text_telephony *tt,
+					void *data)
+{
+	tt->driver_data = data;
+}
+
+void *ofono_text_telephony_get_data(struct ofono_text_telephony *tt)
+{
+	return tt->driver_data;
+}
-- 
1.7.3.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] phonesim: implement TTY interface
  2010-11-18 11:26 [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
@ 2010-11-18 11:26 ` Lucas De Marchi
  2010-11-18 11:26 ` [PATCH 3/3] Add script to enable/disable TTY support Lucas De Marchi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2010-11-18 11:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 5464 bytes --]

---
 plugins/phonesim.c |  148 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 144 insertions(+), 4 deletions(-)

diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index d2faf42..8c31df4 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -54,6 +54,7 @@
 #include <ofono/stk.h>
 #include <ofono/sms.h>
 #include <ofono/ssn.h>
+#include <ofono/text-telephony.h>
 #include <ofono/ussd.h>
 #include <ofono/voicecall.h>
 #include <ofono/gprs.h>
@@ -64,6 +65,7 @@
 #include <drivers/atmodem/atutil.h>
 
 static const char *none_prefix[] = { NULL };
+static const char *ptty_prefix[] = { "+PTTY:", NULL };
 static int next_iface = 0;
 
 struct phonesim_data {
@@ -78,6 +80,11 @@ struct gprs_context_data {
 	char *interface;
 };
 
+struct text_telephony_data {
+	GAtChat *chat;
+	char *interface;
+};
+
 static void at_cgact_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct cb_data *cbd = user_data;
@@ -190,12 +197,140 @@ static void phonesim_context_remove(struct ofono_gprs_context *gc)
 	g_free(gcd);
 }
 
+static int phonesim_tty_probe(struct ofono_text_telephony *tt,
+				unsigned int vendor, void *data)
+{
+	GAtChat *chat = data;
+	struct text_telephony_data *ttd;
+
+	ttd = g_try_new0(struct text_telephony_data, 1);
+	if (!ttd)
+		return -ENOMEM;
+
+	ttd->chat = g_at_chat_clone(chat);
+	ttd->interface = g_strdup_printf("dummy%d", next_iface++);
+
+	ofono_text_telephony_set_data(tt, ttd);
+	ofono_text_telephony_register(tt);
+
+	return 0;
+}
+
+static void phonesim_tty_remove(struct ofono_text_telephony *tt)
+{
+	struct text_telephony_data *ttd = ofono_text_telephony_get_data(tt);
+
+	DBG("");
+
+	ofono_text_telephony_set_data(tt, NULL);
+
+	g_at_chat_unref(ttd->chat);
+	g_free(ttd->interface);
+
+	g_free(ttd);
+}
+
+static void tty_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	struct ofono_error error;
+	GAtResultIter iter;
+	ofono_text_telephony_query_cb_t cb = cbd->cb;
+	int value;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	if (!ok) {
+		cb(&error, -1, cbd->data);
+		return;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+	if (g_at_result_iter_next(&iter, "+PTTY:") == FALSE)
+		goto error;
+
+	if (g_at_result_iter_next_number(&iter, &value) == FALSE)
+		goto error;
+
+	cb(&error, value, cbd->data);
+
+	return;
+
+error:
+
+	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+}
+
+static void phonesim_tty_query(struct ofono_text_telephony *tt,
+				ofono_text_telephony_query_cb_t cb, void *data)
+{
+	struct text_telephony_data *ttd = ofono_text_telephony_get_data(tt);
+	struct cb_data *cbd = cb_data_new(cb, data);
+
+	DBG("");
+
+	if (!cbd)
+		goto error;
+
+	if (g_at_chat_send(ttd->chat, "AT+PTTY?", ptty_prefix,
+				tty_query_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, 0, data);
+}
+
+static void tty_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_text_telephony_set_cb_t cb = cbd->cb;
+	struct ofono_error error;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+	cb(&error, cbd->data);
+}
+
+static void phonesim_tty_set(struct ofono_text_telephony *tt, int enable,
+				ofono_text_telephony_set_cb_t cb, void *data)
+{
+	struct text_telephony_data *ttd = ofono_text_telephony_get_data(tt);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char buf[12];
+
+	DBG("");
+
+	if (!cbd)
+		goto error;
+
+	enable = !!enable;
+	snprintf(buf, sizeof(buf), "AT+PTTY=%d", enable);
+
+	if (g_at_chat_send(ttd->chat, buf, none_prefix,
+					tty_set_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	CALLBACK_WITH_FAILURE(cb, data);
+	g_free(cbd);
+}
+
 static struct ofono_gprs_context_driver context_driver = {
+	.name                   = "phonesim",
+	.probe                  = phonesim_context_probe,
+	.remove                 = phonesim_context_remove,
+	.activate_primary       = phonesim_activate_primary,
+	.deactivate_primary     = phonesim_deactivate_primary,
+};
+
+static struct ofono_text_telephony_driver tty_driver = {
 	.name			= "phonesim",
-	.probe			= phonesim_context_probe,
-	.remove			= phonesim_context_remove,
-	.activate_primary	= phonesim_activate_primary,
-	.deactivate_primary	= phonesim_deactivate_primary,
+	.probe			= phonesim_tty_probe,
+	.remove			= phonesim_tty_remove,
+	.query_tty		= phonesim_tty_query,
+	.set_tty		= phonesim_tty_set,
 };
 
 static int phonesim_probe(struct ofono_modem *modem)
@@ -465,6 +600,7 @@ static void phonesim_post_sim(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	ofono_text_telephony_create(modem, 0, "phonesim", data->chat);
 	ofono_phonebook_create(modem, 0, "atmodem", data->chat);
 
 	if (!data->calypso)
@@ -630,6 +766,8 @@ static int phonesim_init(void)
 
 	ofono_gprs_context_driver_register(&context_driver);
 
+	ofono_text_telephony_driver_register(&tty_driver);
+
 	parse_config(CONFIGDIR "/phonesim.conf");
 
 	return 0;
@@ -648,6 +786,8 @@ static void phonesim_exit(void)
 	g_slist_free(modem_list);
 	modem_list = NULL;
 
+	ofono_text_telephony_driver_unregister(&tty_driver);
+
 	ofono_gprs_context_driver_unregister(&context_driver);
 
 	ofono_modem_driver_unregister(&phonesim_driver);
-- 
1.7.3.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] Add script to enable/disable TTY support
  2010-11-18 11:26 [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
  2010-11-18 11:26 ` [PATCH 2/3] phonesim: implement TTY interface Lucas De Marchi
@ 2010-11-18 11:26 ` Lucas De Marchi
  2010-11-18 11:30 ` [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
  2010-11-19 22:18 ` Gustavo F. Padovan
  3 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2010-11-18 11:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 935 bytes --]

---
 test/set-tty |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 test/set-tty

diff --git a/test/set-tty b/test/set-tty
new file mode 100755
index 0000000..cbbb043
--- /dev/null
+++ b/test/set-tty
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+if len(sys.argv) == 3:
+	path = sys.argv[1]
+	enable = int(sys.argv[2])
+elif len(sys.argv) == 2:
+	manager = dbus.Interface(bus.get_object('org.ofono', '/'),
+						'org.ofono.Manager')
+	modems = manager.GetModems()
+	path = modems[0][0]
+	enable = int(sys.argv[1])
+else:
+	print "%s [PATH] {0|1}" % (sys.argv[0])
+	exit(1)
+
+print "Setting TTY for modem %s..." % path
+texttelephony = dbus.Interface(bus.get_object('org.ofono', path),
+						'org.ofono.TextTelephony')
+
+texttelephony.SetProperty("Powered", dbus.Boolean(enable));
-- 
1.7.3.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] Add TTY (hearing impaired) support
  2010-11-18 11:26 [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
  2010-11-18 11:26 ` [PATCH 2/3] phonesim: implement TTY interface Lucas De Marchi
  2010-11-18 11:26 ` [PATCH 3/3] Add script to enable/disable TTY support Lucas De Marchi
@ 2010-11-18 11:30 ` Lucas De Marchi
  2010-11-22 11:21   ` Denis Kenzior
  2010-11-19 22:18 ` Gustavo F. Padovan
  3 siblings, 1 reply; 8+ messages in thread
From: Lucas De Marchi @ 2010-11-18 11:30 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 508 bytes --]

On Thu, Nov 18, 2010 at 9:26 AM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> +                       Changes the value of the specified property. Only
> +                       properties that are listed as read-write are

A minor issue I found with other docs, it's written here as
"read-write" and in some places as "readwrite". Can these two forms be
used interchangeably? I think it would be better to let all as
read-write.



regards,

Lucas De Marchi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] Add TTY (hearing impaired) support
  2010-11-18 11:26 [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
                   ` (2 preceding siblings ...)
  2010-11-18 11:30 ` [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
@ 2010-11-19 22:18 ` Gustavo F. Padovan
  2010-11-19 22:26   ` Lucas De Marchi
  3 siblings, 1 reply; 8+ messages in thread
From: Gustavo F. Padovan @ 2010-11-19 22:18 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2938 bytes --]

Hi Lucas,

* Lucas De Marchi <lucas.demarchi@profusion.mobi> [2010-11-18 09:26:54 -0200]:

> ---
>  Makefile.am                |    5 +-
>  doc/text-telephony-api.txt |   38 +++++
>  include/dbus.h             |    1 +
>  include/text-telephony.h   |   71 ++++++++++
>  src/modem.c                |    1 +
>  src/ofono.h                |    2 +
>  src/text-telephony.c       |  333 ++++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 449 insertions(+), 2 deletions(-)
>  create mode 100644 doc/text-telephony-api.txt
>  create mode 100644 include/text-telephony.h
>  create mode 100644 src/text-telephony.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index f841b4c..ee1313d 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -13,7 +13,8 @@ include_HEADERS = include/log.h include/plugin.h include/history.h \
>  			include/cbs.h include/call-volume.h \
>  			include/gprs.h include/gprs-context.h \
>  			include/radio-settings.h include/stk.h \
> -			include/audio-settings.h include/nettime.h
> +			include/audio-settings.h include/nettime.h \
> +			include/text-telephony.h
>  
>  nodist_include_HEADERS = include/version.h
>  
> @@ -318,7 +319,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
>  			src/radio-settings.c src/stkutil.h src/stkutil.c \
>  			src/nettime.c src/stkagent.c src/stkagent.h \
>  			src/simfs.c src/simfs.h src/audio-settings.c \
> -			src/smsagent.c src/smsagent.h
> +			src/smsagent.c src/smsagent.h src/text-telephony.c
>  
>  src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
>  
> diff --git a/doc/text-telephony-api.txt b/doc/text-telephony-api.txt
> new file mode 100644
> index 0000000..8623d5f
> --- /dev/null
> +++ b/doc/text-telephony-api.txt
> @@ -0,0 +1,38 @@
> +Text Telephony hierarchy
> +========================
> +
> +Service		org.ofono
> +Interface	org.ofono.TextTelephony
> +Object path	[variable prefix]/{modem0,modem1,...}
> +
> +Methods		dict GetProperties()
> +
> +			Returns all Text Telephony properties. See the
> +			properties section for available properties.
> +
> +			Possible Errors: [service].Error.InvalidArguments
> +
> +		void SetProperty(string name, variant value)
> +
> +			Changes the value of the specified property. Only
> +			properties that are listed as read-write are
> +			changeable. On success a PropertyChanged signal
> +			will be emitted.
> +
> +			Possible Errors: [service].Error.InvalidArguments
> +					 [service].Error.DoesNotExist
> +					 [service].Error.InProgress
> +
> +Signals		PropertyChanged(string property, variant value)
> +
> +			This signal indicates a changed value of the given
> +			property.
> +
> +Properties	boolean	Powered [readwrite]

From what I remember in the discussion in the IRC, this should be
Enabled and not Powered.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] Add TTY (hearing impaired) support
  2010-11-19 22:18 ` Gustavo F. Padovan
@ 2010-11-19 22:26   ` Lucas De Marchi
  0 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2010-11-19 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 411 bytes --]

Hi, Gustavo

On Fri, Nov 19, 2010 at 8:18 PM, Gustavo F. Padovan
<padovan@profusion.mobi> wrote:
>> +Properties   boolean Powered [readwrite]
>
> From what I remember in the discussion in the IRC, this should be
> Enabled and not Powered.
>

Dennis told me to send the patch with "Powered", so we can agree here
what is the best name. Seems that Marcel prefers Powered though.


Lucas De Marchi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] Add TTY (hearing impaired) support
  2010-11-18 11:30 ` [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
@ 2010-11-22 11:21   ` Denis Kenzior
  0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2010-11-22 11:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 624 bytes --]

Hi Lucas,

On 11/18/2010 05:30 AM, Lucas De Marchi wrote:
> On Thu, Nov 18, 2010 at 9:26 AM, Lucas De Marchi
> <lucas.demarchi@profusion.mobi> wrote:
>> +                       Changes the value of the specified property. Only
>> +                       properties that are listed as read-write are
> 
> A minor issue I found with other docs, it's written here as
> "read-write" and in some places as "readwrite". Can these two forms be
> used interchangeably? I think it would be better to let all as
> read-write.

Good point, I've updated the docs to use the preferred 'readwrite' form.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] phonesim: implement TTY interface
@ 2010-11-18  2:50 Lucas De Marchi
  0 siblings, 0 replies; 8+ messages in thread
From: Lucas De Marchi @ 2010-11-18  2:50 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 5464 bytes --]

---
 plugins/phonesim.c |  148 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 144 insertions(+), 4 deletions(-)

diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index d2faf42..8c31df4 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -54,6 +54,7 @@
 #include <ofono/stk.h>
 #include <ofono/sms.h>
 #include <ofono/ssn.h>
+#include <ofono/text-telephony.h>
 #include <ofono/ussd.h>
 #include <ofono/voicecall.h>
 #include <ofono/gprs.h>
@@ -64,6 +65,7 @@
 #include <drivers/atmodem/atutil.h>
 
 static const char *none_prefix[] = { NULL };
+static const char *ptty_prefix[] = { "+PTTY:", NULL };
 static int next_iface = 0;
 
 struct phonesim_data {
@@ -78,6 +80,11 @@ struct gprs_context_data {
 	char *interface;
 };
 
+struct text_telephony_data {
+	GAtChat *chat;
+	char *interface;
+};
+
 static void at_cgact_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct cb_data *cbd = user_data;
@@ -190,12 +197,140 @@ static void phonesim_context_remove(struct ofono_gprs_context *gc)
 	g_free(gcd);
 }
 
+static int phonesim_tty_probe(struct ofono_text_telephony *tt,
+				unsigned int vendor, void *data)
+{
+	GAtChat *chat = data;
+	struct text_telephony_data *ttd;
+
+	ttd = g_try_new0(struct text_telephony_data, 1);
+	if (!ttd)
+		return -ENOMEM;
+
+	ttd->chat = g_at_chat_clone(chat);
+	ttd->interface = g_strdup_printf("dummy%d", next_iface++);
+
+	ofono_text_telephony_set_data(tt, ttd);
+	ofono_text_telephony_register(tt);
+
+	return 0;
+}
+
+static void phonesim_tty_remove(struct ofono_text_telephony *tt)
+{
+	struct text_telephony_data *ttd = ofono_text_telephony_get_data(tt);
+
+	DBG("");
+
+	ofono_text_telephony_set_data(tt, NULL);
+
+	g_at_chat_unref(ttd->chat);
+	g_free(ttd->interface);
+
+	g_free(ttd);
+}
+
+static void tty_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	struct ofono_error error;
+	GAtResultIter iter;
+	ofono_text_telephony_query_cb_t cb = cbd->cb;
+	int value;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	if (!ok) {
+		cb(&error, -1, cbd->data);
+		return;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+	if (g_at_result_iter_next(&iter, "+PTTY:") == FALSE)
+		goto error;
+
+	if (g_at_result_iter_next_number(&iter, &value) == FALSE)
+		goto error;
+
+	cb(&error, value, cbd->data);
+
+	return;
+
+error:
+
+	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+}
+
+static void phonesim_tty_query(struct ofono_text_telephony *tt,
+				ofono_text_telephony_query_cb_t cb, void *data)
+{
+	struct text_telephony_data *ttd = ofono_text_telephony_get_data(tt);
+	struct cb_data *cbd = cb_data_new(cb, data);
+
+	DBG("");
+
+	if (!cbd)
+		goto error;
+
+	if (g_at_chat_send(ttd->chat, "AT+PTTY?", ptty_prefix,
+				tty_query_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, 0, data);
+}
+
+static void tty_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_text_telephony_set_cb_t cb = cbd->cb;
+	struct ofono_error error;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+	cb(&error, cbd->data);
+}
+
+static void phonesim_tty_set(struct ofono_text_telephony *tt, int enable,
+				ofono_text_telephony_set_cb_t cb, void *data)
+{
+	struct text_telephony_data *ttd = ofono_text_telephony_get_data(tt);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char buf[12];
+
+	DBG("");
+
+	if (!cbd)
+		goto error;
+
+	enable = !!enable;
+	snprintf(buf, sizeof(buf), "AT+PTTY=%d", enable);
+
+	if (g_at_chat_send(ttd->chat, buf, none_prefix,
+					tty_set_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	CALLBACK_WITH_FAILURE(cb, data);
+	g_free(cbd);
+}
+
 static struct ofono_gprs_context_driver context_driver = {
+	.name                   = "phonesim",
+	.probe                  = phonesim_context_probe,
+	.remove                 = phonesim_context_remove,
+	.activate_primary       = phonesim_activate_primary,
+	.deactivate_primary     = phonesim_deactivate_primary,
+};
+
+static struct ofono_text_telephony_driver tty_driver = {
 	.name			= "phonesim",
-	.probe			= phonesim_context_probe,
-	.remove			= phonesim_context_remove,
-	.activate_primary	= phonesim_activate_primary,
-	.deactivate_primary	= phonesim_deactivate_primary,
+	.probe			= phonesim_tty_probe,
+	.remove			= phonesim_tty_remove,
+	.query_tty		= phonesim_tty_query,
+	.set_tty		= phonesim_tty_set,
 };
 
 static int phonesim_probe(struct ofono_modem *modem)
@@ -465,6 +600,7 @@ static void phonesim_post_sim(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	ofono_text_telephony_create(modem, 0, "phonesim", data->chat);
 	ofono_phonebook_create(modem, 0, "atmodem", data->chat);
 
 	if (!data->calypso)
@@ -630,6 +766,8 @@ static int phonesim_init(void)
 
 	ofono_gprs_context_driver_register(&context_driver);
 
+	ofono_text_telephony_driver_register(&tty_driver);
+
 	parse_config(CONFIGDIR "/phonesim.conf");
 
 	return 0;
@@ -648,6 +786,8 @@ static void phonesim_exit(void)
 	g_slist_free(modem_list);
 	modem_list = NULL;
 
+	ofono_text_telephony_driver_unregister(&tty_driver);
+
 	ofono_gprs_context_driver_unregister(&context_driver);
 
 	ofono_modem_driver_unregister(&phonesim_driver);
-- 
1.7.3.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-11-22 11:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-18 11:26 [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
2010-11-18 11:26 ` [PATCH 2/3] phonesim: implement TTY interface Lucas De Marchi
2010-11-18 11:26 ` [PATCH 3/3] Add script to enable/disable TTY support Lucas De Marchi
2010-11-18 11:30 ` [PATCH 1/3] Add TTY (hearing impaired) support Lucas De Marchi
2010-11-22 11:21   ` Denis Kenzior
2010-11-19 22:18 ` Gustavo F. Padovan
2010-11-19 22:26   ` Lucas De Marchi
  -- strict thread matches above, loose matches on Subject: below --
2010-11-18  2:50 [PATCH 2/3] phonesim: implement TTY interface Lucas De Marchi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.