/**
 * g_dbus_object_manager_server_set_connection:
 * @manager: A #GDBusObjectManagerServer.
 * @connection: (allow-none): A #GDBusConnection or %NULL.
 *
 * Exports all objects managed by @manager on @connection. If
 * @connection is %NULL, stops exporting objects.
 */
void
g_dbus_object_manager_server_set_connection (GDBusObjectManagerServer  *manager,
                                             GDBusConnection           *connection)
{
  g_return_if_fail (G_IS_DBUS_OBJECT_MANAGER_SERVER (manager));
  g_return_if_fail (connection == NULL || G_IS_DBUS_CONNECTION (connection));

  if (manager->priv->connection == connection)
    goto out;

  if (manager->priv->connection != NULL)
    {
      unexport_all (manager, FALSE);
      g_object_unref (manager->priv->connection);
      manager->priv->connection = NULL;
    }

  manager->priv->connection = connection != NULL ? g_object_ref (connection) : NULL;
  if (manager->priv->connection != NULL)
    export_all (manager);

  g_object_notify (G_OBJECT (manager), "connection");
 out:
  ;
}
/* < internal >
 * _g_dbus_method_invocation_new:
 * @sender: The bus name that invoked the method or %NULL if @connection is not a bus connection.
 * @object_path: The object path the method was invoked on.
 * @interface_name: The name of the D-Bus interface the method was invoked on.
 * @method_name: The name of the method that was invoked.
 * @method_info: Information about the method call or %NULL.
 * @connection: The #GDBusConnection the method was invoked on.
 * @message: The D-Bus message as a #GDBusMessage.
 * @parameters: The parameters as a #GVariant tuple.
 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
 *
 * Creates a new #GDBusMethodInvocation object.
 *
 * Returns: A #GDBusMethodInvocation. Free with g_object_unref().
 *
 * Since: 2.26
 */
GDBusMethodInvocation *
_g_dbus_method_invocation_new (const gchar           *sender,
                               const gchar           *object_path,
                               const gchar           *interface_name,
                               const gchar           *method_name,
                               const GDBusMethodInfo *method_info,
                               GDBusConnection       *connection,
                               GDBusMessage          *message,
                               GVariant              *parameters,
                               gpointer               user_data)
{
  GDBusMethodInvocation *invocation;

  g_return_val_if_fail (sender == NULL || g_dbus_is_name (sender), NULL);
  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
  g_return_val_if_fail (interface_name == NULL || g_dbus_is_interface_name (interface_name), NULL);
  g_return_val_if_fail (g_dbus_is_member_name (method_name), NULL);
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
  g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
  g_return_val_if_fail (g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);

  invocation = G_DBUS_METHOD_INVOCATION (g_object_new (G_TYPE_DBUS_METHOD_INVOCATION, NULL));
  invocation->sender = g_strdup (sender);
  invocation->object_path = g_strdup (object_path);
  invocation->interface_name = g_strdup (interface_name);
  invocation->method_name = g_strdup (method_name);
  invocation->method_info = g_dbus_method_info_ref ((GDBusMethodInfo *)method_info);
  invocation->connection = g_object_ref (connection);
  invocation->message = g_object_ref (message);
  invocation->parameters = g_variant_ref (parameters);
  invocation->user_data = user_data;

  return invocation;
}
예제 #3
0
/**
 * daemon_new:
 * @connection: A #GDBusConnection.
 *
 * Create a new daemon object for exporting objects on @connection.
 *
 * Returns: A #Daemon object. Free with g_object_unref().
 */
Daemon *
daemon_new (GDBusConnection *connection)
{
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
  return DAEMON (g_object_new (TYPE_DAEMON,
                                    "connection", connection,
                                    NULL));
}
예제 #4
0
void
ide_worker_register_service (IdeWorker       *self,
                             GDBusConnection *connection)
{
  g_return_if_fail (IDE_IS_WORKER (self));
  g_return_if_fail (G_IS_DBUS_CONNECTION (connection));

  IDE_WORKER_GET_IFACE (self)->register_service (self, connection);
}
예제 #5
0
/**
 * ide_worker_create_proxy:
 * @self: An #IdeWorker.
 * @connection: A #GDBusConnection connected to the worker process.
 * @error: (allow-none): a location for a #GError, or %NULL.
 *
 * Creates a new proxy to be connected to the subprocess peer on the other
 * end of @connection.
 *
 * Returns: (transfer full): A #GDBusProxy or %NULL.
 */
GDBusProxy *
ide_worker_create_proxy (IdeWorker        *self,
                         GDBusConnection  *connection,
                         GError          **error)
{
  g_return_val_if_fail (IDE_IS_WORKER (self), NULL);
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);

  return IDE_WORKER_GET_IFACE (self)->create_proxy (self, connection, error);
}
예제 #6
0
파일: gdbus-bz627724.c 프로젝트: GNOME/glib
static void
my_object_class_init (MyObjectClass *klass)
{
  GError *error;
  error = NULL;
  the_connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
                                   NULL, /* GCancellable* */
                                   &error);
  g_assert_no_error (error);
  g_assert (G_IS_DBUS_CONNECTION (the_connection));
}
예제 #7
0
/**
 * g_paste_bus_object_register_on_connection:
 * @self: a #GPasteBusObject
 * @connection: a #GDBusConnection
 * @error: a #GError
 *
 * Register the #GPasteBusObject on the connection
 *
 * Returns: Whether the action succeeded or not
 */
G_PASTE_VISIBLE gboolean
g_paste_bus_object_register_on_connection (GPasteBusObject *self,
                                           GDBusConnection *connection,
                                           GError         **error)
{
    g_return_val_if_fail (_G_PASTE_IS_BUS_OBJECT (self), FALSE);
    g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
    g_return_val_if_fail (!error || !(*error), FALSE);

    return G_PASTE_BUS_OBJECT_GET_CLASS (self)->register_on_connection (self, connection, error);
}
/**
 * g_dbus_object_proxy_new:
 * @connection: a #GDBusConnection
 * @object_path: the object path
 *
 * Creates a new #GDBusObjectProxy for the given connection and
 * object path.
 *
 * Returns: a new #GDBusObjectProxy
 *
 * Since: 2.30
 */
GDBusObjectProxy *
g_dbus_object_proxy_new (GDBusConnection *connection,
                         const gchar     *object_path)
{
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
  return G_DBUS_OBJECT_PROXY (g_object_new (G_TYPE_DBUS_OBJECT_PROXY,
                                            "object-path", object_path,
                                            "connection", connection,
                                            NULL));
}
예제 #9
0
MMManager *
mm_manager_new (GDBusConnection *connection,
                GError **error)
{
    g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);

    return g_initable_new (MM_TYPE_MANAGER,
                           NULL, /* cancellable */
                           error,
                           MM_MANAGER_CONNECTION, connection,
                           NULL);
}
/**
 * la_handler_service_new:
 * @connection: A connection to the system bus.
 * @job_manager: A reference to the #JobManager object.
 * 
 * Creates a new #LAHandlerService object.
 * 
 * Returns: A new instance of the #LAHandlerService.
 */
LAHandlerService *
la_handler_service_new (GDBusConnection *connection,
                        JobManager      *job_manager)
{
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
  g_return_val_if_fail (IS_JOB_MANAGER (job_manager), NULL);

  return g_object_new (LA_HANDLER_TYPE_SERVICE,
                       "connection", connection,
                       "job-manager", job_manager,
                       NULL);
}
예제 #11
0
/**
 * g_bus_own_name_on_connection:
 * @connection: A #GDBusConnection that is not closed.
 * @name: The well-known name to own.
 * @flags: A set of flags from the #GBusNameOwnerFlags enumeration.
 * @name_acquired_handler: Handler to invoke when @name is acquired or %NULL.
 * @name_lost_handler: Handler to invoke when @name is lost or %NULL.
 * @user_data: User data to pass to handlers.
 * @user_data_free_func: Function for freeing @user_data or %NULL.
 *
 * Like g_bus_own_name() but takes a #GDBusConnection instead of a
 * #GBusType.
 *
 * Returns: An identifier (never 0) that an be used with
 * g_bus_unown_name() to stop owning the name.
 *
 * Since: 2.26
 */
guint
g_bus_own_name_on_connection (GDBusConnection          *connection,
                              const gchar              *name,
                              GBusNameOwnerFlags        flags,
                              GBusNameAcquiredCallback  name_acquired_handler,
                              GBusNameLostCallback      name_lost_handler,
                              gpointer                  user_data,
                              GDestroyNotify            user_data_free_func)
{
  Client *client;

  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0);
  g_return_val_if_fail (!g_dbus_connection_is_closed (connection), 0);
  g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), 0);

  G_LOCK (lock);

  client = g_new0 (Client, 1);
  client->ref_count = 1;
  client->id = next_global_id++; /* TODO: uh oh, handle overflow */
  client->name = g_strdup (name);
  client->flags = flags;
  client->name_acquired_handler = name_acquired_handler;
  client->name_lost_handler = name_lost_handler;
  client->user_data = user_data;
  client->user_data_free_func = user_data_free_func;
  client->main_context = g_main_context_get_thread_default ();
  if (client->main_context != NULL)
    g_main_context_ref (client->main_context);

  client->connection = g_object_ref (connection);

  if (map_id_to_client == NULL)
    {
      map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);
    }
  g_hash_table_insert (map_id_to_client,
                       GUINT_TO_POINTER (client->id),
                       client);

  G_UNLOCK (lock);

  has_connection (client);

  return client->id;
}
예제 #12
0
MMBaseManager *
mm_base_manager_new (GDBusConnection *connection,
                     const gchar *plugin_dir,
                     gboolean auto_scan,
                     gboolean enable_test,
                     GError **error)
{
    g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);

    return g_initable_new (MM_TYPE_BASE_MANAGER,
                           NULL, /* cancellable */
                           error,
                           MM_BASE_MANAGER_CONNECTION, connection,
                           MM_BASE_MANAGER_PLUGIN_DIR, plugin_dir,
                           MM_BASE_MANAGER_AUTO_SCAN, auto_scan,
                           MM_BASE_MANAGER_ENABLE_TEST, enable_test,
                           NULL);
}
예제 #13
0
static void
dspy_introspection_model_introspect (GTask           *task,
                                     GDBusConnection *connection,
                                     const gchar     *path)
{
  DspyIntrospectionModel *self;
  Introspect *state;
  gint *n_active;

  g_assert (G_IS_TASK (task));
  g_assert (G_IS_DBUS_CONNECTION (connection));
  g_assert (path != NULL);

  self = g_task_get_source_object (task);
  n_active = g_task_get_task_data (task);

  g_assert (G_IS_TASK (task));
  g_assert (n_active != NULL);

  /* If we already have this path, then ignore the suplimental query */
  if (has_node_with_path (self, path))
    return;

  (*n_active)++;

  state = g_slice_new0 (Introspect);
  state->task = g_object_ref (task);
  state->connection = g_object_ref (connection);
  state->path = g_strdup (path);

  g_dbus_connection_call (connection,
                          dspy_name_get_owner (self->name),
                          path,
                          "org.freedesktop.DBus.Introspectable",
                          "Introspect",
                          NULL, /* Params */
                          G_VARIANT_TYPE ("(s)"),
                          G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
                          -1,
                          self->cancellable,
                          dspy_introspection_model_init_introspect_cb,
                          state);
}
예제 #14
0
파일: ext-proxy.c 프로젝트: ckolos/vimb
static gboolean on_new_connection(GDBusServer *server,
        GDBusConnection *connection, gpointer data)
{
    /* Create dbus proxy. */
    g_return_val_if_fail(G_IS_DBUS_CONNECTION(connection), FALSE);

    g_signal_connect(connection, "closed", G_CALLBACK(on_connection_close), NULL);

    g_dbus_proxy_new(connection,
            G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES|G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
            NULL,
            NULL,
            VB_WEBEXTENSION_OBJECT_PATH,
            VB_WEBEXTENSION_INTERFACE,
            NULL,
            (GAsyncReadyCallback)on_proxy_created,
            NULL);

    return TRUE;
}
예제 #15
0
/**
 * g_bus_watch_name_on_connection:
 * @connection: A #GDBusConnection.
 * @name: The name (well-known or unique) to watch.
 * @flags: Flags from the #GBusNameWatcherFlags enumeration.
 * @name_appeared_handler: (nullable): Handler to invoke when @name is known to exist or %NULL.
 * @name_vanished_handler: (nullable): Handler to invoke when @name is known to not exist or %NULL.
 * @user_data: User data to pass to handlers.
 * @user_data_free_func: (nullable): Function for freeing @user_data or %NULL.
 *
 * Like g_bus_watch_name() but takes a #GDBusConnection instead of a
 * #GBusType.
 *
 * Returns: An identifier (never 0) that an be used with
 * g_bus_unwatch_name() to stop watching the name.
 *
 * Since: 2.26
 */
guint g_bus_watch_name_on_connection (GDBusConnection          *connection,
                                      const gchar              *name,
                                      GBusNameWatcherFlags      flags,
                                      GBusNameAppearedCallback  name_appeared_handler,
                                      GBusNameVanishedCallback  name_vanished_handler,
                                      gpointer                  user_data,
                                      GDestroyNotify            user_data_free_func)
{
  Client *client;

  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0);
  g_return_val_if_fail (g_dbus_is_name (name), 0);

  G_LOCK (lock);

  client = g_new0 (Client, 1);
  client->ref_count = 1;
  client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */
  client->name = g_strdup (name);
  client->flags = flags;
  client->name_appeared_handler = name_appeared_handler;
  client->name_vanished_handler = name_vanished_handler;
  client->user_data = user_data;
  client->user_data_free_func = user_data_free_func;
  client->main_context = g_main_context_ref_thread_default ();

  if (map_id_to_client == NULL)
    map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);

  g_hash_table_insert (map_id_to_client,
                       GUINT_TO_POINTER (client->id),
                       client);

  client->connection = g_object_ref (connection);
  G_UNLOCK (lock);

  has_connection (client);

  return client->id;
}
예제 #16
0
static gboolean
ide_worker_manager_new_connection_cb (IdeWorkerManager *self,
                                      GDBusConnection  *connection,
                                      GDBusServer      *server)
{
  GCredentials *credentials;
  GHashTableIter iter;
  gpointer key, value;

  IDE_ENTRY;

  g_assert (IDE_IS_WORKER_MANAGER (self));
  g_assert (G_IS_DBUS_CONNECTION (connection));
  g_assert (G_IS_DBUS_SERVER (server));

  g_dbus_connection_set_exit_on_close (connection, FALSE);

  credentials = g_dbus_connection_get_peer_credentials (connection);
  if ((credentials == NULL) || (-1 == g_credentials_get_unix_pid (credentials, NULL)))
    IDE_RETURN (FALSE);

  g_hash_table_iter_init (&iter, self->plugin_name_to_worker);

  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      IdeWorkerProcess *process = value;

      if (ide_worker_process_matches_credentials (process, credentials))
        {
          ide_worker_process_set_connection (process, connection);
          IDE_RETURN (TRUE);
        }
    }

  IDE_RETURN (FALSE);
}
예제 #17
0
int main(int argc, char *argv[]) {
        GDBusConnection *bus;
	GError *error = NULL;
        int max_realtime_priority, min_nice_level;
	long long rttime_usec_max;
	struct rlimit rlim;

	bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
	if (!G_IS_DBUS_CONNECTION (bus)) {
		fprintf (stderr, "Failed to connect to system bus: %s\n", error->message);
		g_error_free (error);
		return EXIT_FAILURE;
	}

	max_realtime_priority = arv_rtkit_get_max_realtime_priority (bus, &error);
	if (error != NULL) {
		fprintf (stderr, "Failed to get MaxRealtimePriority: %s\n", error->message);
		g_error_free (error);
		error = NULL;
	} else
		printf ("MaxRealtimePriority = %d\n", max_realtime_priority);

	min_nice_level = arv_rtkit_get_min_nice_level (bus, &error);
	if (error != NULL) {
		fprintf (stderr, "Failed to get MinNiceLevel: %s\n", error->message);
		g_error_free (error);
		error = NULL;
	} else
		printf ("MinNiceLevel = %d\n", min_nice_level);

	rttime_usec_max = arv_rtkit_get_rttime_usec_max (bus, &error);
	if (error != NULL) {
		fprintf (stderr, "Failed to get RTTimeUSecMax: %s\n", error->message);
		g_error_free (error);
		error = NULL;
	} else
		printf ("RTTimeUSecMax = %Ld\n", rttime_usec_max);

	memset(&rlim, 0, sizeof(rlim));
	rlim.rlim_cur = rlim.rlim_max = 100000000ULL; /* 100ms */
	if ((setrlimit(RLIMIT_RTTIME, &rlim) < 0))
		fprintf(stderr, "Failed to set RLIMIT_RTTIME: %s\n", strerror(errno));

	print_status("before");

	arv_rtkit_make_high_priority (bus, 0, -10, &error);
	if (error != NULL) {
		fprintf (stderr, "Failed to become high priority: %s\n", error->message);
		g_error_free (error);
		error = NULL;
	} else
		printf ("Successfully became high priority\n");

	print_status("after high priority");

	arv_rtkit_make_realtime (bus, 0, 10, &error);
	if (error != NULL) {
		fprintf (stderr, "Failed to get become realtime: %s\n", error->message);
		g_error_free (error);
		error = NULL;
	} else
		printf ("Successfully became realtime\n");

	print_status("after realtime");

	g_object_unref (bus);

        return EXIT_SUCCESS;
}
예제 #18
0
static void
dspy_introspection_model_init_introspect_cb (GObject      *object,
                                             GAsyncResult *result,
                                             gpointer      user_data)
{
  GDBusConnection *bus = (GDBusConnection *)object;
  DspyIntrospectionModel *self;
  g_autoptr(Introspect) state = user_data;
  g_autoptr(GVariant) reply = NULL;
  g_autoptr(GError) error = NULL;
  GCancellable *cancellable;
  gint *n_active;

  g_assert (G_IS_DBUS_CONNECTION (bus));
  g_assert (G_IS_ASYNC_RESULT (result));
  g_assert (state != NULL);
  g_assert (G_IS_TASK (state->task));
  g_assert (state->path != NULL);

  self = g_task_get_source_object (state->task);
  n_active = g_task_get_task_data (state->task);
  cancellable = g_task_get_cancellable (state->task);

  g_assert (self != NULL);
  g_assert (DSPY_IS_INTROSPECTION_MODEL (self));
  g_assert (n_active != NULL);
  g_assert (*n_active > 0);

  if ((reply = g_dbus_connection_call_finish (bus, result, &error)))
    {
      g_autoptr(GBytes) bytes = NULL;
      const gchar *str = NULL;

      /* Get the XML contents, and wrap it in a new GBytes that will
       * reference the original GVariant to avoid a copy as this might
       * contain a large amount of text.
       */
      g_variant_get (reply, "(&s)", &str);

      if (str[0] != 0)
        {
          bytes = g_bytes_new_with_free_func (str,
                                              strlen (str),
                                              (GDestroyNotify) g_variant_unref,
                                              g_variant_ref (reply));
          parse_xml_async (self,
                           bytes,
                           cancellable,
                           dspy_introspection_model_init_parse_cb,
                           g_steal_pointer (&state));
          return;
        }
    }
  else
    {
      DspyConnection *connection = dspy_name_get_connection (self->name);

      dspy_connection_add_error (connection, error);
    }

  if (--(*n_active) == 0)
    g_task_return_boolean (state->task, TRUE);
}