[PATCH] common: Fix parsing SS control string

2013-05-22 Thread Lucas De Marchi
It's not possible to be both greater than '9' and less than '0'. This
would lead to accepting things like #$33# as activation and *$33# as
deactivation, even though the string makes no sense.
---
 src/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/common.c b/src/common.c
index 94d70dd..17d1d58 100644
--- a/src/common.c
+++ b/src/common.c
@@ -554,7 +554,7 @@ gboolean parse_ss_control_string(char *str, int *ss_type,
 
cur = 1;
 
-   if (str[1] != '*'  str[1] != '#'  str[1]  '9'  str[1]  '0')
+   if (str[1] != '*'  str[1] != '#'  (str[1]  '9' || str[1]  '0'))
goto out;
 
if (str[0] == '#'  str[1] == '*')
-- 
1.8.2.3

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH] common: Fix parsing SS control string

2013-05-22 Thread Lucas De Marchi
On Wed, May 22, 2013 at 6:28 PM, Lucas De Marchi
lucas.demar...@profusion.mobi wrote:
 It's not possible to be both greater than '9' and less than '0'. This
 would lead to accepting things like #$33# as activation and *$33# as
 deactivation, even though the string makes no sense.
 ---
  src/common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/src/common.c b/src/common.c
 index 94d70dd..17d1d58 100644
 --- a/src/common.c
 +++ b/src/common.c
 @@ -554,7 +554,7 @@ gboolean parse_ss_control_string(char *str, int *ss_type,

 cur = 1;

 -   if (str[1] != '*'  str[1] != '#'  str[1]  '9'  str[1]  '0')
 +   if (str[1] != '*'  str[1] != '#'  (str[1]  '9' || str[1]  '0'))
 goto out;

this is actually caught later in the function:

for (i = 0; i  strlen(*sc); i++)
if (!g_ascii_isdigit((*sc)[i]))
goto out;

But fixing the check would be good.


Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 2/2] gitignore: Ignore file generated by Automake 1.13

2013-05-22 Thread Lucas De Marchi
Automake = 1.13 enables parallel-tests option by default which uses a
test-driver script (copied by automake). Ignore this file and the files
generated by this script.
---
 .gitignore | 4 
 1 file changed, 4 insertions(+)

diff --git a/.gitignore b/.gitignore
index 91668c7..b9c23a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,8 @@ ltmain.sh
 missing
 stamp-h1
 autom4te.cache
+test-driver
+test-suite.log
 
 ofono.pc
 include/ofono
@@ -42,6 +44,8 @@ unit/test-mux
 unit/test-caif
 unit/test-stkutil
 unit/test-cdmasms
+unit/test-*.log
+unit/test-*.trs
 
 tools/huawei-audio
 tools/auto-enable
-- 
1.8.2.3

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 1/2] stk: Fix sizeof on memcpy

2013-05-22 Thread Lucas De Marchi
src/stk.c: In function ‘__ofono_cbs_sim_download’:
src/stk.c:283:45: error: argument to ‘sizeof’ in ‘memcpy’ call is the
same expression as the source; did you mean to dereference it?
[-Werror=sizeof-pointer-memaccess]
  memcpy(e.cbs_pp_download.page, msg, sizeof(msg));
   ^
---
 src/stk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/stk.c b/src/stk.c
index 7974751..01c95b5 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -280,7 +280,7 @@ void __ofono_cbs_sim_download(struct ofono_stk *stk, const 
struct cbs *msg)
 
e.type = STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD;
e.src = STK_DEVICE_IDENTITY_TYPE_NETWORK;
-   memcpy(e.cbs_pp_download.page, msg, sizeof(msg));
+   memcpy(e.cbs_pp_download.page, msg, sizeof(*msg));
 
err = stk_send_envelope(stk, e, stk_cbs_download_cb,
ENVELOPE_RETRIES_DEFAULT);
-- 
1.8.2.3

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH mmsd 2/3] build: Do not use deprecated AM_CONFIG_HEADER

2013-02-14 Thread Lucas De Marchi
The long-obsoleted AM_CONFIG_HEADER macro was removed in automake 1.13.
Use AC_CONFIG_HEADERS instead.
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 6b5e1b1..dd8e93a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ(2.60)
 AC_INIT(mmsd, 0.0)
 
 AM_INIT_AUTOMAKE([foreign subdir-objects color-tests])
-AM_CONFIG_HEADER(config.h)
+AC_CONFIG_HEADERS(config.h)
 
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
-- 
1.8.1.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 3/3] build: Use AM_CPPFLAGS instead of INCLUDES

2013-02-14 Thread Lucas De Marchi
Makefile.am:49: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or 
'*_CPPFLAGS')
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index f802388..ee2c715 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -46,7 +46,7 @@ AM_CFLAGS = @GLIB_CFLAGS@ @DBUS_CFLAGS@ $(builtin_cflags) \
-DPLUGINDIR=\$(plugindir)\ \
-DPUSHCONFDIR=\$(pushconfdir)\
 
-INCLUDES = -I$(builddir)/src -I$(srcdir)/src -I$(srcdir)/gdbus
+AM_CPPFLAGS = -I$(builddir)/src -I$(srcdir)/src -I$(srcdir)/gdbus
 
 CLEANFILES = src/builtin.h
 
-- 
1.8.1.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/3] build: Do not use deprecated AM_CONFIG_HEADER

2013-01-16 Thread Lucas De Marchi
The long-obsoleted AM_CONFIG_HEADER macro was removed in automake 1.13.
Use AC_CONFIG_HEADERS instead.
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 7db4198..a4a350f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ(2.60)
 AC_INIT(ofono, 1.12)
 
 AM_INIT_AUTOMAKE([foreign subdir-objects color-tests])
-AM_CONFIG_HEADER(config.h)
+AC_CONFIG_HEADERS(config.h)
 
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
-- 
1.8.1.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/3] build: Use AM_CPPFLAGS instead of INCLUDES

2013-01-16 Thread Lucas De Marchi
Makefile.am:518: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or 
'*_CPPFLAGS')
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index ad12c0f..f24cac7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -528,7 +528,7 @@ AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @USB_CFLAGS@ \
-DOFONO_PLUGIN_BUILTIN \
-DPLUGINDIR=\$(build_plugindir)\
 
-INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/src \
+AM_CPPFLAGS = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/src \
-I$(srcdir)/gdbus -I$(srcdir)/gisi -I$(srcdir)/gatchat \
-I$(srcdir)/btio
 
-- 
1.8.1.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/3] storage: Include sys/types.h for ssize_t

2013-01-16 Thread Lucas De Marchi
src/storage.h:32:1: error: unknown type name 'ssize_t'
src/storage.h:36:1: error: unknown type name 'ssize_t'
---
 src/storage.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/storage.h b/src/storage.h
index c455bae..70446ad 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -26,6 +26,7 @@
 #endif
 
 #include fcntl.h
+#include sys/types.h
 
 int create_dirs(const char *filename, const mode_t mode);
 
-- 
1.8.1.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 1/3] README: add information about mailing list

2013-01-10 Thread Lucas De Marchi
---
 README | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/README b/README
index e33be69..fdfeafb 100644
--- a/README
+++ b/README
@@ -19,3 +19,9 @@ Configure automatically searches for all required components 
and packages.
 
 To compile and install run:
make  make install
+
+Information
+===
+
+Mailing list:
+   ofono@ofono.org
-- 
1.8.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 2/3] build: Do not use deprecated AM_CONFIG_HEADER

2013-01-10 Thread Lucas De Marchi
The long-obsoleted AM_CONFIG_HEADER macro was removed in automake 1.13.
Use AC_CONFIG_HEADERS instead.
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 6b5e1b1..dd8e93a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ(2.60)
 AC_INIT(mmsd, 0.0)
 
 AM_INIT_AUTOMAKE([foreign subdir-objects color-tests])
-AM_CONFIG_HEADER(config.h)
+AC_CONFIG_HEADERS(config.h)
 
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
-- 
1.8.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 3/3] build: Use AM_CPPFLAGS instead of INCLUDES

2013-01-10 Thread Lucas De Marchi
Makefile.am:49: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or 
'*_CPPFLAGS')
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index f802388..ee2c715 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -46,7 +46,7 @@ AM_CFLAGS = @GLIB_CFLAGS@ @DBUS_CFLAGS@ $(builtin_cflags) \
-DPLUGINDIR=\$(plugindir)\ \
-DPUSHCONFDIR=\$(pushconfdir)\
 
-INCLUDES = -I$(builddir)/src -I$(srcdir)/src -I$(srcdir)/gdbus
+AM_CPPFLAGS = -I$(builddir)/src -I$(srcdir)/src -I$(srcdir)/gdbus
 
 CLEANFILES = src/builtin.h
 
-- 
1.8.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/4] build: Do not use deprecated AM_CONFIG_HEADER

2013-01-10 Thread Lucas De Marchi
The long-obsoleted AM_CONFIG_HEADER macro was removed in automake 1.13.
Use AC_CONFIG_HEADERS instead.
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 2d6247d..badbf9b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ(2.60)
 AC_INIT(ofono, 1.11)
 
 AM_INIT_AUTOMAKE([foreign subdir-objects color-tests])
-AM_CONFIG_HEADER(config.h)
+AC_CONFIG_HEADERS(config.h)
 
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
-- 
1.8.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/4] build: Do not use the deprecated AM_PROG_MKDIR_P

2013-01-10 Thread Lucas De Marchi
configure.ac:25: warning: The 'AM_PROG_MKDIR_P' macro is deprecated, and will 
soon be removed.
configure.ac:25: You should use the Autoconf-provided 'AC_PROG_MKDIR_P' macro 
instead,
configure.ac:25: and use '$(MKDIR_P)' instead of '$(mkdir_p)'in your 
Makefile.am files.

We were already using MKDIR_P everywhere.
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index badbf9b..e4561b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@ AC_PROG_CC
 AM_PROG_CC_C_O
 AC_PROG_CC_PIE
 AC_PROG_INSTALL
-AM_PROG_MKDIR_P
+AC_PROG_MKDIR_P
 
 m4_define([_LT_AC_TAGCONFIG], [])
 m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])])
-- 
1.8.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/4] build: Use AM_CPPFLAGS instead of INCLUDES

2013-01-10 Thread Lucas De Marchi
Makefile.am:518: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or 
'*_CPPFLAGS')
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 40a83dc..86a1f30 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -515,7 +515,7 @@ AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @USB_CFLAGS@ \
-DOFONO_PLUGIN_BUILTIN \
-DPLUGINDIR=\$(build_plugindir)\
 
-INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/src \
+AM_CPPFLAGS = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/src \
-I$(srcdir)/gdbus -I$(srcdir)/gisi -I$(srcdir)/gatchat \
-I$(srcdir)/btio
 
-- 
1.8.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 4/4] storage: Include sys/types.h for ssize_t

2013-01-10 Thread Lucas De Marchi
src/storage.h:32:1: error: unknown type name 'ssize_t'
src/storage.h:36:1: error: unknown type name 'ssize_t'
---
 src/storage.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/storage.h b/src/storage.h
index c455bae..70446ad 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -26,6 +26,7 @@
 #endif
 
 #include fcntl.h
+#include sys/types.h
 
 int create_dirs(const char *filename, const mode_t mode);
 
-- 
1.8.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 0/3] gdbus patches

2012-09-27 Thread Lucas De Marchi
These patches were applied to BlueZ repository. Please, have a look and apply
them on other projects.

Johan Hedberg (1):
  gdbus: Fix crash when getting disconnected from the bus

Lucas De Marchi (2):
  gdbus: Fix wrong signal handler match
  gdbus: Refactor filter_data_find()

 gdbus/mainloop.c |   9 ++--
 gdbus/watch.c| 122 ---
 2 files changed, 86 insertions(+), 45 deletions(-)

-- 
1.7.12.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/3] gdbus: Fix crash when getting disconnected from the bus

2012-09-27 Thread Lucas De Marchi
From: Johan Hedberg johan.hedb...@intel.com

When getting disconnected from the bus sometimes (maybe always?)
dbus_watch_handle() can cause the info context to be free'd meaning
that we should not try to access it after the call. The only member we
need access to is the connection pointer and as the code already has a
ref() call for it it's only natural to solve the issue by adding a local
variable not dependent on info.

The backtrace of the crash fixed looks as follows:

 Invalid read of size 8
   at 0x121085: watch_func (mainloop.c:105)
   by 0x4C72694: g_main_context_dispatch (gmain.c:2539)
   by 0x4C729C7: g_main_context_iterate.isra.23 (gmain.c:3146)
   by 0x4C72DC1: g_main_loop_run (gmain.c:3340)
   by 0x120541: main (main.c:551)
 Address 0x5bbcd90 is 16 bytes inside a block of size 24 free'd
   at 0x4A079AE: free (vg_replace_malloc.c:427)
   by 0x4C7837E: g_free (gmem.c:252)
   by 0x4F708BF: dbus_watch_set_data (dbus-watch.c:614)
   by 0x4F70938: _dbus_watch_unref (dbus-watch.c:132)
   by 0x4F6E9A7: _dbus_transport_handle_watch (dbus-transport.c:884)
   by 0x4F59AFB: _dbus_connection_handle_watch (dbus-connection.c:1497)
   by 0x4F70AF9: dbus_watch_handle (dbus-watch.c:683)
   by 0x121084: watch_func (mainloop.c:103)
   by 0x4C72694: g_main_context_dispatch (gmain.c:2539)
   by 0x4C729C7: g_main_context_iterate.isra.23 (gmain.c:3146)
   by 0x4C72DC1: g_main_loop_run (gmain.c:3340)
   by 0x120541: main (main.c:551)
---
 gdbus/mainloop.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdbus/mainloop.c b/gdbus/mainloop.c
index cff326f..099b67f 100644
--- a/gdbus/mainloop.c
+++ b/gdbus/mainloop.c
@@ -92,8 +92,9 @@ static gboolean watch_func(GIOChannel *chan, GIOCondition 
cond, gpointer data)
struct watch_info *info = data;
unsigned int flags = 0;
DBusDispatchStatus status;
+   DBusConnection *conn;
 
-   dbus_connection_ref(info-conn);
+   conn = dbus_connection_ref(info-conn);
 
if (cond  G_IO_IN)  flags |= DBUS_WATCH_READABLE;
if (cond  G_IO_OUT) flags |= DBUS_WATCH_WRITABLE;
@@ -102,10 +103,10 @@ static gboolean watch_func(GIOChannel *chan, GIOCondition 
cond, gpointer data)
 
dbus_watch_handle(info-watch, flags);
 
-   status = dbus_connection_get_dispatch_status(info-conn);
-   queue_dispatch(info-conn, status);
+   status = dbus_connection_get_dispatch_status(conn);
+   queue_dispatch(conn, status);
 
-   dbus_connection_unref(info-conn);
+   dbus_connection_unref(conn);
 
return TRUE;
 }
-- 
1.7.12.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/3] gdbus: Fix wrong signal handler match

2012-09-27 Thread Lucas De Marchi
When we add a signal handler with g_dbus_add_signal_watch(), this
function tries to multiplex the matches added in libdbus by checking
if there's a previous filter_data with the same fields. However, if the
field is NULL it accepts as being the same. The result is that the
following watches will use the same filter data:

watch1 = g_dbus_add_signal_watch(conn, BUS_NAME, NULL, iface, member,
cb1, data1, NULL);
watch2 = g_dbus_add_signal_watch(conn, BUS_NAME, /path2, iface, member,
cb2, data2, NULL);
watch3 = g_dbus_add_signal_watch(conn, BUS_NAME, /path3, iface, member,
cb3, data3, NULL);

The result is that when a signal arrives with path == /path2, all 3
callbacks above will be called, with the same signal delivered to all of
them.

Another problem is that, if we invert the calls like below, only signals
to cb1 will never be trigerred, nonetheless it used path == NULL.

watch2 = g_dbus_add_signal_watch(conn, BUS_NAME, /path2, iface, member,
cb2, data2, NULL);
watch1 = g_dbus_add_signal_watch(conn, BUS_NAME, NULL, iface, member,
cb1, data1, NULL);
watch3 = g_dbus_add_signal_watch(conn, BUS_NAME, /path3, iface, member,
cb3, data3, NULL);

This is fixed by not multiplexing the matchs with filter data if any of
the fields are different, including being NULL. When a signal arrives,
if a field is NULL we accept it as a match, but not when adding the
signal handler.
---
 gdbus/watch.c | 115 +++---
 1 file changed, 94 insertions(+), 21 deletions(-)

diff --git a/gdbus/watch.c b/gdbus/watch.c
index d749176..2661928 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -78,6 +78,47 @@ struct filter_data {
gboolean registered;
 };
 
+static struct filter_data *filter_data_find_match(DBusConnection *connection,
+   const char *name,
+   const char *owner,
+   const char *path,
+   const char *interface,
+   const char *member,
+   const char *argument)
+{
+   GSList *current;
+
+   for (current = listeners;
+   current != NULL; current = current-next) {
+   struct filter_data *data = current-data;
+
+   if (connection != data-connection)
+   continue;
+
+   if (g_strcmp0(name, data-name) != 0)
+   continue;
+
+   if (g_strcmp0(owner, data-owner) != 0)
+   continue;
+
+   if (g_strcmp0(path, data-path) != 0)
+   continue;
+
+   if (g_strcmp0(interface, data-interface) != 0)
+   continue;
+
+   if (g_strcmp0(member, data-member) != 0)
+   continue;
+
+   if (g_strcmp0(argument, data-argument) != 0)
+   continue;
+
+   return data;
+   }
+
+   return NULL;
+}
+
 static struct filter_data *filter_data_find(DBusConnection *connection,
const char *name,
const char *owner,
@@ -221,8 +262,8 @@ static struct filter_data *filter_data_get(DBusConnection 
*connection,
name = sender;
 
 proceed:
-   data = filter_data_find(connection, name, owner, path, interface,
-   member, argument);
+   data = filter_data_find_match(connection, name, owner, path,
+   interface, member, argument);
if (data)
return data;
 
@@ -501,6 +542,7 @@ static DBusHandlerResult message_filter(DBusConnection 
*connection,
 {
struct filter_data *data;
const char *sender, *path, *iface, *member, *arg = NULL;
+   GSList *current, *delete_listener = NULL;
 
/* Only filter signals */
if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
@@ -512,30 +554,63 @@ static DBusHandlerResult message_filter(DBusConnection 
*connection,
member = dbus_message_get_member(message);
dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, arg, 
DBUS_TYPE_INVALID);
 
-   /* Sender is always bus name */
-   data = filter_data_find(connection, NULL, sender, path, iface, member,
-   arg);
-   if (data == NULL) {
-   error(Got %s.%s signal which has no listeners, iface, member);
-   return 

[PATCH 3/3] gdbus: Refactor filter_data_find()

2012-09-27 Thread Lucas De Marchi
Now this function is only used for searching the listeners of a
connection and the other parameters are not needed anymore.
---
 gdbus/watch.c | 43 +--
 1 file changed, 5 insertions(+), 38 deletions(-)

diff --git a/gdbus/watch.c b/gdbus/watch.c
index 2661928..a402ca9 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -119,13 +119,7 @@ static struct filter_data 
*filter_data_find_match(DBusConnection *connection,
return NULL;
 }
 
-static struct filter_data *filter_data_find(DBusConnection *connection,
-   const char *name,
-   const char *owner,
-   const char *path,
-   const char *interface,
-   const char *member,
-   const char *argument)
+static struct filter_data *filter_data_find(DBusConnection *connection)
 {
GSList *current;
 
@@ -136,30 +130,6 @@ static struct filter_data *filter_data_find(DBusConnection 
*connection,
if (connection != data-connection)
continue;
 
-   if (name  data-name 
-   g_str_equal(name, data-name) == FALSE)
-   continue;
-
-   if (owner  data-owner 
-   g_str_equal(owner, data-owner) == FALSE)
-   continue;
-
-   if (path  data-path 
-   g_str_equal(path, data-path) == FALSE)
-   continue;
-
-   if (interface  data-interface 
-   g_str_equal(interface, data-interface) == 
FALSE)
-   continue;
-
-   if (member  data-member 
-   g_str_equal(member, data-member) == FALSE)
-   continue;
-
-   if (argument  data-argument 
-   g_str_equal(argument, data-argument) == FALSE)
-   continue;
-
return data;
}
 
@@ -245,7 +215,7 @@ static struct filter_data *filter_data_get(DBusConnection 
*connection,
struct filter_data *data;
const char *name = NULL, *owner = NULL;
 
-   if (filter_data_find(connection, NULL, NULL, NULL, NULL, NULL, NULL) == 
NULL) {
+   if (filter_data_find(connection) == NULL) {
if (!dbus_connection_add_filter(connection,
message_filter, NULL, NULL)) {
error(dbus_connection_add_filter() failed);
@@ -419,8 +389,7 @@ static gboolean filter_data_remove_callback(struct 
filter_data *data,
listeners = g_slist_remove(listeners, data);
 
/* Remove filter if there are no listeners left for the connection */
-   if (filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
-   NULL) == NULL)
+   if (filter_data_find(connection) == NULL)
dbus_connection_remove_filter(connection, message_filter,
NULL);
 
@@ -613,8 +582,7 @@ static DBusHandlerResult message_filter(DBusConnection 
*connection,
g_slist_free(delete_listener);
 
/* Remove filter if there are no listeners left for the connection */
-   if (filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
-   NULL) == NULL)
+   if (filter_data_find(connection) == NULL)
dbus_connection_remove_filter(connection, message_filter,
NULL);
 
@@ -810,8 +778,7 @@ void g_dbus_remove_all_watches(DBusConnection *connection)
 {
struct filter_data *data;
 
-   while ((data = filter_data_find(connection, NULL, NULL, NULL, NULL,
-   NULL, NULL))) {
+   while ((data = filter_data_find(connection))) {
listeners = g_slist_remove(listeners, data);
filter_data_call_and_free(data);
}
-- 
1.7.12.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC] HFP support into oFono and BlueZ

2012-08-21 Thread Lucas De Marchi
Hi Zhao,

On Thu, Jan 21, 2010 at 5:54 AM, Zhao Forrest forrest.z...@gmail.com wrote:
 Your patch removes many DBus APIs provided by audio/gateway.c, which
 was originally designed to provide a set of DBus functions/signals for
 ease of application development. In other words, your patch is too
 oFono-specific, and is not a general support for HFP HF unit role in
 BlueZ IMO. The DBus interface provided by your patch is not easy to
 develop the application because the application developer has to parse
 the AT commands by himself. I know that oFono could parse AT commands.
 But I don't think it a common case for other application developers.
 Why not extend audio/gateway.c instead of removing its DBus APIs or
 create a new file to support HFP for oFono in blueZ?

 I think maybe Marcel would have more comments on this to give a clear 
 direction.

First of all, please don't top-post to this list.

Applications developers don't have to parse the AT commands by
themselves but rather use a telephony stack that implements the DBus
APIs.

This is kind of an agent (as in the pairing process)  that anyone
could implement. oFono implements it, so it's 1 option.


Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/4] stemgr: watch for signals only on MGR_SERVICE

2012-06-28 Thread Lucas De Marchi
---
 plugins/stemgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/stemgr.c b/plugins/stemgr.c
index 126ec4e..7e434d3 100644
--- a/plugins/stemgr.c
+++ b/plugins/stemgr.c
@@ -337,8 +337,8 @@ static gboolean property_changed(DBusConnection *connection,
 
 static void mgr_connect(DBusConnection *connection, void *user_data)
 {
-   property_changed_watch = g_dbus_add_signal_watch(connection, NULL,
-   NULL,
+   property_changed_watch = g_dbus_add_signal_watch(connection,
+   MGR_SERVICE, NULL,
MGR_MODEM_INTERFACE,
PROPERTY_CHANGED,
property_changed,
-- 
1.7.11.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 0/4] Add bus name to signal watches

2012-06-28 Thread Lucas De Marchi
First patch is just one that was still pending locally. The other ones fix the
calls to g_dbus_add_signal_watch() to actually watch only the desired bus. It
depends on previous patch for gdbus to be applied first, otherwise libdbus may
call abort() when we exit.

Lucas De Marchi (4):
  README: add information about mailing list and site
  bluetooth: watch for signals only on BLUEZ_SERVICE
  stemgr: watch for signals only on MGR_SERVICE
  tools: watch for signals only on OFONO_SERVICE

 README   |  9 +
 plugins/bluetooth.c  | 13 -
 plugins/stemgr.c |  4 ++--
 tools/auto-enable.c  | 20 ++--
 tools/huawei-audio.c | 17 +
 5 files changed, 38 insertions(+), 25 deletions(-)

-- 
1.7.11.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/4] bluetooth: watch for signals only on BLUEZ_SERVICE

2012-06-28 Thread Lucas De Marchi
---
 plugins/bluetooth.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index cb5fe24..91c8d18 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -840,22 +840,25 @@ static void bluetooth_ref(void)
bluetooth_connect,
bluetooth_disconnect, NULL, NULL);
 
-   adapter_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
-   BLUEZ_MANAGER_INTERFACE,
+   adapter_added_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE,
+   NULL, BLUEZ_MANAGER_INTERFACE,
AdapterAdded,
adapter_added, NULL, NULL);
 
-   adapter_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+   adapter_removed_watch = g_dbus_add_signal_watch(connection,
+   BLUEZ_SERVICE, NULL,
BLUEZ_MANAGER_INTERFACE,
AdapterRemoved,
adapter_removed, NULL, NULL);
 
-   device_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+   device_removed_watch = g_dbus_add_signal_watch(connection,
+   BLUEZ_SERVICE, NULL,
BLUEZ_ADAPTER_INTERFACE,
DeviceRemoved,
device_removed, NULL, NULL);
 
-   property_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+   property_watch = g_dbus_add_signal_watch(connection,
+   BLUEZ_SERVICE, NULL,
BLUEZ_DEVICE_INTERFACE,
PropertyChanged,
property_changed, NULL, NULL);
-- 
1.7.11.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH 3/3] doc: Add new D-Bus methods to service interface

2012-05-22 Thread Lucas De Marchi
On Mon, May 21, 2012 at 12:59 PM, Ronald Tessier
ronald.tess...@linux.intel.com wrote:
 ---
  doc/service-api.txt |   20 
  1 files changed, 20 insertions(+), 0 deletions(-)

 diff --git a/doc/service-api.txt b/doc/service-api.txt
 index 36e1161..02396ff 100644
 --- a/doc/service-api.txt
 +++ b/doc/service-api.txt
 @@ -63,6 +63,26 @@ Methods              array{object,dict} GetMessages()
                                [service].Error.PermanentContentNotAccepted
                                [service].Error.PermanentLackOfPrepaid

 +               void DeleteMessages(array{object})
 +
 +                       Delete an array of message objects that represents
 +                       the currently stored messages to delete.
 +
 +                       Possible Errors: [service].Error.InvalidArguments
 +
 +               void DeleteConversation(string number)


Could we mark these as [TODO], so we don't  get confused while reading
the doc + code and realizing they don't match?


Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 01/12] Constify GDBus method tables

2012-05-19 Thread Lucas De Marchi
From: Henrique Dante de Almeida hda...@profusion.mobi

Constify method tables with the following command:

find . -name '*.[ch]' -exec \
 sed -i 's/\(GDBusMethodTable .* =\)/const \1/g' {} \;
---
 plugins/hfp_hf.c|2 +-
 plugins/push-notification.c |2 +-
 plugins/smart-messaging.c   |2 +-
 src/audio-settings.c|2 +-
 src/call-barring.c  |2 +-
 src/call-forwarding.c   |2 +-
 src/call-meter.c|2 +-
 src/call-settings.c |2 +-
 src/call-volume.c   |2 +-
 src/cbs.c   |2 +-
 src/cdma-connman.c  |2 +-
 src/cdma-netreg.c   |2 +-
 src/cdma-sms.c  |2 +-
 src/cdma-voicecall.c|2 +-
 src/ctm.c   |2 +-
 src/gnss.c  |2 +-
 src/gprs.c  |4 ++--
 src/handsfree.c |2 +-
 src/location-reporting.c|2 +-
 src/manager.c   |2 +-
 src/message-waiting.c   |2 +-
 src/message.c   |2 +-
 src/modem.c |2 +-
 src/network.c   |4 ++--
 src/phonebook.c |2 +-
 src/radio-settings.c|2 +-
 src/sim.c   |2 +-
 src/sms.c   |2 +-
 src/stk.c   |2 +-
 src/ussd.c  |2 +-
 src/voicecall.c |4 ++--
 31 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index c11525e..19a362f 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -198,7 +198,7 @@ static DBusMessage *hfp_agent_release(DBusConnection *conn,
return dbus_message_new_method_return(msg);
 }
 
-static GDBusMethodTable agent_methods[] = {
+static const GDBusMethodTable agent_methods[] = {
{ NewConnection, hq, , hfp_agent_new_connection,
G_DBUS_METHOD_FLAG_ASYNC },
{ Release, , , hfp_agent_release },
diff --git a/plugins/push-notification.c b/plugins/push-notification.c
index 1c19bf2..1b8f729 100644
--- a/plugins/push-notification.c
+++ b/plugins/push-notification.c
@@ -151,7 +151,7 @@ static DBusMessage 
*push_notification_unregister_agent(DBusConnection *conn,
return dbus_message_new_method_return(msg);
 }
 
-static GDBusMethodTable push_notification_methods[] = {
+static const GDBusMethodTable push_notification_methods[] = {
{ RegisterAgent,o,   ,  push_notification_register_agent },
{ UnregisterAgent,  o,   ,  push_notification_unregister_agent },
{ }
diff --git a/plugins/smart-messaging.c b/plugins/smart-messaging.c
index d6d77cf..6820b20 100644
--- a/plugins/smart-messaging.c
+++ b/plugins/smart-messaging.c
@@ -268,7 +268,7 @@ static DBusMessage 
*smart_messaging_send_vcal(DBusConnection *conn,
return NULL;
 }
 
-static GDBusMethodTable smart_messaging_methods[] = {
+static const GDBusMethodTable smart_messaging_methods[] = {
{ RegisterAgent,o, ,  smart_messaging_register_agent },
{ UnregisterAgent,  o, ,  smart_messaging_unregister_agent },
{ SendBusinessCard, say,   o, smart_messaging_send_vcard,
diff --git a/src/audio-settings.c b/src/audio-settings.c
index 77930d9..6388c3e 100644
--- a/src/audio-settings.c
+++ b/src/audio-settings.c
@@ -117,7 +117,7 @@ static DBusMessage *audio_get_properties(DBusConnection 
*conn,
return audio_get_properties_reply(msg, as);
 }
 
-static GDBusMethodTable audio_methods[] = {
+static const GDBusMethodTable audio_methods[] = {
{ GetProperties, , a{sv}, audio_get_properties,
G_DBUS_METHOD_FLAG_ASYNC },
{ }
diff --git a/src/call-barring.c b/src/call-barring.c
index afb3fce..952e4c2 100644
--- a/src/call-barring.c
+++ b/src/call-barring.c
@@ -966,7 +966,7 @@ static DBusMessage *cb_set_passwd(DBusConnection *conn, 
DBusMessage *msg,
return NULL;
 }
 
-static GDBusMethodTable cb_methods[] = {
+static const GDBusMethodTable cb_methods[] = {
{ GetProperties,  , a{sv},cb_get_properties,

G_DBUS_METHOD_FLAG_ASYNC },
{ SetProperty,svs,  , cb_set_property,
diff --git a/src/call-forwarding.c b/src/call-forwarding.c
index c025942..c70d140 100644
--- a/src/call-forwarding.c
+++ b/src/call-forwarding.c
@@ -881,7 +881,7 @@ static DBusMessage *cf_disable_all(DBusConnection *conn, 
DBusMessage *msg,
return NULL;
 }
 
-static GDBusMethodTable cf_methods[] = {
+static const GDBusMethodTable cf_methods[] = {
{ GetProperties,  , a{sv},cf_get_properties,
G_DBUS_METHOD_FLAG_ASYNC },
{ SetProperty,sv,   , cf_set_property,
diff --git a/src/call-meter.c b/src/call-meter.c
index c3ae6f7..fd5edc2 100644
--- a/src/call-meter.c
+++ b/src/call-meter.c
@@ -646,7 +646,7 @@ static 

[PATCH 02/12] Constify GDBus signal tables

2012-05-19 Thread Lucas De Marchi
From: Henrique Dante de Almeida hda...@profusion.mobi

Constify signal tables with the following command:

find . -name '*.[ch]' -exec \
 sed -i 's/\(GDBusSignalTable .* =\)/const \1/g' {} \;
---
 src/audio-settings.c |2 +-
 src/call-barring.c   |2 +-
 src/call-forwarding.c|2 +-
 src/call-meter.c |2 +-
 src/call-settings.c  |2 +-
 src/call-volume.c|2 +-
 src/cbs.c|2 +-
 src/cdma-connman.c   |2 +-
 src/cdma-netreg.c|2 +-
 src/cdma-sms.c   |2 +-
 src/cdma-voicecall.c |2 +-
 src/ctm.c|2 +-
 src/gprs.c   |4 ++--
 src/handsfree.c  |2 +-
 src/location-reporting.c |2 +-
 src/manager.c|2 +-
 src/message-waiting.c|2 +-
 src/message.c|2 +-
 src/modem.c  |2 +-
 src/network.c|4 ++--
 src/phonebook.c  |2 +-
 src/radio-settings.c |2 +-
 src/sim.c|2 +-
 src/sms.c|2 +-
 src/stk.c|2 +-
 src/ussd.c   |2 +-
 src/voicecall.c  |4 ++--
 27 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/src/audio-settings.c b/src/audio-settings.c
index 6388c3e..0e52761 100644
--- a/src/audio-settings.c
+++ b/src/audio-settings.c
@@ -123,7 +123,7 @@ static const GDBusMethodTable audio_methods[] = {
{ }
 };
 
-static GDBusSignalTable audio_signals[] = {
+static const GDBusSignalTable audio_signals[] = {
{ PropertyChanged, sv },
{ }
 };
diff --git a/src/call-barring.c b/src/call-barring.c
index 952e4c2..6b9bf6e 100644
--- a/src/call-barring.c
+++ b/src/call-barring.c
@@ -982,7 +982,7 @@ static const GDBusMethodTable cb_methods[] = {
{ }
 };
 
-static GDBusSignalTable cb_signals[] = {
+static const GDBusSignalTable cb_signals[] = {
{ PropertyChanged,sv },
{ }
 };
diff --git a/src/call-forwarding.c b/src/call-forwarding.c
index c70d140..7a73ff1 100644
--- a/src/call-forwarding.c
+++ b/src/call-forwarding.c
@@ -891,7 +891,7 @@ static const GDBusMethodTable cf_methods[] = {
{ }
 };
 
-static GDBusSignalTable cf_signals[] = {
+static const GDBusSignalTable cf_signals[] = {
{ PropertyChanged,sv },
{ }
 };
diff --git a/src/call-meter.c b/src/call-meter.c
index fd5edc2..67965a4 100644
--- a/src/call-meter.c
+++ b/src/call-meter.c
@@ -656,7 +656,7 @@ static const GDBusMethodTable cm_methods[] = {
{ }
 };
 
-static GDBusSignalTable cm_signals[] = {
+static const GDBusSignalTable cm_signals[] = {
{ PropertyChanged,sv },
{ NearMaximumWarning,  },
{ }
diff --git a/src/call-settings.c b/src/call-settings.c
index 9d4ff7b..014deb8 100644
--- a/src/call-settings.c
+++ b/src/call-settings.c
@@ -1338,7 +1338,7 @@ static const GDBusMethodTable cs_methods[] = {
{ }
 };
 
-static GDBusSignalTable cs_signals[] = {
+static const GDBusSignalTable cs_signals[] = {
{ PropertyChanged,sv },
{ }
 };
diff --git a/src/call-volume.c b/src/call-volume.c
index 81b7564..528e39c 100644
--- a/src/call-volume.c
+++ b/src/call-volume.c
@@ -308,7 +308,7 @@ static const GDBusMethodTable cv_methods[] = {
{ }
 };
 
-static GDBusSignalTable cv_signals[] = {
+static const GDBusSignalTable cv_signals[] = {
{ PropertyChanged,sv },
{ }
 };
diff --git a/src/cbs.c b/src/cbs.c
index 1c20cc6..f81cfb7 100644
--- a/src/cbs.c
+++ b/src/cbs.c
@@ -547,7 +547,7 @@ static const GDBusMethodTable cbs_methods[] = {
{ }
 };
 
-static GDBusSignalTable cbs_signals[] = {
+static const GDBusSignalTable cbs_signals[] = {
{ PropertyChanged,sv},
{ IncomingBroadcast,  sq},
{ EmergencyBroadcast, sa{sv}},
diff --git a/src/cdma-connman.c b/src/cdma-connman.c
index 90652e7..92866ba 100644
--- a/src/cdma-connman.c
+++ b/src/cdma-connman.c
@@ -525,7 +525,7 @@ static const GDBusMethodTable cdma_connman_methods[] = {
{ }
 };
 
-static GDBusSignalTable cdma_connman_signals[] = {
+static const GDBusSignalTable cdma_connman_signals[] = {
{ PropertyChanged,sv },
{ }
 };
diff --git a/src/cdma-netreg.c b/src/cdma-netreg.c
index e6074a8..7b63cd7 100644
--- a/src/cdma-netreg.c
+++ b/src/cdma-netreg.c
@@ -112,7 +112,7 @@ static const GDBusMethodTable cdma_netreg_manager_methods[] 
= {
{ }
 };
 
-static GDBusSignalTable cdma_netreg_manager_signals[] = {
+static const GDBusSignalTable cdma_netreg_manager_signals[] = {
{ }
 };
 
diff --git a/src/cdma-sms.c b/src/cdma-sms.c
index a368124..bef214c 100644
--- a/src/cdma-sms.c
+++ b/src/cdma-sms.c
@@ -48,7 +48,7 @@ static const GDBusMethodTable cdma_sms_manager_methods[] = {
{ }
 };
 
-static GDBusSignalTable cdma_sms_manager_signals[] = {
+static const GDBusSignalTable cdma_sms_manager_signals[] = {
{ 

[PATCH 03/12] gdbus: add argument info to methods and signals

2012-05-19 Thread Lucas De Marchi
---
 gdbus/gdbus.h |8 
 1 file changed, 8 insertions(+)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index a0583e6..e5e7938 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -85,16 +85,24 @@ typedef enum {
 typedef struct {
const char *name;
const char *signature;
+} GDBusArgInfo;
+
+typedef struct {
+   const char *name;
+   const char *signature;
const char *reply;
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
+   const GDBusArgInfo *in_args;
+   const GDBusArgInfo *out_args;
 } GDBusMethodTable;
 
 typedef struct {
const char *name;
const char *signature;
GDBusSignalFlags flags;
+   const GDBusArgInfo *args;
 } GDBusSignalTable;
 
 typedef struct {
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 05/12] Convert GDBus methods to use macro helpers

2012-05-19 Thread Lucas De Marchi
With these macro helpers we can separate in/out arguments and use their
own vector.
---
 plugins/hfp_hf.c|9 +++--
 plugins/push-notification.c |8 +++-
 plugins/smart-messaging.c   |   21 +++---
 src/audio-settings.c|8 ++--
 src/call-barring.c  |   34 ++---
 src/call-forwarding.c   |   18 +
 src/call-meter.c|   21 ++
 src/call-settings.c |   13 ---
 src/call-volume.c   |   12 --
 src/cbs.c   |   18 ++---
 src/cdma-connman.c  |   13 ---
 src/cdma-netreg.c   |4 +-
 src/cdma-sms.c  |3 +-
 src/cdma-voicecall.c|   34 ++---
 src/ctm.c   |   13 ---
 src/gnss.c  |   15 +---
 src/gprs.c  |   48 +++
 src/handsfree.c |   19 +
 src/location-reporting.c|   16 +---
 src/manager.c   |   10 +++--
 src/message-waiting.c   |   12 --
 src/message.c   |9 +++--
 src/modem.c |   12 --
 src/network.c   |   31 +--
 src/phonebook.c |5 ++-
 src/radio-settings.c|   13 ---
 src/sim.c   |   45 ++
 src/sms.c   |   36 +++--
 src/stk.c   |   22 +++
 src/ussd.c  |   29 --
 src/voicecall.c |   89 ++-
 31 files changed, 406 insertions(+), 234 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 19a362f..628e034 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -199,10 +199,11 @@ static DBusMessage *hfp_agent_release(DBusConnection 
*conn,
 }
 
 static const GDBusMethodTable agent_methods[] = {
-   { NewConnection, hq, , hfp_agent_new_connection,
-   G_DBUS_METHOD_FLAG_ASYNC },
-   { Release, , , hfp_agent_release },
-   { NULL, NULL, NULL, NULL }
+   { _GDBUS_ASYNC_METHOD(NewConnection, hq, ,
+ GDBUS_ARGS({ fd, h }, { version, q }),
+ NULL, hfp_agent_new_connection) },
+   { _GDBUS_METHOD(Release, , , NULL, NULL, hfp_agent_release) },
+   { }
 };
 
 static int hfp_hf_probe(const char *device, const char *dev_addr,
diff --git a/plugins/push-notification.c b/plugins/push-notification.c
index 1b8f729..b916a6a 100644
--- a/plugins/push-notification.c
+++ b/plugins/push-notification.c
@@ -152,8 +152,12 @@ static DBusMessage 
*push_notification_unregister_agent(DBusConnection *conn,
 }
 
 static const GDBusMethodTable push_notification_methods[] = {
-   { RegisterAgent,o,   ,  push_notification_register_agent },
-   { UnregisterAgent,  o,   ,  push_notification_unregister_agent },
+   { _GDBUS_METHOD(RegisterAgent, o, ,
+   GDBUS_ARGS({ path, o }), NULL,
+   push_notification_register_agent) },
+   { _GDBUS_METHOD(UnregisterAgent, o, ,
+   GDBUS_ARGS({ path, o }), NULL,
+   push_notification_unregister_agent) },
{ }
 };
 
diff --git a/plugins/smart-messaging.c b/plugins/smart-messaging.c
index 6820b20..a924f00 100644
--- a/plugins/smart-messaging.c
+++ b/plugins/smart-messaging.c
@@ -269,12 +269,21 @@ static DBusMessage 
*smart_messaging_send_vcal(DBusConnection *conn,
 }
 
 static const GDBusMethodTable smart_messaging_methods[] = {
-   { RegisterAgent,o, ,  smart_messaging_register_agent },
-   { UnregisterAgent,  o, ,  smart_messaging_unregister_agent },
-   { SendBusinessCard, say,   o, smart_messaging_send_vcard,
-   G_DBUS_METHOD_FLAG_ASYNC },
-   { SendAppointment,  say,   o, smart_messaging_send_vcal,
-   G_DBUS_METHOD_FLAG_ASYNC },
+   { _GDBUS_METHOD(RegisterAgent, o, ,
+   GDBUS_ARGS({ path, o }), NULL,
+   smart_messaging_register_agent) },
+   { _GDBUS_METHOD(UnregisterAgent, o, ,
+   GDBUS_ARGS({ path, o }), NULL,
+   smart_messaging_unregister_agent) },
+   { _GDBUS_ASYNC_METHOD(SendBusinessCard, say, o,
+ GDBUS_ARGS({ to, s }, { card, ay }),
+ GDBUS_ARGS({ path, o }),
+ smart_messaging_send_vcard) },
+   { _GDBUS_ASYNC_METHOD(SendAppointment, say, o,
+ GDBUS_ARGS({ to, s },
+ { appointment, ay }),
+ GDBUS_ARGS({ path, o }),
+ smart_messaging_send_vcal) },
{ }
 };
 
diff --git a/src/audio-settings.c b/src/audio-settings.c
index 0e52761..a83e9ac 100644
--- a/src/audio-settings.c
+++ b/src/audio-settings.c
@@ -118,13 +118,15 @@ 

[PATCH 06/12] gdbus: use GDBusArgInfo to generate introspection

2012-05-19 Thread Lucas De Marchi
By using GDBusArgInfo in methods and signals, the introspection
generation is much simpler and we can add each argument name.
---
 gdbus/object.c |   75 +++-
 1 file changed, 14 insertions(+), 61 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 2ddc574..3ac6a0b 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -59,68 +59,20 @@ struct security_data {
void *iface_user_data;
 };
 
-static void print_arguments(GString *gstr, const char *sig,
+static void print_arguments(GString *gstr, const GDBusArgInfo *args,
const char *direction)
 {
-   int i;
-
-   for (i = 0; sig[i]; i++) {
-   char type[32];
-   int struct_level, dict_level;
-   unsigned int len;
-   gboolean complete;
-
-   complete = FALSE;
-   struct_level = dict_level = 0;
-
-   /* Gather enough data to have a single complete type */
-   for (len = 0; len  (sizeof(type) - 1)  sig[i]; len++, i++) {
-   switch (sig[i]) {
-   case '(':
-   struct_level++;
-   break;
-   case ')':
-   struct_level--;
-   if (struct_level = 0  dict_level = 0)
-   complete = TRUE;
-   break;
-   case '{':
-   dict_level++;
-   break;
-   case '}':
-   dict_level--;
-   if (struct_level = 0  dict_level = 0)
-   complete = TRUE;
-   break;
-   case 'a':
-   break;
-   default:
-   if (struct_level = 0  dict_level = 0)
-   complete = TRUE;
-   break;
-   }
-
-   type[len] = sig[i];
-
-   if (complete)
-   break;
-   }
-
-   type[len + 1] = '\0';
-
-   if (!complete) {
-   error(Unexpected signature: %s, sig);
-   return;
-   }
+   for (; args  args-name; args++) {
+   g_string_append_printf(gstr,
+   \t\t\targ name=\%s\ type=\%s\,
+   args-name, args-signature);
 
if (direction)
g_string_append_printf(gstr,
-   \t\t\targ type=\%s\ 
direction=\%s\/\n,
-   type, direction);
+direction=\%s\/\n, direction);
else
-   g_string_append_printf(gstr,
-   \t\t\targ type=\%s\/\n,
-   type);
+   g_string_append_printf(gstr, /\n);
+
}
 }
 
@@ -130,26 +82,27 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
const GDBusSignalTable *signal;
 
for (method = iface-methods; method  method-name; method++) {
-   if (!strlen(method-signature)  !strlen(method-reply))
+   if (!(method-in_args  method-in_args-name) 
+   !(method-out_args  method-out_args-name))
g_string_append_printf(gstr, \t\tmethod 
name=\%s\/\n,
method-name);
else {
g_string_append_printf(gstr, \t\tmethod 
name=\%s\\n,
method-name);
-   print_arguments(gstr, method-signature, in);
-   print_arguments(gstr, method-reply, out);
+   print_arguments(gstr, method-in_args, in);
+   print_arguments(gstr, method-out_args, out);
g_string_append_printf(gstr, \t\t/method\n);
}
}
 
for (signal = iface-signals; signal  signal-name; signal++) {
-   if (!strlen(signal-signature))
+   if (!(signal-args  signal-args-name))
g_string_append_printf(gstr, \t\tsignal 
name=\%s\/\n,
signal-name);
else {
g_string_append_printf(gstr, \t\tsignal 
name=\%s\\n,
signal-name);
-   print_arguments(gstr, signal-signature, NULL);
+ 

[PATCH 07/12] gdbus: loop over args to check message signature

2012-05-19 Thread Lucas De Marchi
---
 gdbus/object.c |   34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 3ac6a0b..b187bb5 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -374,6 +374,27 @@ static struct interface_data *find_interface(GSList 
*interfaces,
return NULL;
 }
 
+static gboolean g_dbus_args_have_signature(const GDBusArgInfo *args,
+   DBusMessage *message)
+{
+   const char *sig = dbus_message_get_signature(message);
+   const char *p = NULL;
+
+   for (; args  args-signature  *sig; args++) {
+   p = args-signature;
+
+   for (; *sig  *p; sig++, p++) {
+   if (*p != *sig)
+   return FALSE;
+   }
+   }
+
+   if (*sig || (p  *p) || (args  args-signature))
+   return FALSE;
+
+   return TRUE;
+}
+
 static DBusHandlerResult generic_message(DBusConnection *connection,
DBusMessage *message, void *user_data)
 {
@@ -394,8 +415,8 @@ static DBusHandlerResult generic_message(DBusConnection 
*connection,
method-name) == FALSE)
continue;
 
-   if (dbus_message_has_signature(message,
-   method-signature) == FALSE)
+   if (g_dbus_args_have_signature(method-in_args,
+   message) == FALSE)
continue;
 
if (check_privilege(connection, message, method,
@@ -552,7 +573,7 @@ static void object_path_unref(DBusConnection *connection, 
const char *path)
 
 static gboolean check_signal(DBusConnection *conn, const char *path,
const char *interface, const char *name,
-   const char **args)
+   const GDBusArgInfo **args)
 {
struct generic_data *data = NULL;
struct interface_data *iface;
@@ -575,7 +596,7 @@ static gboolean check_signal(DBusConnection *conn, const 
char *path,
 
for (signal = iface-signals; signal  signal-name; signal++) {
if (!strcmp(signal-name, name)) {
-   *args = signal-signature;
+   *args = signal-args;
break;
}
}
@@ -597,7 +618,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
 {
DBusMessage *signal;
dbus_bool_t ret;
-   const char *signature, *args;
+   const GDBusArgInfo *args;
 
if (!check_signal(conn, path, interface, name, args))
return FALSE;
@@ -612,8 +633,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
if (!ret)
goto fail;
 
-   signature = dbus_message_get_signature(signal);
-   if (strcmp(args, signature) != 0) {
+   if (g_dbus_args_have_signature(args, signal) == FALSE) {
error(%s.%s: expected signature'%s' but got '%s',
interface, name, args, signature);
ret = FALSE;
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 09/12] gdbus: remove signature and reply from tables

2012-05-19 Thread Lucas De Marchi
---
 gdbus/gdbus.h  |   60 
 gdbus/object.c |2 +-
 2 files changed, 1 insertion(+), 61 deletions(-)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index 868c8d5..0a8a27c 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -89,8 +89,6 @@ typedef struct {
 
 typedef struct {
const char *name;
-   const char *signature;
-   const char *reply;
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
@@ -100,7 +98,6 @@ typedef struct {
 
 typedef struct {
const char *name;
-   const char *signature;
GDBusSignalFlags flags;
const GDBusArgInfo *args;
 } GDBusSignalTable;
@@ -120,63 +117,6 @@ typedef struct {
 
 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
 
-#define _GDBUS_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function
-
-#define _GDBUS_ASYNC_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_ASYNC
-
-#define _GDBUS_DEPRECATED_METHOD(_name, _signature, _reply, _in_args, 
_out_args, _function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_DEPRECATED
-
-#define _GDBUS_DEPRECATED_ASYNC_METHOD(_name, _signature, _reply, _in_args, 
_out_args, _function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
-
-#define _GDBUS_NOREPLY_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_NOREPLY
-
-#define _GDBUS_SIGNAL(_name, _signature, _args) \
-   .name = _name, \
-   .signature = _signature, \
-   .args = _args
-
-#define _GDBUS_DEPRECATED_SIGNAL(_name, _signature, _args) \
-   .name = _name, \
-   .signature = _signature, \
-   .args = _args, \
-   .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
-
-/* Helpers with no signature and reply */
-
 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
.name = _name, \
.in_args = _in_args, \
diff --git a/gdbus/object.c b/gdbus/object.c
index b187bb5..fcdd6ec 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -471,7 +471,7 @@ done:
 }
 
 static const GDBusMethodTable introspect_methods[] = {
-   { _GDBUS_METHOD(Introspect, , s, NULL,
+   { GDBUS_METHOD(Introspect, NULL,
GDBUS_ARGS({ xml, s }), introspect) },
{ }
 };
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 11/12] gdbus: add Method.NoReply annotation in introspection

2012-05-19 Thread Lucas De Marchi
---
 gdbus/object.c |7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 95947f3..dacbe58 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -84,8 +84,10 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
for (method = iface-methods; method  method-name; method++) {
gboolean deprecated = method-flags 
G_DBUS_METHOD_FLAG_DEPRECATED;
+   gboolean noreply = method-flags 
+   G_DBUS_METHOD_FLAG_NOREPLY;
 
-   if (!deprecated 
+   if (!deprecated  !noreply 
!(method-in_args  method-in_args-name) 
!(method-out_args  method-out_args-name))
g_string_append_printf(gstr, \t\tmethod 
name=\%s\/\n,
@@ -99,6 +101,9 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
if (deprecated)
g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Deprecated\ value=\true\/\n);
 
+   if (noreply)
+   g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Method.NoReply\ value=\true\/\n);
+
g_string_append_printf(gstr, \t\t/method\n);
}
}
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 12/12] gdbus: do not check signature twice

2012-05-19 Thread Lucas De Marchi
Message signature is already checked in generic_message(), so there's no
need to check again in the callback.
---
 gdbus/object.c |5 -
 1 file changed, 5 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index dacbe58..2dd7c0e 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -174,11 +174,6 @@ static DBusMessage *introspect(DBusConnection *connection,
struct generic_data *data = user_data;
DBusMessage *reply;
 
-   if (!dbus_message_has_signature(message, DBUS_TYPE_INVALID_AS_STRING)) {
-   error(Unexpected signature to introspect call);
-   return NULL;
-   }
-
if (data-introspect == NULL)
generate_introspection_xml(connection, data,
dbus_message_get_path(message));
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 02/12] gdbus: add argument info to methods and signals

2012-05-18 Thread Lucas De Marchi
---
 gdbus/gdbus.h |8 
 1 file changed, 8 insertions(+)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index a0583e6..e5e7938 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -85,16 +85,24 @@ typedef enum {
 typedef struct {
const char *name;
const char *signature;
+} GDBusArgInfo;
+
+typedef struct {
+   const char *name;
+   const char *signature;
const char *reply;
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
+   const GDBusArgInfo *in_args;
+   const GDBusArgInfo *out_args;
 } GDBusMethodTable;
 
 typedef struct {
const char *name;
const char *signature;
GDBusSignalFlags flags;
+   const GDBusArgInfo *args;
 } GDBusSignalTable;
 
 typedef struct {
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 04/12] gdbus: add macro for methods marked as NOREPLY

2012-05-18 Thread Lucas De Marchi
---
 gdbus/gdbus.h |   16 
 1 file changed, 16 insertions(+)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index 8354633..868c8d5 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -155,6 +155,15 @@ typedef struct {
.function = _function, \
.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
 
+#define _GDBUS_NOREPLY_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
+   .name = _name, \
+   .signature = _signature, \
+   .reply = _reply, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_NOREPLY
+
 #define _GDBUS_SIGNAL(_name, _signature, _args) \
.name = _name, \
.signature = _signature, \
@@ -195,6 +204,13 @@ typedef struct {
.function = _function, \
.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
 
+#define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
+   .name = _name, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_NOREPLY
+
 #define GDBUS_SIGNAL(_name, _args) \
.name = _name, \
.args = _args
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 05/12] Convert GDBus methods to use macro helpers

2012-05-18 Thread Lucas De Marchi
With these macro helpers we can separate in/out arguments and use their
own vector.
---
 plugins/ofono.c |8 +---
 src/service.c   |   40 +---
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index 29e8f06..fcdb228 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -115,9 +115,11 @@ static DBusMessage *agent_release(DBusConnection *conn,
 }
 
 static const GDBusMethodTable agent_methods[] = {
-   { ReceiveNotification, aya{sv}, , agent_receive },
-   { Release, ,, agent_release,
-   G_DBUS_METHOD_FLAG_NOREPLY },
+   { _GDBUS_METHOD(ReceiveNotification, aya{sv}, ,
+   GDBUS_ARGS({ notification, ay },
+   { info, a{sv} }),
+   NULL, agent_receive) },
+   { _GDBUS_NOREPLY_METHOD(Release, , , NULL, NULL, agent_release) },
{ }
 };
 
diff --git a/src/service.c b/src/service.c
index a269556..669d10e 100644
--- a/src/service.c
+++ b/src/service.c
@@ -223,13 +223,14 @@ static DBusMessage *msg_mark_read(DBusConnection *conn,
 }
 
 static const GDBusMethodTable message_methods[] = {
-   { MarkRead, , , msg_mark_read },
-   { Delete,   , , msg_delete },
+   { _GDBUS_METHOD(MarkRead, , , NULL, NULL, msg_mark_read) },
+   { _GDBUS_METHOD(Delete, , , NULL, NULL, msg_delete) },
{ }
 };
 
 static const GDBusSignalTable message_signals[] = {
-   { PropertyChanged, sv },
+   { _GDBUS_SIGNAL(PropertyChanged, sv,
+   GDBUS_ARGS({ name, s }, { value, v })) },
{ }
 };
 
@@ -980,15 +981,27 @@ release_msg:
 }
 
 static const GDBusMethodTable service_methods[] = {
-   { SendMessage, assa(sss), o, send_message },
-   { GetMessages, , a(oa{sv}), get_messages },
-   { GetConversation, su, a(oa{sv}), get_conversation },
+   { _GDBUS_METHOD(SendMessage, assa(sss), o,
+   GDBUS_ARGS({ recipients, as }, { smil, s },
+   { attachments, a(sss) }),
+   GDBUS_ARGS({ path, o }),
+   send_message) },
+   { _GDBUS_METHOD(GetMessages, , a(oa{sv}),
+   NULL,
+   GDBUS_ARGS({ messages_with_properties, a(oa{sv}) }),
+   get_messages) },
+   { _GDBUS_METHOD(GetConversation, su, a(oa{sv}),
+   GDBUS_ARGS({ number, s }, { count, s }),
+   GDBUS_ARGS({ messages_with_properties, a(oa{sv} }),
+   get_conversation) },
{ }
 };
 
 static const GDBusSignalTable service_signals[] = {
-   { MessageAdded,   oa{sv} },
-   { MessageRemoved, o },
+   { _GDBUS_SIGNAL(MessageAdded, oa{sv},
+   GDBUS_ARGS({ path, o },
+   { properties, a{sv} })) },
+   { _GDBUS_SIGNAL(MessageRemoved, o, GDBUS_ARGS({ path, o })) },
{ }
 };
 
@@ -2343,13 +2356,18 @@ static DBusMessage *get_services(DBusConnection *conn,
 }
 
 static const GDBusMethodTable manager_methods[] = {
-   { GetServices, , a(oa{sv}), get_services },
+   { _GDBUS_METHOD(GetServices, , a(oa{sv}),
+   NULL,
+   GDBUS_ARGS({ services_with_properties, a(oa{sv}) }),
+   get_services) },
{ }
 };
 
 static const GDBusSignalTable manager_signals[] = {
-   { ServiceAdded,   oa{sv} },
-   { ServiceRemoved, o  },
+   { _GDBUS_SIGNAL(ServiceAdded, oa{sv},
+   GDBUS_ARGS({ path, o },
+   { properties, a{sv} })) },
+   { _GDBUS_SIGNAL(ServiceRemoved, o, GDBUS_ARGS({ path, o })) },
{ }
 };
 
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 07/12] gdbus: loop over args to check message signature

2012-05-18 Thread Lucas De Marchi
---
 gdbus/object.c |   34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 3ac6a0b..b187bb5 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -374,6 +374,27 @@ static struct interface_data *find_interface(GSList 
*interfaces,
return NULL;
 }
 
+static gboolean g_dbus_args_have_signature(const GDBusArgInfo *args,
+   DBusMessage *message)
+{
+   const char *sig = dbus_message_get_signature(message);
+   const char *p = NULL;
+
+   for (; args  args-signature  *sig; args++) {
+   p = args-signature;
+
+   for (; *sig  *p; sig++, p++) {
+   if (*p != *sig)
+   return FALSE;
+   }
+   }
+
+   if (*sig || (p  *p) || (args  args-signature))
+   return FALSE;
+
+   return TRUE;
+}
+
 static DBusHandlerResult generic_message(DBusConnection *connection,
DBusMessage *message, void *user_data)
 {
@@ -394,8 +415,8 @@ static DBusHandlerResult generic_message(DBusConnection 
*connection,
method-name) == FALSE)
continue;
 
-   if (dbus_message_has_signature(message,
-   method-signature) == FALSE)
+   if (g_dbus_args_have_signature(method-in_args,
+   message) == FALSE)
continue;
 
if (check_privilege(connection, message, method,
@@ -552,7 +573,7 @@ static void object_path_unref(DBusConnection *connection, 
const char *path)
 
 static gboolean check_signal(DBusConnection *conn, const char *path,
const char *interface, const char *name,
-   const char **args)
+   const GDBusArgInfo **args)
 {
struct generic_data *data = NULL;
struct interface_data *iface;
@@ -575,7 +596,7 @@ static gboolean check_signal(DBusConnection *conn, const 
char *path,
 
for (signal = iface-signals; signal  signal-name; signal++) {
if (!strcmp(signal-name, name)) {
-   *args = signal-signature;
+   *args = signal-args;
break;
}
}
@@ -597,7 +618,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
 {
DBusMessage *signal;
dbus_bool_t ret;
-   const char *signature, *args;
+   const GDBusArgInfo *args;
 
if (!check_signal(conn, path, interface, name, args))
return FALSE;
@@ -612,8 +633,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
if (!ret)
goto fail;
 
-   signature = dbus_message_get_signature(signal);
-   if (strcmp(args, signature) != 0) {
+   if (g_dbus_args_have_signature(args, signal) == FALSE) {
error(%s.%s: expected signature'%s' but got '%s',
interface, name, args, signature);
ret = FALSE;
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 08/12] Do not set signature and reply in GDBus tables

2012-05-18 Thread Lucas De Marchi
Use GDBUS_* macros, so signature and reply fields are not set in each
method/signal.
---
 plugins/ofono.c |4 ++--
 src/service.c   |   25 +++--
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index fcdb228..45fac91 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -115,11 +115,11 @@ static DBusMessage *agent_release(DBusConnection *conn,
 }
 
 static const GDBusMethodTable agent_methods[] = {
-   { _GDBUS_METHOD(ReceiveNotification, aya{sv}, ,
+   { GDBUS_METHOD(ReceiveNotification,
GDBUS_ARGS({ notification, ay },
{ info, a{sv} }),
NULL, agent_receive) },
-   { _GDBUS_NOREPLY_METHOD(Release, , , NULL, NULL, agent_release) },
+   { GDBUS_NOREPLY_METHOD(Release, NULL, NULL, agent_release) },
{ }
 };
 
diff --git a/src/service.c b/src/service.c
index 669d10e..83e1fe1 100644
--- a/src/service.c
+++ b/src/service.c
@@ -223,13 +223,13 @@ static DBusMessage *msg_mark_read(DBusConnection *conn,
 }
 
 static const GDBusMethodTable message_methods[] = {
-   { _GDBUS_METHOD(MarkRead, , , NULL, NULL, msg_mark_read) },
-   { _GDBUS_METHOD(Delete, , , NULL, NULL, msg_delete) },
+   { GDBUS_METHOD(MarkRead, NULL, NULL, msg_mark_read) },
+   { GDBUS_METHOD(Delete, NULL, NULL, msg_delete) },
{ }
 };
 
 static const GDBusSignalTable message_signals[] = {
-   { _GDBUS_SIGNAL(PropertyChanged, sv,
+   { GDBUS_SIGNAL(PropertyChanged,
GDBUS_ARGS({ name, s }, { value, v })) },
{ }
 };
@@ -981,16 +981,16 @@ release_msg:
 }
 
 static const GDBusMethodTable service_methods[] = {
-   { _GDBUS_METHOD(SendMessage, assa(sss), o,
+   { GDBUS_METHOD(SendMessage,
GDBUS_ARGS({ recipients, as }, { smil, s },
{ attachments, a(sss) }),
GDBUS_ARGS({ path, o }),
send_message) },
-   { _GDBUS_METHOD(GetMessages, , a(oa{sv}),
+   { GDBUS_METHOD(GetMessages,
NULL,
GDBUS_ARGS({ messages_with_properties, a(oa{sv}) }),
get_messages) },
-   { _GDBUS_METHOD(GetConversation, su, a(oa{sv}),
+   { GDBUS_METHOD(GetConversation,
GDBUS_ARGS({ number, s }, { count, s }),
GDBUS_ARGS({ messages_with_properties, a(oa{sv} }),
get_conversation) },
@@ -998,10 +998,9 @@ static const GDBusMethodTable service_methods[] = {
 };
 
 static const GDBusSignalTable service_signals[] = {
-   { _GDBUS_SIGNAL(MessageAdded, oa{sv},
-   GDBUS_ARGS({ path, o },
+   { GDBUS_SIGNAL(MessageAdded, GDBUS_ARGS({ path, o },
{ properties, a{sv} })) },
-   { _GDBUS_SIGNAL(MessageRemoved, o, GDBUS_ARGS({ path, o })) },
+   { GDBUS_SIGNAL(MessageRemoved, GDBUS_ARGS({ path, o })) },
{ }
 };
 
@@ -2356,18 +2355,16 @@ static DBusMessage *get_services(DBusConnection *conn,
 }
 
 static const GDBusMethodTable manager_methods[] = {
-   { _GDBUS_METHOD(GetServices, , a(oa{sv}),
-   NULL,
+   { GDBUS_METHOD(GetServices, NULL,
GDBUS_ARGS({ services_with_properties, a(oa{sv}) }),
get_services) },
{ }
 };
 
 static const GDBusSignalTable manager_signals[] = {
-   { _GDBUS_SIGNAL(ServiceAdded, oa{sv},
-   GDBUS_ARGS({ path, o },
+   { GDBUS_SIGNAL(ServiceAdded, GDBUS_ARGS({ path, o },
{ properties, a{sv} })) },
-   { _GDBUS_SIGNAL(ServiceRemoved, o, GDBUS_ARGS({ path, o })) },
+   { GDBUS_SIGNAL(ServiceRemoved, GDBUS_ARGS({ path, o })) },
{ }
 };
 
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 09/12] gdbus: remove signature and reply from tables

2012-05-18 Thread Lucas De Marchi
---
 gdbus/gdbus.h  |   60 
 gdbus/object.c |2 +-
 2 files changed, 1 insertion(+), 61 deletions(-)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index 868c8d5..0a8a27c 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -89,8 +89,6 @@ typedef struct {
 
 typedef struct {
const char *name;
-   const char *signature;
-   const char *reply;
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
@@ -100,7 +98,6 @@ typedef struct {
 
 typedef struct {
const char *name;
-   const char *signature;
GDBusSignalFlags flags;
const GDBusArgInfo *args;
 } GDBusSignalTable;
@@ -120,63 +117,6 @@ typedef struct {
 
 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
 
-#define _GDBUS_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function
-
-#define _GDBUS_ASYNC_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_ASYNC
-
-#define _GDBUS_DEPRECATED_METHOD(_name, _signature, _reply, _in_args, 
_out_args, _function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_DEPRECATED
-
-#define _GDBUS_DEPRECATED_ASYNC_METHOD(_name, _signature, _reply, _in_args, 
_out_args, _function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
-
-#define _GDBUS_NOREPLY_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
-   .name = _name, \
-   .signature = _signature, \
-   .reply = _reply, \
-   .in_args = _in_args, \
-   .out_args = _out_args, \
-   .function = _function, \
-   .flags = G_DBUS_METHOD_FLAG_NOREPLY
-
-#define _GDBUS_SIGNAL(_name, _signature, _args) \
-   .name = _name, \
-   .signature = _signature, \
-   .args = _args
-
-#define _GDBUS_DEPRECATED_SIGNAL(_name, _signature, _args) \
-   .name = _name, \
-   .signature = _signature, \
-   .args = _args, \
-   .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
-
-/* Helpers with no signature and reply */
-
 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
.name = _name, \
.in_args = _in_args, \
diff --git a/gdbus/object.c b/gdbus/object.c
index b187bb5..fcdd6ec 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -471,7 +471,7 @@ done:
 }
 
 static const GDBusMethodTable introspect_methods[] = {
-   { _GDBUS_METHOD(Introspect, , s, NULL,
+   { GDBUS_METHOD(Introspect, NULL,
GDBUS_ARGS({ xml, s }), introspect) },
{ }
 };
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 10/12] gdbus: add Deprecated annotation in introspection

2012-05-18 Thread Lucas De Marchi
---
 gdbus/object.c |   19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index fcdd6ec..95947f3 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -82,7 +82,11 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
const GDBusSignalTable *signal;
 
for (method = iface-methods; method  method-name; method++) {
-   if (!(method-in_args  method-in_args-name) 
+   gboolean deprecated = method-flags 
+   G_DBUS_METHOD_FLAG_DEPRECATED;
+
+   if (!deprecated 
+   !(method-in_args  method-in_args-name) 
!(method-out_args  method-out_args-name))
g_string_append_printf(gstr, \t\tmethod 
name=\%s\/\n,
method-name);
@@ -91,18 +95,29 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
method-name);
print_arguments(gstr, method-in_args, in);
print_arguments(gstr, method-out_args, out);
+
+   if (deprecated)
+   g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Deprecated\ value=\true\/\n);
+
g_string_append_printf(gstr, \t\t/method\n);
}
}
 
for (signal = iface-signals; signal  signal-name; signal++) {
-   if (!(signal-args  signal-args-name))
+   gboolean deprecated = signal-flags 
+   G_DBUS_SIGNAL_FLAG_DEPRECATED;
+
+   if (!deprecated  !(signal-args  signal-args-name))
g_string_append_printf(gstr, \t\tsignal 
name=\%s\/\n,
signal-name);
else {
g_string_append_printf(gstr, \t\tsignal 
name=\%s\\n,
signal-name);
print_arguments(gstr, signal-args, NULL);
+
+   if (deprecated)
+   g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Deprecated\ value=\true\/\n);
+
g_string_append_printf(gstr, \t\t/signal\n);
}
}
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 11/12] gdbus: add Method.NoReply annotation in introspection

2012-05-18 Thread Lucas De Marchi
---
 gdbus/object.c |7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 95947f3..dacbe58 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -84,8 +84,10 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
for (method = iface-methods; method  method-name; method++) {
gboolean deprecated = method-flags 
G_DBUS_METHOD_FLAG_DEPRECATED;
+   gboolean noreply = method-flags 
+   G_DBUS_METHOD_FLAG_NOREPLY;
 
-   if (!deprecated 
+   if (!deprecated  !noreply 
!(method-in_args  method-in_args-name) 
!(method-out_args  method-out_args-name))
g_string_append_printf(gstr, \t\tmethod 
name=\%s\/\n,
@@ -99,6 +101,9 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
if (deprecated)
g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Deprecated\ value=\true\/\n);
 
+   if (noreply)
+   g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Method.NoReply\ value=\true\/\n);
+
g_string_append_printf(gstr, \t\t/method\n);
}
}
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 12/12] gdbus: do not check signature twice

2012-05-18 Thread Lucas De Marchi
Message signature is already checked in generic_message(), so there's no
need to check again in the callback.
---
 gdbus/object.c |5 -
 1 file changed, 5 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index dacbe58..2dd7c0e 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -174,11 +174,6 @@ static DBusMessage *introspect(DBusConnection *connection,
struct generic_data *data = user_data;
DBusMessage *reply;
 
-   if (!dbus_message_has_signature(message, DBUS_TYPE_INVALID_AS_STRING)) {
-   error(Unexpected signature to introspect call);
-   return NULL;
-   }
-
if (data-introspect == NULL)
generate_introspection_xml(connection, data,
dbus_message_get_path(message));
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 01/12] Constify GDBus tables

2012-05-18 Thread Lucas De Marchi
Constify method tables with the following commands:

find . -name '*.[ch]' -exec sed -i \
 's/\(c\)\(GDBusSignalTable .* =\)/\1 const \2/g' {} \;

find . -name '*.[ch]' -exec sed -i \
 's/\(c\)\(GDBusMethodTable .* =\)/\1 const \2/g' {} \;
---
 plugins/ofono.c |2 +-
 src/service.c   |   12 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index f598c5e..29e8f06 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -114,7 +114,7 @@ static DBusMessage *agent_release(DBusConnection *conn,
return NULL;
 }
 
-static GDBusMethodTable agent_methods[] = {
+static const GDBusMethodTable agent_methods[] = {
{ ReceiveNotification, aya{sv}, , agent_receive },
{ Release, ,, agent_release,
G_DBUS_METHOD_FLAG_NOREPLY },
diff --git a/src/service.c b/src/service.c
index 6bcdede..a269556 100644
--- a/src/service.c
+++ b/src/service.c
@@ -222,13 +222,13 @@ static DBusMessage *msg_mark_read(DBusConnection *conn,
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
-static GDBusMethodTable message_methods[] = {
+static const GDBusMethodTable message_methods[] = {
{ MarkRead, , , msg_mark_read },
{ Delete,   , , msg_delete },
{ }
 };
 
-static GDBusSignalTable message_signals[] = {
+static const GDBusSignalTable message_signals[] = {
{ PropertyChanged, sv },
{ }
 };
@@ -979,14 +979,14 @@ release_msg:
return __mms_error_trans_failure(dbus_msg);
 }
 
-static GDBusMethodTable service_methods[] = {
+static const GDBusMethodTable service_methods[] = {
{ SendMessage, assa(sss), o, send_message },
{ GetMessages, , a(oa{sv}), get_messages },
{ GetConversation, su, a(oa{sv}), get_conversation },
{ }
 };
 
-static GDBusSignalTable service_signals[] = {
+static const GDBusSignalTable service_signals[] = {
{ MessageAdded,   oa{sv} },
{ MessageRemoved, o },
{ }
@@ -2342,12 +2342,12 @@ static DBusMessage *get_services(DBusConnection *conn,
return reply;
 }
 
-static GDBusMethodTable manager_methods[] = {
+static const GDBusMethodTable manager_methods[] = {
{ GetServices, , a(oa{sv}), get_services },
{ }
 };
 
-static GDBusSignalTable manager_signals[] = {
+static const GDBusSignalTable manager_signals[] = {
{ ServiceAdded,   oa{sv} },
{ ServiceRemoved, o  },
{ }
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 02/12] gdbus: add argument info to methods and signals

2012-05-18 Thread Lucas De Marchi
---
 gdbus/gdbus.h |8 
 1 file changed, 8 insertions(+)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index a0583e6..e5e7938 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -85,16 +85,24 @@ typedef enum {
 typedef struct {
const char *name;
const char *signature;
+} GDBusArgInfo;
+
+typedef struct {
+   const char *name;
+   const char *signature;
const char *reply;
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
+   const GDBusArgInfo *in_args;
+   const GDBusArgInfo *out_args;
 } GDBusMethodTable;
 
 typedef struct {
const char *name;
const char *signature;
GDBusSignalFlags flags;
+   const GDBusArgInfo *args;
 } GDBusSignalTable;
 
 typedef struct {
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 03/12] gdbus: add and use helpers for table declarations

2012-05-18 Thread Lucas De Marchi
---
 gdbus/gdbus.h  |   86 
 gdbus/object.c |3 +-
 2 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index e5e7938..8354633 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -118,6 +118,92 @@ typedef struct {
GDBusSecurityFunction function;
 } GDBusSecurityTable;
 
+#define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
+
+#define _GDBUS_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
+   .name = _name, \
+   .signature = _signature, \
+   .reply = _reply, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function
+
+#define _GDBUS_ASYNC_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
+   .name = _name, \
+   .signature = _signature, \
+   .reply = _reply, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_ASYNC
+
+#define _GDBUS_DEPRECATED_METHOD(_name, _signature, _reply, _in_args, 
_out_args, _function) \
+   .name = _name, \
+   .signature = _signature, \
+   .reply = _reply, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define _GDBUS_DEPRECATED_ASYNC_METHOD(_name, _signature, _reply, _in_args, 
_out_args, _function) \
+   .name = _name, \
+   .signature = _signature, \
+   .reply = _reply, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define _GDBUS_SIGNAL(_name, _signature, _args) \
+   .name = _name, \
+   .signature = _signature, \
+   .args = _args
+
+#define _GDBUS_DEPRECATED_SIGNAL(_name, _signature, _args) \
+   .name = _name, \
+   .signature = _signature, \
+   .args = _args, \
+   .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
+
+/* Helpers with no signature and reply */
+
+#define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
+   .name = _name, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function
+
+#define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+   .name = _name, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_ASYNC
+
+#define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
+   .name = _name, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+   .name = _name, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_SIGNAL(_name, _args) \
+   .name = _name, \
+   .args = _args
+
+#define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
+   .name = _name, \
+   .args = _args, \
+   .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
+
 gboolean g_dbus_register_interface(DBusConnection *connection,
const char *path, const char *name,
const GDBusMethodTable *methods,
diff --git a/gdbus/object.c b/gdbus/object.c
index 0ef6c80..2ddc574 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -497,7 +497,8 @@ done:
 }
 
 static const GDBusMethodTable introspect_methods[] = {
-   { Introspect, , s, introspect },
+   { _GDBUS_METHOD(Introspect, , s, NULL,
+   GDBUS_ARGS({ xml, s }), introspect) },
{ }
 };
 
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 04/12] gdbus: add macro for methods marked as NOREPLY

2012-05-18 Thread Lucas De Marchi
---
 gdbus/gdbus.h |   16 
 1 file changed, 16 insertions(+)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index 8354633..868c8d5 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -155,6 +155,15 @@ typedef struct {
.function = _function, \
.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
 
+#define _GDBUS_NOREPLY_METHOD(_name, _signature, _reply, _in_args, _out_args, 
_function) \
+   .name = _name, \
+   .signature = _signature, \
+   .reply = _reply, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_NOREPLY
+
 #define _GDBUS_SIGNAL(_name, _signature, _args) \
.name = _name, \
.signature = _signature, \
@@ -195,6 +204,13 @@ typedef struct {
.function = _function, \
.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
 
+#define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
+   .name = _name, \
+   .in_args = _in_args, \
+   .out_args = _out_args, \
+   .function = _function, \
+   .flags = G_DBUS_METHOD_FLAG_NOREPLY
+
 #define GDBUS_SIGNAL(_name, _args) \
.name = _name, \
.args = _args
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 05/12] Convert GDBus methods to use macro helpers

2012-05-18 Thread Lucas De Marchi
With these macro helpers we can separate in/out arguments and use their
own vector.
---
 plugins/ofono.c |8 +---
 src/service.c   |   40 +---
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index 29e8f06..fcdb228 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -115,9 +115,11 @@ static DBusMessage *agent_release(DBusConnection *conn,
 }
 
 static const GDBusMethodTable agent_methods[] = {
-   { ReceiveNotification, aya{sv}, , agent_receive },
-   { Release, ,, agent_release,
-   G_DBUS_METHOD_FLAG_NOREPLY },
+   { _GDBUS_METHOD(ReceiveNotification, aya{sv}, ,
+   GDBUS_ARGS({ notification, ay },
+   { info, a{sv} }),
+   NULL, agent_receive) },
+   { _GDBUS_NOREPLY_METHOD(Release, , , NULL, NULL, agent_release) },
{ }
 };
 
diff --git a/src/service.c b/src/service.c
index a269556..669d10e 100644
--- a/src/service.c
+++ b/src/service.c
@@ -223,13 +223,14 @@ static DBusMessage *msg_mark_read(DBusConnection *conn,
 }
 
 static const GDBusMethodTable message_methods[] = {
-   { MarkRead, , , msg_mark_read },
-   { Delete,   , , msg_delete },
+   { _GDBUS_METHOD(MarkRead, , , NULL, NULL, msg_mark_read) },
+   { _GDBUS_METHOD(Delete, , , NULL, NULL, msg_delete) },
{ }
 };
 
 static const GDBusSignalTable message_signals[] = {
-   { PropertyChanged, sv },
+   { _GDBUS_SIGNAL(PropertyChanged, sv,
+   GDBUS_ARGS({ name, s }, { value, v })) },
{ }
 };
 
@@ -980,15 +981,27 @@ release_msg:
 }
 
 static const GDBusMethodTable service_methods[] = {
-   { SendMessage, assa(sss), o, send_message },
-   { GetMessages, , a(oa{sv}), get_messages },
-   { GetConversation, su, a(oa{sv}), get_conversation },
+   { _GDBUS_METHOD(SendMessage, assa(sss), o,
+   GDBUS_ARGS({ recipients, as }, { smil, s },
+   { attachments, a(sss) }),
+   GDBUS_ARGS({ path, o }),
+   send_message) },
+   { _GDBUS_METHOD(GetMessages, , a(oa{sv}),
+   NULL,
+   GDBUS_ARGS({ messages_with_properties, a(oa{sv}) }),
+   get_messages) },
+   { _GDBUS_METHOD(GetConversation, su, a(oa{sv}),
+   GDBUS_ARGS({ number, s }, { count, s }),
+   GDBUS_ARGS({ messages_with_properties, a(oa{sv} }),
+   get_conversation) },
{ }
 };
 
 static const GDBusSignalTable service_signals[] = {
-   { MessageAdded,   oa{sv} },
-   { MessageRemoved, o },
+   { _GDBUS_SIGNAL(MessageAdded, oa{sv},
+   GDBUS_ARGS({ path, o },
+   { properties, a{sv} })) },
+   { _GDBUS_SIGNAL(MessageRemoved, o, GDBUS_ARGS({ path, o })) },
{ }
 };
 
@@ -2343,13 +2356,18 @@ static DBusMessage *get_services(DBusConnection *conn,
 }
 
 static const GDBusMethodTable manager_methods[] = {
-   { GetServices, , a(oa{sv}), get_services },
+   { _GDBUS_METHOD(GetServices, , a(oa{sv}),
+   NULL,
+   GDBUS_ARGS({ services_with_properties, a(oa{sv}) }),
+   get_services) },
{ }
 };
 
 static const GDBusSignalTable manager_signals[] = {
-   { ServiceAdded,   oa{sv} },
-   { ServiceRemoved, o  },
+   { _GDBUS_SIGNAL(ServiceAdded, oa{sv},
+   GDBUS_ARGS({ path, o },
+   { properties, a{sv} })) },
+   { _GDBUS_SIGNAL(ServiceRemoved, o, GDBUS_ARGS({ path, o })) },
{ }
 };
 
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 06/12] gdbus: use GDBusArgInfo to generate introspection

2012-05-18 Thread Lucas De Marchi
By using GDBusArgInfo in methods and signals, the introspection
generation is much simpler and we can add each argument name.
---
 gdbus/object.c |   75 +++-
 1 file changed, 14 insertions(+), 61 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 2ddc574..3ac6a0b 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -59,68 +59,20 @@ struct security_data {
void *iface_user_data;
 };
 
-static void print_arguments(GString *gstr, const char *sig,
+static void print_arguments(GString *gstr, const GDBusArgInfo *args,
const char *direction)
 {
-   int i;
-
-   for (i = 0; sig[i]; i++) {
-   char type[32];
-   int struct_level, dict_level;
-   unsigned int len;
-   gboolean complete;
-
-   complete = FALSE;
-   struct_level = dict_level = 0;
-
-   /* Gather enough data to have a single complete type */
-   for (len = 0; len  (sizeof(type) - 1)  sig[i]; len++, i++) {
-   switch (sig[i]) {
-   case '(':
-   struct_level++;
-   break;
-   case ')':
-   struct_level--;
-   if (struct_level = 0  dict_level = 0)
-   complete = TRUE;
-   break;
-   case '{':
-   dict_level++;
-   break;
-   case '}':
-   dict_level--;
-   if (struct_level = 0  dict_level = 0)
-   complete = TRUE;
-   break;
-   case 'a':
-   break;
-   default:
-   if (struct_level = 0  dict_level = 0)
-   complete = TRUE;
-   break;
-   }
-
-   type[len] = sig[i];
-
-   if (complete)
-   break;
-   }
-
-   type[len + 1] = '\0';
-
-   if (!complete) {
-   error(Unexpected signature: %s, sig);
-   return;
-   }
+   for (; args  args-name; args++) {
+   g_string_append_printf(gstr,
+   \t\t\targ name=\%s\ type=\%s\,
+   args-name, args-signature);
 
if (direction)
g_string_append_printf(gstr,
-   \t\t\targ type=\%s\ 
direction=\%s\/\n,
-   type, direction);
+direction=\%s\/\n, direction);
else
-   g_string_append_printf(gstr,
-   \t\t\targ type=\%s\/\n,
-   type);
+   g_string_append_printf(gstr, /\n);
+
}
 }
 
@@ -130,26 +82,27 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
const GDBusSignalTable *signal;
 
for (method = iface-methods; method  method-name; method++) {
-   if (!strlen(method-signature)  !strlen(method-reply))
+   if (!(method-in_args  method-in_args-name) 
+   !(method-out_args  method-out_args-name))
g_string_append_printf(gstr, \t\tmethod 
name=\%s\/\n,
method-name);
else {
g_string_append_printf(gstr, \t\tmethod 
name=\%s\\n,
method-name);
-   print_arguments(gstr, method-signature, in);
-   print_arguments(gstr, method-reply, out);
+   print_arguments(gstr, method-in_args, in);
+   print_arguments(gstr, method-out_args, out);
g_string_append_printf(gstr, \t\t/method\n);
}
}
 
for (signal = iface-signals; signal  signal-name; signal++) {
-   if (!strlen(signal-signature))
+   if (!(signal-args  signal-args-name))
g_string_append_printf(gstr, \t\tsignal 
name=\%s\/\n,
signal-name);
else {
g_string_append_printf(gstr, \t\tsignal 
name=\%s\\n,
signal-name);
-   print_arguments(gstr, signal-signature, NULL);
+ 

[PATCH mmsd 07/12] gdbus: loop over args to check message signature

2012-05-18 Thread Lucas De Marchi
---
 gdbus/object.c |   34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 3ac6a0b..b187bb5 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -374,6 +374,27 @@ static struct interface_data *find_interface(GSList 
*interfaces,
return NULL;
 }
 
+static gboolean g_dbus_args_have_signature(const GDBusArgInfo *args,
+   DBusMessage *message)
+{
+   const char *sig = dbus_message_get_signature(message);
+   const char *p = NULL;
+
+   for (; args  args-signature  *sig; args++) {
+   p = args-signature;
+
+   for (; *sig  *p; sig++, p++) {
+   if (*p != *sig)
+   return FALSE;
+   }
+   }
+
+   if (*sig || (p  *p) || (args  args-signature))
+   return FALSE;
+
+   return TRUE;
+}
+
 static DBusHandlerResult generic_message(DBusConnection *connection,
DBusMessage *message, void *user_data)
 {
@@ -394,8 +415,8 @@ static DBusHandlerResult generic_message(DBusConnection 
*connection,
method-name) == FALSE)
continue;
 
-   if (dbus_message_has_signature(message,
-   method-signature) == FALSE)
+   if (g_dbus_args_have_signature(method-in_args,
+   message) == FALSE)
continue;
 
if (check_privilege(connection, message, method,
@@ -552,7 +573,7 @@ static void object_path_unref(DBusConnection *connection, 
const char *path)
 
 static gboolean check_signal(DBusConnection *conn, const char *path,
const char *interface, const char *name,
-   const char **args)
+   const GDBusArgInfo **args)
 {
struct generic_data *data = NULL;
struct interface_data *iface;
@@ -575,7 +596,7 @@ static gboolean check_signal(DBusConnection *conn, const 
char *path,
 
for (signal = iface-signals; signal  signal-name; signal++) {
if (!strcmp(signal-name, name)) {
-   *args = signal-signature;
+   *args = signal-args;
break;
}
}
@@ -597,7 +618,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
 {
DBusMessage *signal;
dbus_bool_t ret;
-   const char *signature, *args;
+   const GDBusArgInfo *args;
 
if (!check_signal(conn, path, interface, name, args))
return FALSE;
@@ -612,8 +633,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
if (!ret)
goto fail;
 
-   signature = dbus_message_get_signature(signal);
-   if (strcmp(args, signature) != 0) {
+   if (g_dbus_args_have_signature(args, signal) == FALSE) {
error(%s.%s: expected signature'%s' but got '%s',
interface, name, args, signature);
ret = FALSE;
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 08/12] Do not set signature and reply in GDBus tables

2012-05-18 Thread Lucas De Marchi
Use GDBUS_* macros, so signature and reply fields are not set in each
method/signal.
---
 plugins/ofono.c |4 ++--
 src/service.c   |   25 +++--
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index fcdb228..45fac91 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -115,11 +115,11 @@ static DBusMessage *agent_release(DBusConnection *conn,
 }
 
 static const GDBusMethodTable agent_methods[] = {
-   { _GDBUS_METHOD(ReceiveNotification, aya{sv}, ,
+   { GDBUS_METHOD(ReceiveNotification,
GDBUS_ARGS({ notification, ay },
{ info, a{sv} }),
NULL, agent_receive) },
-   { _GDBUS_NOREPLY_METHOD(Release, , , NULL, NULL, agent_release) },
+   { GDBUS_NOREPLY_METHOD(Release, NULL, NULL, agent_release) },
{ }
 };
 
diff --git a/src/service.c b/src/service.c
index 669d10e..83e1fe1 100644
--- a/src/service.c
+++ b/src/service.c
@@ -223,13 +223,13 @@ static DBusMessage *msg_mark_read(DBusConnection *conn,
 }
 
 static const GDBusMethodTable message_methods[] = {
-   { _GDBUS_METHOD(MarkRead, , , NULL, NULL, msg_mark_read) },
-   { _GDBUS_METHOD(Delete, , , NULL, NULL, msg_delete) },
+   { GDBUS_METHOD(MarkRead, NULL, NULL, msg_mark_read) },
+   { GDBUS_METHOD(Delete, NULL, NULL, msg_delete) },
{ }
 };
 
 static const GDBusSignalTable message_signals[] = {
-   { _GDBUS_SIGNAL(PropertyChanged, sv,
+   { GDBUS_SIGNAL(PropertyChanged,
GDBUS_ARGS({ name, s }, { value, v })) },
{ }
 };
@@ -981,16 +981,16 @@ release_msg:
 }
 
 static const GDBusMethodTable service_methods[] = {
-   { _GDBUS_METHOD(SendMessage, assa(sss), o,
+   { GDBUS_METHOD(SendMessage,
GDBUS_ARGS({ recipients, as }, { smil, s },
{ attachments, a(sss) }),
GDBUS_ARGS({ path, o }),
send_message) },
-   { _GDBUS_METHOD(GetMessages, , a(oa{sv}),
+   { GDBUS_METHOD(GetMessages,
NULL,
GDBUS_ARGS({ messages_with_properties, a(oa{sv}) }),
get_messages) },
-   { _GDBUS_METHOD(GetConversation, su, a(oa{sv}),
+   { GDBUS_METHOD(GetConversation,
GDBUS_ARGS({ number, s }, { count, s }),
GDBUS_ARGS({ messages_with_properties, a(oa{sv} }),
get_conversation) },
@@ -998,10 +998,9 @@ static const GDBusMethodTable service_methods[] = {
 };
 
 static const GDBusSignalTable service_signals[] = {
-   { _GDBUS_SIGNAL(MessageAdded, oa{sv},
-   GDBUS_ARGS({ path, o },
+   { GDBUS_SIGNAL(MessageAdded, GDBUS_ARGS({ path, o },
{ properties, a{sv} })) },
-   { _GDBUS_SIGNAL(MessageRemoved, o, GDBUS_ARGS({ path, o })) },
+   { GDBUS_SIGNAL(MessageRemoved, GDBUS_ARGS({ path, o })) },
{ }
 };
 
@@ -2356,18 +2355,16 @@ static DBusMessage *get_services(DBusConnection *conn,
 }
 
 static const GDBusMethodTable manager_methods[] = {
-   { _GDBUS_METHOD(GetServices, , a(oa{sv}),
-   NULL,
+   { GDBUS_METHOD(GetServices, NULL,
GDBUS_ARGS({ services_with_properties, a(oa{sv}) }),
get_services) },
{ }
 };
 
 static const GDBusSignalTable manager_signals[] = {
-   { _GDBUS_SIGNAL(ServiceAdded, oa{sv},
-   GDBUS_ARGS({ path, o },
+   { GDBUS_SIGNAL(ServiceAdded, GDBUS_ARGS({ path, o },
{ properties, a{sv} })) },
-   { _GDBUS_SIGNAL(ServiceRemoved, o, GDBUS_ARGS({ path, o })) },
+   { GDBUS_SIGNAL(ServiceRemoved, GDBUS_ARGS({ path, o })) },
{ }
 };
 
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH mmsd 11/12] gdbus: add Method.NoReply annotation in introspection

2012-05-18 Thread Lucas De Marchi
---
 gdbus/object.c |7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 95947f3..dacbe58 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -84,8 +84,10 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
for (method = iface-methods; method  method-name; method++) {
gboolean deprecated = method-flags 
G_DBUS_METHOD_FLAG_DEPRECATED;
+   gboolean noreply = method-flags 
+   G_DBUS_METHOD_FLAG_NOREPLY;
 
-   if (!deprecated 
+   if (!deprecated  !noreply 
!(method-in_args  method-in_args-name) 
!(method-out_args  method-out_args-name))
g_string_append_printf(gstr, \t\tmethod 
name=\%s\/\n,
@@ -99,6 +101,9 @@ static void generate_interface_xml(GString *gstr, struct 
interface_data *iface)
if (deprecated)
g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Deprecated\ value=\true\/\n);
 
+   if (noreply)
+   g_string_append_printf(gstr, \t\t\tannotation 
name=\org.freedesktop.DBus.Method.NoReply\ value=\true\/\n);
+
g_string_append_printf(gstr, \t\t/method\n);
}
}
-- 
1.7.10.2

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: buildroot

2011-03-23 Thread Lucas De Marchi
On Wed, Mar 23, 2011 at 1:01 PM, Jerry Casette gjerry...@gmail.com wrote:
 Hello List,

 first mail, please be gentle. I wish to create a new rootfs for my ARM920T
 microcontroller based device using BUILDROOT. The device has a serial port
 attached huawei 3G modem that could theoretically be used with stock
 chap/ppp. I do vividly remember though my aggreviance with this before
 finding wvdial, a simple, easy-to-use package to configure, initialize,
 start, and monitor the pppd. Unfortunately, wvdial just can not be added to
 my buidroot created rootFS. My question to the listmembers is twofold:
 1) am I right to assume that ofono is more than capable replacing my old
 friend vwdial as shown here:
 http://ofono.org/wiki/how-work-newly-bought-3g-key

Yes, but make sure to use udev instead of mdev (AFAIR mdev is the
default in buildroot).

Other problem is that buildroot uses uClibc. Denis, do you know if
there's any problem in building oFono with uClibc?

If there is, you'd need to provide your own toolchain (take one from
CodeSourcery).


 2) if so, is there a makefile I could use to add ofono to my otherwise
 functional buildroot conf?

oFono uses autotools for building. If you are using the git
repository, you need to run './bootstrap  ./configure' first. Then
you'll have a Makefile.


regards,

Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] voicecall: allow pause to be sent through SendTones()

2011-03-18 Thread Lucas De Marchi
manager_tone() converts all tone chars to uppercase. Since everywhere we
check for both 'p' and 'P' for a pause, tone_queue() should also check
both before claiming the string is invalid.
---
 src/voicecall.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index cb5258d..4932ffa 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -287,8 +287,9 @@ static int tone_queue(struct ofono_voicecall *vc, const 
char *tone_str,
 */
for (i = 0; tone_str[i]; i++)
if (!g_ascii_isdigit(tone_str[i])  tone_str[i] != 'p' 
-   tone_str[i] != '*'  tone_str[i] != '#' 
-   (tone_str[i]  'A' || tone_str[i]  'D'))
+   tone_str[i] != 'P'  tone_str[i] != '*' 
+   tone_str[i] != '#'  (tone_str[i]  'A' ||
+   tone_str[i]  'D'))
return -EINVAL;
 
while ((entry = g_queue_peek_nth(vc-toneq, n++)) != NULL)
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] TODO: mark 'GPS power control atom' task as done

2011-03-11 Thread Lucas De Marchi
---
 TODO |   11 ---
 doc/features.txt |8 
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/TODO b/TODO
index c432cba..9db9e0b 100644
--- a/TODO
+++ b/TODO
@@ -444,17 +444,6 @@ Miscellaneous
   Complexity: C8
   Owner: Jukka Saunamäki jukka.saunam...@nokia.com
 
-- Add support for GPS power control atom.  Many modem manufacturers provide
-  a GPS unit with their modem hardware.  This unit can be turned on or off
-  and frequently takes over one of the tty ports that the modem provides.
-
-  This feature is not discussed in 27.007, thus manufacturer specific commands
-  are required.
-
-  Priority: Low
-  Complexity: C4
-  Owner: Rafael Ignacio Zurita rafael.zur...@profusion.mobi
-
 - Add Location Service API for providing basic E911 support.
   This will be based on the 27.007 defined AT commands using
   XML for transport of positioning request and responses.
diff --git a/doc/features.txt b/doc/features.txt
index ed4c058..ce36265 100644
--- a/doc/features.txt
+++ b/doc/features.txt
@@ -492,6 +492,14 @@ GPRS
   suspended while a circuit switched service such as voice call or SMS is
   active.
 
+Location Reporting
+==
+
+- GPS support. Many modem manufacturers provide a GPS unit with their modem
+  hardware.  Upon client request oFono can turn this unit on or off and pass a
+  file descriptor in which client may receive the desired location reporting
+  data.
+
 SIM
 ===
 
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/2] mbmmodem: do not check for NULL pointer

2011-03-04 Thread Lucas De Marchi
cb_data_new() uses g_new0(), hence there's no need to check the return
value being NULL.
---
 drivers/mbmmodem/location-reporting.c |4 
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/drivers/mbmmodem/location-reporting.c 
b/drivers/mbmmodem/location-reporting.c
index b76a5c2..1080e62 100644
--- a/drivers/mbmmodem/location-reporting.c
+++ b/drivers/mbmmodem/location-reporting.c
@@ -166,16 +166,12 @@ static void mbm_location_reporting_enable(struct 
ofono_location_reporting *lr,
 
DBG(lr=%p, lr);
 
-   if (cbd == NULL)
-   goto out;
-
cbd-user = lr;
 
if (g_at_chat_send(gd-chat, AT*E2GPSCTL=1,5,1, none_prefix,
mbm_e2gpsctl_enable_cb, cbd, g_free)  0)
return;
 
-out:
CALLBACK_WITH_FAILURE(cb, -1, data);
g_free(cbd);
 }
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/2] huawei: do not check for NULL pointer

2011-03-04 Thread Lucas De Marchi
cb_data_new() uses g_new0(), hence there's no need to check the return
value being NULL.
---
 plugins/huawei.c |4 
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/plugins/huawei.c b/plugins/huawei.c
index 6f05677..afa804d 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -600,13 +600,9 @@ static void huawei_set_online(struct ofono_modem *modem, 
ofono_bool_t online,
 
DBG(modem %p %s, modem, online ? online : offline);
 
-   if (cbd == NULL)
-   goto error;
-
if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
return;
 
-error:
g_free(cbd);
 
CALLBACK_WITH_FAILURE(cb, cbd-data);
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] mbmmodem: don't let chat open after fd is sent

2011-03-03 Thread Lucas De Marchi
Instead of using a GAtChat, just use a GIOChannel and close it as soon
as its fd is sent to core.

Moreover, when oFono exits it's just a matter of checking if there's an
idle callback scheduled to control if we need to close the GIOChannel.
---

Hi Denis,

Following patch implements what the previous one were trying to accomplish, but
without the problem of closing the chat before the command was sent to tty. As
we talked on IRC, now I'm using the GIOChannel directly, without bothering with
creating the chat. Even if the command to send to this channel is very short, I
preferred to use async calls. Hence the use of an idle callback.


regards,
Lucas De Marchi


 drivers/mbmmodem/location-reporting.c |  105 +++--
 1 files changed, 60 insertions(+), 45 deletions(-)

diff --git a/drivers/mbmmodem/location-reporting.c 
b/drivers/mbmmodem/location-reporting.c
index 941fac4..30571fe 100644
--- a/drivers/mbmmodem/location-reporting.c
+++ b/drivers/mbmmodem/location-reporting.c
@@ -48,7 +48,14 @@ static const char *e2gpsctl_prefix[] = { *E2GPSCTL:, NULL 
};
 
 struct gps_data {
GAtChat *chat;
-   GAtChat *data_chat;
+
+   struct {
+   GIOChannel *channel;
+   guint idle_source;
+   gsize written;
+   ofono_location_reporting_enable_cb_t cb;
+   void *cb_data;
+   } stream;
 };
 
 static void mbm_e2gpsctl_disable_cb(gboolean ok, GAtResult *result,
@@ -57,7 +64,6 @@ static void mbm_e2gpsctl_disable_cb(gboolean ok, GAtResult 
*result,
struct cb_data *cbd = user_data;
struct ofono_location_reporting *lr = cbd-user;
ofono_location_reporting_disable_cb_t cb = cbd-cb;
-   struct gps_data *gd = ofono_location_reporting_get_data(lr);
 
DBG(lr=%p, ok=%d, lr, ok);
 
@@ -70,8 +76,6 @@ static void mbm_e2gpsctl_disable_cb(gboolean ok, GAtResult 
*result,
return;
}
 
-   g_at_chat_unref(gd-data_chat);
-
CALLBACK_WITH_SUCCESS(cb, cbd-data);
 }
 
@@ -94,69 +98,81 @@ static void mbm_location_reporting_disable(struct 
ofono_location_reporting *lr,
g_free(cbd);
 }
 
-static int mbm_create_data_chat(struct ofono_location_reporting *lr)
+static gboolean enable_data_stream(gpointer data)
 {
-   struct gps_data *gd = ofono_location_reporting_get_data(lr);
-   struct ofono_modem *modem;
-   const char *gps_dev;
-   GAtSyntax *syntax;
-   GIOChannel *channel;
+   static const char *buf = AT*E2GPSNPD\r\n;
+   gsize len = strlen(buf);
+   struct gps_data *gd = data;
+   GIOStatus status;
+   gsize written;
int fd;
 
-   modem = ofono_location_reporting_get_modem(lr);
-   gps_dev = ofono_modem_get_string(modem, GPSDevice);
+   status = g_io_channel_write_chars(gd-stream.channel,
+   buf + gd-stream.written,
+   len - gd-stream.written,
+   written, NULL);
+   if (status == G_IO_STATUS_AGAIN)
+   return TRUE;
 
-   channel = g_at_tty_open(gps_dev, NULL);
-   if (channel == NULL)
-   return -1;
+   if (status != G_IO_STATUS_NORMAL) {
+   CALLBACK_WITH_FAILURE(gd-stream.cb, -1, gd-stream.cb_data);
 
-   syntax = g_at_syntax_new_gsm_permissive();
-   gd-data_chat = g_at_chat_new(channel, syntax);
-   fd = g_io_channel_unix_get_fd(channel);
+   return FALSE;
+   }
+
+   gd-stream.written += written;
 
-   g_at_syntax_unref(syntax);
-   g_io_channel_unref(channel);
+   if (gd-stream.written != len)
+   return TRUE;
 
-   if (gd-data_chat == NULL)
-   return -1;
+   fd = g_io_channel_unix_get_fd(gd-stream.channel);
+   CALLBACK_WITH_SUCCESS(gd-stream.cb, fd, gd-stream.cb_data);
 
-   return fd;
+   return FALSE;
+}
+
+static void destroy_data_stream(gpointer data)
+{
+   struct gps_data *gd = data;
+
+   g_io_channel_unref(gd-stream.channel);
+   gd-stream.idle_source = 0;
+   gd-stream.written = 0;
 }
 
 static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult *result,
gpointer user_data)
 {
-   struct cb_data *cbd = user_data;
-   ofono_location_reporting_enable_cb_t cb = cbd-cb;
-   struct ofono_location_reporting *lr = cbd-user;
+   struct ofono_location_reporting *lr = user_data;
struct gps_data *gd = ofono_location_reporting_get_data(lr);
+   struct ofono_modem *modem;
+   const char *gps_dev;
struct ofono_error error;
-   int fd;
 
DBG(lr=%p ok=%d, lr, ok);
 
decode_at_error(error, g_at_result_final_response(result));
 
if (!ok) {
-   cb(error, -1, cbd-data);
+   gd-stream.cb(error, -1, gd-stream.cb_data);
 
return;
}
 
-   fd = mbm_create_data_chat(lr

Re: [PATCH] mbmmodem: don't let chat open after fd is sent

2011-03-03 Thread Lucas De Marchi
On Thu, Mar 3, 2011 at 2:21 PM, Marcel Holtmann mar...@holtmann.org wrote:
 Hi Lucas,

  struct gps_data {
       GAtChat *chat;
 -     GAtChat *data_chat;
 +
 +     struct {
 +             GIOChannel *channel;
 +             guint idle_source;
 +             gsize written;
 +             ofono_location_reporting_enable_cb_t cb;
 +             void *cb_data;
 +     } stream;
  };

 why do you bother with the struct in struct here?

Just to group these related fields.


regards,
Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] mbmmodem: don't let chat open after fd is sent

2011-03-03 Thread Lucas De Marchi
Instead of using a GAtChat, just use a GIOChannel and close it as soon
as its fd is sent to core.
---
 drivers/mbmmodem/location-reporting.c |   32 +++-
 1 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/drivers/mbmmodem/location-reporting.c 
b/drivers/mbmmodem/location-reporting.c
index 941fac4..b76a5c2 100644
--- a/drivers/mbmmodem/location-reporting.c
+++ b/drivers/mbmmodem/location-reporting.c
@@ -94,13 +94,13 @@ static void mbm_location_reporting_disable(struct 
ofono_location_reporting *lr,
g_free(cbd);
 }
 
-static int mbm_create_data_chat(struct ofono_location_reporting *lr)
+static int enable_data_stream(struct ofono_location_reporting *lr)
 {
-   struct gps_data *gd = ofono_location_reporting_get_data(lr);
struct ofono_modem *modem;
const char *gps_dev;
-   GAtSyntax *syntax;
GIOChannel *channel;
+   GIOStatus status;
+   gsize written;
int fd;
 
modem = ofono_location_reporting_get_modem(lr);
@@ -110,15 +110,18 @@ static int mbm_create_data_chat(struct 
ofono_location_reporting *lr)
if (channel == NULL)
return -1;
 
-   syntax = g_at_syntax_new_gsm_permissive();
-   gd-data_chat = g_at_chat_new(channel, syntax);
fd = g_io_channel_unix_get_fd(channel);
+   status = g_io_channel_write_chars(channel, AT*E2GPSNPD\r\n, -1,
+   written, NULL);
 
-   g_at_syntax_unref(syntax);
+   g_io_channel_set_close_on_unref(channel, FALSE);
g_io_channel_unref(channel);
 
-   if (gd-data_chat == NULL)
+   if (status != G_IO_STATUS_NORMAL || written != 13) {
+   close(fd);
+
return -1;
+   }
 
return fd;
 }
@@ -129,7 +132,6 @@ static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult 
*result,
struct cb_data *cbd = user_data;
ofono_location_reporting_enable_cb_t cb = cbd-cb;
struct ofono_location_reporting *lr = cbd-user;
-   struct gps_data *gd = ofono_location_reporting_get_data(lr);
struct ofono_error error;
int fd;
 
@@ -143,20 +145,16 @@ static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult 
*result,
return;
}
 
-   fd = mbm_create_data_chat(lr);
+   fd = enable_data_stream(lr);
 
-   if (fd  0)
-   goto out;
-
-   if (g_at_chat_send(gd-data_chat, AT*E2GPSNPD, NULL, NULL, NULL,
-   NULL)  0) {
-   cb(error, fd, cbd-data);
+   if (fd  0) {
+   CALLBACK_WITH_FAILURE(cb, -1, cbd-data);
 
return;
}
 
-out:
-   CALLBACK_WITH_FAILURE(cb, -1, cbd-data);
+   cb(error, fd, cbd-data);
+   close(fd);
 }
 
 static void mbm_location_reporting_enable(struct ofono_location_reporting *lr,
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/3] mbmmodem: close chat before sending fd

2011-02-28 Thread Lucas De Marchi
---
 drivers/mbmmodem/location-reporting.c |   44 ++---
 1 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/drivers/mbmmodem/location-reporting.c 
b/drivers/mbmmodem/location-reporting.c
index 941fac4..b671d71 100644
--- a/drivers/mbmmodem/location-reporting.c
+++ b/drivers/mbmmodem/location-reporting.c
@@ -48,7 +48,7 @@ static const char *e2gpsctl_prefix[] = { *E2GPSCTL:, NULL };
 
 struct gps_data {
GAtChat *chat;
-   GAtChat *data_chat;
+   GIOChannel *data_channel;
 };
 
 static void mbm_e2gpsctl_disable_cb(gboolean ok, GAtResult *result,
@@ -70,7 +70,7 @@ static void mbm_e2gpsctl_disable_cb(gboolean ok, GAtResult 
*result,
return;
}
 
-   g_at_chat_unref(gd-data_chat);
+   g_io_channel_unref(gd-data_channel);
 
CALLBACK_WITH_SUCCESS(cb, cbd-data);
 }
@@ -94,33 +94,33 @@ static void mbm_location_reporting_disable(struct 
ofono_location_reporting *lr,
g_free(cbd);
 }
 
-static int mbm_create_data_chat(struct ofono_location_reporting *lr)
+static GAtChat *mbm_create_data_chat(struct ofono_location_reporting *lr)
 {
struct gps_data *gd = ofono_location_reporting_get_data(lr);
struct ofono_modem *modem;
const char *gps_dev;
GAtSyntax *syntax;
-   GIOChannel *channel;
-   int fd;
+   GAtChat *chat;
 
modem = ofono_location_reporting_get_modem(lr);
gps_dev = ofono_modem_get_string(modem, GPSDevice);
 
-   channel = g_at_tty_open(gps_dev, NULL);
-   if (channel == NULL)
-   return -1;
+   gd-data_channel = g_at_tty_open(gps_dev, NULL);
+   if (gd-data_channel == NULL)
+   return NULL;
 
syntax = g_at_syntax_new_gsm_permissive();
-   gd-data_chat = g_at_chat_new(channel, syntax);
-   fd = g_io_channel_unix_get_fd(channel);
+   chat = g_at_chat_new(gd-data_channel, syntax);
 
g_at_syntax_unref(syntax);
-   g_io_channel_unref(channel);
 
-   if (gd-data_chat == NULL)
-   return -1;
+   if (chat == NULL) {
+   g_io_channel_unref(gd-data_channel);
+
+   return NULL;
+   }
 
-   return fd;
+   return chat;
 }
 
 static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult *result,
@@ -131,7 +131,7 @@ static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult 
*result,
struct ofono_location_reporting *lr = cbd-user;
struct gps_data *gd = ofono_location_reporting_get_data(lr);
struct ofono_error error;
-   int fd;
+   GAtChat *chat;
 
DBG(lr=%p ok=%d, lr, ok);
 
@@ -143,18 +143,22 @@ static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult 
*result,
return;
}
 
-   fd = mbm_create_data_chat(lr);
-
-   if (fd  0)
+   chat = mbm_create_data_chat(lr);
+   if (chat == NULL)
goto out;
 
-   if (g_at_chat_send(gd-data_chat, AT*E2GPSNPD, NULL, NULL, NULL,
-   NULL)  0) {
+   if (g_at_chat_send(chat, AT*E2GPSNPD, NULL, NULL, NULL, NULL)  0) {
+   int fd = g_io_channel_unix_get_fd(gd-data_channel);
+
+   g_at_chat_unref(chat);
cb(error, fd, cbd-data);
 
return;
}
 
+   g_at_chat_unref(chat);
+   g_io_channel_unref(gd-data_channel);
+
 out:
CALLBACK_WITH_FAILURE(cb, -1, cbd-data);
 }
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/3] location-reporting: don't add client-exit watch too early

2011-02-28 Thread Lucas De Marchi
Wait until driver gives us a file descriptor to start watching for
client exit. This fixes a race when client exits before the driver
calls location_reporting_enable_cb().
---
 src/location-reporting.c |   10 --
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/location-reporting.c b/src/location-reporting.c
index 6ab0914..f19ccf5 100644
--- a/src/location-reporting.c
+++ b/src/location-reporting.c
@@ -170,13 +170,12 @@ static void location_reporting_enable_cb(const struct 
ofono_error *error,
int fd, void *data)
 {
struct ofono_location_reporting *lr = data;
+   DBusConnection *conn = ofono_dbus_get_connection();
DBusMessage *reply;
 
if (error-type != OFONO_ERROR_TYPE_NO_ERROR) {
ofono_error(Enabling location-reporting failed);
 
-   client_remove(lr);
-
reply = __ofono_error_failed(lr-pending);
__ofono_dbus_pending_reply(lr-pending, reply);
 
@@ -184,6 +183,9 @@ static void location_reporting_enable_cb(const struct 
ofono_error *error,
}
 
lr-enabled = TRUE;
+   lr-client_owner = g_strdup(dbus_message_get_sender(lr-pending));
+   lr-disconnect_watch = g_dbus_add_disconnect_watch(conn,
+   lr-client_owner, client_exited, lr, NULL);
 
reply = dbus_message_new_method_return(lr-pending);
dbus_message_append_args(reply, DBUS_TYPE_UNIX_FD, fd,
@@ -198,7 +200,6 @@ static DBusMessage 
*location_reporting_request(DBusConnection *conn,
DBusMessage *msg, void *data)
 {
struct ofono_location_reporting *lr = data;
-   const char *caller = dbus_message_get_sender(msg);
 
if (lr-pending != NULL)
return __ofono_error_busy(msg);
@@ -206,9 +207,6 @@ static DBusMessage 
*location_reporting_request(DBusConnection *conn,
if (lr-enabled)
return __ofono_error_in_use(msg);
 
-   lr-client_owner = g_strdup(caller);
-   lr-disconnect_watch = g_dbus_add_disconnect_watch(conn,
-   lr-client_owner, client_exited, lr, NULL);
lr-pending = dbus_message_ref(msg);
 
lr-driver-enable(lr, location_reporting_enable_cb, lr);
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/3] mbmmodem: ensure we close fd when ofono exits

2011-02-28 Thread Lucas De Marchi
---
 drivers/mbmmodem/location-reporting.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/mbmmodem/location-reporting.c 
b/drivers/mbmmodem/location-reporting.c
index b671d71..24ff4b8 100644
--- a/drivers/mbmmodem/location-reporting.c
+++ b/drivers/mbmmodem/location-reporting.c
@@ -71,6 +71,7 @@ static void mbm_e2gpsctl_disable_cb(gboolean ok, GAtResult 
*result,
}
 
g_io_channel_unref(gd-data_channel);
+   gd-data_channel = NULL;
 
CALLBACK_WITH_SUCCESS(cb, cbd-data);
 }
@@ -116,6 +117,7 @@ static GAtChat *mbm_create_data_chat(struct 
ofono_location_reporting *lr)
 
if (chat == NULL) {
g_io_channel_unref(gd-data_channel);
+   gd-data_channel = NULL;
 
return NULL;
}
@@ -158,6 +160,7 @@ static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult 
*result,
 
g_at_chat_unref(chat);
g_io_channel_unref(gd-data_channel);
+   gd-data_channel = NULL;
 
 out:
CALLBACK_WITH_FAILURE(cb, -1, cbd-data);
@@ -225,6 +228,9 @@ static void mbm_location_reporting_remove(struct 
ofono_location_reporting *lr)
 {
struct gps_data *gd = ofono_location_reporting_get_data(lr);
 
+   if (gd-data_channel != NULL)
+   g_io_channel_unref(gd-data_channel);
+
ofono_location_reporting_set_data(lr, NULL);
 
g_at_chat_unref(gd-chat);
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] tools: add client to receive location reporting

2011-02-23 Thread Lucas De Marchi
As of now there's no support for fd-passing in D-Bus Python bindings,
hence a small C client is needed in order to test location-reporting
atom.
---
 Makefile.am  |5 +-
 tools/get-location.c |  259 ++
 2 files changed, 263 insertions(+), 1 deletions(-)
 create mode 100644 tools/get-location.c

diff --git a/Makefile.am b/Makefile.am
index ca558ea..81c39b1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -553,13 +553,16 @@ unit_test_caif_LDADD = @GLIB_LIBS@
 unit_objects += $(unit_test_caif_OBJECTS)
 
 if TOOLS
-noinst_PROGRAMS += tools/huawei-audio tools/auto-enable
+noinst_PROGRAMS += tools/huawei-audio tools/auto-enable tools/get-location
 
 tools_huawei_audio_SOURCES = $(gdbus_sources) tools/huawei-audio.c
 tools_huawei_audio_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
 
 tools_auto_enable_SOURCES = $(gdbus_sources) tools/auto-enable.c
 tools_auto_enable_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
+
+tools_get_location_SOURCES = tools/get-location.c
+tools_get_location_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
 endif
 
 noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
diff --git a/tools/get-location.c b/tools/get-location.c
new file mode 100644
index 000..4ca2f99
--- /dev/null
+++ b/tools/get-location.c
@@ -0,0 +1,259 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2011  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
+ *
+ */
+
+#define OFONO_SERVICE org.ofono
+
+#define MANAGER_PATH   /
+#define MANAGER_INTERFACE OFONO_SERVICE .Manager
+#define LOCATION_REPORTING_INTERFACE OFONO_SERVICE .LocationReporting
+
+#include errno.h
+#include fcntl.h
+#include stdio.h
+#include stdlib.h
+#include string.h
+#include signal.h
+#include sys/signalfd.h
+
+#include dbus/dbus.h
+#include glib.h
+
+static GMainLoop *event_loop;
+
+static char *get_first_modem_path(DBusConnection *conn)
+{
+   DBusMessage *msg, *reply;
+   DBusMessageIter iter, array, entry;
+   DBusError error;
+   int arg_type;
+   const char *path;
+
+   msg = dbus_message_new_method_call(OFONO_SERVICE, MANAGER_PATH,
+   MANAGER_INTERFACE, GetModems);
+
+   dbus_error_init(error);
+
+   reply = dbus_connection_send_with_reply_and_block(conn, msg, -1,
+   error);
+
+   dbus_message_unref(msg);
+
+   if (!reply) {
+   if (dbus_error_is_set(error)) {
+   fprintf(stderr, %s\n, error.message);
+   dbus_error_free(error);
+   } else {
+   fprintf(stderr, GetModems failed);
+   }
+
+
+   return NULL;
+   }
+
+   dbus_message_iter_init(reply, iter);
+
+   dbus_message_iter_recurse(iter, array);
+   dbus_message_iter_recurse(array, entry);
+
+   arg_type = dbus_message_iter_get_arg_type(entry);
+   while (arg_type != DBUS_TYPE_INVALID 
+   arg_type != DBUS_TYPE_OBJECT_PATH) {
+   dbus_message_iter_next(entry);
+   arg_type = dbus_message_iter_get_arg_type(entry);
+   }
+
+   if (arg_type != DBUS_TYPE_OBJECT_PATH) {
+   fprintf(stderr, modem not found\n);
+   return NULL;
+   }
+
+   dbus_message_iter_get_basic(entry, path);
+   fprintf(stderr, Using modem: %s\n, path);
+
+   return strdup(path);
+}
+
+static gboolean data_read_cb(GIOChannel *channel, GIOCondition cond,
+   gpointer data)
+{
+   int fd = GPOINTER_TO_INT(data);
+   char buf[128];
+   ssize_t len;
+   int ret;
+
+   while ((ret = read(fd, buf, sizeof(buf) - 1)) = 0) {
+   buf[ret] = '\0';
+   printf(%s, buf);
+   }
+
+   if (errno != EAGAIN  errno != EWOULDBLOCK)
+   fprintf(stderr, Error reading fd);
+
+   return TRUE;
+}
+
+static int setup_data_channel(DBusConnection *conn, const char *path)
+{
+   DBusMessage *msg, *reply;
+   DBusError error;
+   int fd, fd_source;
+   GIOChannel *channel;
+
+   msg = dbus_message_new_method_call(OFONO_SERVICE, path,
+   LOCATION_REPORTING_INTERFACE, Request);
+
+   

Re: [PATCH] tools: add client to receive location reporting

2011-02-23 Thread Lucas De Marchi
Hi all,

On Wed, Feb 23, 2011 at 3:47 PM, Lucas De Marchi
lucas.demar...@profusion.mobi wrote:
 As of now there's no support for fd-passing in D-Bus Python bindings,
 hence a small C client is needed in order to test location-reporting
 atom.
 ---
  Makefile.am          |    5 +-
  tools/get-location.c |  259 
 ++
  2 files changed, 263 insertions(+), 1 deletions(-)
  create mode 100644 tools/get-location.c


Argh... don't merge this... there were some changes that I forgot to add.

regards,

Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2] tools: add client to receive location reporting

2011-02-23 Thread Lucas De Marchi
As of now there's no support for fd-passing in D-Bus Python bindings,
hence a small C client is needed in order to test location-reporting
atom.
---
 Makefile.am  |5 +-
 tools/get-location.c |  259 ++
 2 files changed, 263 insertions(+), 1 deletions(-)
 create mode 100644 tools/get-location.c

diff --git a/Makefile.am b/Makefile.am
index ca558ea..81c39b1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -553,13 +553,16 @@ unit_test_caif_LDADD = @GLIB_LIBS@
 unit_objects += $(unit_test_caif_OBJECTS)
 
 if TOOLS
-noinst_PROGRAMS += tools/huawei-audio tools/auto-enable
+noinst_PROGRAMS += tools/huawei-audio tools/auto-enable tools/get-location
 
 tools_huawei_audio_SOURCES = $(gdbus_sources) tools/huawei-audio.c
 tools_huawei_audio_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
 
 tools_auto_enable_SOURCES = $(gdbus_sources) tools/auto-enable.c
 tools_auto_enable_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
+
+tools_get_location_SOURCES = tools/get-location.c
+tools_get_location_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
 endif
 
 noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
diff --git a/tools/get-location.c b/tools/get-location.c
new file mode 100644
index 000..dafb3c4
--- /dev/null
+++ b/tools/get-location.c
@@ -0,0 +1,259 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2011  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
+ *
+ */
+
+#define OFONO_SERVICE org.ofono
+
+#define MANAGER_PATH   /
+#define MANAGER_INTERFACE OFONO_SERVICE .Manager
+#define LOCATION_REPORTING_INTERFACE OFONO_SERVICE .LocationReporting
+
+#include errno.h
+#include fcntl.h
+#include stdio.h
+#include stdlib.h
+#include string.h
+#include signal.h
+#include sys/signalfd.h
+#include unistd.h
+
+#include dbus/dbus.h
+#include glib.h
+
+static GMainLoop *event_loop;
+
+static char *get_first_modem_path(DBusConnection *conn)
+{
+   DBusMessage *msg, *reply;
+   DBusMessageIter iter, array, entry;
+   DBusError error;
+   int arg_type;
+   const char *path;
+
+   msg = dbus_message_new_method_call(OFONO_SERVICE, MANAGER_PATH,
+   MANAGER_INTERFACE, GetModems);
+
+   dbus_error_init(error);
+
+   reply = dbus_connection_send_with_reply_and_block(conn, msg, -1,
+   error);
+
+   dbus_message_unref(msg);
+
+   if (!reply) {
+   if (dbus_error_is_set(error)) {
+   fprintf(stderr, %s\n, error.message);
+   dbus_error_free(error);
+   } else {
+   fprintf(stderr, GetModems failed);
+   }
+
+
+   return NULL;
+   }
+
+   dbus_message_iter_init(reply, iter);
+
+   dbus_message_iter_recurse(iter, array);
+   dbus_message_iter_recurse(array, entry);
+
+   arg_type = dbus_message_iter_get_arg_type(entry);
+   while (arg_type != DBUS_TYPE_INVALID 
+   arg_type != DBUS_TYPE_OBJECT_PATH) {
+   dbus_message_iter_next(entry);
+   arg_type = dbus_message_iter_get_arg_type(entry);
+   }
+
+   if (arg_type != DBUS_TYPE_OBJECT_PATH) {
+   fprintf(stderr, modem not found\n);
+   return NULL;
+   }
+
+   dbus_message_iter_get_basic(entry, path);
+   fprintf(stderr, Using modem: %s\n, path);
+
+   return strdup(path);
+}
+
+static gboolean data_read_cb(GIOChannel *channel, GIOCondition cond,
+   gpointer data)
+{
+   int fd = GPOINTER_TO_INT(data);
+   char buf[128];
+   int ret;
+
+   while ((ret = read(fd, buf, sizeof(buf) - 1)) = 0) {
+   buf[ret] = '\0';
+   printf(%s, buf);
+   }
+
+   if (errno != EAGAIN  errno != EWOULDBLOCK)
+   fprintf(stderr, Error reading fd);
+
+   return TRUE;
+}
+
+static int setup_data_channel(DBusConnection *conn, const char *path)
+{
+   DBusMessage *msg, *reply;
+   DBusError error;
+   int fd, fd_source;
+   GIOChannel *channel;
+
+   msg = dbus_message_new_method_call(OFONO_SERVICE, path,
+   LOCATION_REPORTING_INTERFACE, Request);
+
+   

Re: [PATCH v4 3/6] mbmmodem: add location-reporting driver implementation

2011-02-23 Thread Lucas De Marchi
Hi Denis

On Wed, Feb 23, 2011 at 9:57 PM, Denis Kenzior denk...@gmail.com wrote:
 Hi Lucas,

 +static int mbm_create_data_chat(struct ofono_location_reporting *lr)
 +{
 +     struct gps_data *gd = ofono_location_reporting_get_data(lr);
 +     struct ofono_modem *modem;
 +     const char *gps_dev;
 +     GAtSyntax *syntax;
 +     GIOChannel *channel;
 +     int fd;
 +
 +     modem = ofono_location_reporting_get_modem(lr);
 +     gps_dev = ofono_modem_get_string(modem, GPSDevice);
 +
 +     channel = g_at_tty_open(gps_dev, NULL);
 +     if (channel == NULL)
 +             return -1;
 +
 +     syntax = g_at_syntax_new_gsm_permissive();
 +     gd-data_chat = g_at_chat_new(channel, syntax);
 +     fd = g_io_channel_unix_get_fd(channel);
 +
 +     g_at_syntax_unref(syntax);
 +     g_io_channel_unref(channel);
 +
 +     if (gd-data_chat == NULL)
 +             return -1;
 +
 +     return fd;
 +}
 +

 Why do you bother creating a GAtChat for the NMEA port?  It seems that a
 GIOChannel or a simple fd would be enough.

This is because of this line:

+   if (g_at_chat_send(gd-data_chat, AT*E2GPSNPD, NULL, NULL, NULL,
+   NULL)  0) {

AT*E2GPSNPD is sent on the tty that will contain the nmea stream, not
the control one.

 Also, what happens if the channel is hupped by the modem?  Shouldn't we
 have a watch in the core for that and set Enabled accordingly?

Humn... maybe. Though client should have called Release(). Otherwise,
isn't the Release() method superfluous?



regards,
Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH v2] tools: add client to receive location reporting

2011-02-23 Thread Lucas De Marchi
Hi Denis

On Wed, Feb 23, 2011 at 9:58 PM, Denis Kenzior denk...@gmail.com wrote:
 Hi Lucas,

 On 02/23/2011 01:49 PM, Lucas De Marchi wrote:
 As of now there's no support for fd-passing in D-Bus Python bindings,
 hence a small C client is needed in order to test location-reporting
 atom.
 ---
  Makefile.am          |    5 +-
  tools/get-location.c |  259 
 ++
  2 files changed, 263 insertions(+), 1 deletions(-)
  create mode 100644 tools/get-location.c


 Patch has been applied, but please check my follow on commit for
 correctness.


You are right. In the test app I forgot the poor guys that don't have
fd-passing.


thanks for fixing that.


regards,
Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v4 0/6] Add location-reporting atom

2011-02-22 Thread Lucas De Marchi
From: Lucas De Marchi lucas.de.mar...@gmail.com

This is the 4th version of the location-reporting patches (previous title was
Add GPS atom). I worked with Rafael Ignacio Zurita to implement this last
version, making some changes in order to fit the new design as discussed on irc.

Now when a client calls 'Request()' we give it a file
descriptor in which the location reporting will be written. By checking the
'Type' property the client can decide what to do with such information. As of
now only NMEA is supported and it's implemented on mbm modem.

If client exits or calls 'Release()', the location reporting is disabled.

Rafael Ignacio Zurita (6):
  location-reporting: add public header
  location-reporting: add atom implementation
  mbmmodem: add location-reporting driver implementation
  mbm: add location-reporting atom
  udev: add location-reporting device to mbm
  location-reporting: add documentation

 Makefile.am   |   11 +-
 doc/location-reporting-api.txt|   39 
 drivers/mbmmodem/location-reporting.c |  247 +
 drivers/mbmmodem/mbmmodem.c   |2 +
 drivers/mbmmodem/mbmmodem.h   |3 +
 include/location-reporting.h  |   81 +++
 plugins/mbm.c |8 +
 plugins/udev.c|5 +-
 src/location-reporting.c  |  393 +
 src/ofono.h   |2 +
 10 files changed, 785 insertions(+), 6 deletions(-)
 create mode 100644 doc/location-reporting-api.txt
 create mode 100644 drivers/mbmmodem/location-reporting.c
 create mode 100644 include/location-reporting.h
 create mode 100644 src/location-reporting.c

-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v4 1/6] location-reporting: add public header

2011-02-22 Thread Lucas De Marchi
From: Rafael Ignacio Zurita rafael.zur...@profusion.mobi

---
 Makefile.am  |3 +-
 include/location-reporting.h |   81 ++
 2 files changed, 83 insertions(+), 1 deletions(-)
 create mode 100644 include/location-reporting.h

diff --git a/Makefile.am b/Makefile.am
index 7bd7f4f..f9a1bd9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,8 @@ pkginclude_HEADERS = include/log.h include/plugin.h 
include/history.h \
include/audio-settings.h include/nettime.h \
include/ctm.h include/cdma-voicecall.h \
include/cdma-sms.h include/sim-auth.h \
-   include/gprs-provision.h include/emulator.h
+   include/gprs-provision.h include/emulator.h \
+   include/location-reporting.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
diff --git a/include/location-reporting.h b/include/location-reporting.h
new file mode 100644
index 000..d932d9d
--- /dev/null
+++ b/include/location-reporting.h
@@ -0,0 +1,81 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *  Copyright (C) 2010 ProFUSION embedded systems.
+ *
+ *  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_LOCATION_REPORTING_H
+#define __OFONO_LOCATION_REPORTING_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include ofono/types.h
+
+struct ofono_location_reporting;
+
+enum ofono_location_reporting_type {
+   OFONO_LOCATION_REPORTING_TYPE_NMEA = 0,
+};
+
+typedef void (*ofono_location_reporting_enable_cb_t)(
+   const struct ofono_error *error,
+   int fd, void *data);
+typedef void (*ofono_location_reporting_disable_cb_t)(
+   const struct ofono_error *error,
+   void *data);
+
+struct ofono_location_reporting_driver {
+   const char *name;
+   enum ofono_location_reporting_type type;
+   int (*probe)(struct ofono_location_reporting *lr, unsigned int vendor,
+   void *data);
+   void (*remove)(struct ofono_location_reporting *lr);
+   void (*enable)(struct ofono_location_reporting *lr,
+   ofono_location_reporting_enable_cb_t cb, void *data);
+   void (*disable)(struct ofono_location_reporting *lr,
+   ofono_location_reporting_disable_cb_t cb, void *data);
+};
+
+int ofono_location_reporting_driver_register(
+   const struct ofono_location_reporting_driver *d);
+void ofono_location_reporting_driver_unregister(
+   const struct ofono_location_reporting_driver *d);
+
+struct ofono_location_reporting *ofono_location_reporting_create(
+   struct ofono_modem *modem,
+   unsigned int vendor,
+   const char *driver, void *data);
+
+void ofono_location_reporting_register(struct ofono_location_reporting *lr);
+void ofono_location_reporting_remove(struct ofono_location_reporting *lr);
+
+void ofono_location_reporting_set_data(struct ofono_location_reporting *lr,
+   void *data);
+void *ofono_location_reporting_get_data(struct ofono_location_reporting *lr);
+
+struct ofono_modem *ofono_location_reporting_get_modem(
+   struct ofono_location_reporting *lr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_LOCATION_REPORTING_H */
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v4 3/6] mbmmodem: add location-reporting driver implementation

2011-02-22 Thread Lucas De Marchi
From: Rafael Ignacio Zurita rafael.zur...@profusion.mobi

---
 Makefile.am   |3 +-
 drivers/mbmmodem/location-reporting.c |  247 +
 drivers/mbmmodem/mbmmodem.c   |2 +
 drivers/mbmmodem/mbmmodem.h   |3 +
 4 files changed, 254 insertions(+), 1 deletions(-)
 create mode 100644 drivers/mbmmodem/location-reporting.c

diff --git a/Makefile.am b/Makefile.am
index 48d84c8..9b6edf4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -212,7 +212,8 @@ builtin_sources += drivers/atmodem/atutil.h \
drivers/mbmmodem/mbmmodem.h \
drivers/mbmmodem/mbmmodem.c \
drivers/mbmmodem/gprs-context.c \
-   drivers/mbmmodem/stk.c
+   drivers/mbmmodem/stk.c \
+   drivers/mbmmodem/location-reporting.c
 
 builtin_modules += hsomodem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/mbmmodem/location-reporting.c 
b/drivers/mbmmodem/location-reporting.c
new file mode 100644
index 000..7d3e212
--- /dev/null
+++ b/drivers/mbmmodem/location-reporting.c
@@ -0,0 +1,247 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2010 ProFUSION embedded systems.
+ *
+ *  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
+
+#define _GNU_SOURCE
+#include string.h
+#include stdlib.h
+#include stdio.h
+#include errno.h
+#include unistd.h
+
+#include glib.h
+
+#include ofono/log.h
+#include ofono/modem.h
+#include ofono/location-reporting.h
+
+#include gatchat.h
+#include gatresult.h
+#include gattty.h
+
+#include mbmmodem.h
+
+static const char *none_prefix[] = { NULL };
+static const char *e2gpsctl_prefix[] = { *E2GPSCTL:, NULL };
+
+struct gps_data {
+   GAtChat *chat;
+   GAtChat *data_chat;
+};
+
+static void mbm_e2gpsctl_disable_cb(gboolean ok, GAtResult *result,
+   gpointer user_data)
+{
+   struct cb_data *cbd = user_data;
+   struct ofono_location_reporting *lr = cbd-user;
+   ofono_location_reporting_disable_cb_t cb = cbd-cb;
+   struct gps_data *gd = ofono_location_reporting_get_data(lr);
+
+   DBG(lr=%p, ok=%d, lr, ok);
+
+   if (!ok) {
+   struct ofono_error error;
+
+   decode_at_error(error, g_at_result_final_response(result));
+   cb(error, cbd-data);
+
+   return;
+   }
+
+   g_at_chat_unref(gd-data_chat);
+
+   CALLBACK_WITH_SUCCESS(cb, cbd-data);
+}
+
+static void mbm_location_reporting_disable(struct ofono_location_reporting *lr,
+   ofono_location_reporting_disable_cb_t cb,
+   void *data)
+{
+   struct gps_data *gd = ofono_location_reporting_get_data(lr);
+   struct cb_data *cbd = cb_data_new(cb, data);
+
+   DBG(lr=%p, lr);
+
+   cbd-user = lr;
+
+   if (g_at_chat_send(gd-chat, AT*E2GPSCTL=0,5,1, none_prefix,
+   mbm_e2gpsctl_disable_cb, cbd, g_free)  0)
+   return;
+
+   CALLBACK_WITH_FAILURE(cb, data);
+   g_free(cbd);
+}
+
+static int mbm_create_data_chat(struct ofono_location_reporting *lr)
+{
+   struct gps_data *gd = ofono_location_reporting_get_data(lr);
+   struct ofono_modem *modem;
+   const char *gps_dev;
+   GAtSyntax *syntax;
+   GIOChannel *channel;
+   int fd;
+
+   modem = ofono_location_reporting_get_modem(lr);
+   gps_dev = ofono_modem_get_string(modem, GPSDevice);
+
+   channel = g_at_tty_open(gps_dev, NULL);
+   if (channel == NULL)
+   return -1;
+
+   syntax = g_at_syntax_new_gsm_permissive();
+   gd-data_chat = g_at_chat_new(channel, syntax);
+   fd = g_io_channel_unix_get_fd(channel);
+
+   g_at_syntax_unref(syntax);
+   g_io_channel_unref(channel);
+
+   if (gd-data_chat == NULL)
+   return -1;
+
+   return fd;
+}
+
+static void mbm_e2gpsctl_enable_cb(gboolean ok, GAtResult *result,
+gpointer user_data)
+{
+   struct cb_data *cbd = user_data;
+   ofono_location_reporting_enable_cb_t cb = cbd-cb;
+   struct 

[PATCH v4 4/6] mbm: add location-reporting atom

2011-02-22 Thread Lucas De Marchi
From: Rafael Ignacio Zurita rafael.zur...@profusion.mobi

---
 plugins/mbm.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/plugins/mbm.c b/plugins/mbm.c
index 2ab80b4..105843f 100644
--- a/plugins/mbm.c
+++ b/plugins/mbm.c
@@ -46,6 +46,7 @@
 #include ofono/gprs-context.h
 #include ofono/radio-settings.h
 #include ofono/log.h
+#include ofono/location-reporting.h
 
 #include drivers/atmodem/atutil.h
 #include drivers/atmodem/vendor.h
@@ -67,6 +68,7 @@ struct mbm_data {
gboolean have_sim;
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
+   struct ofono_location_reporting *lr;
guint reopen_source;
enum mbm_variant variant;
 };
@@ -510,9 +512,15 @@ static void mbm_post_online(struct ofono_modem *modem)
 {
struct mbm_data *data = ofono_modem_get_data(modem);
struct ofono_gprs_context *gc;
+   const char *gps_dev;
 
DBG(%p, modem);
 
+   gps_dev = ofono_modem_get_string(modem, GPSDevice);
+   if (gps_dev)
+   data-lr = ofono_location_reporting_create(modem, 0,
+   mbmmodem, data-modem_port);
+
ofono_netreg_create(modem, OFONO_VENDOR_MBM,
atmodem, data-modem_port);
 
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v4 5/6] udev: add location-reporting device to mbm

2011-02-22 Thread Lucas De Marchi
From: Rafael Ignacio Zurita rafael.zur...@profusion.mobi

---
 plugins/udev.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/plugins/udev.c b/plugins/udev.c
index 84478d7..aa5702e 100644
--- a/plugins/udev.c
+++ b/plugins/udev.c
@@ -105,7 +105,7 @@ static void add_mbm(struct ofono_modem *modem,
struct udev_device *udev_device)
 {
const char *desc, *devnode;
-   const char *device, *data, *network;
+   const char *device, *data, *network, *gps;
int registered;
 
desc = udev_device_get_sysattr_value(udev_device, device/interface);
@@ -152,8 +152,9 @@ static void add_mbm(struct ofono_modem *modem,
device  = ofono_modem_get_string(modem, MODEM_DEVICE);
data = ofono_modem_get_string(modem, DATA_DEVICE);
network = ofono_modem_get_string(modem, NETWORK_INTERFACE);
+   gps = ofono_modem_get_string(modem, GPS_DEVICE);
 
-   if (device != NULL  data != NULL  network != NULL) {
+   if (device != NULL  data != NULL  network != NULL  gps != NULL) {
ofono_modem_set_integer(modem, Registered, 1);
ofono_modem_register(modem);
}
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v4 6/6] location-reporting: add documentation

2011-02-22 Thread Lucas De Marchi
From: Rafael Ignacio Zurita rafael.zur...@profusion.mobi

---
 Makefile.am|3 ++-
 doc/location-reporting-api.txt |   39 +++
 2 files changed, 41 insertions(+), 1 deletions(-)
 create mode 100644 doc/location-reporting-api.txt

diff --git a/Makefile.am b/Makefile.am
index 9b6edf4..ca558ea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -420,7 +420,8 @@ doc_files = doc/overview.txt doc/ofono-paper.txt 
doc/release-faq.txt \
doc/phonebook-api.txt doc/radio-settings-api.txt \
doc/sim-api.txt doc/stk-api.txt \
doc/audio-settings-api.txt doc/text-telephony-api.txt \
-   doc/calypso-modem.txt doc/message-api.txt
+   doc/calypso-modem.txt doc/message-api.txt \
+   doc/location-reporting-api.txt
 
 
 test_scripts = test/backtrace \
diff --git a/doc/location-reporting-api.txt b/doc/location-reporting-api.txt
new file mode 100644
index 000..b8ce840
--- /dev/null
+++ b/doc/location-reporting-api.txt
@@ -0,0 +1,39 @@
+Location Reporting Hierarchy [experimental]
+=
+
+Serviceorg.ofono
+Interface  org.ofono.LocationReporting
+Object path[variable prefix]/{modem0,modem1,...}
+
+Methodsdict GetProperties()
+
+   Returns all LocationReporting properties. See the
+   properties section for available properties.
+
+   byte Request()
+
+   Asks to turn ON the NMEA stream and supplies the
+   gps device file descriptor. The external cliend should
+   use the file descriptor to receive the NMEA data.
+
+   Possible Errors: [service].Error.InProgress
+[service].Error.InUse
+[service].Error.Failed
+
+   void Release()
+
+   Releases the gps device file descriptor and turns
+   OFF the NMEA stream.
+
+   Possible Errors: [service].Error.InProgress
+[service].Error.NotAvailable
+[service].Error.Failed
+
+Properties boolean Enabled [readonly]
+
+Boolean representing the state of the NMEA stream.
+
+   string Type [readonly]
+
+   Holds the type of the device. Currently only NMEA is
+   supported.
-- 
1.7.4.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v4 2/6] location-reporting: add atom implementation

2011-02-22 Thread Lucas De Marchi
From: Rafael Ignacio Zurita rafael.zur...@profusion.mobi

---
 Makefile.am  |2 +-
 src/location-reporting.c |  393 ++
 src/ofono.h  |2 +
 3 files changed, 396 insertions(+), 1 deletions(-)
 create mode 100644 src/location-reporting.c

diff --git a/Makefile.am b/Makefile.am
index f9a1bd9..48d84c8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -377,7 +377,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) 
src/ofono.ver \
src/smsagent.c src/smsagent.h src/ctm.c \
src/cdma-voicecall.c src/sim-auth.c \
src/message.h src/message.c src/gprs-provision.c \
-   src/emulator.c
+   src/emulator.c src/location-reporting.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/location-reporting.c b/src/location-reporting.c
new file mode 100644
index 000..6ab0914
--- /dev/null
+++ b/src/location-reporting.c
@@ -0,0 +1,393 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010  Nokia Corporation and/or its subsidiary(-ies).
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2011  ProFUSION embedded systems.
+ *
+ *  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
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
+
+static GSList *g_drivers = NULL;
+
+struct ofono_location_reporting {
+   DBusMessage *pending;
+   const struct ofono_location_reporting_driver *driver;
+   void *driver_data;
+   struct ofono_atom *atom;
+   ofono_bool_t enabled;
+   char *client_owner;
+   guint disconnect_watch;
+};
+
+static const char *location_reporting_type_to_string(
+   enum ofono_location_reporting_type type)
+{
+   switch (type) {
+   case OFONO_LOCATION_REPORTING_TYPE_NMEA:
+   return nmea;
+   };
+
+   return NULL;
+}
+
+static DBusMessage *location_reporting_get_properties(DBusConnection *conn,
+   DBusMessage *msg, void *data)
+
+{
+   struct ofono_location_reporting *lr = data;
+   DBusMessage *reply;
+   DBusMessageIter iter;
+   DBusMessageIter dict;
+   const char *type;
+   int value;
+
+   reply = dbus_message_new_method_return(msg);
+   if (reply == NULL)
+   return NULL;
+
+   dbus_message_iter_init_append(reply, iter);
+   dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+   OFONO_PROPERTIES_ARRAY_SIGNATURE,
+   dict);
+
+   value = lr-enabled;
+   ofono_dbus_dict_append(dict, Enabled, DBUS_TYPE_BOOLEAN, value);
+
+   type = location_reporting_type_to_string(lr-driver-type);
+   ofono_dbus_dict_append(dict, Type, DBUS_TYPE_STRING, type);
+
+   dbus_message_iter_close_container(iter, dict);
+
+   return reply;
+}
+
+static void client_remove(struct ofono_location_reporting *lr)
+{
+   DBusConnection *conn = ofono_dbus_get_connection();
+
+   if (lr-disconnect_watch) {
+   g_dbus_remove_watch(conn, lr-disconnect_watch);
+   lr-disconnect_watch = 0;
+   }
+
+   g_free(lr-client_owner);
+}
+
+static void signal_enabled(const struct ofono_location_reporting *lr)
+{
+   DBusConnection *conn = ofono_dbus_get_connection();
+   const char *path = __ofono_atom_get_path(lr-atom);
+   int value = lr-enabled;
+
+   ofono_dbus_signal_property_changed(conn, path,
+   OFONO_LOCATION_REPORTING_INTERFACE,
+   Enabled, DBUS_TYPE_BOOLEAN, value);
+}
+
+static void client_exited_disable_cb(const struct ofono_error *error,
+   void *data)
+{
+   struct ofono_location_reporting *lr = data;
+
+   if (error-type != OFONO_ERROR_TYPE_NO_ERROR) {
+   ofono_error(Disabling location-reporting failed);
+
+   return;
+   }
+
+   

[PATCH 0/7] sms: Cancel pending message

2011-02-04 Thread Lucas De Marchi
This patch set exports on MessageManager interface a method to cancel messages
that are pending on tx queue.

As the doc says, only messages that are currently waiting on message queue and
not being handled by the modem can be cancelled. Otherwise a race could occur.

First 4 patches are some refactors needed to accommodate this feature, that has
been added on 5th patch.

Lucas De Marchi (7):
  history: add cancelled status
  examples: handle cancelled history status
  message: add cancelled state
  sms: factor out 'remove entry' from tx_finished()
  sms: allow message submission to be cancelled
  doc: add CancelMessage to MessageManager
  TODO: mark task 'cancel pending SMS' as done

 TODO   |9 --
 doc/messagemanager-api.txt |   10 +++
 examples/history.c |5 +
 include/history.h  |1 +
 src/message.c  |2 +
 src/message.h  |3 +-
 src/sms.c  |  181 ++--
 7 files changed, 161 insertions(+), 50 deletions(-)

-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/7] examples: handle cancelled history status

2011-02-04 Thread Lucas De Marchi
---
 examples/history.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/examples/history.c b/examples/history.c
index 0a1e8d7..21668ec 100644
--- a/examples/history.c
+++ b/examples/history.c
@@ -172,6 +172,11 @@ static void example_history_sms_send_status(
ofono_debug(Sending SMS %s failed, ofono_uuid_to_str(uuid));
ofono_debug(Failure Time: %s, buf);
break;
+   case OFONO_HISTORY_SMS_STATUS_SUBMIT_CANCELLED:
+   ofono_debug(Submission of SMS %s was canceled,
+   ofono_uuid_to_str(uuid));
+   ofono_debug(Cancel time: %s, buf);
+   break;
case OFONO_HISTORY_SMS_STATUS_DELIVERED:
ofono_debug(SMS delivered, msg_id: %s, time: %s,
ofono_uuid_to_str(uuid), buf);
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/7] message: add cancelled state

2011-02-04 Thread Lucas De Marchi
Based on patch from Yang Gu gya...@gmail.com
---
 src/message.c |2 ++
 src/message.h |3 ++-
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/message.c b/src/message.c
index eb85adf..668a693 100644
--- a/src/message.c
+++ b/src/message.c
@@ -46,6 +46,8 @@ static const char *message_state_to_string(enum message_state 
s)
return sent;
case MESSAGE_STATE_FAILED:
return failed;
+   case MESSAGE_STATE_CANCELLED:
+   return cancelled;
}
 
return NULL;
diff --git a/src/message.h b/src/message.h
index 14e66c3..ad30798 100644
--- a/src/message.h
+++ b/src/message.h
@@ -24,7 +24,8 @@
 enum message_state {
MESSAGE_STATE_PENDING,
MESSAGE_STATE_SENT,
-   MESSAGE_STATE_FAILED
+   MESSAGE_STATE_FAILED,
+   MESSAGE_STATE_CANCELLED,
 };
 
 struct ofono_atom;
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/7] history: add cancelled status

2011-02-04 Thread Lucas De Marchi
Based on patch from Yang Gu gya...@gmail.com
---
 include/history.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/history.h b/include/history.h
index c1c4aa1..756097e 100644
--- a/include/history.h
+++ b/include/history.h
@@ -35,6 +35,7 @@ enum ofono_history_sms_status {
OFONO_HISTORY_SMS_STATUS_PENDING,
OFONO_HISTORY_SMS_STATUS_SUBMITTED,
OFONO_HISTORY_SMS_STATUS_SUBMIT_FAILED,
+   OFONO_HISTORY_SMS_STATUS_SUBMIT_CANCELLED,
OFONO_HISTORY_SMS_STATUS_DELIVERED,
OFONO_HISTORY_SMS_STATUS_DELIVER_FAILED,
 };
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 4/7] sms: factor out 'remove entry' from tx_finished()

2011-02-04 Thread Lucas De Marchi
Refactor tx_finished() and create a function to remove an entry from the
tx queue. This function will be used also when a message is cancelled.
Thus, handle the case in which state is MESSAGE_STATE_CANCELLED as well.

Based on patch from Yang Gu gya...@gmail.com
---
 src/sms.c |   99 
 1 files changed, 59 insertions(+), 40 deletions(-)

diff --git a/src/sms.c b/src/sms.c
index 73e067e..7db91cb 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -65,6 +65,7 @@ struct ofono_sms {
struct sms_assembly *assembly;
guint ref;
GQueue *txq;
+   enum message_state tx_state;
unsigned long tx_counter;
guint tx_source;
struct ofono_message_waiting *mw;
@@ -538,15 +539,65 @@ static void tx_queue_entry_destroy_foreach(gpointer 
_entry, gpointer unused)
tx_queue_entry_destroy(_entry);
 }
 
+static void sms_tx_queue_remove_entry(struct ofono_sms *sms, GList *entry_list)
+{
+   struct tx_queue_entry *entry = entry_list-data;
+   struct ofono_modem *modem = __ofono_atom_get_modem(sms-atom);
+
+   g_queue_delete_link(sms-txq, entry_list);
+
+   DBG(%p, entry);
+
+   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY) {
+   enum ofono_history_sms_status hs;
+
+   switch(sms-tx_state) {
+   case MESSAGE_STATE_SENT:
+   hs = OFONO_HISTORY_SMS_STATUS_SUBMITTED;
+   break;
+   case MESSAGE_STATE_FAILED:
+   hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_FAILED;
+   break;
+   case MESSAGE_STATE_CANCELLED:
+   hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_CANCELLED;
+   break;
+   default:
+   ofono_error(Unexpected sms state %d, sms-tx_state);
+
+   return;
+   }
+
+   __ofono_history_sms_send_status(modem, entry-uuid,
+   time(NULL), hs);
+   }
+
+   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) {
+   struct message *m;
+
+   sms_tx_backup_free(sms-imsi, entry-id, entry-flags,
+   ofono_uuid_to_str(entry-uuid));
+
+   m = g_hash_table_lookup(sms-messages, entry-uuid);
+
+   if (m != NULL) {
+   message_set_state(m, sms-tx_state);
+   g_hash_table_remove(sms-messages, entry-uuid);
+   message_emit_removed(m,
+   OFONO_MESSAGE_MANAGER_INTERFACE);
+   message_dbus_unregister(m);
+   }
+   }
+
+   tx_queue_entry_destroy(entry);
+}
+
 static void tx_finished(const struct ofono_error *error, int mr, void *data)
 {
struct ofono_sms *sms = data;
-   struct ofono_modem *modem = __ofono_atom_get_modem(sms-atom);
struct tx_queue_entry *entry = g_queue_peek_head(sms-txq);
gboolean ok = error-type == OFONO_ERROR_TYPE_NO_ERROR;
-   struct message *m = NULL;
 
-   DBG(tx_finished);
+   DBG(tx_finished %p, entry);
 
if (ok == FALSE) {
/* Retry again when back in online mode */
@@ -554,6 +605,8 @@ static void tx_finished(const struct ofono_error *error, 
int mr, void *data)
if (sms-registered == FALSE)
return;
 
+   sms-tx_state = MESSAGE_STATE_FAILED;
+
if (!(entry-flags  OFONO_SMS_SUBMIT_FLAG_RETRY))
goto next_q;
 
@@ -591,47 +644,13 @@ static void tx_finished(const struct ofono_error *error, 
int mr, void *data)
return;
}
 
-next_q:
-   entry = g_queue_pop_head(sms-txq);
+   sms-tx_state = MESSAGE_STATE_SENT;
 
+next_q:
if (entry-cb)
entry-cb(ok, entry-data);
 
-   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY) {
-   enum ofono_history_sms_status hs;
-
-   if (ok)
-   hs = OFONO_HISTORY_SMS_STATUS_SUBMITTED;
-   else
-   hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_FAILED;
-
-   __ofono_history_sms_send_status(modem, entry-uuid,
-   time(NULL), hs);
-   }
-
-   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) {
-   enum message_state ms;
-
-   sms_tx_backup_free(sms-imsi, entry-id, entry-flags,
-   ofono_uuid_to_str(entry-uuid));
-
-   if (ok)
-   ms = MESSAGE_STATE_SENT;
-   else
-   ms = MESSAGE_STATE_FAILED;
-
-   m = g_hash_table_lookup(sms-messages, entry-uuid);
-
-   if (m != NULL) {
-   message_set_state(m, ms);
-   

[PATCH 6/7] doc: add CancelMessage to MessageManager

2011-02-04 Thread Lucas De Marchi
---
 doc/messagemanager-api.txt |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/doc/messagemanager-api.txt b/doc/messagemanager-api.txt
index 0723e9c..3d66193 100644
--- a/doc/messagemanager-api.txt
+++ b/doc/messagemanager-api.txt
@@ -32,6 +32,16 @@ Methods  dict GetProperties()
Possible Errors: [service].Error.InvalidArguments
 [service].Error.DoesNotExist
 
+   void CancelMessage(object path)
+
+   Cancel a message that was previously sent. Only
+   messages that are waiting on queue can be cancelled and
+   it's not possible to cancel messages that already had
+   some parts delivered.
+
+   Possible Errors: [service].Error.InvalidArguments
+[service].Error.Failed
+
object SendMessage(string to, string text)
 
Send the message in text to the number in to.  If the
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 7/7] TODO: mark task 'cancel pending SMS' as done

2011-02-04 Thread Lucas De Marchi
---
 TODO |9 -
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/TODO b/TODO
index 13a6baa..8790209 100644
--- a/TODO
+++ b/TODO
@@ -31,15 +31,6 @@ SMS
   Priority: Low
   Complexity: C8
 
-- See / Cancel pending SMS messages over DBus.  When oFono sends SMS messages
-  the method call is only returned when the message has been submitted to the
-  network.  Instead we should return an object path and allow cancellation of
-  pending messages.
-
-  Priority: High
-  Complexity: C2
-  Owner: Yang Gu yang...@intel.com
-
 - Asynchronously acknowledge SMS DELIVER messages sent by the SMS driver
   to core using ofono_sms_deliver_notify().  This may require the struct
   ofono_sms_driver to be extended with one more function pointer like:
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 5/7] sms: allow message submission to be cancelled

2011-02-04 Thread Lucas De Marchi
Based on patch from Yang Gu gya...@gmail.com
---
 src/sms.c |   82 +
 1 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/src/sms.c b/src/sms.c
index 7db91cb..91b0a31 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -685,6 +685,8 @@ static gboolean tx_next(gpointer user_data)
|| (entry-num_pdus - entry-cur_pdu)  1)
send_mms = 1;
 
+   sms-tx_state = MESSAGE_STATE_PENDING;
+
sms-driver-submit(sms, pdu-pdu, pdu-pdu_len, pdu-tpdu_len,
send_mms, tx_finished, sms);
 
@@ -970,6 +972,85 @@ static DBusMessage *sms_get_messages(DBusConnection *conn, 
DBusMessage *msg,
return reply;
 }
 
+static gboolean uuid_from_message_path(const char *path,
+   struct ofono_uuid *uuid)
+{
+   const char *uuidstr;
+
+   uuidstr = path + strlen(path) - OFONO_SHA1_UUID_LEN * 2;
+
+   if (decode_hex_own_buf(uuidstr, -1, NULL, 0, uuid-uuid) == NULL)
+   return FALSE;
+
+   return TRUE;
+}
+
+static gint entry_compare_by_uuid(gconstpointer a, gconstpointer b)
+{
+   const struct tx_queue_entry *entry = a;
+   const char *uuid = b;
+
+   return memcmp(entry-uuid, uuid, sizeof(entry-uuid));
+}
+
+static DBusMessage *sms_cancel_message(DBusConnection *conn, DBusMessage *msg,
+   void *data)
+{
+   struct ofono_sms *sms = data;
+   char *path;
+   struct ofono_uuid uuid;
+   GList *l;
+   struct tx_queue_entry *entry;
+
+   if (sms-pending)
+   return __ofono_error_busy(msg);
+
+   if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, path,
+   DBUS_TYPE_INVALID) == FALSE)
+   return __ofono_error_invalid_args(msg);
+
+   if (path[0] == '\0')
+   return __ofono_error_invalid_args(msg);
+
+   if (uuid_from_message_path(path, uuid) == FALSE)
+   return __ofono_error_invalid_args(msg);
+
+   l = g_queue_find_custom(sms-txq, uuid.uuid, entry_compare_by_uuid);
+
+   if (l == NULL)
+   return __ofono_error_failed(msg);
+
+   entry = l-data;
+
+   if (entry == g_queue_peek_head(sms-txq)) {
+   /*
+* Fail if any pdu was already transmitted or if we are
+* waiting the answer from driver.
+*/
+   if (entry-cur_pdu  0 ||
+   sms-tx_state == MESSAGE_STATE_PENDING)
+   return __ofono_error_failed(msg);
+
+   /*
+* Make sure we don't call tx_next() if there are no entries
+* and that next entry doesn't have to wait a 'retry time'
+* from this one.
+*/
+   if (sms-tx_source) {
+   g_source_remove(sms-tx_source);
+   sms-tx_source = 0;
+
+   if (g_queue_get_length(sms-txq)  1)
+   sms-tx_source = g_timeout_add(0, tx_next, sms);
+   }
+   }
+
+   sms-tx_state = MESSAGE_STATE_CANCELLED;
+   sms_tx_queue_remove_entry(sms, l);
+
+   return dbus_message_new_method_return(msg);
+}
+
 static GDBusMethodTable sms_manager_methods[] = {
{ GetProperties,,a{sv},sms_get_properties,
G_DBUS_METHOD_FLAG_ASYNC },
@@ -977,6 +1058,7 @@ static GDBusMethodTable sms_manager_methods[] = {
G_DBUS_METHOD_FLAG_ASYNC },
{ SendMessage,  ss,  o, sms_send_message,
G_DBUS_METHOD_FLAG_ASYNC },
+   { CancelMessage,o,   ,  sms_cancel_message },
{ GetMessages,   ,a(oa{sv}),sms_get_messages },
{ }
 };
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH 5/7] sms: allow message submission to be cancelled

2011-02-04 Thread Lucas De Marchi
Hi Andrzej,

On Fri, Feb 4, 2011 at 1:58 PM, andrzej zaborowski balr...@gmail.com wrote:
 Hi,

 On 4 February 2011 16:02, Lucas De Marchi lucas.demar...@profusion.mobi 
 wrote:
 Based on patch from Yang Gu gya...@gmail.com
 ---
  src/sms.c |   82 
 +
  1 files changed, 82 insertions(+), 0 deletions(-)

 diff --git a/src/sms.c b/src/sms.c
 index 7db91cb..91b0a31 100644
 --- a/src/sms.c
 +++ b/src/sms.c
 @@ -685,6 +685,8 @@ static gboolean tx_next(gpointer user_data)
                        || (entry-num_pdus - entry-cur_pdu)  1)
                send_mms = 1;

 +       sms-tx_state = MESSAGE_STATE_PENDING;
 +
        sms-driver-submit(sms, pdu-pdu, pdu-pdu_len, pdu-tpdu_len,
                                send_mms, tx_finished, sms);

 @@ -970,6 +972,85 @@ static DBusMessage *sms_get_messages(DBusConnection 
 *conn, DBusMessage *msg,
        return reply;
  }

 +static gboolean uuid_from_message_path(const char *path,
 +                                               struct ofono_uuid *uuid)
 +{
 +       const char *uuidstr;
 +
 +       uuidstr = path + strlen(path) - OFONO_SHA1_UUID_LEN * 2;
 +
 +       if (decode_hex_own_buf(uuidstr, -1, NULL, 0, uuid-uuid) == NULL)
 +               return FALSE;

 I think you need to at least check that strlen(path) =
 OFONO_SHA1_UUID_LEN * 2 or we might segfault.

Indeed. I'll fix this.


 +static DBusMessage *sms_cancel_message(DBusConnection *conn, DBusMessage 
 *msg,
 +                                                               void *data)
 +{
 +       struct ofono_sms *sms = data;
 +       char *path;
 +       struct ofono_uuid uuid;
 +       GList *l;
 +       struct tx_queue_entry *entry;
 +
 +       if (sms-pending)
 +               return __ofono_error_busy(msg);
 +
 +       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, path,
 +                                       DBUS_TYPE_INVALID) == FALSE)
 +               return __ofono_error_invalid_args(msg);
 +
 +       if (path[0] == '\0')
 +               return __ofono_error_invalid_args(msg);
 +
 +       if (uuid_from_message_path(path, uuid) == FALSE)
 +               return __ofono_error_invalid_args(msg);
 +
 +       l = g_queue_find_custom(sms-txq, uuid.uuid, entry_compare_by_uuid);
 +
 +       if (l == NULL)
 +               return __ofono_error_failed(msg);

 Maybe __ofono_error_not_found?

ok.


 +
 +       entry = l-data;
 +
 +       if (entry == g_queue_peek_head(sms-txq)) {
 +               /*
 +                * Fail if any pdu was already transmitted or if we are
 +                * waiting the answer from driver.
 +                */
 +               if (entry-cur_pdu  0 ||
 +                                       sms-tx_state == 
 MESSAGE_STATE_PENDING)
 +                       return __ofono_error_failed(msg);
 +
 +               /*
 +                * Make sure we don't call tx_next() if there are no entries
 +                * and that next entry doesn't have to wait a 'retry time'
 +                * from this one.
 +                */
 +               if (sms-tx_source) {
 +                       g_source_remove(sms-tx_source);
 +                       sms-tx_source = 0;
 +
 +                       if (g_queue_get_length(sms-txq)  1)
 +                               sms-tx_source = g_timeout_add(0, tx_next, 
 sms);
 +               }
 +       }
 +
 +       sms-tx_state = MESSAGE_STATE_CANCELLED;
 +       sms_tx_queue_remove_entry(sms, l);

 As you mentioned on IRC we may need to call the submitted callback
 with ok == FALSE.

ok.


 I also wonder if we need to check that (entry-flags 
 OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) and update some property.

It's already handled inside sms_tx_queue_remove_entry().


thanks,

Lucas De Marchi
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 1/8] history: add cancelled status

2011-02-04 Thread Lucas De Marchi
Based on patch from Yang Gu gya...@gmail.com
---
 include/history.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/history.h b/include/history.h
index c1c4aa1..756097e 100644
--- a/include/history.h
+++ b/include/history.h
@@ -35,6 +35,7 @@ enum ofono_history_sms_status {
OFONO_HISTORY_SMS_STATUS_PENDING,
OFONO_HISTORY_SMS_STATUS_SUBMITTED,
OFONO_HISTORY_SMS_STATUS_SUBMIT_FAILED,
+   OFONO_HISTORY_SMS_STATUS_SUBMIT_CANCELLED,
OFONO_HISTORY_SMS_STATUS_DELIVERED,
OFONO_HISTORY_SMS_STATUS_DELIVER_FAILED,
 };
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 2/8] examples: handle cancelled history status

2011-02-04 Thread Lucas De Marchi
---
 examples/history.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/examples/history.c b/examples/history.c
index 0a1e8d7..21668ec 100644
--- a/examples/history.c
+++ b/examples/history.c
@@ -172,6 +172,11 @@ static void example_history_sms_send_status(
ofono_debug(Sending SMS %s failed, ofono_uuid_to_str(uuid));
ofono_debug(Failure Time: %s, buf);
break;
+   case OFONO_HISTORY_SMS_STATUS_SUBMIT_CANCELLED:
+   ofono_debug(Submission of SMS %s was canceled,
+   ofono_uuid_to_str(uuid));
+   ofono_debug(Cancel time: %s, buf);
+   break;
case OFONO_HISTORY_SMS_STATUS_DELIVERED:
ofono_debug(SMS delivered, msg_id: %s, time: %s,
ofono_uuid_to_str(uuid), buf);
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 3/8] message: add cancelled state

2011-02-04 Thread Lucas De Marchi
Based on patch from Yang Gu gya...@gmail.com
---
 src/message.c |2 ++
 src/message.h |3 ++-
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/message.c b/src/message.c
index eb85adf..668a693 100644
--- a/src/message.c
+++ b/src/message.c
@@ -46,6 +46,8 @@ static const char *message_state_to_string(enum message_state 
s)
return sent;
case MESSAGE_STATE_FAILED:
return failed;
+   case MESSAGE_STATE_CANCELLED:
+   return cancelled;
}
 
return NULL;
diff --git a/src/message.h b/src/message.h
index 14e66c3..ad30798 100644
--- a/src/message.h
+++ b/src/message.h
@@ -24,7 +24,8 @@
 enum message_state {
MESSAGE_STATE_PENDING,
MESSAGE_STATE_SENT,
-   MESSAGE_STATE_FAILED
+   MESSAGE_STATE_FAILED,
+   MESSAGE_STATE_CANCELLED,
 };
 
 struct ofono_atom;
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 4/8] sms: factor out 'remove entry' from tx_finished()

2011-02-04 Thread Lucas De Marchi
Refactor tx_finished() and create a function to remove an entry from the
tx queue. This function will be used also when a message is cancelled.
Thus, handle the case in which state is MESSAGE_STATE_CANCELLED as well.

Based on patch from Yang Gu gya...@gmail.com
---
 src/sms.c |  105 -
 1 files changed, 62 insertions(+), 43 deletions(-)

diff --git a/src/sms.c b/src/sms.c
index 73e067e..dfec456 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -65,6 +65,7 @@ struct ofono_sms {
struct sms_assembly *assembly;
guint ref;
GQueue *txq;
+   enum message_state tx_state;
unsigned long tx_counter;
guint tx_source;
struct ofono_message_waiting *mw;
@@ -538,15 +539,68 @@ static void tx_queue_entry_destroy_foreach(gpointer 
_entry, gpointer unused)
tx_queue_entry_destroy(_entry);
 }
 
+static void sms_tx_queue_remove_entry(struct ofono_sms *sms, GList *entry_list)
+{
+   struct tx_queue_entry *entry = entry_list-data;
+   struct ofono_modem *modem = __ofono_atom_get_modem(sms-atom);
+
+   g_queue_delete_link(sms-txq, entry_list);
+
+   DBG(%p, entry);
+
+   if (entry-cb)
+   entry-cb(sms-tx_state == MESSAGE_STATE_SENT, entry-data);
+
+   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY) {
+   enum ofono_history_sms_status hs;
+
+   switch(sms-tx_state) {
+   case MESSAGE_STATE_SENT:
+   hs = OFONO_HISTORY_SMS_STATUS_SUBMITTED;
+   break;
+   case MESSAGE_STATE_FAILED:
+   hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_FAILED;
+   break;
+   case MESSAGE_STATE_CANCELLED:
+   hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_CANCELLED;
+   break;
+   default:
+   ofono_error(Unexpected sms state %d, sms-tx_state);
+
+   return;
+   }
+
+   __ofono_history_sms_send_status(modem, entry-uuid,
+   time(NULL), hs);
+   }
+
+   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) {
+   struct message *m;
+
+   sms_tx_backup_free(sms-imsi, entry-id, entry-flags,
+   ofono_uuid_to_str(entry-uuid));
+
+   m = g_hash_table_lookup(sms-messages, entry-uuid);
+
+   if (m != NULL) {
+   message_set_state(m, sms-tx_state);
+   g_hash_table_remove(sms-messages, entry-uuid);
+   message_emit_removed(m,
+   OFONO_MESSAGE_MANAGER_INTERFACE);
+   message_dbus_unregister(m);
+   }
+   }
+
+   tx_queue_entry_destroy(entry);
+}
+
 static void tx_finished(const struct ofono_error *error, int mr, void *data)
 {
struct ofono_sms *sms = data;
-   struct ofono_modem *modem = __ofono_atom_get_modem(sms-atom);
struct tx_queue_entry *entry = g_queue_peek_head(sms-txq);
gboolean ok = error-type == OFONO_ERROR_TYPE_NO_ERROR;
-   struct message *m = NULL;
 
-   DBG(tx_finished);
+   DBG(tx_finished %p, entry);
 
if (ok == FALSE) {
/* Retry again when back in online mode */
@@ -554,6 +608,8 @@ static void tx_finished(const struct ofono_error *error, 
int mr, void *data)
if (sms-registered == FALSE)
return;
 
+   sms-tx_state = MESSAGE_STATE_FAILED;
+
if (!(entry-flags  OFONO_SMS_SUBMIT_FLAG_RETRY))
goto next_q;
 
@@ -591,47 +647,10 @@ static void tx_finished(const struct ofono_error *error, 
int mr, void *data)
return;
}
 
-next_q:
-   entry = g_queue_pop_head(sms-txq);
-
-   if (entry-cb)
-   entry-cb(ok, entry-data);
-
-   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY) {
-   enum ofono_history_sms_status hs;
-
-   if (ok)
-   hs = OFONO_HISTORY_SMS_STATUS_SUBMITTED;
-   else
-   hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_FAILED;
-
-   __ofono_history_sms_send_status(modem, entry-uuid,
-   time(NULL), hs);
-   }
-
-   if (entry-flags  OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) {
-   enum message_state ms;
-
-   sms_tx_backup_free(sms-imsi, entry-id, entry-flags,
-   ofono_uuid_to_str(entry-uuid));
-
-   if (ok)
-   ms = MESSAGE_STATE_SENT;
-   else
-   ms = MESSAGE_STATE_FAILED;
+   sms-tx_state = MESSAGE_STATE_SENT;
 
-   m = g_hash_table_lookup(sms-messages, entry-uuid);
-
-   if (m != NULL) {
-

[PATCH v2 5/8] sms: allow message submission to be cancelled

2011-02-04 Thread Lucas De Marchi
Based on patch from Yang Gu gya...@gmail.com
---
 src/sms.c |   88 +
 1 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/src/sms.c b/src/sms.c
index dfec456..212a470 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -685,6 +685,8 @@ static gboolean tx_next(gpointer user_data)
|| (entry-num_pdus - entry-cur_pdu)  1)
send_mms = 1;
 
+   sms-tx_state = MESSAGE_STATE_PENDING;
+
sms-driver-submit(sms, pdu-pdu, pdu-pdu_len, pdu-tpdu_len,
send_mms, tx_finished, sms);
 
@@ -970,6 +972,91 @@ static DBusMessage *sms_get_messages(DBusConnection *conn, 
DBusMessage *msg,
return reply;
 }
 
+static gboolean uuid_from_message_path(const char *path,
+   struct ofono_uuid *uuid)
+{
+   const char *uuidstr;
+   size_t len;
+
+   len = strlen(path);
+
+   if (len  OFONO_SHA1_UUID_LEN * 2)
+   return FALSE;
+
+   uuidstr = path + len - OFONO_SHA1_UUID_LEN * 2;
+
+   if (decode_hex_own_buf(uuidstr, -1, NULL, 0, uuid-uuid) == NULL)
+   return FALSE;
+
+   return TRUE;
+}
+
+static gint entry_compare_by_uuid(gconstpointer a, gconstpointer b)
+{
+   const struct tx_queue_entry *entry = a;
+   const char *uuid = b;
+
+   return memcmp(entry-uuid, uuid, sizeof(entry-uuid));
+}
+
+static DBusMessage *sms_cancel_message(DBusConnection *conn, DBusMessage *msg,
+   void *data)
+{
+   struct ofono_sms *sms = data;
+   char *path;
+   struct ofono_uuid uuid;
+   GList *l;
+   struct tx_queue_entry *entry;
+
+   if (sms-pending)
+   return __ofono_error_busy(msg);
+
+   if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, path,
+   DBUS_TYPE_INVALID) == FALSE)
+   return __ofono_error_invalid_args(msg);
+
+   if (path[0] == '\0')
+   return __ofono_error_invalid_args(msg);
+
+   if (uuid_from_message_path(path, uuid) == FALSE)
+   return __ofono_error_invalid_args(msg);
+
+   l = g_queue_find_custom(sms-txq, uuid.uuid, entry_compare_by_uuid);
+
+   if (l == NULL)
+   return __ofono_error_not_found(msg);
+
+   entry = l-data;
+
+   if (entry == g_queue_peek_head(sms-txq)) {
+   /*
+* Fail if any pdu was already transmitted or if we are
+* waiting the answer from driver.
+*/
+   if (entry-cur_pdu  0 ||
+   sms-tx_state == MESSAGE_STATE_PENDING)
+   return __ofono_error_failed(msg);
+
+   /*
+* Make sure we don't call tx_next() if there are no entries
+* and that next entry doesn't have to wait a 'retry time'
+* from this one.
+*/
+   if (sms-tx_source) {
+   g_source_remove(sms-tx_source);
+   sms-tx_source = 0;
+
+   if (g_queue_get_length(sms-txq)  1)
+   sms-tx_source = g_timeout_add(0, tx_next, sms);
+   }
+   }
+
+   sms-tx_state = MESSAGE_STATE_CANCELLED;
+   sms_tx_queue_remove_entry(sms, l);
+
+   return dbus_message_new_method_return(msg);
+}
+
 static GDBusMethodTable sms_manager_methods[] = {
{ GetProperties,,a{sv},sms_get_properties,
G_DBUS_METHOD_FLAG_ASYNC },
@@ -977,6 +1064,7 @@ static GDBusMethodTable sms_manager_methods[] = {
G_DBUS_METHOD_FLAG_ASYNC },
{ SendMessage,  ss,  o, sms_send_message,
G_DBUS_METHOD_FLAG_ASYNC },
+   { CancelMessage,o,   ,  sms_cancel_message },
{ GetMessages,   ,a(oa{sv}),sms_get_messages },
{ }
 };
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 7/8] TODO: mark task 'cancel pending SMS' as done

2011-02-04 Thread Lucas De Marchi
---
 TODO |9 -
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/TODO b/TODO
index 13a6baa..8790209 100644
--- a/TODO
+++ b/TODO
@@ -31,15 +31,6 @@ SMS
   Priority: Low
   Complexity: C8
 
-- See / Cancel pending SMS messages over DBus.  When oFono sends SMS messages
-  the method call is only returned when the message has been submitted to the
-  network.  Instead we should return an object path and allow cancellation of
-  pending messages.
-
-  Priority: High
-  Complexity: C2
-  Owner: Yang Gu yang...@intel.com
-
 - Asynchronously acknowledge SMS DELIVER messages sent by the SMS driver
   to core using ofono_sms_deliver_notify().  This may require the struct
   ofono_sms_driver to be extended with one more function pointer like:
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 6/8] doc: add CancelMessage to MessageManager

2011-02-04 Thread Lucas De Marchi
---
 doc/messagemanager-api.txt |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/doc/messagemanager-api.txt b/doc/messagemanager-api.txt
index 0723e9c..29453c3 100644
--- a/doc/messagemanager-api.txt
+++ b/doc/messagemanager-api.txt
@@ -32,6 +32,18 @@ Methods  dict GetProperties()
Possible Errors: [service].Error.InvalidArguments
 [service].Error.DoesNotExist
 
+   void CancelMessage(object path)
+
+   Cancel a message that was previously sent. Only
+   messages that are waiting on queue can be cancelled and
+   it's not possible to cancel messages that already had
+   some parts delivered.
+
+   Possible Errors: [service].Error.InvalidArguments
+[service].Error.InProgress
+[service].Error.NotFound
+[service].Error.Failed
+
object SendMessage(string to, string text)
 
Send the message in text to the number in to.  If the
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 8/8] sms: remove check for impossible NULL condition

2011-02-04 Thread Lucas De Marchi
tx_next() must never be called with entry == NULL and currently it
was already being dereferenced before making this check. Thus just
remove it.
---
 src/sms.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/src/sms.c b/src/sms.c
index 212a470..be7132a5 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -675,9 +675,6 @@ static gboolean tx_next(gpointer user_data)
 
sms-tx_source = 0;
 
-   if (entry == NULL)
-   return FALSE;
-
if (sms-registered == FALSE)
return FALSE;
 
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] smart-messaging: set agent to NULL after free

2011-02-02 Thread Lucas De Marchi
If agent is not set to NULL after it's freed, the following situation
would not work:

smart_messaging_register_agent()
smart_messaging_unregister_agent()
smart_messaging_register_agent()

And this one could potentially crash oFono:

smart_messaging_register_agent()
smart_messaging_unregister_agent()
smart_messaging_unregister_agent()
---
 plugins/smart-messaging.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/plugins/smart-messaging.c b/plugins/smart-messaging.c
index 40af89f..52344de 100644
--- a/plugins/smart-messaging.c
+++ b/plugins/smart-messaging.c
@@ -165,6 +165,7 @@ static DBusMessage 
*smart_messaging_unregister_agent(DBusConnection *conn,
return __ofono_error_failed(msg);
 
sms_agent_free(sm-agent);
+   sm-agent = NULL;
 
return dbus_message_new_method_return(msg);
 }
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/9] common: implement initializer for ofono_call

2011-02-01 Thread Lucas De Marchi
---
 src/common.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/common.c b/src/common.c
index 8bf9dbb..f25f105 100644
--- a/src/common.c
+++ b/src/common.c
@@ -762,3 +762,10 @@ const char *ofono_uuid_to_str(const struct ofono_uuid 
*uuid)
 
return encode_hex_own_buf(uuid-uuid, OFONO_SHA1_UUID_LEN, 0, buf);
 }
+
+void ofono_call_init(struct ofono_call *call)
+{
+   memset(call, 0, sizeof(struct ofono_call));
+   call-cnap_validity = CNAP_VALIDITY_NOT_AVAILABLE;
+   call-clip_validity = CLIP_VALIDITY_NOT_AVAILABLE;
+}
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 4/9] calypsomodem: use ofono_call initializer

2011-02-01 Thread Lucas De Marchi
---
 drivers/calypsomodem/voicecall.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/calypsomodem/voicecall.c b/drivers/calypsomodem/voicecall.c
index 01be990..fed442c 100644
--- a/drivers/calypsomodem/voicecall.c
+++ b/drivers/calypsomodem/voicecall.c
@@ -314,7 +314,7 @@ static void cpi_notify(GAtResult *result, gpointer 
user_data)
g_at_chat_send(vd-chat, AT%N0187, none_prefix,
NULL, NULL, NULL);
 
-   memset(call, 0, sizeof(call));
+   ofono_call_init(call);
 
switch (msgtype) {
case 0:
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 6/9] huaweimodem: use ofono_call initializer

2011-02-01 Thread Lucas De Marchi
---
 drivers/huaweimodem/voicecall.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/huaweimodem/voicecall.c b/drivers/huaweimodem/voicecall.c
index a30513a..53377d9 100644
--- a/drivers/huaweimodem/voicecall.c
+++ b/drivers/huaweimodem/voicecall.c
@@ -56,10 +56,12 @@ static struct ofono_call *create_call(struct 
ofono_voicecall *vc, int type,
struct ofono_call *call;
 
/* Generate a call structure for the waiting call */
-   call = g_try_new0(struct ofono_call, 1);
+   call = g_try_new(struct ofono_call, 1);
if (call == NULL)
return NULL;
 
+   ofono_call_init(call);
+
call-id = id;
call-type = type;
call-direction = direction;
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 7/9] ifxmodem: use ofono_call initializer

2011-02-01 Thread Lucas De Marchi
---
 drivers/ifxmodem/voicecall.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/ifxmodem/voicecall.c b/drivers/ifxmodem/voicecall.c
index 716652c..e7f72fc 100644
--- a/drivers/ifxmodem/voicecall.c
+++ b/drivers/ifxmodem/voicecall.c
@@ -87,10 +87,12 @@ static struct ofono_call *create_call(struct 
ofono_voicecall *vc, int type,
struct ofono_call *call;
 
/* Generate a call structure for the waiting call */
-   call = g_try_new0(struct ofono_call, 1);
+   call = g_try_new(struct ofono_call, 1);
if (call == NULL)
return NULL;
 
+   ofono_call_init(call);
+
call-id = ofono_voicecall_get_next_callid(vc);
call-type = type;
call-direction = direction;
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/5] doc: fix misspelling

2011-02-01 Thread Lucas De Marchi
---
 doc/sim-api.txt |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/doc/sim-api.txt b/doc/sim-api.txt
index 65c920d..c8091f7 100644
--- a/doc/sim-api.txt
+++ b/doc/sim-api.txt
@@ -129,7 +129,7 @@ Properties  boolean Present [readonly]
 
string CardIdentifier [readonly]
 
-   Contains the Intergrated Circuit Card Identifer (ICCID)
+   Contains the Integrated Circuit Card Identifer (ICCID)
which is read directly from the SIM.
 
boolean FixedDialing [readonly]
-- 
1.7.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 0/3] Persist TX SMS messages

2011-01-27 Thread Lucas De Marchi
Differences from previous version:

- Now we don't re-encode the SMS to a PDU when storing it to disk
- Sms' ref is not incremented
- When restoring sms pdus, directories and files that do not match the expected
  names are filtered out

I've tested this patch series using phonesim by calling exit(1) in some places
to simulate crashes. The pending sms messages were correctly sent once oFono
was up again.


Lucas De Marchi (3):
  sms: store pending tx pdus on disk
  sms: delete sent sms messages from backup
  sms: restore pending tx messages from backup

 src/ofono.h   |1 +
 src/sms.c |   96 +
 src/smsutil.c |  260 +
 src/smsutil.h |   19 
 4 files changed, 376 insertions(+), 0 deletions(-)

-- 
1.7.3.5

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 3/3] sms: restore pending tx messages from backup

2011-01-27 Thread Lucas De Marchi
Based on patch from: Kristen Carlson Accardi kris...@linux.intel.com
---
 src/ofono.h   |1 +
 src/sms.c |   67 +
 src/smsutil.c |  185 +
 src/smsutil.h |8 +++
 4 files changed, 261 insertions(+), 0 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index df20103..6ba0187 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -245,6 +245,7 @@ enum ofono_sms_submit_flag {
OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY =  0x2,
OFONO_SMS_SUBMIT_FLAG_RETRY =   0x4,
OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS = 0x8,
+   OFONO_SMS_SUBMIT_FLAG_REUSE_UUID =  0x10,
 };
 
 typedef void (*ofono_sms_txq_submit_cb_t)(gboolean ok, void *data);
diff --git a/src/sms.c b/src/sms.c
index 2fe67c8..7b85257 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -798,6 +798,9 @@ static struct tx_queue_entry *tx_queue_entry_new(GSList 
*msg_list,
pdu-pdu_len, pdu-tpdu_len);
}
 
+   if (flags  OFONO_SMS_SUBMIT_FLAG_REUSE_UUID)
+   return entry;
+
if (sms_uuid_from_pdus(entry-pdus, entry-num_pdus, entry-uuid))
return entry;
 
@@ -1694,6 +1697,68 @@ static void bearer_init_callback(const struct 
ofono_error *error, void *data)
ofono_error(Error bootstrapping SMS Bearer Preference);
 }
 
+static void sms_restore_tx_queue(struct ofono_sms *sms)
+{
+   GQueue *backupq;
+   struct txq_backup_entry *backup_entry;
+   struct ofono_uuid ofono_uuid;
+
+   DBG();
+
+   backupq = sms_tx_queue_load(sms-imsi);
+
+   if (backupq == NULL)
+   return;
+
+   while ((backup_entry = g_queue_pop_head(backupq))) {
+   struct message *m;
+   struct tx_queue_entry *txq_entry;
+
+   decode_hex_own_buf(backup_entry-uuid, -1, NULL, 0,
+   ofono_uuid.uuid);
+
+   backup_entry-flags |= OFONO_SMS_SUBMIT_FLAG_REUSE_UUID;
+   txq_entry = tx_queue_entry_new(backup_entry-msg_list,
+   backup_entry-flags);
+   if (txq_entry == NULL)
+   goto loop_out;
+
+   txq_entry-flags = ~OFONO_SMS_SUBMIT_FLAG_REUSE_UUID;
+   memcpy(txq_entry-uuid, ofono_uuid, sizeof(ofono_uuid));
+
+   m = message_create(txq_entry-uuid, sms-atom);
+   if (m == NULL) {
+   tx_queue_entry_destroy(txq_entry);
+
+   goto loop_out;
+   }
+
+   if (message_dbus_register(m) == FALSE) {
+   tx_queue_entry_destroy(txq_entry);
+
+   goto loop_out;
+   }
+
+   message_set_data(m, txq_entry);
+   g_hash_table_insert(sms-messages, txq_entry-uuid, m);
+
+   txq_entry-id = sms-tx_counter++;
+   g_queue_push_tail(sms-txq, txq_entry);
+
+loop_out:
+   g_slist_foreach(backup_entry-msg_list, (GFunc)g_free, NULL);
+   g_slist_free(backup_entry-msg_list);
+
+   g_free(backup_entry-uuid);
+   g_free(backup_entry);
+   }
+
+   if (g_queue_get_length(sms-txq)  0)
+   sms-tx_source = g_timeout_add(0, tx_next, sms);
+
+   g_queue_free(backupq);
+}
+
 /*
  * Indicate oFono that a SMS driver is ready for operation
  *
@@ -1766,6 +1831,8 @@ void ofono_sms_register(struct ofono_sms *sms)
sms-driver-bearer_set(sms, sms-bearer,
bearer_init_callback, sms);
 
+   sms_restore_tx_queue(sms);
+
sms-text_handlers = __ofono_watchlist_new(g_free);
sms-datagram_handlers = __ofono_watchlist_new(g_free);
 
diff --git a/src/smsutil.c b/src/smsutil.c
index 72f498a..52219b4 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -34,6 +34,7 @@
 
 #include glib.h
 
+#include ofono/types.h
 #include util.h
 #include storage.h
 #include smsutil.h
@@ -2327,6 +2328,15 @@ static gboolean sms_deserialize(const unsigned char *buf,
return sms_decode(buf + 1, len - 1, FALSE, buf[0], sms);
 }
 
+static gboolean sms_deserialize_outgoing(const unsigned char *buf,
+   struct sms *sms, int len)
+{
+   if (len  1)
+   return FALSE;
+
+   return sms_decode(buf + 1, len - 1, TRUE, buf[0], sms);
+}
+
 static gboolean sms_assembly_extract_address(const char *straddr,
struct sms_address *out)
 {
@@ -3147,6 +3157,181 @@ void status_report_assembly_expire(struct 
status_report_assembly *assembly,
}
 }
 
+static int sms_tx_load_filter(const struct dirent *dent)
+{
+   char *endp;
+   guint8 seq;
+
+   if (dent-d_type != DT_REG)
+   return 0;
+
+   seq = strtol(dent-d_name, endp, 10);
+
+   if (*endp != '\0')
+   return 0;
+
+   return 1;
+}
+
+/*
+ 

  1   2   3   >