Open Source Telephony
 help / color / mirror / Atom feed
From: Philippe Nunes <philippe.nunes@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH v2 1/2] dbus: Add __ofono_error_from_error utility function
Date: Wed, 30 May 2012 15:53:09 +0200	[thread overview]
Message-ID: <1338385990-27526-1-git-send-email-philippe.nunes@linux.intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2370 bytes --]

---
 src/dbus.c  |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/ofono.h |    3 +++
 2 files changed, 45 insertions(+)

diff --git a/src/dbus.c b/src/dbus.c
index 5cccc32..4ae6969 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -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();
diff --git a/src/ofono.h b/src/ofono.h
index 81d5f71..f0e1072 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -66,6 +66,9 @@ DBusMessage *__ofono_error_emergency_active(DBusMessage *msg);
 DBusMessage *__ofono_error_incorrect_password(DBusMessage *msg);
 DBusMessage *__ofono_error_not_allowed(DBusMessage *msg);
 
+DBusMessage *__ofono_error_from_error(const struct ofono_error *error,
+						DBusMessage *msg);
+
 void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply);
 
 gboolean __ofono_dbus_valid_object_path(const char *path);
-- 
1.7.9.5


             reply	other threads:[~2012-05-30 13:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 13:53 Philippe Nunes [this message]
2012-05-30 13:53 ` [PATCH v2 2/2] SS: Return specific ofono errors after SS failure Philippe Nunes
2012-05-30 14:07   ` Denis Kenzior
2012-05-30 14:06 ` [PATCH v2 1/2] dbus: Add __ofono_error_from_error utility function Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338385990-27526-1-git-send-email-philippe.nunes@linux.intel.com \
    --to=philippe.nunes@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox