static void
on_notify_ofono_state (ModemCall *self,
                       GParamSpec *pspec,
                       gpointer user_data)
{
  ModemCallPrivate *priv = self->priv;
  ModemCallState state;

  DEBUG ("enter with \"%s\"", priv->state_str);

  state = modem_call_state_from_ofono_state (priv->state_str);
  if (state == priv->state)
    return;

  g_object_set (self, "state", state, NULL);
  g_signal_emit (self, call_signals[SIGNAL_STATE], 0, state);
}
Exemplo n.º 2
0
static ModemCall *
modem_call_service_ensure_instance (ModemCallService *self,
                                    char const *object_path,
                                    GHashTable *properties)
{
  ModemCallServicePrivate *priv = self->priv;
  char *key;
  GValue *value;
  GHashTableIter iter[1];
  gchar const *remote;
  ModemCallState state;
  gboolean incoming = FALSE, originating = FALSE;
  ModemCall *ci;

  DEBUG ("path %s", object_path);

  if (DEBUGGING)
    {
      for (g_hash_table_iter_init (iter, properties);
           g_hash_table_iter_next (iter, (gpointer)&key, (gpointer)&value);)
        {
          char *s = g_strdup_value_contents (value);
          DEBUG ("%s = %s", key, s);
          g_free (s);
        }
    }

  ci = g_hash_table_lookup (priv->instances, object_path);
  if (ci)
    {
      DEBUG ("call already exists %p", (void *)ci);
      return ci;
    }

  value = g_hash_table_lookup (properties, "LineIdentification");
  remote = g_value_get_string (value);

  value = g_hash_table_lookup (properties, "State");
  state = modem_call_state_from_ofono_state (g_value_get_string (value));

  switch (state)
    {
    case MODEM_CALL_STATE_INCOMING:
    case MODEM_CALL_STATE_WAITING:
      incoming = TRUE;
      originating = FALSE;
      break;

    case MODEM_CALL_STATE_DIALING:
    case MODEM_CALL_STATE_ALERTING:
    case MODEM_CALL_STATE_ACTIVE:
    case MODEM_CALL_STATE_HELD:
      incoming = FALSE;
      originating = TRUE;
      break;

    case MODEM_CALL_STATE_INVALID:
    case MODEM_CALL_STATE_DISCONNECTED:
      DEBUG ("call already in invalid state");
      return NULL;
    }

  ci = g_object_new (MODEM_TYPE_CALL,
      "object-path", object_path,
      "call-service", self,
      "state", state,
      "terminating", !originating,
      "originating",  originating,
      NULL);

  modem_oface_update_properties (MODEM_OFACE (ci), properties);
  modem_call_service_connect_to_instance (self, ci);

  if (incoming)
    {
      DEBUG ("emit \"incoming\" (\"%s\" (%p), \"%s\")",
          modem_call_get_name (ci), ci, remote);
      g_signal_emit (self, signals[SIGNAL_INCOMING], 0, ci, remote);
      if (priv->forwarded && !strcmp(priv->forwarded, "incoming"))
        {
          g_signal_emit_by_name (ci, "forwarded");
        }
    }
  else if (g_queue_is_empty (priv->dialing.queue))
    {
      DEBUG ("emit \"created\" (\"%s\" (%p), \"%s\")",
          modem_call_get_name (ci), ci, remote);
      g_signal_emit (self, signals[SIGNAL_CREATED], 0, ci, remote);
      if (priv->forwarded && !strcmp(priv->forwarded, "outgoing"))
        {
          g_signal_emit_by_name (ci, "forwarded");
        }
    }
  else {
    g_queue_push_tail (priv->dialing.created, ci);
  }

  if (priv->forwarded)
    {
      g_free(priv->forwarded);
      priv->forwarded = NULL;
    }

  return ci;
}