Example #1
0
static void
new_connection_cb (DBusServer    * server,
                   DBusConnection* connection,
                   gpointer        user_data)
{
  dbus_int32_t  slot = -1;
  GObject     * object;
  if (!dbus_connection_allocate_data_slot (&slot))
    {
      g_warning ("error allocating data slot for DBusConnection");
      dbus_connection_close (connection);
      return;
    }

  dbus_connection_ref (connection);

  dbus_connection_set_allow_anonymous (connection, TRUE);
  dbus_connection_setup_with_g_main (connection, NULL);

  object = g_object_new (p2p_object_get_type (), NULL);
  dbus_g_connection_register_g_object (dbus_connection_get_g_connection (connection),
                                       "/", object);
  dbus_connection_set_data (connection, slot,
                            object, g_object_unref);
}
static gboolean
io_handler_dispatch (GIOChannel *source, GIOCondition condition, gpointer data)
{
	IOHandler *handler = data;
	guint dbus_condition = 0;
	DBusConnection *connection = handler->cs->connection;

	if (connection)
		dbus_connection_ref (connection);

	if (condition & G_IO_IN)
		dbus_condition |= DBUS_WATCH_READABLE;
	if (condition & G_IO_OUT)
		dbus_condition |= DBUS_WATCH_WRITABLE;
	if (condition & G_IO_ERR)
		dbus_condition |= DBUS_WATCH_ERROR;
	if (condition & G_IO_HUP)
		dbus_condition |= DBUS_WATCH_HANGUP;

	/* Note that we don't touch the handler after this, because
	 * dbus may have disabled the watch and thus killed the
	 * handler.
	 */
	dbus_watch_handle (handler->watch, dbus_condition);
	handler = NULL;

	if (connection)
		dbus_connection_unref (connection);

	return TRUE;
}
Example #3
0
struct connline_context *connline_open(enum connline_bearer bearer_type,
						bool background_connection,
						connline_callback_f callback,
						void *user_data)
{
	struct connline_context *context;
	__connline_open_f _connline_open;

	if (is_connline_initialized() == false)
		return NULL;

	context = __connline_context_new();
	if (context == NULL)
		return NULL;

	context->bearer_type = bearer_type;
	context->background_connection = background_connection;
	context->event_callback = callback;
	context->user_data = user_data;
	context->dbus_cnx = dbus_connection_ref(dbus_cnx);

	if (is_backend_up() == false)
		return context;

	_connline_open = connection_backend->__connline_open;
	_connline_open(context);

	return context;
}
Example #4
0
DBusConnection *manager_dbus_get_connection(void)
{
	if (connection == NULL)
		return NULL;

	return dbus_connection_ref(connection);
}
static void
_new_connection (DBusServer *server,
		 DBusConnection *connection,
		 void *data)
{
	ServiceData *svc = (ServiceData *)data;
	DBusObjectPathVTable vt = {
		_unregister_handler,
		_handle_message,
		NULL, NULL, NULL, NULL
	};

	rb_debug ("new connection to metadata service");

	/* don't allow more than one connection at a time */
	if (svc->connection) {
		rb_debug ("metadata service already has a client.  go away.");
		return;
	}

	dbus_connection_register_object_path (connection,
					      RB_METADATA_DBUS_OBJECT_PATH,
					      &vt,
					      svc);
	dbus_connection_ref (connection);
	dbus_connection_setup_with_g_main (connection,
					   g_main_loop_get_context (svc->loop));
	if (!svc->external)
		dbus_connection_set_exit_on_disconnect (connection, TRUE);
}
Example #6
0
void
ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus_connection, gboolean shared)
{
    gboolean result;
    IBusConnectionPrivate *priv;

    g_assert (IBUS_IS_CONNECTION (connection));
    g_assert (dbus_connection != NULL);
    g_assert (dbus_connection_get_is_connected (dbus_connection));

    priv = IBUS_CONNECTION_GET_PRIVATE (connection);
    g_assert (priv->connection == NULL);

    priv->connection = dbus_connection_ref (dbus_connection);
    priv->shared = shared;

    dbus_connection_set_data (priv->connection, _get_slot(), connection, NULL);

    dbus_connection_set_unix_user_function (priv->connection,
                                            (DBusAllowUnixUserFunction) _connection_allow_unix_user_cb,
                                            connection, NULL);

    result = dbus_connection_add_filter (priv->connection,
                                         (DBusHandleMessageFunction) _connection_handle_message_cb,
                                         connection, NULL);

    ibus_dbus_connection_setup (priv->connection);
    g_warn_if_fail (result);
}
Example #7
0
static struct serial_device *create_serial_device(DBusConnection *conn,
					const char *path, bdaddr_t *src,
					bdaddr_t *dst)
{
	struct serial_device *device;

	device = g_new0(struct serial_device, 1);
	device->conn = dbus_connection_ref(conn);
	bacpy(&device->dst, dst);
	bacpy(&device->src, src);
	device->path = g_strdup(path);

	if (!g_dbus_register_interface(conn, path,
				SERIAL_PORT_INTERFACE,
				port_methods, NULL, NULL,
				device, path_unregister)) {
		error("D-Bus failed to register %s interface",
				SERIAL_PORT_INTERFACE);
		serial_device_free(device);
		return NULL;
	}

	debug("Registered interface %s on path %s",
		SERIAL_PORT_INTERFACE, path);

	return device;
}
Example #8
0
static struct generic_data *object_path_ref(DBusConnection *connection,
							const char *path)
{
	struct generic_data *data;

	if (dbus_connection_get_object_path_data(connection, path,
						(void *) &data) == TRUE) {
		if (data != NULL) {
			data->refcount++;
			return data;
		}
	}

	data = g_new0(struct generic_data, 1);
	data->conn = dbus_connection_ref(connection);
	data->path = g_strdup(path);
	data->refcount = 1;

	data->introspect = g_strdup(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE "<node></node>");

	if (!dbus_connection_register_object_path(connection, path,
						&generic_table, data)) {
		g_free(data->introspect);
		g_free(data);
		return NULL;
	}

	invalidate_parent_data(connection, path);

	add_interface(data, DBUS_INTERFACE_INTROSPECTABLE, introspect_methods,
						NULL, NULL, data, NULL);

	return data;
}
Example #9
0
static dbus_bool_t add_watch(DBusWatch *watch, void *data)
{
	GIOCondition cond = G_IO_HUP | G_IO_ERR;
	DBusConnection *conn = data;
	struct watch_info *info;
	int fd, flags;

	if (!dbus_watch_get_enabled(watch))
		return TRUE;

	info = g_new(struct watch_info, 1);

	fd = dbus_watch_get_unix_fd(watch);
	info->io = g_io_channel_unix_new(fd);
	info->conn = dbus_connection_ref(conn);

	dbus_watch_set_data(watch, info, NULL);

	flags = dbus_watch_get_flags(watch);

	if (flags & DBUS_WATCH_READABLE) cond |= G_IO_IN;
	if (flags & DBUS_WATCH_WRITABLE) cond |= G_IO_OUT;

	info->watch_id = g_io_add_watch(info->io, cond, watch_func, watch);

	return TRUE;
}
static DBusMessage *remove_sdp_record(DBusConnection *conn,
                        DBusMessage *msg, void *data)
{
    struct service_adapter *serv_adapter = data;   
    tDTUN_METHOD_DM_REMOVE_SDP_REC_EX       method;
    dbus_uint32_t handle;
    const char *sender;
    
    debug( "SDP: remove_sdp_record  conn=%p", conn );

    if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle,
                            DBUS_TYPE_INVALID) == FALSE)
        return NULL;

    sender = dbus_message_get_sender(msg);
    
    g_conn = dbus_connection_ref(conn);
    g_msg = dbus_message_ref(msg);
    
    memset(&method,0, sizeof(method));
    method.handle = handle;
    method.hdr.len= sizeof(handle);
    method.hdr.id = DTUN_METHOD_SDP_REMOVE_RECORD;
    dtun_client_call_method((tDTUN_DEVICE_METHOD *)&method);
    return NULL;

}
Example #11
0
static DBusMessage *sink_connect(DBusConnection *conn,
				DBusMessage *msg, void *data)
{
	struct audio_device *dev = data;
	struct sink *sink = dev->sink;
	struct pending_request *pending;

	if (!sink->session)
		sink->session = avdtp_get(&dev->src, &dev->dst);

	if (!sink->session)
		return btd_error_failed(msg, "Unable to get a session");

	if (sink->connect || sink->disconnect)
		return btd_error_busy(msg);

	if (sink->stream_state >= AVDTP_STATE_OPEN)
		return btd_error_already_connected(msg);

	if (!sink_setup_stream(sink, NULL))
		return btd_error_failed(msg, "Failed to create a stream");

	dev->auto_connect = FALSE;

	pending = sink->connect;

	pending->conn = dbus_connection_ref(conn);
	pending->msg = dbus_message_ref(msg);

	DBG("stream creation in progress");

	return NULL;
}
static DBusMessage *sink_disconnect(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct audio_device *device = data;
	struct sink *sink = device->sink;
	struct pending_request *pending;
	int err;

	if (!sink->session)
		return btd_error_not_connected(msg);

	if (sink->connect || sink->disconnect)
		return btd_error_busy(msg);

	if (sink->stream_state < AVDTP_STATE_OPEN) {
		DBusMessage *reply = dbus_message_new_method_return(msg);
		if (!reply)
			return NULL;
		avdtp_unref(sink->session);
		sink->session = NULL;
		return reply;
	}

	err = avdtp_close(sink->session, sink->stream, FALSE);
	if (err < 0)
		return btd_error_failed(msg, strerror(-err));

	pending = g_new0(struct pending_request, 1);
	pending->conn = dbus_connection_ref(conn);
	pending->msg = dbus_message_ref(msg);
	sink->disconnect = pending;

	return NULL;
}
Example #13
0
File: dbus.c Project: NieHao/wl500g
void check_dbus_listeners(fd_set *rset, fd_set *wset, fd_set *eset)
{
  DBusConnection *connection = (DBusConnection *)daemon->dbus;
  struct watch *w;

  for (w = daemon->watches; w; w = w->next)
    if (dbus_watch_get_enabled(w->watch))
      {
	unsigned int flags = 0;
	int fd = dbus_watch_get_unix_fd(w->watch);
	
	if (FD_ISSET(fd, rset))
	  flags |= DBUS_WATCH_READABLE;
	
	if (FD_ISSET(fd, wset))
	  flags |= DBUS_WATCH_WRITABLE;
	
	if (FD_ISSET(fd, eset))
	  flags |= DBUS_WATCH_ERROR;

	if (flags != 0)
	  dbus_watch_handle(w->watch, flags);
      }

  if (connection)
    {
      dbus_connection_ref (connection);
      while (dbus_connection_dispatch (connection) == DBUS_DISPATCH_DATA_REMAINS);
      dbus_connection_unref (connection);
    }
}
static dbus_bool_t
add_cancel_ownership_to_transaction (BusTransaction *transaction,
                                     BusService     *service,
                                     BusOwner       *owner)
{
  OwnershipCancelData *d;

  d = dbus_new (OwnershipCancelData, 1);
  if (d == NULL)
    return FALSE;
  
  d->service = service;
  d->owner = owner;

  if (!bus_transaction_add_cancel_hook (transaction, cancel_ownership, d,
                                        free_ownership_cancel_data))
    {
      dbus_free (d);
      return FALSE;
    }

  bus_service_ref (d->service);
  bus_owner_ref (owner);
  dbus_connection_ref (d->owner->conn);
 
  return TRUE;
}
int input_manager_init(DBusConnection *conn, GKeyFile *config)
{
	GError *err = NULL;

	if (config) {
		idle_timeout = g_key_file_get_integer(config, "General",
						"IdleTimeout", &err);
		if (err) {
			DBG("input.conf: %s", err->message);
			g_error_free(err);
		}
	}

	connection = dbus_connection_ref(conn);

#ifndef BT_ALT_STACK
	btd_register_adapter_driver(&input_server_driver);
#endif

	btd_register_device_driver(&input_hid_driver);
#ifndef BT_ALT_STACK
	btd_register_device_driver(&input_headset_driver);
#endif

	return 0;
}
Example #16
0
static struct input_device *input_device_new(DBusConnection *conn,
					struct btd_device *device, const char *path,
					const bdaddr_t *src, const bdaddr_t *dst,
					const uint32_t handle)
{
	struct input_device *idev;
	char name[249], src_addr[18], dst_addr[18];

	idev = g_new0(struct input_device, 1);
	bacpy(&idev->src, src);
	bacpy(&idev->dst, dst);
	idev->device = btd_device_ref(device);
	idev->path = g_strdup(path);
	idev->conn = dbus_connection_ref(conn);
	idev->handle = handle;

	ba2str(src, src_addr);
	ba2str(dst, dst_addr);
	if (read_device_name(src_addr, dst_addr, name) == 0)
		idev->name = g_strdup(name);

	if (g_dbus_register_interface(conn, idev->path, INPUT_DEVICE_INTERFACE,
					device_methods, device_signals, NULL,
					idev, device_unregister) == FALSE) {
		error("Failed to register interface %s on path %s",
			INPUT_DEVICE_INTERFACE, path);
		input_device_free(idev);
		return NULL;
	}

	debug("Registered interface %s on path %s",
			INPUT_DEVICE_INTERFACE, idev->path);

	return idev;
}
Example #17
0
static DBusMessage *sink_connect(DBusConnection *conn,
				DBusMessage *msg, void *data)
{
	struct audio_device *dev = data;
	struct sink *sink = dev->sink;
	struct pending_request *pending;

	if (!sink->session)
		sink->session = avdtp_get(&dev->src, &dev->dst);

	if (!sink->session)
		return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
						"Unable to get a session");

	if (sink->connect || sink->disconnect)
		return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
						"%s", strerror(EBUSY));

	if (sink->state >= AVDTP_STATE_OPEN)
		return g_dbus_create_error(msg, ERROR_INTERFACE
						".AlreadyConnected",
						"Device Already Connected");

	pending = g_new0(struct pending_request, 1);
	pending->conn = dbus_connection_ref(conn);
	pending->msg = dbus_message_ref(msg);
	sink->connect = pending;

	avdtp_discover(sink->session, discovery_complete, sink);

	debug("stream creation in progress");

	return NULL;
}
static struct generic_data *object_path_ref(DBusConnection *connection,
							const char *path)
{
	struct generic_data *data;

	if (dbus_connection_get_object_path_data(connection, path,
						(void *) &data) == TRUE) {
		if (data != NULL) {
			data->refcount++;
			return data;
		}
	}

	data = g_new0(struct generic_data, 1);
	data->conn = dbus_connection_ref(connection);
	data->path = g_strdup(path);
	data->refcount = 1;
	LOG("object_path_ref(data->conn:%p,data->path:%s)",
			data->conn,data->path);
	if (!dbus_connection_register_object_path(connection, path,
						&generic_table, data)) {
		g_free(data);
		return NULL;
	}

	return data;
}
Example #19
0
int proxy_register(DBusConnection *conn, struct btd_adapter *btd_adapter)
{
    struct serial_adapter *adapter;
    const char *path;

    adapter = find_adapter(adapters, btd_adapter);
    if (adapter)
        return -EINVAL;

    adapter = g_new0(struct serial_adapter, 1);
    adapter->conn = dbus_connection_ref(conn);
    adapter->btd_adapter = btd_adapter_ref(btd_adapter);

    path = adapter_get_path(btd_adapter);

    if (!g_dbus_register_interface(conn, path,
                                   SERIAL_MANAGER_INTERFACE,
                                   manager_methods, manager_signals, NULL,
                                   adapter, manager_path_unregister)) {
        error("Failed to register %s interface to %s",
              SERIAL_MANAGER_INTERFACE, path);
        return -1;
    }

    register_stored(adapter);

    adapters = g_slist_append(adapters, adapter);

    debug("Registered interface %s on path %s",
          SERIAL_MANAGER_INTERFACE, path);

    return 0;
}
Example #20
0
int server_init(DBusConnection *conn, gboolean secure)
{
    security = secure;
    connection = dbus_connection_ref(conn);

    return 0;
}
Example #21
0
int network_manager_init(DBusConnection *conn)
{
	read_config(CONFIGDIR "/network.conf");

	if (bnep_init()) {
		error("Can't init bnep module");
		return -1;
	}

	/*
	 * There is one socket to handle the incomming connections. NAP,
	 * GN and PANU servers share the same PSM. The initial BNEP message
	 * (setup connection request) contains the destination service
	 * field that defines which service the source is connecting to.
	 */

	if (server_init(conn, conf_security, conf_master) < 0)
		return -1;

	/* Register network server if it doesn't exist */
	btd_register_adapter_driver(&network_server_driver);

	if (connection_init(conn) < 0)
		return -1;

	btd_register_device_driver(&network_panu_driver);
	btd_register_device_driver(&network_gn_driver);
	btd_register_device_driver(&network_nap_driver);

	connection = dbus_connection_ref(conn);

	return 0;
}
Example #22
0
static dbus_bool_t add_watch(DBusWatch *watch, void *data)
{
	DBusConnection *conn = data;
	GIOCondition cond = G_IO_HUP | G_IO_ERR;
	GIOChannel *chan;
	struct watch_info *info;
	unsigned int flags;
	int fd;

	if (!dbus_watch_get_enabled(watch))
		return TRUE;

	info = g_new0(struct watch_info, 1);

	fd = dbus_watch_get_unix_fd(watch);
	chan = g_io_channel_unix_new(fd);

	info->watch = watch;
	info->conn = dbus_connection_ref(conn);

	dbus_watch_set_data(watch, info, watch_info_free);

	flags = dbus_watch_get_flags(watch);

	if (flags & DBUS_WATCH_READABLE) cond |= G_IO_IN;
	if (flags & DBUS_WATCH_WRITABLE) cond |= G_IO_OUT;

	info->id = g_io_add_watch(chan, cond, watch_func, info);

	g_io_channel_unref(chan);

	return TRUE;
}
static DBusMessage *add_sdp_record(DBusConnection *conn,
                        DBusMessage *msg, void *data)
{
    const char *sender, *record;

    int err;
    debug("%s", __FUNCTION__);
    debug( "SDP: add_sdp_record  conn=%p ", conn );

    if (dbus_message_get_args(msg, NULL,
            DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) {
        error("SDP: error getting args");        
        return NULL;
    }
    debug( "SDP: add_sdp_record  record=%s ", record );

    sender = dbus_message_get_sender(msg);
    
    err = add_xml_record(conn, sender, record);
    if (err < 0)
        return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",strerror(err));

    g_conn = dbus_connection_ref(conn);
    g_msg = dbus_message_ref(msg);

    return NULL;
}
Example #24
0
static void handle_watch(struct sock_com *s, short revents)
{
	struct DBusWatch *w = s->data;
	unsigned int flags = 0;

	if(!w)
		return;
	if(!dbus_watch_get_enabled(w)) {
		s->enabled = false;
		return;
	}

	flags |= revents & POLLIN  ? DBUS_WATCH_READABLE : 0;
	flags |= revents & POLLOUT ? DBUS_WATCH_WRITABLE : 0;
	flags |= revents & POLLERR ? DBUS_WATCH_ERROR    : 0;
	flags |= revents & POLLHUP ? DBUS_WATCH_HANGUP   : 0;
	if(flags)
		dbus_watch_handle(w, flags);
	if(idbus_connection)
	{
		dbus_connection_ref(idbus_connection);
		while(DBUS_DISPATCH_DATA_REMAINS == dbus_connection_dispatch(idbus_connection)) {
			/* nop */;
		}
		dbus_connection_unref(idbus_connection);
	}
}
Example #25
0
DBusMessage*
hippo_dbus_handle_get_preference(HippoDBus   *dbus,
                                 DBusMessage *message)
{
    const char *key;
    const char *signature;
    HippoSettings *settings;
    SettingArrivedData *sad;
    DBusConnection *dbus_connection;
    
    key = NULL;
    signature = NULL;
    if (!dbus_message_get_args(message, NULL,
                               DBUS_TYPE_STRING, &key,
                               DBUS_TYPE_SIGNATURE, &signature,
                               DBUS_TYPE_INVALID)) {
        return dbus_message_new_error(message,
                                      DBUS_ERROR_INVALID_ARGS,
                                      _("Expected two arguments, the key and the expected type signature"));
    }

    if (!dbus_signature_validate_single(signature, NULL)) {
        return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
                                      _("Type signature must be a single complete type, not a list of types"));
    }

    if ( ! (*signature == DBUS_TYPE_INT32 ||
            *signature == DBUS_TYPE_STRING ||
            *signature == DBUS_TYPE_BOOLEAN) ) {
        return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
                                      _("Only STRING, INT32, BOOLEAN values supported for now"));
    }

    dbus_connection = hippo_dbus_get_connection(dbus);    
    
    settings = get_and_ref_settings(dbus_connection);

    if (!hippo_settings_get_ready(settings)) {
        g_object_unref(G_OBJECT(settings));
        return dbus_message_new_error(message, HIPPO_DBUS_PREFS_ERROR_NOT_READY,
                                      _("Have not yet connected to server, can't get preferences"));
    }

    sad = g_new0(SettingArrivedData, 1);
    sad->connection = dbus_connection;
    dbus_connection_ref(sad->connection);
    
    sad->settings = settings;

    sad->method_call = message;
    dbus_message_ref(sad->method_call);
    sad->signature = signature; /* points inside sad->method_call */

    
    /* this may call setting_arrived synchronously if we already have it */
    hippo_settings_get(settings, key, setting_arrived, sad);    
    
    return NULL; /* no synchronous reply, we'll send it async or we just sent it above */
}
::DBusConnection* createConnection() {
   const ::DBusBusType libdbusType = ::DBusBusType::DBUS_BUS_SESSION;
   ::DBusConnection* libdbusConnection = dbus_bus_get_private(libdbusType, NULL);
   dbus_connection_ref(libdbusConnection);
   dbus_connection_set_exit_on_disconnect(libdbusConnection, false);

   return libdbusConnection;
}
Example #27
0
void DBusProcessEventForConnection(DBusConnection* connection)
{
    if (connection) {
        dbus_connection_ref(connection);
        while (dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS);
        dbus_connection_unref(connection);
    }
}
Example #28
0
/** Return reference to dbus connection cached at mce-dbus module
 *
 * For use in situations where the abstraction provided by mce-dbus
 * makes things too complicated.
 *
 * Caller must release non-null return values with dbus_connection_unref().
 *
 * @return DBusConnection, or NULL if mce has no dbus connection
 */
DBusConnection *dbus_connection_get(void)
{
	if( !dbus_connection ) {
		mce_log(LL_WARN, "no dbus connection");
		return NULL;
	}
	return dbus_connection_ref(dbus_connection);
}
/**
 * Increment refcount on a #DBusGConnection
 * 
 * @param gconnection the connection to ref
 * @returns the connection that was ref'd
 */
DBusGConnection*
dbus_g_connection_ref (DBusGConnection *gconnection)
{
  DBusConnection *c;

  c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
  dbus_connection_ref (c);
  return gconnection;
}
Example #30
0
int serial_manager_init(DBusConnection *conn)
{
	connection = dbus_connection_ref(conn);

	btd_register_adapter_driver(&serial_proxy_driver);
	btd_register_device_driver(&serial_port_driver);

	return 0;
}