From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH_v4 5/6] cdmamodem: add status info to cdma network atom.
Date: Sun, 31 Jul 2011 05:26:03 -0500 [thread overview]
Message-ID: <4E352DBB.5010809@gmail.com> (raw)
In-Reply-To: <1312289122-22845-6-git-send-email-bertrand.aygon@intel.com>
[-- Attachment #1: Type: text/plain, Size: 5590 bytes --]
Hi Bertrand,
On 08/02/2011 07:45 AM, Bertrand Aygon wrote:
> ---
> include/cdma-netreg.h | 11 +++++++++
> src/cdma-netreg.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
Two separate patches please, and the API changes should probably be
merged into the earlier include/cdma-netreg patch.
> 2 files changed, 67 insertions(+), 0 deletions(-)
>
> diff --git a/include/cdma-netreg.h b/include/cdma-netreg.h
> index 0da7cbb..b18d500 100644
> --- a/include/cdma-netreg.h
> +++ b/include/cdma-netreg.h
> @@ -28,6 +28,12 @@ extern "C" {
>
> #include <ofono/types.h>
>
> +enum cdma_network_registration_status {
> + CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED = 0,
> + CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED = 1,
> + CDMA_NETWORK_REGISTRATION_STATUS_UNKNOWN = 2,
Is the unknown status even used by the hardware? In general oFono tries
not to introduce such 'unknown' states whenever possible.
Regardless, please keep the API definition and API implementation
consistent. Right now doc/cdma-network-api.txt does not have a value
for 'unknown'. So you must either send an RFC to update the
cdma-network-api.txt first, or remove the reference to unknown. Using
not registered as the default seems just fine to me right now...
> +};
> +
> struct ofono_cdma_netreg;
>
> struct ofono_cdma_netreg_driver {
> @@ -37,6 +43,9 @@ struct ofono_cdma_netreg_driver {
> void (*remove)(struct ofono_cdma_netreg *cdma_netreg);
> };
>
> +void ofono_cdma_netreg_status_notify(struct ofono_cdma_netreg *netreg,
> + int status);
Since you went to the trouble of defining an enum for status
information, please use that here instead of 'int'.
> +
> int ofono_cdma_netreg_driver_register(const struct ofono_cdma_netreg_driver *d);
> void ofono_cdma_netreg_driver_unregister(const struct ofono_cdma_netreg_driver *d);
>
> @@ -51,6 +60,8 @@ void ofono_cdma_netreg_remove(struct ofono_cdma_netreg *cdma_netreg);
> void ofono_cdma_netreg_set_data(struct ofono_cdma_netreg *cdma_netreg, void *data);
> void *ofono_cdma_netreg_get_data(struct ofono_cdma_netreg *cdma_netreg);
>
> +int ofono_cdma_netreg_get_status(struct ofono_cdma_netreg *cdma_netreg);
> +
Do you actually have immediate need for this function? If not, then
please remove it. It is better to not to define an API than dealing
with the repercussions of changing it later on.
> #ifdef __cplusplus
> }
> #endif
> diff --git a/src/cdma-netreg.c b/src/cdma-netreg.c
> index b1cbd53..0d7dc03 100644
> --- a/src/cdma-netreg.c
> +++ b/src/cdma-netreg.c
> @@ -32,18 +32,36 @@
> static GSList *g_drivers;
>
> struct ofono_cdma_netreg {
> + int status;
Again, please use an enum here
> const struct ofono_cdma_netreg_driver *driver;
> void *driver_data;
> struct ofono_atom *atom;
> };
>
> +static const char *cdma_registration_status_to_string(int status)
> +{
> + switch (status) {
> + case CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED:
> + return "unregistered";
> + case CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED:
> + return "registered";
> + case CDMA_NETWORK_REGISTRATION_STATUS_UNKNOWN:
> + return "unknown";
> + }
> +
> + return "";
> +}
> +
> static DBusMessage *network_get_properties(DBusConnection *conn,
> DBusMessage *msg, void *data)
> {
> + struct ofono_cdma_netreg *cdma_netreg = data;
> DBusMessage *reply;
> DBusMessageIter iter;
> DBusMessageIter dict;
>
> + const char *status = cdma_registration_status_to_string(cdma_netreg->status);
> +
> reply = dbus_message_new_method_return(msg);
> if (reply == NULL)
> return NULL;
> @@ -54,6 +72,8 @@ static DBusMessage *network_get_properties(DBusConnection *conn,
> OFONO_PROPERTIES_ARRAY_SIGNATURE,
> &dict);
>
> + ofono_dbus_dict_append(&dict, "Status", DBUS_TYPE_STRING, &status);
> +
> dbus_message_iter_close_container(&iter, &dict);
>
> return reply;
> @@ -68,6 +88,40 @@ static GDBusSignalTable cdma_netreg_manager_signals[] = {
> { }
> };
>
> +
> +static void set_registration_status(struct ofono_cdma_netreg *cdma_netreg,
> + int status)
> +{
> + const char *str_status = cdma_registration_status_to_string(status);
> + const char *path = __ofono_atom_get_path(cdma_netreg->atom);
> + DBusConnection *conn = ofono_dbus_get_connection();
> +
> + cdma_netreg->status = status;
> +
> + ofono_dbus_signal_property_changed(conn, path,
> + OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE,
> + "Status", DBUS_TYPE_STRING,
> + &str_status);
> +}
> +
> +void ofono_cdma_netreg_status_notify(struct ofono_cdma_netreg *cdma_netreg,
> + int status)
> +{
> + if (cdma_netreg == NULL)
> + return;
> +
> + if (cdma_netreg->status != status)
> + set_registration_status(cdma_netreg, status);
> +}
> +
> +int ofono_cdma_netreg_get_status(struct ofono_cdma_netreg *cdma_netreg)
> +{
> + if (cdma_netreg == NULL)
> + return -1;
> +
> + return cdma_netreg->status;
> +}
> +
> int ofono_cdma_netreg_driver_register(const struct ofono_cdma_netreg_driver *d)
> {
> DBG("driver: %p, name: %s", d, d->name);
> @@ -130,6 +184,8 @@ struct ofono_cdma_netreg *ofono_cdma_netreg_create(struct ofono_modem *modem,
> if (cdma_netreg == NULL)
> return NULL;
>
> + cdma_netreg->status = CDMA_NETWORK_REGISTRATION_STATUS_UNKNOWN;
> +
> cdma_netreg->atom = __ofono_modem_add_atom(modem,
> OFONO_ATOM_TYPE_CDMA_NETREG,
> cdma_netreg_remove, cdma_netreg);
Regards,
-Denis
next prev parent reply other threads:[~2011-07-31 10:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 12:45 [PATCH_v4 0/6] Create CDMA Network Registration atom Bertrand Aygon
2011-08-02 12:45 ` [PATCH_v4 1/6] cdmamodem: Define " Bertrand Aygon
2011-07-31 10:12 ` Denis Kenzior
2011-08-02 12:45 ` [PATCH_v4 2/6] cdmamodem: Create org.ofono.cdma.NetworkRegistration interface Bertrand Aygon
2011-07-31 10:14 ` Denis Kenzior
2011-08-02 12:45 ` [PATCH_v4 3/6] cdmamodem: Create CDMA network registration atom Bertrand Aygon
2011-08-02 12:45 ` [PATCH_v4 4/6] speedupcdma: register to " Bertrand Aygon
2011-07-31 10:15 ` Denis Kenzior
2011-08-02 12:45 ` [PATCH_v4 5/6] cdmamodem: add status info to cdma network atom Bertrand Aygon
2011-07-31 10:26 ` Denis Kenzior [this message]
2011-08-02 12:45 ` [PATCH_v4 6/6] cdmamodem: register for network status notification Bertrand Aygon
2011-07-31 10:34 ` Denis Kenzior
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=4E352DBB.5010809@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.