All of lore.kernel.org
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 2/7] emulator: add call, callsetup and callheld indicators
Date: Tue, 05 Apr 2011 17:40:26 +0200	[thread overview]
Message-ID: <1302018031-12401-3-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1302018031-12401-1-git-send-email-frederic.danis@linux.intel.com>

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

---
 src/emulator.c  |    5 ++
 src/voicecall.c |  131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 136 insertions(+), 0 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index c84f0a9..2707592 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -455,6 +455,11 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 
 	if (em->type == OFONO_EMULATOR_TYPE_HFP) {
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_CALL, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_CALLSETUP, 0, 3,
+									0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_CALLHELD, 0, 2,
+									0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5);
diff --git a/src/voicecall.c b/src/voicecall.c
index 469b939..a3ea6de 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -59,6 +59,7 @@ struct ofono_voicecall {
 	struct dial_request *dial_req;
 	GQueue *toneq;
 	guint tone_source;
+	unsigned int hfp_watch;
 };
 
 struct voicecall {
@@ -689,6 +690,107 @@ static void voicecall_emit_multiparty(struct voicecall *call, gboolean mpty)
 						&val);
 }
 
+static void emulator_call_status_cb(struct ofono_atom *atom, void *data)
+{
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+
+	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALL,
+						GPOINTER_TO_INT(data));
+}
+
+static void emulator_callsetup_status_cb(struct ofono_atom *atom, void *data)
+{
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+
+	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLSETUP,
+						GPOINTER_TO_INT(data));
+}
+
+static void emulator_callheld_status_cb(struct ofono_atom *atom, void *data)
+{
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+
+	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLHELD,
+						GPOINTER_TO_INT(data));
+}
+
+static void notify_emulator_call_status(struct ofono_voicecall *vc)
+{
+	struct ofono_modem *modem = __ofono_atom_get_modem(vc->atom);
+	int status;
+	gboolean call = FALSE;
+	gboolean held = FALSE;
+	gboolean incoming = FALSE;
+	gboolean dialing = FALSE;
+	gboolean alerting = FALSE;
+	gboolean waiting = FALSE;
+	GSList *l;
+	struct voicecall *v;
+
+	for (l = vc->call_list; l; l = l->next) {
+		v = l->data;
+
+		switch (v->call->status) {
+		case CALL_STATUS_ACTIVE:
+			call = TRUE;
+			break;
+
+		case CALL_STATUS_HELD:
+			held = TRUE;
+			break;
+
+		case CALL_STATUS_DIALING:
+			dialing = TRUE;
+			break;
+
+		case CALL_STATUS_ALERTING:
+			alerting = TRUE;
+			break;
+
+		case CALL_STATUS_INCOMING:
+			incoming = TRUE;
+			break;
+
+		case CALL_STATUS_WAITING:
+			waiting = TRUE;
+			break;
+		}
+	}
+
+	status = call || held ? OFONO_EMULATOR_CALL_ACTIVE :
+					OFONO_EMULATOR_CALL_INACTIVE;
+
+	__ofono_modem_foreach_registered_atom(modem,
+						OFONO_ATOM_TYPE_EMULATOR_HFP,
+						emulator_call_status_cb,
+						GINT_TO_POINTER(status));
+
+	if (incoming || waiting)
+		status = OFONO_EMULATOR_CALLSETUP_INCOMING;
+	else if (dialing)
+		status = OFONO_EMULATOR_CALLSETUP_OUTGOING;
+	else if (alerting)
+		status = OFONO_EMULATOR_CALLSETUP_ALERTING;
+	else
+		status = OFONO_EMULATOR_CALLSETUP_INACTIVE;
+
+	__ofono_modem_foreach_registered_atom(modem,
+						OFONO_ATOM_TYPE_EMULATOR_HFP,
+						emulator_callsetup_status_cb,
+						GINT_TO_POINTER(status));
+
+	if (held)
+		status = call ? OFONO_EMULATOR_CALLHELD_MULTIPLE :
+					OFONO_EMULATOR_CALLHELD_ON_HOLD;
+	else
+		status = OFONO_EMULATOR_CALLHELD_NONE;
+
+	__ofono_modem_foreach_registered_atom(modem,
+						OFONO_ATOM_TYPE_EMULATOR_HFP,
+						emulator_callheld_status_cb,
+						GINT_TO_POINTER(status));
+}
+
 static void voicecall_set_call_status(struct voicecall *call, int status)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
@@ -711,6 +813,8 @@ static void voicecall_set_call_status(struct voicecall *call, int status)
 						"State", DBUS_TYPE_STRING,
 						&status_str);
 
+	notify_emulator_call_status(call->vc);
+
 	if (status == CALL_STATUS_ACTIVE &&
 		(old_status == CALL_STATUS_INCOMING ||
 			old_status == CALL_STATUS_DIALING ||
@@ -1040,6 +1144,8 @@ static void voicecalls_emit_call_added(struct ofono_voicecall *vc,
 	DBusMessageIter dict;
 	const char *path;
 
+	notify_emulator_call_status(vc);
+
 	path = __ofono_atom_get_path(vc->atom);
 
 	signal = dbus_message_new_signal(path,
@@ -2203,6 +2309,19 @@ static void voicecall_unregister(struct ofono_atom *atom)
 	const char *path = __ofono_atom_get_path(atom);
 	GSList *l;
 
+	__ofono_modem_foreach_registered_atom(modem,
+						OFONO_ATOM_TYPE_EMULATOR_HFP,
+						emulator_call_status_cb, 0);
+	__ofono_modem_foreach_registered_atom(modem,
+						OFONO_ATOM_TYPE_EMULATOR_HFP,
+						emulator_callsetup_status_cb,
+						0);
+	__ofono_modem_foreach_registered_atom(modem,
+						OFONO_ATOM_TYPE_EMULATOR_HFP,
+						emulator_callheld_status_cb, 0);
+
+	__ofono_modem_remove_atom_watch(modem, vc->hfp_watch);
+
 	if (vc->sim_watch) {
 		__ofono_modem_remove_atom_watch(modem, vc->sim_watch);
 		vc->sim_watch = 0;
@@ -2378,6 +2497,14 @@ static void sim_watch(struct ofono_atom *atom,
 	sim_state_watch(ofono_sim_get_state(sim), vc);
 }
 
+static void emulator_hfp_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED)
+		notify_emulator_call_status(data);
+}
+
 void ofono_voicecall_register(struct ofono_voicecall *vc)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
@@ -2408,6 +2535,10 @@ void ofono_voicecall_register(struct ofono_voicecall *vc)
 						sim_watch, vc, NULL);
 
 	__ofono_atom_register(vc->atom, voicecall_unregister);
+
+	vc->hfp_watch = __ofono_modem_add_atom_watch(modem,
+					OFONO_ATOM_TYPE_EMULATOR_HFP,
+					emulator_hfp_watch, vc, NULL);
 }
 
 void ofono_voicecall_remove(struct ofono_voicecall *vc)
-- 
1.7.1


  parent reply	other threads:[~2011-04-05 15:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05 15:40 [PATCH 0/7] emulator: add simple incoming call support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-05 15:40 ` [PATCH 1/7] emulator: add defines for call, callsetup and callheld indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-05 15:40 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2011-04-05 15:40 ` [PATCH 3/7] emulator: add RING for HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-05 15:49   ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-04-05 15:54     ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-04-05 15:40 ` [PATCH 4/7] emulator: add incoming call API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-05 15:40 ` [PATCH 5/7] emulator: add +CLIP support for HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-05 15:40 ` [PATCH 6/7] voicecall: add ATA support for HFP emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-05 15:40 ` [PATCH 7/7] voicecall: add +CHUP " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis

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=1302018031-12401-3-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.