diff options
author | Philippe Nunes <philippe.nunes@linux.intel.com> | 2012-05-30 15:53:09 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2012-05-30 09:03:23 -0500 |
commit | 07a2e7028367a22fbebb073dabd25d605b04438b (patch) | |
tree | 225d71b02e3604cfc0933bf40bad91018f005c56 /src/dbus.c | |
parent | 21369944ad51cf9fe5f2f831c1afae33a18ecceb (diff) | |
download | ofono-07a2e7028367a22fbebb073dabd25d605b04438b.tar.bz2 |
dbus: Add __ofono_error_from_error utility function
Diffstat (limited to 'src/dbus.c')
-rw-r--r-- | src/dbus.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -32,6 +32,21 @@ static DBusConnection *g_connection; +struct error_mapping_entry { + int error; + DBusMessage *(*ofono_error_func)(DBusMessage *); +}; + +struct error_mapping_entry cme_errors_mapping[] = { + { 3, __ofono_error_not_allowed }, + { 4, __ofono_error_not_supported }, + { 16, __ofono_error_incorrect_password }, + { 30, __ofono_error_not_registered }, + { 31, __ofono_error_timed_out }, + { 32, __ofono_error_access_denied }, + { 50, __ofono_error_invalid_args }, +}; + static void append_variant(DBusMessageIter *iter, int type, void *value) { @@ -388,6 +403,33 @@ DBusMessage *__ofono_error_not_allowed(DBusMessage *msg) "Operation is not allowed"); } +DBusMessage *__ofono_error_from_error(const struct ofono_error *error, + DBusMessage *msg) +{ + 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); + for (i = 0; i < maxentries; i++) + if (e[i].error == error->error) + return e[i].ofono_error_func(msg); + break; + case OFONO_ERROR_TYPE_CMS: + return __ofono_error_failed(msg); + case OFONO_ERROR_TYPE_CEER: + return __ofono_error_failed(msg); + default: + return __ofono_error_failed(msg); + } + + return __ofono_error_failed(msg); +} + void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply) { DBusConnection *conn = ofono_dbus_get_connection(); |