Re: [PATCH 1/3] include: Add OFONO_ERROR_TYPE_ERRNO

2018-06-28 Thread Denis Kenzior

Hi Slava,

On 06/28/2018 11:30 AM, Slava Monich wrote:

---
  include/types.h | 1 +
  1 file changed, 1 insertion(+)



All three applied, thanks.

Regards,
-Denis

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


[PATCH 3/3] dbus: Add D-Bus mapping for OFONO_ERROR_TYPE_ERRNO

2018-06-28 Thread Slava Monich
---
 src/dbus.c | 38 +++---
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/dbus.c b/src/dbus.c
index cadf5c6..a175178 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -24,6 +24,7 @@
 #endif
 
 #include 
+#include 
 #include 
 
 #include "ofono.h"
@@ -45,6 +46,16 @@ static const struct error_mapping_entry cme_errors_mapping[] 
= {
{ 31,   __ofono_error_timed_out },
{ 32,   __ofono_error_access_denied },
{ 50,   __ofono_error_invalid_args },
+   { }
+};
+
+static const struct error_mapping_entry errno_errors_mapping[] = {
+   { EACCES,  __ofono_error_access_denied },
+   { EOPNOTSUPP,  __ofono_error_not_supported },
+   { ENOSYS,  __ofono_error_not_implemented },
+   { ETIMEDOUT,   __ofono_error_timed_out },
+   { EINPROGRESS, __ofono_error_busy },
+   { }
 };
 
 static void append_variant(DBusMessageIter *iter,
@@ -419,26 +430,31 @@ DBusMessage *__ofono_error_network_terminated(DBusMessage 
*msg)
" network");
 }
 
-DBusMessage *__ofono_error_from_error(const struct ofono_error *error,
-   DBusMessage *msg)
+static DBusMessage *__ofono_map_error(const struct error_mapping_entry *map,
+   int error, DBusMessage *msg)
 {
const struct error_mapping_entry *e;
-   int maxentries;
-   int i;
 
+   for (e = map; e->ofono_error_func; e++)
+   if (e->error == error)
+   return e->ofono_error_func(msg);
+
+   return __ofono_error_failed(msg);
+}
+
+DBusMessage *__ofono_error_from_error(const struct ofono_error *error,
+   DBusMessage *msg)
+{
switch (error->type) {
case OFONO_ERROR_TYPE_CME:
-   e = cme_errors_mapping;
-   maxentries = sizeof(cme_errors_mapping) /
-   sizeof(struct error_mapping_entry);
-   for (i = 0; i < maxentries; i++)
-   if (e[i].error == error->error)
-   return e[i].ofono_error_func(msg);
-   break;
+   return __ofono_map_error(cme_errors_mapping, error->error, msg);
case OFONO_ERROR_TYPE_CMS:
return __ofono_error_failed(msg);
case OFONO_ERROR_TYPE_CEER:
return __ofono_error_failed(msg);
+   case OFONO_ERROR_TYPE_ERRNO:
+   return __ofono_map_error(errno_errors_mapping,
+   ABS(error->error), msg);
default:
return __ofono_error_failed(msg);
}
-- 
1.9.1

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


[PATCH 2/3] emulator: Handle OFONO_ERROR_TYPE_ERRNO in switch

2018-06-28 Thread Slava Monich
---
 src/emulator.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/emulator.c b/src/emulator.c
index ccb26dc..b3afb3d 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -1347,6 +1347,7 @@ void ofono_emulator_send_final(struct ofono_emulator *em,
case OFONO_ERROR_TYPE_CEER:
case OFONO_ERROR_TYPE_SIM:
case OFONO_ERROR_TYPE_FAILURE:
+   case OFONO_ERROR_TYPE_ERRNO:
 failure:
g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
break;
-- 
1.9.1

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


[PATCH 1/3] include: Add OFONO_ERROR_TYPE_ERRNO

2018-06-28 Thread Slava Monich
---
 include/types.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/types.h b/include/types.h
index 2c64b20..90d8c2c 100644
--- a/include/types.h
+++ b/include/types.h
@@ -56,6 +56,7 @@ enum ofono_error_type {
OFONO_ERROR_TYPE_CEER,
OFONO_ERROR_TYPE_SIM,
OFONO_ERROR_TYPE_FAILURE,
+   OFONO_ERROR_TYPE_ERRNO
 };
 
 enum ofono_disconnect_reason {
-- 
1.9.1

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


Re: [PATCH] dbus: Make cme_errors_mapping static const

2018-06-28 Thread Denis Kenzior

Hi Slava,

On 06/28/2018 10:51 AM, Slava Monich wrote:

---
  src/dbus.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)



Applied, thanks.

Regards,
-Denis

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


[PATCH] dbus: Make cme_errors_mapping static const

2018-06-28 Thread Slava Monich
---
 src/dbus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/dbus.c b/src/dbus.c
index 3e1e162..cadf5c6 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -37,7 +37,7 @@ struct error_mapping_entry {
DBusMessage *(*ofono_error_func)(DBusMessage *);
 };
 
-struct error_mapping_entry cme_errors_mapping[] = {
+static const struct error_mapping_entry cme_errors_mapping[] = {
{ 3,__ofono_error_not_allowed },
{ 4,__ofono_error_not_supported },
{ 16,   __ofono_error_incorrect_password },
@@ -422,7 +422,7 @@ DBusMessage *__ofono_error_network_terminated(DBusMessage 
*msg)
 DBusMessage *__ofono_error_from_error(const struct ofono_error *error,
DBusMessage *msg)
 {
-   struct error_mapping_entry *e;
+   const struct error_mapping_entry *e;
int maxentries;
int i;
 
-- 
1.9.1

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


Re: [PATCH] dbus: Add D-Bus mapping for generic errors

2018-06-28 Thread Denis Kenzior

Hi Slava,

On 06/28/2018 09:50 AM, Slava Monich wrote:

This allows plugins/drivers to be a bit more specific about
what went wrong.
---
  src/dbus.c | 28 
  1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/dbus.c b/src/dbus.c
index 3e1e162..7ea86ed 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -24,6 +24,7 @@
  #endif
  
  #include 

+#include 
  #include 
  
  #include "ofono.h"

@@ -37,7 +38,7 @@ struct error_mapping_entry {
DBusMessage *(*ofono_error_func)(DBusMessage *);
  };
  
-struct error_mapping_entry cme_errors_mapping[] = {

+static const struct error_mapping_entry cme_errors_mapping[] = {


This should probably be a separate patch...


{ 3,__ofono_error_not_allowed },
{ 4,__ofono_error_not_supported },
{ 16,   __ofono_error_incorrect_password },
@@ -47,6 +48,14 @@ struct error_mapping_entry cme_errors_mapping[] = {
{ 50,   __ofono_error_invalid_args },
  };
  
+static const struct error_mapping_entry generic_errors_mapping[] = {

+   { EACCES,  __ofono_error_access_denied },
+   { EOPNOTSUPP,  __ofono_error_not_supported },
+   { ENOSYS,  __ofono_error_not_implemented },
+   { ETIMEDOUT,   __ofono_error_timed_out },
+   { EINPROGRESS, __ofono_error_busy }
+};
+
  static void append_variant(DBusMessageIter *iter,
int type, const void *value)
  {
@@ -422,15 +431,14 @@ DBusMessage *__ofono_error_network_terminated(DBusMessage 
*msg)
  DBusMessage *__ofono_error_from_error(const struct ofono_error *error,
DBusMessage *msg)
  {
-   struct error_mapping_entry *e;
+   const struct error_mapping_entry *e;
int maxentries;
int i;
  
  	switch (error->type) {

case OFONO_ERROR_TYPE_CME:
e = cme_errors_mapping;
-   maxentries = sizeof(cme_errors_mapping) /
-   sizeof(struct error_mapping_entry);
+   maxentries = G_N_ELEMENTS(cme_errors_mapping);
for (i = 0; i < maxentries; i++)
if (e[i].error == error->error)
return e[i].ofono_error_func(msg);
@@ -439,6 +447,18 @@ DBusMessage *__ofono_error_from_error(const struct 
ofono_error *error,
return __ofono_error_failed(msg);
case OFONO_ERROR_TYPE_CEER:
return __ofono_error_failed(msg);
+   case OFONO_ERROR_TYPE_FAILURE:


So I'm okay with the concept, but I'm not okay with trying to hi-jack an 
existing error type for this.  TYPE_FAILURE is used mostly for the 
internal emulator framework in the core or where we are returning an 
generic unknown error.


If you want to introduce an error type for ERRNO errors (which I still 
wonder how you plan to use this), okay, but at least add this as a 
specific type to ofono/types.h



+   if (error->error) {
+   int err = error->error;
+
+   if (err < 0) err = -err;
+   e = generic_errors_mapping;
+   maxentries = G_N_ELEMENTS(generic_errors_mapping);
+   for (i = 0; i < maxentries; i++)
+   if (e[i].error == err)
+   return e[i].ofono_error_func(msg);
+   }


Should this part be a separate utility function instead of a copy-paste job?


+   break;
default:
return __ofono_error_failed(msg);
}



Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH] dbus: Add D-Bus mapping for generic errors

2018-06-28 Thread Slava Monich
This allows plugins/drivers to be a bit more specific about
what went wrong.
---
 src/dbus.c | 28 
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/dbus.c b/src/dbus.c
index 3e1e162..7ea86ed 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -24,6 +24,7 @@
 #endif
 
 #include 
+#include 
 #include 
 
 #include "ofono.h"
@@ -37,7 +38,7 @@ struct error_mapping_entry {
DBusMessage *(*ofono_error_func)(DBusMessage *);
 };
 
-struct error_mapping_entry cme_errors_mapping[] = {
+static const struct error_mapping_entry cme_errors_mapping[] = {
{ 3,__ofono_error_not_allowed },
{ 4,__ofono_error_not_supported },
{ 16,   __ofono_error_incorrect_password },
@@ -47,6 +48,14 @@ struct error_mapping_entry cme_errors_mapping[] = {
{ 50,   __ofono_error_invalid_args },
 };
 
+static const struct error_mapping_entry generic_errors_mapping[] = {
+   { EACCES,  __ofono_error_access_denied },
+   { EOPNOTSUPP,  __ofono_error_not_supported },
+   { ENOSYS,  __ofono_error_not_implemented },
+   { ETIMEDOUT,   __ofono_error_timed_out },
+   { EINPROGRESS, __ofono_error_busy }
+};
+
 static void append_variant(DBusMessageIter *iter,
int type, const void *value)
 {
@@ -422,15 +431,14 @@ DBusMessage *__ofono_error_network_terminated(DBusMessage 
*msg)
 DBusMessage *__ofono_error_from_error(const struct ofono_error *error,
DBusMessage *msg)
 {
-   struct error_mapping_entry *e;
+   const struct error_mapping_entry *e;
int maxentries;
int i;
 
switch (error->type) {
case OFONO_ERROR_TYPE_CME:
e = cme_errors_mapping;
-   maxentries = sizeof(cme_errors_mapping) /
-   sizeof(struct error_mapping_entry);
+   maxentries = G_N_ELEMENTS(cme_errors_mapping);
for (i = 0; i < maxentries; i++)
if (e[i].error == error->error)
return e[i].ofono_error_func(msg);
@@ -439,6 +447,18 @@ DBusMessage *__ofono_error_from_error(const struct 
ofono_error *error,
return __ofono_error_failed(msg);
case OFONO_ERROR_TYPE_CEER:
return __ofono_error_failed(msg);
+   case OFONO_ERROR_TYPE_FAILURE:
+   if (error->error) {
+   int err = error->error;
+
+   if (err < 0) err = -err;
+   e = generic_errors_mapping;
+   maxentries = G_N_ELEMENTS(generic_errors_mapping);
+   for (i = 0; i < maxentries; i++)
+   if (e[i].error == err)
+   return e[i].ofono_error_func(msg);
+   }
+   break;
default:
return __ofono_error_failed(msg);
}
-- 
1.9.1

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