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 <glib.h>
+#include <errno.h>
#include <gdbus.h>
#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