From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH v2 4/7] text-telephony: implement interface/atom
Date: Wed, 24 Nov 2010 09:58:29 -0600 [thread overview]
Message-ID: <4CED3625.3020409@gmail.com> (raw)
In-Reply-To: <1290535458-18786-5-git-send-email-lucas.demarchi@profusion.mobi>
[-- Attachment #1: Type: text/plain, Size: 9566 bytes --]
Hi Lucas,
On 11/23/2010 12:04 PM, Lucas De Marchi wrote:
> ---
> Makefile.am | 2 +-
> src/ofono.h | 2 +
> src/text-telephony.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 344 insertions(+), 1 deletions(-)
> create mode 100644 src/text-telephony.c
>
> diff --git a/Makefile.am b/Makefile.am
> index fb075a0..ee1313d 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -319,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/src/ofono.h b/src/ofono.h
> index d1a4bdc..42736bb 100644
> --- a/src/ofono.h
> +++ b/src/ofono.h
> @@ -125,6 +125,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 {
> @@ -205,6 +206,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..df87378
> --- /dev/null
> +++ b/src/text-telephony.c
> @@ -0,0 +1,341 @@
> +/*
> + *
> + * 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"
> +
> +#define TEXT_TELEPHONY_FLAG_CACHED 0x1
> +
> +static GSList *g_drivers = NULL;
> +
> +struct ofono_text_telephony {
> + DBusMessage *pending;
> + int flags;
> + 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);
As mentioned previously, please use "Enabled" here.
> + 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;
> +
> + tt->flags |= TEXT_TELEPHONY_FLAG_CACHED;
> +
> + reply = tt_get_properties_reply(tt->pending, tt);
> + __ofono_dbus_pending_reply(&tt->pending, reply);
I actually prefer to fold this function into powered_callback
> +}
> +
> +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);
The oFono convention is to reply to the pending D-Bus method call and
then signal the property changed signals.
> +}
> +
> +static DBusMessage *tt_get_properties(DBusConnection *conn,
> + DBusMessage *msg, void *data)
> +{
> + struct ofono_text_telephony *tt = data;
> +
> + if (tt->flags & TEXT_TELEPHONY_FLAG_CACHED)
> + return tt_get_properties_reply(msg, tt);
> +
> + 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);
> +}
<snip>
> +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)
The preferred style is to compare to NULL, e.g. if (d == NULL)
> + return;
> +
> + g_drivers = g_slist_remove(g_drivers, (void *)d);
> +}
> +
<snip>
> +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;
Please add a newline here
> + 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;
I think it is safe to default this to 0 (off).
> +
> + 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;
> +}
> +
Otherwise, looks good.
Regards,
-Denis
next prev parent reply other threads:[~2010-11-24 15:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-23 18:04 Add text telephony support Lucas De Marchi
2010-11-23 18:04 ` [PATCH v2 1/7] text-telephony: add public header Lucas De Marchi
2010-11-24 15:28 ` Denis Kenzior
2010-11-23 18:04 ` [PATCH v2 2/7] text-telephony: define new dbus interface Lucas De Marchi
2010-11-24 15:26 ` Denis Kenzior
2010-11-23 18:04 ` [PATCH v2 3/7] text-telephony: add new interface to feature map Lucas De Marchi
2010-11-24 15:26 ` Denis Kenzior
2010-11-23 18:04 ` [PATCH v2 4/7] text-telephony: implement interface/atom Lucas De Marchi
2010-11-24 15:58 ` Denis Kenzior [this message]
2010-11-24 18:51 ` Lucas De Marchi
2010-11-24 21:29 ` Denis Kenzior
2010-11-25 11:26 ` Lucas De Marchi
2010-11-23 18:04 ` [PATCH v2 5/7] text-telephony: add documentation Lucas De Marchi
2010-11-24 15:25 ` Denis Kenzior
2010-11-25 9:53 ` Kai.Vehmanen
2010-11-23 18:04 ` [PATCH v2 6/7] phonesim: implement text-telephony atom Lucas De Marchi
2010-11-23 18:04 ` [PATCH v2 7/7] Add script to enable/disable text-telephony support Lucas De Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CED3625.3020409@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.