Commit 28b3b251 authored by Guido Gunther's avatar Guido Gunther
Browse files

calls-manager: Add active-call property



This holds a unique identifier for the currently active call.
It allows other parts of the shell to track changes.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 9877f90f
......@@ -26,9 +26,27 @@
* interaction with them.
*/
/**
* PhoshCallState:
*
* The call state. Must match call's CallsCallState.
*/
typedef enum
{
/*< private >*/
PHOSH_CALL_STATE_ACTIVE = 1,
PHOSH_CALL_STATE_HELD,
PHOSH_CALL_STATE_DIALING,
PHOSH_CALL_STATE_ALERTING,
PHOSH_CALL_STATE_INCOMING,
PHOSH_CALL_STATE_WAITING,
PHOSH_CALL_STATE_DISCONNECTED
} PhoshCallState;
enum {
PROP_0,
PROP_PRESENT,
PROP_ACTIVE_CALL,
PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];
......@@ -46,6 +64,7 @@ struct _PhoshCallsManager {
gboolean present;
gboolean incoming;
char *active_call;
PhoshDBusCalls *proxy;
GHashTable *calls;
......@@ -53,12 +72,47 @@ struct _PhoshCallsManager {
G_DEFINE_TYPE (PhoshCallsManager, phosh_calls_manager, G_TYPE_OBJECT);
static void
on_call_state_changed (PhoshCallsManager *self,
GParamSpec *pspec,
PhoshDBusCallsCall *proxy)
{
const char *path;
PhoshCallState state;
g_return_if_fail (PHOSH_IS_CALLS_MANAGER (self));
g_return_if_fail (PHOSH_DBUS_IS_CALLS_CALL (proxy));
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (proxy));
state = phosh_dbus_calls_call_get_state (proxy);
if (g_strcmp0 (path, self->active_call) == 0) {
/* current active call became inactive */
if (state != PHOSH_CALL_STATE_ACTIVE) {
g_clear_pointer (&self->active_call, g_free);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACTIVE_CALL]);
/* TODO: pick new active call from list once calls supports multiple active calls */
}
return;
}
if (state != PHOSH_CALL_STATE_ACTIVE)
return;
/* New active call */
g_free (self->active_call);
self->active_call = g_strdup (path);
g_debug ("New active call %s", path);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACTIVE_CALL]);
}
static void
on_call_proxy_new_for_bus_finish (GObject *source_object,
GAsyncResult *res,
PhoshCallsManager *self)
{
g_autofree gchar *path = NULL;
const char *path;
PhoshDBusCallsCall *proxy;
gboolean inbound;
......@@ -72,12 +126,18 @@ on_call_proxy_new_for_bus_finish (GObject *source_object,
goto out;
}
path = g_strdup (g_dbus_proxy_get_object_path (G_DBUS_PROXY (proxy)));
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (proxy));
if (g_hash_table_contains (self->calls, path))
g_critical ("Already got a call with path %s", path);
else
g_hash_table_insert (self->calls, g_steal_pointer (&path), proxy);
g_hash_table_insert (self->calls, g_strdup (path), proxy);
g_signal_connect_swapped (proxy,
"notify::state",
G_CALLBACK (on_call_state_changed),
self);
on_call_state_changed (self, NULL, proxy);
inbound = phosh_dbus_calls_call_get_inbound (proxy);
g_debug ("Added call %s, incoming: %d", path, inbound);
......@@ -90,7 +150,7 @@ out:
static void
on_call_added (PhoshCallsManager *self, const gchar *path, PhoshDBusCalls *proxy)
on_call_added (PhoshCallsManager *self, const char *path, PhoshDBusCalls *proxy)
{
g_return_if_fail (PHOSH_IS_CALLS_MANAGER (self));
......@@ -105,7 +165,7 @@ on_call_added (PhoshCallsManager *self, const gchar *path, PhoshDBusCalls *proxy
static void
on_call_removed (PhoshCallsManager *self, const gchar *path, PhoshDBusCalls *proxy)
on_call_removed (PhoshCallsManager *self, const char *path, PhoshDBusCalls *proxy)
{
gboolean incoming;
PhoshDBusCallsCall *call_proxy;
......@@ -115,9 +175,15 @@ on_call_removed (PhoshCallsManager *self, const gchar *path, PhoshDBusCalls *pro
call_proxy = g_hash_table_lookup (self->calls, path);
g_return_if_fail (PHOSH_DBUS_IS_CALLS_CALL (call_proxy));
incoming = phosh_dbus_calls_call_get_inbound (call_proxy);
if (g_strcmp0 (path, self->active_call) == 0) {
g_clear_pointer (&self->active_call, g_free);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACTIVE_CALL]);
/* TODO: pick new active call from list once calls supports multiple active calls */
}
incoming = phosh_dbus_calls_call_get_inbound (call_proxy);
g_debug ("Removed call %s, incoming: %d", path, incoming);
g_return_if_fail (g_hash_table_remove (self->calls, path));
}
......@@ -134,6 +200,9 @@ phosh_calls_manager_get_property (GObject *object,
case PROP_PRESENT:
g_value_set_boolean (value, self->present);
break;
case PROP_ACTIVE_CALL:
g_value_set_string (value, self->active_call);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -176,6 +245,7 @@ phosh_calls_manager_dispose (GObject *object)
g_clear_pointer (&self->calls, g_hash_table_unref);
g_clear_object (&self->proxy);
g_clear_pointer (&self->active_call, g_free);
G_OBJECT_CLASS (phosh_calls_manager_parent_class)->dispose (object);
}
......@@ -203,6 +273,20 @@ phosh_calls_manager_class_init (PhoshCallsManagerClass *klass)
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
/**
* PhoshCallsManager:active-call:
*
* The currently active call
*/
props[PROP_ACTIVE_CALL] =
g_param_spec_string ("active-call",
"",
"",
NULL,
G_PARAM_READABLE |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
signals[CALL_INBOUND] = g_signal_new ("call-inbound",
......@@ -303,3 +387,12 @@ phosh_calls_manager_get_incoming (PhoshCallsManager *self)
return self->incoming;
}
const char *
phosh_calls_manager_get_active_call (PhoshCallsManager *self)
{
g_return_val_if_fail (PHOSH_IS_CALLS_MANAGER (self), NULL);
return self->active_call;
}
......@@ -17,5 +17,6 @@ G_DECLARE_FINAL_TYPE (PhoshCallsManager, phosh_calls_manager, PHOSH, CALLS_MANAG
PhoshCallsManager *phosh_calls_manager_get_default (void);
gboolean phosh_calls_manager_get_present (PhoshCallsManager *self);
gboolean phosh_calls_manager_get_incoming (PhoshCallsManager *self);
const char *phosh_calls_manager_get_active_call (PhoshCallsManager *self);
G_END_DECLS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment