Exemplo n.º 1
0
/** Initiate asynchronous connman property change D-Bus method call
 *
 * @param key property name
 * @param val value to set
 *
 * @return TRUE if the method call was initiated, or FALSE in case of errors
 */
static gboolean xconnman_set_property_bool(const char *key, gboolean val)
{
	gboolean         res  = FALSE;
	DBusMessage     *req  = 0;
	DBusPendingCall *pc   = 0;
	dbus_bool_t      dta  = val;

	DBusMessageIter miter, viter;

	mce_log(LL_DEBUG, "%s = %s", key, val ? "true" : "false");

	if( !(req = dbus_message_new_method_call(CONNMAN_SERVICE,
						 CONNMAN_OBJECT_PATH,
						 CONNMAN_INTERFACE,
						 CONNMAN_SET_PROPERTY_REQ)) )
		goto EXIT;

	dbus_message_iter_init_append(req, &miter);
	dbus_message_iter_append_basic(&miter, DBUS_TYPE_STRING, &key);

	if( !dbus_message_iter_open_container(&miter, DBUS_TYPE_VARIANT,
					      DBUS_TYPE_BOOLEAN_AS_STRING,
					      &viter) ) {
		mce_log(LL_WARN, "container open failed");
		goto EXIT;
	}

	dbus_message_iter_append_basic(&viter, DBUS_TYPE_BOOLEAN, &dta);

	if( !dbus_message_iter_close_container(&miter, &viter) ) {
		mce_log(LL_WARN, "container close failed");
		goto EXIT;
	}

	if( !dbus_connection_send_with_reply(connman_bus, req, &pc, -1) )
		goto EXIT;

	if( !pc )
		goto EXIT;

	if( !dbus_pending_call_set_notify(pc, xconnman_set_property_cb, 0, 0) )
		goto EXIT;

	// success
	res = TRUE;

EXIT:
	if( pc )  dbus_pending_call_unref(pc);
	if( req ) dbus_message_unref(req);

	return res;
}
Exemplo n.º 2
0
int supplicant_dbus_property_get_all(const char *path, const char *interface,
				supplicant_dbus_property_function function,
							void *user_data)
{
	struct property_get_data *data;
	DBusMessage *message;
	DBusPendingCall *call;

	if (connection == NULL)
		return -EINVAL;

	if (path == NULL || interface == NULL)
		return -EINVAL;

	data = dbus_malloc0(sizeof(*data));
	if (data == NULL)
		return -ENOMEM;

	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
					DBUS_INTERFACE_PROPERTIES, "GetAll");
	if (message == NULL) {
		dbus_free(data);
		return -ENOMEM;
	}

	dbus_message_set_auto_start(message, FALSE);

	dbus_message_append_args(message, DBUS_TYPE_STRING, &interface, NULL);

	if (dbus_connection_send_with_reply(connection, message,
						&call, TIMEOUT) == FALSE) {
		dbus_message_unref(message);
		dbus_free(data);
		return -EIO;
	}

	if (call == NULL) {
		dbus_message_unref(message);
		dbus_free(data);
		return -EIO;
	}

	data->function = function;
	data->user_data = user_data;

	dbus_pending_call_set_notify(call, property_get_all_reply,
							data, dbus_free);

	dbus_message_unref(message);

	return 0;
}
Exemplo n.º 3
0
static int dbus_selector_process_post_send( DBusConnection* conn, char * param,
                                            DBusPendingCall** pendingargptr)
{ /* mostly a copy of query() */
   DBusMessage* msg = NULL;
   DBusMessageIter args = {0};
   DBusError err = {0};
   DBusPendingCall* pending = NULL;
   int ret = 0;

   * pendingargptr = NULL;

   printf("Calling remote method with %s\n", param);

   // initialiset the errors
   dbus_error_init(&err);

    msg = dbus_message_new_method_call(
                                      "test.selector.server", // target for the method call
                                      "/test/method/Object", // object to call on
                                      "test.method.Type", // interface to call on
                                      "Method"); // method name
   if (NULL == msg) {
      fprintf(stderr, "Message Null\n");
      exit(1);
   }

   // append arguments
   dbus_message_iter_init_append(msg, &args);
   if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &param)) {
      fprintf(stderr, "Out Of Memory!\n");
      exit(1);
   }

   // send message and get a handle for a reply
   if (!dbus_connection_send_with_reply (conn, msg, &pending, 300)) { // -1 is default timeout
      fprintf(stderr, "Out Of Memory!\n");
      exit(1);
   }
   if (NULL == pending) {
      fprintf(stderr, "Pending Call Null\n");
      exit(1);
   }
   printf("Request Sent\n");

   dbus_connection_flush(conn); /* Note: block until write finishes */
   printf("Request flushed\n");

   // free message
   dbus_message_unref(msg);
   * pendingargptr = pending;
    return ret;
}
Exemplo n.º 4
0
static int ldbus_connection_send_with_reply(lua_State *L) {
	DBusConnection *connection = check_DBusConnection(L, 1);
	DBusMessage *message = check_DBusMessage(L, 2);
	int timeout_milliseconds = lua_isnoneornil(L, 3) ? (-1) : (luaL_checknumber(L, 3) * 1000);

	DBusPendingCall *pending;
	if (!dbus_connection_send_with_reply(connection, message, &pending, timeout_milliseconds)) {
		return luaL_error(L, LDBUS_NO_MEMORY);
	}

	push_DBusPendingCall(L, pending);
	return 1;
}
void dc_quit(struct razer_daemon_controller *controller)
{
	DBusMessage *msg;
	msg = dbus_message_new_method_call("org.voyagerproject.razer.daemon","/","org.voyagerproject.razer.daemon","quit");
	if(!msg)
		dc_error_close(controller,"Error creating Message\n");
	if(!dbus_connection_send_with_reply(controller->dbus,msg,&controller->pending,-1))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!controller->pending)
		dc_error_close(controller,"No pending call\n"); 
	dbus_connection_flush(controller->dbus);
	dbus_message_unref(msg);
}
Exemplo n.º 6
0
static DBusHandlerResult
handle_run_hello_from_self (DBusConnection     *connection,
                                               DBusMessage        *message)
{
  DBusError error;
  DBusMessage *reply, *self_message;
  DBusPendingCall *pcall;
  char *s;

  dbus_error_init (&error);
  
  if (!dbus_message_get_args (message,
                              &error,
                              DBUS_TYPE_STRING, &s,
                              DBUS_TYPE_INVALID))
    {
      reply = dbus_message_new_error (message,
                                      error.name,
                                      error.message);

      if (reply == NULL)
        die ("No memory\n");

      if (!dbus_connection_send (connection, reply, NULL))
        die ("No memory\n");

      dbus_message_unref (reply);

      return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }
    printf ("Sending HelloFromSelf\n");

 self_message = dbus_message_new_method_call ("org.freedesktop.DBus.GLib.TestEchoService",
                                          "/org/freedesktop/DBus/GLib/TestSuite",
                                          "org.freedesktop.DBus.GLib.TestSuite",
                                          "HelloFromSelf");
  
  if (self_message == NULL)
    die ("No memory");
  
  if (!dbus_connection_send_with_reply (connection, self_message, &pcall, -1))
    die("No memory");
  
  dbus_message_ref (message);
  if (!dbus_pending_call_set_notify (pcall, check_hello_from_self_reply, (void *)message, NULL))
    die("No memory");
    
  printf ("Sent HelloFromSelf\n");
  return DBUS_HANDLER_RESULT_HANDLED;
}
Exemplo n.º 7
0
static int add_interface(struct supplicant_task *task)
{
	const char *driver = connman_option_get_string("wifi");
	DBusMessage *message;
	DBusMessageIter array, dict;
	DBusPendingCall *call;

	_DBG_SUPPLICANT("task %p", task);

	message = dbus_message_new_method_call(SUPPLICANT_NAME, SUPPLICANT_PATH,
					SUPPLICANT_INTF, "addInterface");
	if (message == NULL)
		return -ENOMEM;

	dbus_message_set_auto_start(message, FALSE);

	dbus_message_iter_init_append(message, &array);

	dbus_message_iter_append_basic(&array,
					DBUS_TYPE_STRING, &task->ifname);

	dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);

	connman_dbus_dict_append_variant(&dict, "driver",
						DBUS_TYPE_STRING, &driver);

	dbus_message_iter_close_container(&array, &dict);

	if (dbus_connection_send_with_reply(connection, message,
						&call, TIMEOUT) == FALSE) {
		connman_error("Failed to add interface");
		dbus_message_unref(message);
		return -EIO;
	}

	if (call == NULL) {
		connman_error("D-Bus connection not available");
		dbus_message_unref(message);
		return -EIO;
	}

	dbus_pending_call_set_notify(call, add_interface_reply, task, NULL);

	dbus_message_unref(message);

	return -EINPROGRESS;
}
Exemplo n.º 8
0
/*
 * On success @param msg is unref'd or its ref is stolen by the returned
 * Eldbus_Pending.
 */
Eldbus_Pending *
_eldbus_connection_send(Eldbus_Connection *conn, Eldbus_Message *msg, Eldbus_Message_Cb cb, const void *cb_data, double timeout)
{
   Eldbus_Pending *pending;
   Eldbus_Message *error_msg;
   DBG("conn=%p, msg=%p, cb=%p, cb_data=%p, timeout=%f",
       conn, msg, cb, cb_data, timeout);

   if (!cb)
     {
        dbus_connection_send(conn->dbus_conn, msg->dbus_msg, NULL);
        eldbus_message_unref(msg);
        return NULL;
     }

   pending = calloc(1, sizeof(Eldbus_Pending));
   EINA_SAFETY_ON_NULL_RETURN_VAL(pending, NULL);

   pending->cb = cb;
   pending->cb_data = cb_data;
   pending->conn = conn;
   pending->dest = eina_stringshare_add(dbus_message_get_destination(msg->dbus_msg));
   pending->interface = eina_stringshare_add(dbus_message_get_interface(msg->dbus_msg));
   pending->method = eina_stringshare_add(dbus_message_get_member(msg->dbus_msg));
   pending->path = eina_stringshare_add(dbus_message_get_path(msg->dbus_msg));

   /* Steal the reference */
   pending->msg_sent = msg;

   EINA_MAGIC_SET(pending, ELDBUS_PENDING_MAGIC);

   if (!dbus_connection_send_with_reply(conn->dbus_conn,
                                        msg->dbus_msg,
                                        &pending->dbus_pending, timeout))
     {
        error_msg = eldbus_message_error_new(msg, "org.enlightenment.DBus.NoConnection",
                                            "Eldbus_Connection was closed.");
        eldbus_pending_dispatch(pending, error_msg);
        return NULL;
     }
   if (dbus_pending_call_set_notify(pending->dbus_pending, cb_pending, pending, NULL))
     return pending;

   dbus_pending_call_cancel(pending->dbus_pending);
   error_msg = eldbus_message_error_new(pending->msg_sent,
                                       "org.enlightenment.DBus.Error",
                                       "Error when try set callback to message.");
   eldbus_pending_dispatch(pending, error_msg);
   return NULL;
}
Exemplo n.º 9
0
static void
test_uae (Fixture *f,
          gconstpointer context)
{
    const Config *config = context;
    DBusMessage *m;
    DBusPendingCall *pc;
    DBusMessageIter args_iter;
    DBusMessageIter arr_iter;

    if (f->skip)
        return;

    m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");

    if (m == NULL)
        g_error ("OOM");

    dbus_message_iter_init_append (m, &args_iter);

    /* Append an empty a{ss} (string => string dictionary). */
    if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
                                           "{ss}", &arr_iter) ||
            !dbus_message_iter_close_container (&args_iter, &arr_iter))
        g_error ("OOM");

    if (!dbus_connection_send_with_reply (f->conn, m, &pc,
                                          DBUS_TIMEOUT_USE_DEFAULT) ||
            pc == NULL)
        g_error ("OOM");

    dbus_message_unref (m);
    m = NULL;

    if (dbus_pending_call_get_completed (pc))
        test_pending_call_store_reply (pc, &m);
    else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
                                            &m, NULL))
        g_error ("OOM");

    while (m == NULL)
        test_main_context_iterate (f->ctx, TRUE);

    if (config->expect_success)
    {
        /* it succeeds */
        g_assert_cmpint (dbus_message_get_type (m), ==,
                         DBUS_MESSAGE_TYPE_METHOD_RETURN);
    }
Exemplo n.º 10
0
/* Run a helper program using the commandline, with input as infomation on
 * stdin */
void
hald_runner_run_method(HalDevice *device,
                           const gchar *command_line, char **extra_env, 
                           gchar *input, gboolean error_on_stderr,
                           guint32 timeout,
                           HalRunTerminatedCB  cb,
                           gpointer data1, gpointer data2) {
  DBusMessage *msg;
  DBusMessageIter iter;
  DBusPendingCall *call;
  HelperData *hd = NULL;
  msg = dbus_message_new_method_call("org.freedesktop.HalRunner",
                             "/org/freedesktop/HalRunner",
                             "org.freedesktop.HalRunner",
                             "Run");
  if (msg == NULL) 
    DIE(("No memory"));
  dbus_message_iter_init_append(msg, &iter);
  
  if (!add_first_part(&iter, device, command_line, extra_env)) 
    goto error;

  dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &input);
  dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &error_on_stderr);
  dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &timeout);

  if (!dbus_connection_send_with_reply(runner_connection, 
                                              msg, &call, INT_MAX))
    DIE (("No memory"));

  /* the connection was disconnected */
  if (call == NULL)
    goto error;

  hd = malloc(sizeof(HelperData));
  hd->d = device;
  hd->cb = cb;
  hd->data1 = data1;
  hd->data2 = data2;

  g_object_ref (device);

  dbus_pending_call_set_notify(call, call_notify, hd, free);
  dbus_message_unref(msg);
  return;
error:
  dbus_message_unref(msg);
  free(hd);
  cb(device, HALD_RUN_FAILED, 0, NULL, data1, data2);
}
Exemplo n.º 11
0
PendingCall StubBase::get_property_async(const char* name)
{
   message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), "org.freedesktop.DBus.Properties", "Get"));
   DBusPendingCall* pending = nullptr;

   DBusMessageIter iter;
   dbus_message_iter_init_append(msg.get(), &iter);
    
   encode(iter, iface(), name);

   dbus_connection_send_with_reply(conn(), msg.get(), &pending, DBUS_TIMEOUT_USE_DEFAULT);

   return PendingCall(dbus_message_get_serial(msg.get()), pending);
}
Exemplo n.º 12
0
void get_device_properties(DBusConnection * conn, char dev[], int *type)
{
	DBusMessage *msg;
	DBusMessageIter args;
	DBusPendingCall *pending;
	const char *param1 = "org.freedesktop.NetworkManager.Device";
	const char *param2 = "DeviceType";

	msg = dbus_message_new_method_call("org.freedesktop.NetworkManager",	/* Destination */
					   dev,	/* Object Path */
					   "org.freedesktop.DBus.Properties",	/* Interface */
					   "Get");	/* Method name */
	if (NULL == msg) {
		syslog(LOG_ERR, "Message Null\n");
		syslog(LOG_ERR, "Message Null get_device_properties\n");
		exit(1);
	}

	if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &param1,
				      DBUS_TYPE_STRING, &param2,
				      DBUS_TYPE_INVALID)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}

	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}
	dbus_connection_flush(conn);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	if (NULL == msg) {
		syslog(LOG_ERR, "Reply Null\n");
		exit(1);
	}

	dbus_pending_call_unref(pending);
	if (!dbus_message_iter_init(msg, &args))
		syslog(LOG_ERR, "Message has no arguments!\n");
	else {
		int arg_type = dbus_message_iter_get_arg_type(&args);
		if (arg_type != DBUS_TYPE_INVALID)
			read_variant(&args, type);
	}
	dbus_message_unref(msg);

}
Exemplo n.º 13
0
static void
test_echo (Fixture *f,
    gconstpointer context G_GNUC_UNUSED)
{
  guint count = 2000;
  guint sent;
  guint received = 0;
  double elapsed;

  if (g_test_perf ())
    count = 100000;

  add_echo_filter (f);

  g_test_timer_start ();

  for (sent = 0; sent < count; sent++)
    {
      DBusMessage *m = dbus_message_new_method_call (
          dbus_bus_get_unique_name (f->right_conn), "/",
          "com.example", "Spam");
      DBusPendingCall *pc;

      if (m == NULL)
        g_error ("OOM");

      if (!dbus_connection_send_with_reply (f->left_conn, m, &pc,
                                            DBUS_TIMEOUT_INFINITE) ||
          pc == NULL)
        g_error ("OOM");

      if (dbus_pending_call_get_completed (pc))
        pc_count (pc, &received);
      else if (!dbus_pending_call_set_notify (pc, pc_count, &received,
            NULL))
        g_error ("OOM");

      dbus_pending_call_unref (pc);
      dbus_message_unref (m);
    }

  while (received < count)
    g_main_context_iteration (NULL, TRUE);

  elapsed = g_test_timer_elapsed ();

  g_test_maximized_result (count / elapsed, "%u messages / %f seconds",
      count, elapsed);
}
Exemplo n.º 14
0
int cras_bt_transport_set_volume(struct cras_bt_transport *transport,
				 uint16_t volume)
{
	const char *key = "Volume";
	const char *interface = BLUEZ_INTERFACE_MEDIA_TRANSPORT;
	DBusMessage *method_call;
	DBusMessageIter message_iter, variant;
	DBusPendingCall *pending_call;

	method_call = dbus_message_new_method_call(
		BLUEZ_SERVICE,
		transport->object_path,
		DBUS_INTERFACE_PROPERTIES,
		"Set");
	if (!method_call)
		return -ENOMEM;

	dbus_message_iter_init_append(method_call, &message_iter);

	dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_STRING,
				       &interface);
	dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_STRING, &key);

	dbus_message_iter_open_container(&message_iter, DBUS_TYPE_VARIANT,
					 DBUS_TYPE_UINT16_AS_STRING, &variant);
	dbus_message_iter_append_basic(&variant, DBUS_TYPE_UINT16, &volume);
	dbus_message_iter_close_container(&message_iter, &variant);

	if (!dbus_connection_send_with_reply(transport->conn, method_call,
					     &pending_call,
					     DBUS_TIMEOUT_USE_DEFAULT)) {
		dbus_message_unref(method_call);
		return -ENOMEM;
	}

	dbus_message_unref(method_call);
	if (!pending_call)
		return -EIO;

	if (!dbus_pending_call_set_notify(pending_call,
					  on_transport_volume_set,
					  NULL, NULL)) {
		dbus_pending_call_cancel(pending_call);
		dbus_pending_call_unref(pending_call);
		return -ENOMEM;
	}

	return 0;
}
Exemplo n.º 15
0
/** Verify that a client exists via an asynchronous GetNameOwner method call
 *
 * @param name  the dbus name who's owner we wish to know
 *
 * @return TRUE if the method call was initiated, or FALSE in case of errors
 */
static
gboolean
cka_clients_verify_name(const char *name)
{
  gboolean         res = FALSE;
  DBusMessage     *req = 0;
  DBusPendingCall *pc  = 0;
  gchar           *key = 0;

  if( !(req = cka_dbusutil_create_GetNameOwner_req(name)) )
  {
    goto EXIT;
  }

  if( !dbus_connection_send_with_reply(cka_dbus_systembus, req, &pc, -1) )
  {
    goto EXIT;
  }

  if( !pc )
  {
    goto EXIT;
  }

  mce_dbus_pending_call_blocks_suspend(pc);

  key = g_strdup(name);

  if( !dbus_pending_call_set_notify(pc, cka_clients_verify_name_cb,
                                    key, g_free) )
  {
    goto EXIT;
  }

  // key string is owned by pending call
  key = 0;

  // success
  res = TRUE;

EXIT:

  g_free(key);

  if( pc  ) dbus_pending_call_unref(pc);
  if( req ) dbus_message_unref(req);

  return res;
}
Exemplo n.º 16
0
static void get_properties(struct supplicant_task *task)
{
	DBusMessage *message;
	char *path;

	path = g_slist_nth_data(task->scan_results, 0);
	if (path == NULL)
		goto noscan;

	message = dbus_message_new_method_call(SUPPLICANT_NAME, path,
						SUPPLICANT_INTF ".BSSID",
								"properties");

	task->scan_results = g_slist_remove(task->scan_results, path);
	g_free(path);

	if (message == NULL)
		goto noscan;

	dbus_message_set_auto_start(message, FALSE);

	if (dbus_connection_send_with_reply(connection, message,
				&task->result_call, TIMEOUT) == FALSE) {
		connman_error("Failed to get network properties");
		dbus_message_unref(message);
		goto noscan;
	}

	if (task->result_call == NULL) {
		connman_error("D-Bus connection not available");
		dbus_message_unref(message);
		goto noscan;
	}

	dbus_pending_call_set_notify(task->result_call,
					properties_reply, task, NULL);

	dbus_message_unref(message);

	return;

noscan:
	task->result_call = NULL;

	if (task->scanning == TRUE) {
		connman_device_set_scanning(task->device, FALSE);
		task->scanning = FALSE;
	}
}
Exemplo n.º 17
0
static void server_register(const char *path, const char *uuid,
				struct connman_technology *technology,
				const char *bridge, connman_bool_t enabled)
{
	DBusMessage *message;
	DBusPendingCall *call;
	char *command;

	DBG("path %s enabled %d", path, enabled);

	command = enabled ? REGISTER : UNREGISTER;

	message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
					BLUEZ_NETWORK_SERVER, command);
	if (message == NULL)
		return;

	dbus_message_set_auto_start(message, FALSE);

	dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
							DBUS_TYPE_INVALID);

	if (enabled == TRUE)
		dbus_message_append_args(message, DBUS_TYPE_STRING, &bridge,
							DBUS_TYPE_INVALID);

	if (dbus_connection_send_with_reply(connection, message,
						&call, TIMEOUT) == FALSE) {
		connman_error("Failed to enable PAN server");
		dbus_message_unref(message);
		return;
	}

	if (call == NULL) {
		connman_error("D-Bus connection not available");
		dbus_message_unref(message);
		return;
	}

	if (enabled == TRUE)
		dbus_pending_call_set_notify(call, server_register_reply,
						technology, NULL);
	else
		dbus_pending_call_set_notify(call, server_unregister_reply,
						technology, NULL);

	dbus_message_unref(message);
}
Exemplo n.º 18
0
static struct pending_req *send_method_call(DBusConnection *connection,
				const char *dest, const char *path,
				const char *interface, const char *method,
				DBusPendingCallNotifyFunction cb,
				void *user_data, int type, ...)
{
	DBusMessage *msg;
	DBusPendingCall *call;
	va_list args;
	struct pending_req *req;

	msg = dbus_message_new_method_call(dest, path, interface, method);
	if (!msg) {
		error("Unable to allocate new D-Bus %s message", method);
		return NULL;
	}

	va_start(args, type);

	if (!dbus_message_append_args_valist(msg, type, args)) {
		dbus_message_unref(msg);
		va_end(args);
		return NULL;
	}

	va_end(args);

	if (!cb) {
		g_dbus_send_message(connection, msg);
		return 0;
	}

	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
		error("Sending %s failed", method);
		dbus_message_unref(msg);
		return NULL;
	}

	dbus_pending_call_set_notify(call, cb, user_data, NULL);

	req = g_new0(struct pending_req, 1);
	req->call = call;
	req->user_data = user_data;

	dbus_message_unref(msg);

	return req;
}
Exemplo n.º 19
0
PendingCall StubBase::set_property_async(const char* name, std::function<void(DBusMessageIter&)>&& f)
{
    message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), "org.freedesktop.DBus.Properties", "Set"));

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg.get(), &iter);
    
    encode(iter, iface(), name);
    f(iter);   // and now serialize the variant

    DBusPendingCall* pending = nullptr;

    dbus_connection_send_with_reply(disp().conn_, msg.get(), &pending, DBUS_TIMEOUT_USE_DEFAULT);

    return PendingCall(dbus_message_get_serial(msg.get()), pending);
}
Exemplo n.º 20
0
static void
_libnm_glib_get_nm_state (libnm_glib_ctx *ctx)
{
	DBusMessage *		message;
	DBusPendingCall *	pcall = NULL;

	g_return_if_fail (ctx != NULL);

	if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state")))
	{
		dbus_connection_send_with_reply (ctx->dbus_con, message, &pcall, -1);
		if (pcall)
			dbus_pending_call_set_notify (pcall, _libnm_glib_nm_state_cb, ctx, NULL);
		dbus_message_unref (message);
	}
}
static jboolean setCharacteristicPropertyNative(JNIEnv *env, jobject object, jstring path, jstring property, void *value, jint type)
{
#ifdef HAVE_BLUETOOTH
    LOGV("%s", __FUNCTION__);

    native_data_t *nat = get_native_data(env, object);

    if (nat) {
        DBusMessage *msg;
        DBusMessageIter iter;
        DBusError err;
        dbus_error_init(&err);
        const char *c_path = env->GetStringUTFChars(path, NULL);
        const char *c_key = env->GetStringUTFChars(property, NULL);
        dbus_bool_t reply = JNI_FALSE;

        LOGE("%s c_path=%s",__FUNCTION__, c_path);

        msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC,
                                          c_path, DBUS_CHAR_IFACE, "SetProperty");
        if (!msg) {
            LOGE("%s: Can't allocate new method call for device SetProperty!", __FUNCTION__);
            env->ReleaseStringUTFChars(path, c_path);
            env->ReleaseStringUTFChars(property, c_key);
            return JNI_FALSE;
        }

        dbus_message_append_args(msg, DBUS_TYPE_STRING, &c_key, DBUS_TYPE_INVALID);
        dbus_message_iter_init_append(msg, &iter);
        append_variant(&iter, type, value);

        reply = dbus_connection_send_with_reply(nat->conn, msg, NULL, -1);
        if (!reply) {
            if (dbus_error_is_set(&err)) {
                LOG_AND_FREE_DBUS_ERROR(&err);
            } else {
                LOGE("DBus reply is NULL in function %s", __FUNCTION__);
            }
        }
        dbus_message_unref(msg);
        env->ReleaseStringUTFChars(path, c_path);
        env->ReleaseStringUTFChars(property, c_key);
        return reply ? JNI_TRUE : JNI_FALSE;
    }
#endif
    return JNI_FALSE;
}
Exemplo n.º 22
0
static int provider_remove(struct connman_provider *provider)
{
	DBusPendingCall *call;
	DBusMessage *message;
	struct connection_data *data;

	data = connman_provider_get_data(provider);

	DBG("provider %p data %p", provider, data);

	/*
	 * When provider.c:provider_remove() calls this function,
	 * it will remove the provider itself after the call.
	 * This means that we cannot use the provider pointer later
	 * as it is no longer valid.
	 */
	data->provider = NULL;

	message = dbus_message_new_method_call(VPN_SERVICE, "/",
					VPN_MANAGER_INTERFACE,
					VPN_REMOVE);
	if (message == NULL)
		return -ENOMEM;

	dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &data->path,
				NULL);

	if (dbus_connection_send_with_reply(connection, message,
					&call, DBUS_TIMEOUT) == FALSE) {
		connman_error("Unable to call %s.%s()", VPN_MANAGER_INTERFACE,
							VPN_REMOVE);
		dbus_message_unref(message);
		return -EINVAL;
	}

	if (call == NULL) {
		dbus_message_unref(message);
		return -EINVAL;
	}

	dbus_pending_call_set_notify(call, remove_connection_reply,
							NULL, NULL);

	dbus_message_unref(message);

	return 0;
}
Exemplo n.º 23
0
/* start the D-Bus command chain to find out the already connected
 * devices */
static gboolean get_default_adapter(void)
{

    DBusMessage *request = NULL;
    DBusPendingCall *pending_call = NULL;
    DBusConnection *connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);

    if (!connection) {
        goto error;
    }

    if ((request =
                dbus_message_new_method_call ("org.bluez",
                    "/",
                    "org.bluez.Manager",
                    "DefaultAdapter")) == NULL) {
        goto error;

    }

    if (!dbus_connection_send_with_reply (connection,
                request,
                &pending_call,
                -1)) {
        goto error;
    }

    if (!dbus_pending_call_set_notify (pending_call,
                get_default_adapter_cb,
                NULL,
                NULL)) {

        dbus_pending_call_cancel (pending_call);
        goto error;
    }

    dbus_message_unref(request);

    return TRUE;

error:

    if (request)
        dbus_message_unref(request);

    return FALSE;
}
Exemplo n.º 24
0
static gboolean get_device_list(gchar *adapter_path)
{

    DBusMessage *request = NULL;
    DBusPendingCall *pending_call = NULL;
    DBusConnection *connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);

    if (!connection) {
        goto error;
    }

    if ((request =
                dbus_message_new_method_call ("org.bluez",
                    adapter_path,
                    "org.bluez.Adapter",
                    "ListDevices")) == NULL) {
        goto error;

    }

    if (!dbus_connection_send_with_reply (connection,
                request,
                &pending_call,
                -1)) {
        goto error;
    }

    if (!dbus_pending_call_set_notify (pending_call,
                get_device_list_cb,
                NULL,
                NULL)) {

        dbus_pending_call_cancel (pending_call);
        goto error;
    }

    dbus_message_unref(request);

    return TRUE;

error:

    if (request)
        dbus_message_unref(request);

    return FALSE;
}
Exemplo n.º 25
0
int ep_unregister (DBusConnection *c)
{
    DBusMessage     *msg = NULL, *reply = NULL;
    DBusPendingCall *pend;
    int              success = 0;
    char             polrule[512];

    (void) c;

    /* first, let's remove the filter */
    
    snprintf(polrule, sizeof(polrule), "type='signal',interface='%s',"
             "path='%s/%s'", POLICY_DBUS_INTERFACE, POLICY_DBUS_PATH, POLICY_DECISION);
        
    dbus_connection_remove_filter(connection, filter, NULL);
    dbus_bus_remove_match(connection, polrule, NULL);

    /* then unregister */

    msg = dbus_message_new_method_call(POLICY_DBUS_NAME,
            POLICY_DBUS_PATH,
            POLICY_DBUS_INTERFACE,
            "unregister");

    if (msg == NULL) {
        goto failed;
    }

    success = dbus_connection_send_with_reply(connection, msg, &pend, 1000);
    if (!success) {
        goto failed;
    }
    dbus_pending_call_block(pend);
    reply = dbus_pending_call_steal_reply(pend);

    if (!reply || dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
        goto failed;
    }

    success = 1;

    /* intentional fallthrough */

 failed:
    dbus_message_unref(msg);
    return success;
}
Exemplo n.º 26
0
static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_backend *backend, DBusMessage *m,
        DBusPendingCallNotifyFunction func, void *call_data) {

    pa_dbus_pending *p;
    DBusPendingCall *call;

    pa_assert(backend);
    pa_assert(m);

    pa_assert_se(dbus_connection_send_with_reply(pa_dbus_connection_get(backend->connection), m, &call, -1));

    p = pa_dbus_pending_new(pa_dbus_connection_get(backend->connection), m, call, backend, call_data);
    PA_LLIST_PREPEND(pa_dbus_pending, backend->pending, p);
    dbus_pending_call_set_notify(call, func, p, NULL);

    return p;
}
Exemplo n.º 27
0
static void
check_network (DBusConnection *connection, gpointer user_data)
{
        DBusMessage *message;
        DBusPendingCall *reply;

        message = dbus_message_new_method_call (NM_DBUS_SERVICE,
                                                NM_DBUS_PATH,
                                                NM_DBUS_INTERFACE,
                                                "state");
        if (dbus_connection_send_with_reply (connection, message, &reply, -1)) {
                dbus_pending_call_set_notify (reply, state_notify, user_data, NULL);
                dbus_pending_call_unref (reply);
        }

        dbus_message_unref (message);
}
Exemplo n.º 28
0
void call_name(DBusConnection* conn, char* service_name ){
   DBusError error;
   DBusMessage* msg;
   DBusMessageIter args;
   DBusPendingCall* pending;
   dbus_uint32_t result;

   dbus_error_init(&error);
   char* param = "calling you with something in the param";

   char* target = service_name ; // target for the method call;
   //char* object =  "/org/gnome/Tomboy/RemoteControl";
   char* object =  "/"; // started with root .... 
   // we need to some how create a dynamic linked list of object -> method mapping table to displace for call 
   char* interface = DBUS_INTERFACE_INTROSPECTABLE ; 
   //char* interface = "org.freedesktop.DBus.Introspectable";
   //char* name = "RemoteName"; // name of the method
   char* method = "Introspect";

   if( !dbus_bus_start_service_by_name( conn, service_name, 0, &result, &error)){
      fprintf(stderr, "Can't start service %s\n", error.message);
      exit(1);
   } else { 
	// we can start looping all the methods and interface in the object tree
        msg = dbus_message_new_method_call( target, object, interface, method );
        if( NULL == msg ) {
           fprintf(stderr, "Reply Null\n");
           exit(1);
        } else { 
            // send message and get a handle for a reply
            if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
                fprintf(stderr, "Out Of Memory!\n");
                exit(1);
            }
            if (NULL == pending) {
                fprintf(stderr, "Pending Call Null\n");
                exit(1);
            } else {
                dbus_connection_flush(conn);
                // free message
                dbus_message_unref(msg);
                method_callback(pending);
            }
        }
   }
}
Exemplo n.º 29
0
/* As per: http://www.freedesktop.org/wiki/Software/systemd/inhibit */
static void
virNetDaemonCallInhibit(virNetDaemonPtr dmn,
                        const char *what,
                        const char *who,
                        const char *why,
                        const char *mode)
{
    DBusMessage *message;
    DBusPendingCall *pendingReply;
    DBusConnection *systemBus;

    VIR_DEBUG("dmn=%p what=%s who=%s why=%s mode=%s",
              dmn, NULLSTR(what), NULLSTR(who), NULLSTR(why), NULLSTR(mode));

    if (!(systemBus = virDBusGetSystemBus()))
        return;

    /* Only one outstanding call at a time */
    if (dmn->autoShutdownCallingInhibit)
        return;

    message = dbus_message_new_method_call("org.freedesktop.login1",
                                           "/org/freedesktop/login1",
                                           "org.freedesktop.login1.Manager",
                                           "Inhibit");
    if (message == NULL)
        return;

    dbus_message_append_args(message,
                             DBUS_TYPE_STRING, &what,
                             DBUS_TYPE_STRING, &who,
                             DBUS_TYPE_STRING, &why,
                             DBUS_TYPE_STRING, &mode,
                             DBUS_TYPE_INVALID);

    pendingReply = NULL;
    if (dbus_connection_send_with_reply(systemBus, message,
                                        &pendingReply,
                                        25*1000)) {
        dbus_pending_call_set_notify(pendingReply,
                                     virNetDaemonGotInhibitReply,
                                     dmn, NULL);
        dmn->autoShutdownCallingInhibit = true;
    }
    dbus_message_unref(message);
}
Exemplo n.º 30
0
DBusPendingCall* pcmk_dbus_send(DBusMessage *msg, DBusConnection *connection,
                    void(*done)(DBusPendingCall *pending, void *user_data), void *user_data, int timeout)
{
    DBusError error;
    const char *method = NULL;
    DBusPendingCall* pending = NULL;

    dbus_error_init(&error);

    CRM_ASSERT(done);
    CRM_ASSERT(dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_METHOD_CALL);
    method = dbus_message_get_member (msg);


    if (timeout <= 0) {
        timeout = DBUS_TIMEOUT_USE_DEFAULT;
    }

    // send message and get a handle for a reply
    if (!dbus_connection_send_with_reply (connection, msg, &pending, timeout/* -1 is default timeout, aka. DBUS_TIMEOUT_USE_DEFAULT */)) {
        crm_err("Send with reply failed for %s", method);
        return NULL;

    } else if (pending == NULL) {
        crm_err("No pending call found for %s", method);
        return NULL;
    }

    crm_trace("DBus %s call sent", method);
    if (dbus_pending_call_get_completed(pending)) {
        crm_info("DBus %s call completed too soon", method);
        if(done) {
#if 0
        /* This sounds like a good idea, but allegedly it breaks things */
        done(pending, user_data);
        pending = NULL;
#else
        CRM_ASSERT(dbus_pending_call_set_notify(pending, done, user_data, NULL));
#endif
        }

    } else if(done) {
        CRM_ASSERT(dbus_pending_call_set_notify(pending, done, user_data, NULL));
    }
    return pending;
}