コード例 #1
0
static void
cm_ready (TpConnectionManager	*cm,
	  const GError		*in_error,
	  gpointer		 user_data,
	  GObject		*weak_obj)
{
	char **argv = (char **) user_data;

	g_print (" > cm_ready\n");

	if (in_error) g_error ("%s", in_error->message);

	const TpConnectionManagerProtocol *prot = tp_connection_manager_get_protocol (cm, "local-xmpp");
	if (!prot) g_error ("Protocol is not supported");

	/* request a new connection */
	GHashTable *parameters = tp_asv_new (
			"first-name", G_TYPE_STRING, argv[1],
			"last-name", G_TYPE_STRING, argv[2],
			NULL);

	tp_cli_connection_manager_call_request_connection (cm, -1,
			"local-xmpp",
			parameters,
			request_connection_cb,
			argv, NULL, NULL);

	g_hash_table_destroy (parameters);
}
コード例 #2
0
static void
connection_manager_got_info (TpConnectionManager *cm,
                             guint source,
                             gpointer unused)
{
  g_message ("Emitted got-info (source=%d)", source);

  if (source > 0)
    {
      GHashTable *params;
      GValue value = { 0 };

      if (timer != 0)
        {
          g_source_remove (timer);
          timer = 0;
        }

      params = g_hash_table_new (g_str_hash, g_str_equal);
      g_value_init (&value, G_TYPE_STRING);
      g_value_set_static_string (&value, "myself@server");
      g_hash_table_insert (params, "account", &value);

      /* This example is rather lower-level than most: it's
       * "going behind the account manager's back". This is not recommended
       * in real applications. */
      tp_cli_connection_manager_call_request_connection (cm,
          -1, "example", params, cm_requested_connection, NULL, NULL, NULL);

      g_hash_table_unref (params);
    }
}
コード例 #3
0
// XXX: This will be gone once we implement ToGLib functions
//      Currently this is the only function that needs them
//
// Verify the parameters - otherwise it is tough to distinguish between
// a few parameter types that nsIVariant gives us (Eg: Uint vs Int)
NS_IMETHODIMP
csTpConnectionManagerImp::CallRequestConnection(const nsACString & aProtocol,
                                                nsIArray *aParameters,
                                                csITpConnectionManagerRequestConnectionCB *cb)
{
  if (!m_Proxy)
    return NS_ERROR_NOT_INITIALIZED;

  if (m_Proxy->info_source > TP_CM_INFO_SOURCE_NONE) {
    GHashTable *hash = g_hash_table_new(g_str_hash, g_str_equal);
    const TpConnectionManagerProtocol *const *it;
    PRBool foundProtocol = PR_FALSE;
    nsresult rv;

    for (it = m_Proxy->protocols; it != NULL && *it != NULL; it++) {
      if (g_str_equal((*it)->name, nsCString(aProtocol).get())) {
        const TpConnectionManagerParam *tpparam = (*it)->params;

        PRUint32 parametersCount;
        rv = aParameters->GetLength(&parametersCount);
        NS_ENSURE_SUCCESS(rv, rv);

        // Put all the passed parameters in a hash.
        // XXX: Copy of this code exists in GotParamsForNewConnection.
        nsInterfaceHashtable<nsCStringHashKey, nsIVariant> parameters;
        parameters.Init();
        for (PRUint32 i=0; i<parametersCount; i++) {
          nsCOMPtr<csITpStringVariantMap> param = do_QueryElementAt(aParameters, i);
          nsCOMPtr<nsIVariant> value;
          nsCString key;

          rv = param->GetKey(key);
          NS_ENSURE_SUCCESS(rv, rv);

          rv = param->GetValue(getter_AddRefs(value));
          NS_ENSURE_SUCCESS(rv, rv);

          if (value)
            parameters.Put(key, value);
        }

        // Build a GHashTable out of all the parameters we got
        for (tpparam = (*it)->params; tpparam->name != NULL; tpparam++) {
          nsCOMPtr<nsIVariant> variant;
          if (parameters.Get(nsDependentCString(tpparam->name), getter_AddRefs(variant))) {
            GValue *value = VariantToGValueWithSignature(variant, tpparam->dbus_signature);
            g_hash_table_insert(hash, g_strdup(tpparam->name), value);
          }
        }

        NS_IF_ADDREF(cb);
        tp_cli_connection_manager_call_request_connection(m_Proxy, -1,
                                                    nsCString(aProtocol).get(), hash,
                                                    cb? RequestConnectionResponse: NULL,
                                                    cb? cb: NULL, NULL, NULL);
        foundProtocol = PR_TRUE;
      }
    }

    if (foundProtocol == PR_FALSE)
      return NS_ERROR_INVALID_ARG;
  }
  else {
    // Handle the case where the connection manager is not yet introspected!
    // This is extremely rare!!!
    NS_IF_ADDREF(cb);
    NS_IF_ADDREF(aParameters);

    Get_Params_For_Connection *cb_struct = new Get_Params_For_Connection;
    cb_struct->connectionCB = cb;
    cb_struct->protocolName = aProtocol;
    cb_struct->parameters = aParameters;

    tp_cli_connection_manager_call_get_parameters(m_Proxy, -1,
                                                  nsCString(aProtocol).get(),
                                                  GotParamsForNewConnection,
                                                  cb_struct, NULL, NULL);
  }

  return NS_OK;
}
コード例 #4
0
static void
GotParamsForNewConnection(TpConnectionManager *cm, const GPtrArray *arr,
                          const GError *error, gpointer user_data, GObject *unused)
{
  Get_Params_For_Connection* cb_struct = (Get_Params_For_Connection*)user_data;
  csITpConnectionManagerRequestConnectionCB *cb = cb_struct->connectionCB;
  nsCString aProtocol = cb_struct->protocolName;
  nsIArray *aParameters = cb_struct->parameters;

  if (error != NULL) {
    if (cb) {
      cb->OnRequestConnectionError(nsDependentCString(g_quark_to_string(error->domain)),
                                   error->code, nsDependentCString(error->message));
    }
    return;
  }

  PRUint32 parametersCount;
  nsresult rv = aParameters->GetLength(&parametersCount);
  if (NS_FAILED(rv))
    return;

  // Put all the passed parameters in a hash.
  // XXX: Copy of this code exists in CallRequestConnection.
  nsInterfaceHashtable<nsCStringHashKey, nsIVariant> parameters;
  parameters.Init();
  for (PRUint32 i=0; i<parametersCount; i++) {
    nsCOMPtr<csITpStringVariantMap> param = do_QueryElementAt(aParameters, i);
    nsCOMPtr<nsIVariant> value;
    nsCString key;

    rv = param->GetKey(key);
    if (NS_FAILED(rv))
      continue;

    rv = param->GetValue(getter_AddRefs(value));
    if (NS_FAILED(rv))
      continue;

    if (value)
      parameters.Put(key, value);
  }

  PRUint32 length = arr->len;
  GHashTable *hash = g_hash_table_new(g_str_hash, g_str_equal);

  for (PRUint32 i=0; i<length; i++) {
    GValue structure = {0};
    TpConnectionManagerParam *tpparam = g_new0(TpConnectionManagerParam, 1);

    g_value_init(&structure, TP_STRUCT_TYPE_PARAM_SPEC);
    g_value_set_static_boxed(&structure, g_ptr_array_index(arr, i));

    if (dbus_g_type_struct_get(&structure,
                               0, &tpparam->name, 1, &tpparam->flags,
                               2, &tpparam->dbus_signature, G_MAXUINT)) {
      nsCOMPtr<nsIVariant> variant;

      if (parameters.Get(nsDependentCString(tpparam->name), getter_AddRefs(variant))) {
        GValue *value = VariantToGValueWithSignature(variant, tpparam->dbus_signature);
        g_hash_table_insert(hash, g_strdup(tpparam->name), value);
      }
    }
  }

  NS_IF_ADDREF(cb);
  tp_cli_connection_manager_call_request_connection(cm, -1,
                                              nsCString(aProtocol).get(), hash,
                                              cb? RequestConnectionResponse: NULL,
                                              cb? cb: NULL, NULL, NULL);
  NS_IF_RELEASE(cb);
  NS_IF_RELEASE(aParameters);
}