Re: [PATCH 3/5] cell-info: Atom for neighbor cell info

2011-03-03 Thread Aki Niemi
Hi Antti,

2011/2/14 Antti Paila :
> ---
>  src/cell-info.c |  475 
> +++
>  1 files changed, 475 insertions(+), 0 deletions(-)
>  create mode 100644 src/cell-info.c
>
> diff --git a/src/cell-info.c b/src/cell-info.c
> new file mode 100644
> index 000..6e70202
> --- /dev/null
> +++ b/src/cell-info.c
> @@ -0,0 +1,475 @@
> +/*
> + *
> + *  oFono - Open Source Telephony
> + *
> + *  Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
> + *
> + *  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 
> +#endif
> +
> +#include 
> +
> +#include 
> +#include 
> +
> +#include "ofono.h"
> +
> +#include "common.h"
> +#include "ofono/cell-info.h"

This doesn't belong here; you need to add an include statement for
cell-info.h into src/ofono.h.

> +
> +

Extra empty line here.

> +struct ofono_cell_info {
> +       DBusMessage *pending;
> +       struct ofono_atom *atom;
> +       const struct ofono_cell_info_driver *driver;
> +       void *driver_data;
> +};
> +
> +

Extra empty line here.

> +static DBusMessage *ci_get_cells(DBusConnection *, DBusMessage *, void *);

Can this forward declaration be avoided?

> +
> +static GSList *g_drivers = NULL;
> +
> +static GDBusMethodTable ci_methods[] = {
> +       { "AquireMeasurement",  "",     "aa{sv}",       ci_get_cells,
> +                                       G_DBUS_METHOD_FLAG_ASYNC },
> +       { }
> +};
> +
> +static GDBusSignalTable ci_signals[] = {
> +       { }
> +};
> +
> +int ofono_cell_info_driver_register(struct ofono_cell_info_driver *driver)
> +{
> +       DBG("driver: %p, name: %s", driver, driver->name);
> +
> +       if (driver->probe == NULL)
> +               return -EINVAL;
> +
> +       g_drivers = g_slist_prepend(g_drivers, (void *) driver);
> +
> +       return 0;
> +}
> +
> +void ofono_cell_info_driver_unregister(struct ofono_cell_info_driver *driver)
> +{
> +       DBG("driver: %p, name: %s", driver, driver->name);
> +
> +       g_drivers = g_slist_remove(g_drivers, (void *) driver);
> +}
> +
> +void ofono_cell_info_remove(struct ofono_cell_info *ci)
> +{
> +       __ofono_atom_free(ci->atom);
> +}
> +
> +static void cell_info_unregister(struct ofono_atom *atom)
> +{
> +       struct ofono_cell_info *ci = __ofono_atom_get_data(atom);
> +       const char *path = __ofono_atom_get_path(ci->atom);
> +       DBusConnection *conn = ofono_dbus_get_connection();
> +       struct ofono_modem *modem = __ofono_atom_get_modem(ci->atom);
> +
> +       ofono_modem_remove_interface(modem, OFONO_CELL_INFO_INTERFACE);
> +
> +       if (!g_dbus_unregister_interface(conn, path, 
> OFONO_CELL_INFO_INTERFACE))
> +               ofono_error("Failed to unregister interface %s",
> +                               OFONO_CELL_INFO_INTERFACE);
> +}
> +
> +static void cell_info_remove(struct ofono_atom *atom)
> +{
> +       struct ofono_cell_info *ci = __ofono_atom_get_data(atom);
> +       DBG("atom: %p", atom);
> +
> +       if (ci == NULL)
> +               return;
> +
> +       if (ci->driver && ci->driver->remove)
> +               ci->driver->remove(ci);
> +
> +       g_free(ci);
> +}
> +
> +void ofono_cell_info_register(struct ofono_cell_info *ci)
> +{
> +       DBusConnection *conn = ofono_dbus_get_connection();
> +       struct ofono_modem *modem = __ofono_atom_get_modem(ci->atom);
> +       const char *path = __ofono_atom_get_path(ci->atom);
> +
> +       DBG("Modem: %p", modem);
> +
> +       if (!g_dbus_register_interface(conn, path,
> +                                       OFONO_CELL_INFO_INTERFACE,
> +                                       ci_methods, ci_signals, NULL,
> +                                       ci, NULL)) {
> +               ofono_error("Could not create %s interface",
> +                                       OFONO_CELL_INFO_INTERFACE);

One too many tabs here.

> +
> +               return;
> +       }
> +
> +       ofono_modem_add_interface(modem, OFONO_CELL_INFO_INTERFACE);
> +
> +       __ofono_atom_register(ci->atom, cell_info_unregister);
> +}
> +
> +struct ofono_cell_info *ofono_cell_info_create(struct ofono_modem *modem,
> +                                       unsigned int vendor,
> +                                       const char *driver,
> +                                      

[PATCH 3/5] cell-info: Atom for neighbor cell info

2011-02-14 Thread Antti Paila
---
 src/cell-info.c |  475 +++
 1 files changed, 475 insertions(+), 0 deletions(-)
 create mode 100644 src/cell-info.c

diff --git a/src/cell-info.c b/src/cell-info.c
new file mode 100644
index 000..6e70202
--- /dev/null
+++ b/src/cell-info.c
@@ -0,0 +1,475 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ *  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 
+#endif
+
+#include 
+
+#include 
+#include 
+
+#include "ofono.h"
+
+#include "common.h"
+#include "ofono/cell-info.h"
+
+
+struct ofono_cell_info {
+   DBusMessage *pending;
+   struct ofono_atom *atom;
+   const struct ofono_cell_info_driver *driver;
+   void *driver_data;
+};
+
+
+static DBusMessage *ci_get_cells(DBusConnection *, DBusMessage *, void *);
+
+static GSList *g_drivers = NULL;
+
+static GDBusMethodTable ci_methods[] = {
+   { "AquireMeasurement",  "", "aa{sv}",   ci_get_cells,
+   G_DBUS_METHOD_FLAG_ASYNC },
+   { }
+};
+
+static GDBusSignalTable ci_signals[] = {
+   { }
+};
+
+int ofono_cell_info_driver_register(struct ofono_cell_info_driver *driver)
+{
+   DBG("driver: %p, name: %s", driver, driver->name);
+
+   if (driver->probe == NULL)
+   return -EINVAL;
+
+   g_drivers = g_slist_prepend(g_drivers, (void *) driver);
+
+   return 0;
+}
+
+void ofono_cell_info_driver_unregister(struct ofono_cell_info_driver *driver)
+{
+   DBG("driver: %p, name: %s", driver, driver->name);
+
+   g_drivers = g_slist_remove(g_drivers, (void *) driver);
+}
+
+void ofono_cell_info_remove(struct ofono_cell_info *ci)
+{
+   __ofono_atom_free(ci->atom);
+}
+
+static void cell_info_unregister(struct ofono_atom *atom)
+{
+   struct ofono_cell_info *ci = __ofono_atom_get_data(atom);
+   const char *path = __ofono_atom_get_path(ci->atom);
+   DBusConnection *conn = ofono_dbus_get_connection();
+   struct ofono_modem *modem = __ofono_atom_get_modem(ci->atom);
+
+   ofono_modem_remove_interface(modem, OFONO_CELL_INFO_INTERFACE);
+
+   if (!g_dbus_unregister_interface(conn, path, OFONO_CELL_INFO_INTERFACE))
+   ofono_error("Failed to unregister interface %s",
+   OFONO_CELL_INFO_INTERFACE);
+}
+
+static void cell_info_remove(struct ofono_atom *atom)
+{
+   struct ofono_cell_info *ci = __ofono_atom_get_data(atom);
+   DBG("atom: %p", atom);
+
+   if (ci == NULL)
+   return;
+
+   if (ci->driver && ci->driver->remove)
+   ci->driver->remove(ci);
+
+   g_free(ci);
+}
+
+void ofono_cell_info_register(struct ofono_cell_info *ci)
+{
+   DBusConnection *conn = ofono_dbus_get_connection();
+   struct ofono_modem *modem = __ofono_atom_get_modem(ci->atom);
+   const char *path = __ofono_atom_get_path(ci->atom);
+
+   DBG("Modem: %p", modem);
+
+   if (!g_dbus_register_interface(conn, path,
+   OFONO_CELL_INFO_INTERFACE,
+   ci_methods, ci_signals, NULL,
+   ci, NULL)) {
+   ofono_error("Could not create %s interface",
+   OFONO_CELL_INFO_INTERFACE);
+
+   return;
+   }
+
+   ofono_modem_add_interface(modem, OFONO_CELL_INFO_INTERFACE);
+
+   __ofono_atom_register(ci->atom, cell_info_unregister);
+}
+
+struct ofono_cell_info *ofono_cell_info_create(struct ofono_modem *modem,
+   unsigned int vendor,
+   const char *driver,
+   void *data)
+{
+   struct ofono_cell_info *ci;
+   GSList *l;
+
+   if (driver == NULL)
+   return NULL;
+
+   ci = g_try_new0(struct ofono_cell_info, 1);
+   if (ci == NULL)
+   return NULL;
+
+   ci->atom = __ofono_modem_add_atom(modem,
+   OFONO_ATOM_TYPE_CELL_INFO,
+   cell_info_remove, ci);
+
+   for (l = g_drivers; l; l = l->next) {
+   const struct ofono_cell_info_driver *drv = l->data;
+
+   if (g