Esempio n. 1
0
/**
 * gpk_session_init:
 * @session: This class instance
 **/
static void
gpk_session_init (GpkSession *session)
{
	DBusGConnection *connection;
	GError *error = NULL;

	session->priv = GPK_SESSION_GET_PRIVATE (session);
	session->priv->is_idle_old = FALSE;
	session->priv->is_inhibited_old = FALSE;
	session->priv->proxy_client_private = NULL;

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);

	/* get org.gnome.Session interface */
	session->priv->proxy = dbus_g_proxy_new_for_name_owner (connection, GPK_SESSION_MANAGER_SERVICE,
								GPK_SESSION_MANAGER_PATH,
								GPK_SESSION_MANAGER_INTERFACE, &error);
	if (session->priv->proxy == NULL) {
		g_warning ("DBUS error: %s", error->message);
		g_error_free (error);
		return;
	}

	/* get org.gnome.Session.Presence interface */
	session->priv->proxy_presence = dbus_g_proxy_new_for_name_owner (connection, GPK_SESSION_MANAGER_SERVICE,
									 GPK_SESSION_MANAGER_PRESENCE_PATH,
									 GPK_SESSION_MANAGER_PRESENCE_INTERFACE, &error);
	if (session->priv->proxy_presence == NULL) {
		g_warning ("DBUS error: %s", error->message);
		g_error_free (error);
		return;
	}

	/* get properties interface */
	session->priv->proxy_prop = dbus_g_proxy_new_for_name_owner (connection, GPK_SESSION_MANAGER_SERVICE,
								     GPK_SESSION_MANAGER_PRESENCE_PATH,
								     GPK_DBUS_PROPERTIES_INTERFACE, &error);
	if (session->priv->proxy_prop == NULL) {
		g_warning ("DBUS error: %s", error->message);
		g_error_free (error);
		return;
	}

	/* get StatusChanged */
	dbus_g_proxy_add_signal (session->priv->proxy_presence, "StatusChanged", G_TYPE_UINT, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy_presence, "StatusChanged", G_CALLBACK (gpk_session_presence_status_changed_cb), session, NULL);

	/* get InhibitorAdded */
	dbus_g_proxy_add_signal (session->priv->proxy, "InhibitorAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy, "InhibitorAdded", G_CALLBACK (gpk_session_inhibit_changed_cb), session, NULL);

	/* get InhibitorRemoved */
	dbus_g_proxy_add_signal (session->priv->proxy, "InhibitorRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy, "InhibitorRemoved", G_CALLBACK (gpk_session_inhibit_changed_cb), session, NULL);

	/* coldplug */
	session->priv->is_inhibited_old = gpk_session_is_inhibited (session);
	session->priv->is_idle_old = gpk_session_is_idle (session);
	g_debug ("idle: %i, inhibited: %i", session->priv->is_idle_old, session->priv->is_inhibited_old);
}
Esempio n. 2
0
/**
 * pk_inhibit_init:
 *
 * initializes the inhibit class. NOTE: We expect inhibit objects
 * to *NOT* be removed or added during the session.
 * We only control the first inhibit object if there are more than one.
 **/
static void
pk_inhibit_init (PkInhibit *inhibit)
{
	GError *error = NULL;
	DBusGConnection *connection;

	inhibit->priv = PK_INHIBIT_GET_PRIVATE (inhibit);
	inhibit->priv->is_locked = FALSE;
	inhibit->priv->array = g_ptr_array_new ();

	/* connect to system bus */
	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
	if (error != NULL) {
		g_warning ("Cannot connect to system bus: %s", error->message);
		g_error_free (error);
		return;
	}

	/* use gnome-power-manager for the battery detection */
	inhibit->priv->proxy = dbus_g_proxy_new_for_name_owner (connection,
				  HAL_DBUS_SERVICE, HAL_DBUS_PATH_COMPUTER,
				  HAL_DBUS_INTERFACE_DEVICE, &error);
	if (error != NULL) {
		g_debug ("Cannot connect to HAL: %s", error->message);
		g_error_free (error);
	}

}
static gboolean
create_dbus_proxy (RBGPMPlugin *plugin)
{
	GError *error = NULL;

	if (plugin->proxy != NULL) {
		return TRUE;
	}

	/* try new name first */
	plugin->proxy = dbus_g_proxy_new_for_name_owner (plugin->bus,
						   "org.gnome.SessionManager",
						   "/org/gnome/SessionManager",
						   "org.gnome.SessionManager",
						   &error);
	if (error != NULL && ignore_error (error) == FALSE) {
		g_warning ("Failed to create dbus proxy for org.gnome.SessionManager: %s",
			   error->message);
		g_error_free (error);
		return FALSE;
	}

	g_signal_connect_object (plugin->proxy,
				 "destroy",
				 G_CALLBACK (proxy_destroy_cb),
				 plugin, 0);
	return TRUE;
}
Esempio n. 4
0
static gboolean
_ensure_dbus ()
{
  static DBusGConnection *connection = NULL;
  if (proxy != NULL)
    return TRUE;
  if (connection == NULL)
    connection = ol_dbus_get_connection ();
  if (connection == NULL)
    return FALSE;
  GError *error = NULL;
  proxy = dbus_g_proxy_new_for_name_owner (connection,
                                           SERVICE,
                                           PATH_PLAYER,
                                           INTERFACE_PLAYER,
                                           &error);
  if (proxy == NULL)
  {
    ol_infof ("get proxy failed: %s\n", error->message);
    g_error_free (error);
    error = NULL;
    return FALSE;
  }
  g_signal_connect (proxy,
                    "destroy",
                    G_CALLBACK (_destroy_dbus),
                    NULL);
  return TRUE;
}
Esempio n. 5
0
bool Skype::createDBusProxy() {
	if (m_proxy == NULL) {
		LOG4CXX_INFO(logger, "Creating DBus proxy for com.Skype.Api.");
		m_counter++;

		GError *error = NULL;
		m_proxy = dbus_g_proxy_new_for_name_owner(m_connection, "com.Skype.API", "/com/Skype", "com.Skype.API", &error);
		if (m_proxy == NULL && error != NULL) {
			LOG4CXX_INFO(logger,  m_username << ":" << error->message);

			if (m_counter == MAX_SKYPE_DBUS_RETRIES) {
				LOG4CXX_ERROR(logger, "Logging out, proxy couldn't be created: " << error->message);
				m_np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, error->message);
				logout();
				g_error_free(error);
				return FALSE;
			}
			g_error_free(error);
		}

		if (m_proxy) {
			LOG4CXX_INFO(logger, "Proxy created.");
			DBusObjectPathVTable vtable;
			vtable.message_function = &skype_notify_handler;
			dbus_connection_register_object_path(dbus_g_connection_get_connection(m_connection), "/com/Skype/Client", &vtable, this);

			m_counter = 0;
			m_timer = g_timeout_add_seconds(1, load_skype_buddies, this);
			g_timeout_add_seconds(10, skype_check_missedmessages, this);
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}
Esempio n. 6
0
static gboolean gnome_integration_init(SpiceDesktopIntegration *self)
{
    SpiceDesktopIntegrationPrivate *priv = self->priv;
    GError *error = NULL;

    if (!priv->dbus_conn)
        return FALSE;

    /* We use for_name_owner, to resolve the name now, as we may not be
       running under gnome-session manager at all! */
    priv->gnome_session_proxy = dbus_g_proxy_new_for_name_owner(
                                    priv->dbus_conn,
                                    "org.gnome.SessionManager",
                                    "/org/gnome/SessionManager",
                                    "org.gnome.SessionManager",
                                    &error);
    if (error) {
        g_debug("Could not create org.gnome.SessionManager dbus proxy: %s",
                error->message);
        g_clear_error(&error);
        return FALSE;
    }

    return TRUE;
}
static gboolean
create_rb_shell_proxies (DBusGConnection *bus, DBusGProxy **shell_proxy, DBusGProxy **player_proxy, GError **error)
{
	DBusGProxy *sp;

	rb_debug ("creating shell proxy");
	sp = dbus_g_proxy_new_for_name_owner (bus,
					      "org.gnome.Rhythmbox",
					      "/org/gnome/Rhythmbox/Shell",
					      "org.gnome.Rhythmbox.Shell",
					      error);
	if (*error) {
		*shell_proxy = NULL;
		return ((*error)->code == DBUS_GERROR_NAME_HAS_NO_OWNER);
	}

	rb_debug ("creating player proxy");
	*player_proxy = dbus_g_proxy_new_from_proxy (sp,
						     "org.gnome.Rhythmbox.Player",
						     "/org/gnome/Rhythmbox/Player");
	if (*player_proxy == NULL) {
		g_object_unref (G_OBJECT (sp));
		*shell_proxy = NULL;
		*player_proxy = NULL;
		return FALSE;
	}

	*shell_proxy = sp;
	return TRUE;
}
/**
 * gpm_inhibit_applet_dbus_connect:
 **/
gboolean
gpm_inhibit_applet_dbus_connect (GpmInhibitApplet *applet)
{
	GError *error = NULL;

	if (applet->connection == NULL) {
		egg_debug ("get connection\n");
		g_clear_error (&error);
		applet->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
		if (error != NULL) {
			egg_warning ("Could not connect to DBUS daemon: %s", error->message);
			g_error_free (error);
			applet->connection = NULL;
			return FALSE;
		}
	}
	if (applet->proxy == NULL) {
		egg_debug ("get proxy\n");
		g_clear_error (&error);
		applet->proxy = dbus_g_proxy_new_for_name_owner (applet->connection,
							 GS_DBUS_SERVICE,
							 GS_DBUS_PATH,
							 GS_DBUS_INTERFACE,
							 &error);
		if (error != NULL) {
			egg_warning ("Cannot connect, maybe the daemon is not running: %s\n", error->message);
			g_error_free (error);
			applet->proxy = NULL;
			return FALSE;
		}
	}
	return TRUE;
}
Esempio n. 9
0
static gboolean
ol_player_listen_init_dbus ()
{
  /* ol_log_func (); */
  if (connection == NULL)
  {
    connection = dbus_g_bus_get (DBUS_BUS_SESSION,
                               &error);
    if (connection == NULL)
    {
      ol_debugf ("get connection failed: %s\n", error->message);
      g_error_free(error);
      error = NULL;
      return FALSE;
    }
    if (proxy != NULL)
      g_object_unref (proxy);
    proxy = NULL;
  }
  if (proxy == NULL)
  {
    proxy = dbus_g_proxy_new_for_name_owner (connection, service, path, interface, &error);
    if (proxy == NULL)
    {
      ol_debugf ("get proxy failed: %s\n", error->message);
      g_error_free (error);
      error = NULL;
      return FALSE;
    }
  }
  return TRUE;
}
Esempio n. 10
0
bool zemberek_service_is_running ()
{
  DBusGConnection *connection;
  DBusGProxy *proxy;

  GError *Error = NULL;
  g_type_init ();

  connection = dbus_g_bus_get (DBUS_BUS_SYSTEM,
                               &Error);
  if (connection == NULL) {
      g_error_free (Error);
      return false;
  }
  proxy = dbus_g_proxy_new_for_name_owner (connection,
                                     "net.zemberekserver.server.dbus",
                                     "/net/zemberekserver/server/dbus/ZemberekDbus",
                                     "net.zemberekserver.server.dbus.ZemberekDbusInterface",
                                     &Error);

  dbus_g_connection_unref (connection);
  if (proxy == NULL) {
    return false;
  }

   g_object_unref (proxy);
   return true;
}
Esempio n. 11
0
/**
 * gpm_phone_service_appeared_cb:
 */
static void
gpm_phone_service_appeared_cb (GDBusConnection *connection,
                               const gchar *name, const gchar *name_owner,
                               GpmPhone *phone)
{
    GError *error = NULL;

    g_return_if_fail (GPM_IS_PHONE (phone));

    if (phone->priv->connection == NULL) {
        egg_debug ("get connection");
        g_clear_error (&error);
        phone->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
        if (error != NULL) {
            egg_warning ("Could not connect to DBUS daemon: %s", error->message);
            g_error_free (error);
            phone->priv->connection = NULL;
            return;
        }
    }
    if (phone->priv->proxy == NULL) {
        egg_debug ("get proxy");
        g_clear_error (&error);
        phone->priv->proxy = dbus_g_proxy_new_for_name_owner (phone->priv->connection,
                             MATE_PHONE_MANAGER_DBUS_SERVICE,
                             MATE_PHONE_MANAGER_DBUS_PATH,
                             MATE_PHONE_MANAGER_DBUS_INTERFACE,
                             &error);
        if (error != NULL) {
            egg_warning ("Cannot connect, maybe the daemon is not running: %s", error->message);
            g_error_free (error);
            phone->priv->proxy = NULL;
            return;
        }

        /* complicated type. ick */
        dbus_g_object_register_marshaller(gpm_marshal_VOID__UINT_UINT_BOOLEAN,
                                          G_TYPE_NONE, G_TYPE_UINT, G_TYPE_UINT,
                                          G_TYPE_BOOLEAN, G_TYPE_INVALID);

        /* get BatteryStateChanged */
        dbus_g_proxy_add_signal (phone->priv->proxy, "BatteryStateChanged",
                                 G_TYPE_UINT, G_TYPE_UINT, G_TYPE_BOOLEAN, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal (phone->priv->proxy, "BatteryStateChanged",
                                     G_CALLBACK (gpm_phone_battery_state_changed),
                                     phone, NULL);

        /* get NumberBatteriesChanged */
        dbus_g_proxy_add_signal (phone->priv->proxy, "NumberBatteriesChanged",
                                 G_TYPE_UINT, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal (phone->priv->proxy, "NumberBatteriesChanged",
                                     G_CALLBACK (gpm_phone_num_batteries_changed),
                                     phone, NULL);

    }
}
Esempio n. 12
0
/**
 * gpm_session_register_client:
 **/
gboolean
gpm_session_register_client (GpmSession *session, const gchar *app_id, const gchar *client_startup_id)
{
	gboolean ret = FALSE;
	gchar *client_id = NULL;
	GError *error = NULL;
	DBusGConnection *connection;

	g_return_val_if_fail (GPM_IS_SESSION (session), FALSE);

	/* no mate-session */
	if (session->priv->proxy == NULL) {
		egg_warning ("no mate-session");
		goto out;
	}

	/* find out if this change altered the inhibited state */
	ret = dbus_g_proxy_call (session->priv->proxy, "RegisterClient", &error,
				 G_TYPE_STRING, app_id,
				 G_TYPE_STRING, client_startup_id,
				 G_TYPE_INVALID,
				 DBUS_TYPE_G_OBJECT_PATH, &client_id,
				 G_TYPE_INVALID);
	if (!ret) {
		egg_warning ("failed to register client '%s': %s", client_startup_id, error->message);
		g_error_free (error);
		goto out;
	}

	/* get org.mate.Session.ClientPrivate interface */
	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
	session->priv->proxy_client_private = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE,
									       client_id, GPM_SESSION_MANAGER_CLIENT_PRIVATE_INTERFACE, &error);
	if (session->priv->proxy_client_private == NULL) {
		egg_warning ("DBUS error: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* get Stop */
	dbus_g_proxy_add_signal (session->priv->proxy_client_private, "Stop", G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy_client_private, "Stop", G_CALLBACK (gpm_session_stop_cb), session, NULL);

	/* get QueryEndSession */
	dbus_g_proxy_add_signal (session->priv->proxy_client_private, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy_client_private, "QueryEndSession", G_CALLBACK (gpm_session_query_end_session_cb), session, NULL);

	/* get EndSession */
	dbus_g_proxy_add_signal (session->priv->proxy_client_private, "EndSession", G_TYPE_UINT, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy_client_private, "EndSession", G_CALLBACK (gpm_session_end_session_cb), session, NULL);

	egg_debug ("registered startup '%s' to client id '%s'", client_startup_id, client_id);
out:
	g_free (client_id);
	return ret;
}
Esempio n. 13
0
static gboolean
gsm_util_update_activation_environment (const char  *variable,
                                        const char  *value,
                                        GError     **error)
{
        DBusGConnection *dbus_connection;
        DBusGProxy      *bus_proxy;
        GHashTable      *environment;
        gboolean         environment_updated;

        environment_updated = FALSE;
        bus_proxy = NULL;
        environment = NULL;

        dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);

        if (dbus_connection == NULL) {
                return FALSE;
        }

        bus_proxy = dbus_g_proxy_new_for_name_owner (dbus_connection,
                                                     DBUS_SERVICE_DBUS,
                                                     DBUS_PATH_DBUS,
                                                     DBUS_INTERFACE_DBUS,
                                                     error);

        if (bus_proxy == NULL) {
                goto out;
        }

        environment = g_hash_table_new (g_str_hash, g_str_equal);

        g_hash_table_insert (environment, (void *) variable, (void *) value);

        if (!dbus_g_proxy_call (bus_proxy,
                                "UpdateActivationEnvironment", error,
                                DBUS_TYPE_G_STRING_STRING_HASHTABLE,
                                environment, G_TYPE_INVALID,
                                G_TYPE_INVALID))
                goto out;

        environment_updated = TRUE;

 out:

        if (bus_proxy != NULL) {
                g_object_unref (bus_proxy);
        }

        if (environment != NULL) {
                g_hash_table_destroy (environment);
        }

        return environment_updated;
}
Esempio n. 14
0
/**
 * gpk_dbus_init:
 * @dbus: This class instance
 **/
static void
gpk_dbus_init (GpkDbus *dbus)
{
	DBusGConnection *connection;

	dbus->priv = GPK_DBUS_GET_PRIVATE (dbus);
	dbus->priv->timeout_tmp = -1;
	dbus->priv->settings = g_settings_new (GPK_SETTINGS_SCHEMA);
	dbus->priv->x11 = gpk_x11_new ();
	dbus->priv->timer = g_timer_new ();

	/* find out PIDs on the session bus */
	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
	dbus->priv->proxy_session_pid = dbus_g_proxy_new_for_name_owner (connection,
								 "org.freedesktop.DBus",
								 "/org/freedesktop/DBus/Bus",
								 "org.freedesktop.DBus", NULL);
	/* find out PIDs on the system bus */
	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
	dbus->priv->proxy_system_pid = dbus_g_proxy_new_for_name_owner (connection,
								 "org.freedesktop.DBus",
								 "/org/freedesktop/DBus/Bus",
								 "org.freedesktop.DBus", NULL);
}
Esempio n. 15
0
static DBusGProxy *
panel_dbus_client_get_proxy (GError **error)
{
    DBusGConnection *dbus_connection;

    /* return null if no connection is found */
    dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
    if (G_UNLIKELY (dbus_connection == NULL))
        return NULL;

    return dbus_g_proxy_new_for_name_owner (dbus_connection,
                                            PANEL_DBUS_NAME,
                                            PANEL_DBUS_PATH,
                                            PANEL_DBUS_INTERFACE,
                                            error);
}
Esempio n. 16
0
void FcitxIMClientCreateIC(FcitxIMClient* client)
{
    GError* error = NULL;

    client->proxy = dbus_g_proxy_new_for_name_owner(client->conn,
                    client->servicename,
                    FCITX_IM_DBUS_PATH,
                    FCITX_IM_DBUS_INTERFACE,
                    &error);

    if (!client->proxy)
        return;

    g_signal_connect(client->proxy, "destroy", G_CALLBACK( _destroy_cb), client);

    dbus_g_proxy_begin_call(client->proxy, "CreateIC", FcitxIMClientCreateICCallback, client, NULL, G_TYPE_INVALID);
}
Esempio n. 17
0
static gboolean
skype_connect()
{
    GError *error = NULL;
    DBusObjectPathVTable vtable;

    //Initialise threading
    dbus_threads_init_default();

    if (connection == NULL)
    {
        connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
        if (connection == NULL && error != NULL)
        {
            skype_debug_info("skype_dbus", "Error: %s\n", error->message);
            g_error_free(error);
            return FALSE;
        }
    }

    if (proxy == NULL)
    {
        proxy = dbus_g_proxy_new_for_name_owner (connection,
                "com.Skype.API",
                "/com/Skype",
                "com.Skype.API",
                &error);
        if (proxy == NULL && error != NULL)
        {
            skype_debug_warning("skype_dbus", "%s\n", error->message);
            g_error_free(error);
            return FALSE;
        }

        g_signal_connect(G_OBJECT(proxy), "destroy", G_CALLBACK(skype_destroy_handler), NULL);
#ifdef DBUS_MAJOR_VERSION
        dbus_g_proxy_set_default_timeout(proxy, 3000);
#endif
        vtable.message_function = &skype_notify_handler;
        dbus_connection_register_object_path(dbus_g_connection_get_connection(connection), "/com/Skype/Client", &vtable, NULL);
    }

    return TRUE;
}
Esempio n. 18
0
gboolean
_mojito_client_service_setup_proxy_for_iface (MojitoClientService  *service,
                                              const gchar          *service_name,
                                              MojitoServiceIface    iface,
                                              GError              **error_out)
{
  MojitoClientServicePrivate *priv = GET_PRIVATE (service);
  GError *error = NULL;
  gchar *path;

  if (priv->proxies[iface])
    return TRUE;

  priv->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);

  if (!priv->connection)
  {
    g_critical (G_STRLOC ": Error getting DBUS connection: %s",
                error->message);
    g_propagate_error (error_out, error);
    return FALSE;
  }

  priv->name = g_strdup (service_name);

  path = g_strdup_printf (MOJITO_CLIENT_SERVICE_OBJECT, service_name);
  priv->proxies[iface] = dbus_g_proxy_new_for_name_owner (priv->connection,
                                                          MOJITO_CLIENT_SERVICE_NAME,
                                                          path,
                                                          interface_names[iface],
                                                          &error);
  g_free (path);

  if (!priv->proxies[iface])
  {
    g_critical (G_STRLOC ": Error setting up proxy for remote object: %s",
                error->message);
    g_propagate_error (error_out, error);
    return FALSE;
  }

  return TRUE;
}
Esempio n. 19
0
static gboolean
acquire_name (void)
{
        GError          *error;
        DBusGConnection *connection;

        error = NULL;
        connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
        if (connection == NULL) {
                csm_util_init_error (TRUE,
                                     "Could not connect to session bus: %s",
                                     error->message);
                return FALSE;
        }

        bus_proxy = dbus_g_proxy_new_for_name_owner (connection,
                                                     DBUS_SERVICE_DBUS,
                                                     DBUS_PATH_DBUS,
                                                     DBUS_INTERFACE_DBUS,
                                                     &error);
        if (error != NULL) {
                csm_util_init_error (TRUE,
                                     "Could not connect to session bus: %s",
                                     error->message);
                return FALSE;
        }

        g_signal_connect_swapped (bus_proxy,
                                  "destroy",
                                  G_CALLBACK (shutdown_cb),
                                  NULL);

        if (! acquire_name_on_proxy (bus_proxy, CSM_DBUS_NAME) ) {
                csm_util_init_error (TRUE,
                                     "%s",
                                     "Could not acquire name on session bus");
                return FALSE;
        }

        return TRUE;
}
Esempio n. 20
0
gboolean
ol_dbus_connect (const gchar *service,
                 const gchar *path,
                 const gchar *interface,
                 GCallback disconnect_handler,
                 gpointer disconnect_data,
                 DBusGProxy **proxy)
{
  ol_log_func ();
  GError *error = NULL;
  ol_assert_ret (proxy != NULL, FALSE);
  ol_assert_ret (service != NULL, FALSE);
  ol_assert_ret (path != NULL, FALSE);
  ol_assert_ret (interface != NULL, FALSE);
  DBusGConnection *connection = ol_dbus_get_connection ();
  if (connection == NULL)
    return FALSE;
  *proxy = dbus_g_proxy_new_for_name_owner (connection, service, path, interface, &error);
  if (*proxy == NULL)
  {
    ol_debugf ("get proxy failed: %s\n", error->message);
    g_error_free (error);
    error = NULL;
    return FALSE;
  }
  if (disconnect_handler != NULL)
  {
    if (disconnect_data == NULL)
      disconnect_data = (gpointer) proxy;
    g_signal_connect (*proxy,
                      "destroy",
                      G_CALLBACK (disconnect_handler),
                      disconnect_data);
  }
  return TRUE;
}
static gboolean
impl_activate (TotemPlugin *plugin,
	       TotemObject *totem,
	       GError **error)
{
	TotemMediaPlayerKeysPlugin *pi = TOTEM_MEDIA_PLAYER_KEYS_PLUGIN (plugin);
	DBusGConnection *connection;
	GError *err = NULL;
	GtkWindow *window;

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
	if (connection == NULL) {
		g_warning ("Error connecting to D-Bus: %s", err->message);
		return FALSE;
	}

	/* Try the mate-settings-daemon version,
	 * then the mate-control-center version of things */
	pi->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
								       "org.mate.SettingsDaemon",
								       "/org/mate/SettingsDaemon/MediaKeys",
								       "org.mate.SettingsDaemon.MediaKeys",
								       NULL);
	if (pi->media_player_keys_proxy == NULL) {
		pi->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
									       "org.mate.SettingsDaemon",
									       "/org/mate/SettingsDaemon",
									       "org.mate.SettingsDaemon",
									       &err);
	}

	dbus_g_connection_unref (connection);
	if (err != NULL) {
		gboolean daemon_not_running;
		g_warning ("Failed to create dbus proxy for org.mate.SettingsDaemon: %s",
			   err->message);
		daemon_not_running = (err->code == DBUS_GERROR_NAME_HAS_NO_OWNER);
		g_error_free (err);
		/* don't popup error if settings-daemon is not running,
 		 * ie when starting totem not under MATE desktop */
		return daemon_not_running;
	} else {
		g_signal_connect_object (pi->media_player_keys_proxy,
					 "destroy",
					 G_CALLBACK (proxy_destroy),
					 pi, 0);
	}

	dbus_g_proxy_call (pi->media_player_keys_proxy,
			   "GrabMediaPlayerKeys", NULL,
			   G_TYPE_STRING, "Totem", G_TYPE_UINT, 0, G_TYPE_INVALID,
			   G_TYPE_INVALID);

	dbus_g_object_register_marshaller (totem_marshal_VOID__STRING_STRING,
			G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_add_signal (pi->media_player_keys_proxy, "MediaPlayerKeyPressed",
			G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (pi->media_player_keys_proxy, "MediaPlayerKeyPressed",
			G_CALLBACK (on_media_player_key_pressed), totem, NULL);

	window = totem_get_main_window (totem);
	pi->handler_id = g_signal_connect (G_OBJECT (window), "focus-in-event",
			G_CALLBACK (on_window_focus_in_event), pi);

	g_object_unref (G_OBJECT (window));

	return TRUE;
}
Esempio n. 22
0
int main (int argc, char **argv)
{
	GMainLoop *loop = 0;
	DBusGConnection *conn = 0;
	DBusConnection *conn2 = 0;
	GError *error = 0;
	DBusError error2;
	DBusGProxy *proxy;
	DBusGProxy *proxy2;

	print_header();
		
	g_type_init ();
	
	loop = g_main_loop_new (0, FALSE);

	conn = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
	if (conn == 0) {
		g_error("%s", error->message);
		g_error_free(error);
		exit(1);
	}
	
	proxy = dbus_g_proxy_new_for_name_owner(conn,
		DBUS_SERVICE_NAME, DBUS_RECOGNIZER_PATH, DBUS_RECOGNIZER_NAME,
		&error);
	
	if (proxy == 0) {
		g_error("%s", error->message);
		g_error_free(error);
		exit(2);
	}
	
//	proxy2 = dbus_g_proxy_new_for_name_owner(conn,
//		DBUS_OPHONED_NAME, DBUS_GSM_DEVICE_PATH, DBUS_GSM_DEVICE_CALL_NAME, &error);

//	if (proxy2 == 0) {
//		g_error("%s", error->message);
//		g_error_free(error);
//		exit(3);
//	}

	if (!org_openmoko_accelges_Recognizer_listen (proxy, TRUE, &error)) {
		g_error("%s", error->message);
		g_error_free(error);
		exit(3);
	}

	/* Add the signal to the proxy */
	dbus_g_proxy_add_signal(proxy, "Recognized", 
		G_TYPE_STRING,  G_TYPE_INVALID);
	
	/* Connect the signal handler to the proxy */
	dbus_g_proxy_connect_signal(proxy, "Recognized",
		G_CALLBACK(recognized_cb), conn, 0);
	
//	dbus_g_proxy_add_signal(proxy2, "CallStatus",
//		G_TYPE_INT, G_TYPE_STRING, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), G_TYPE_INVALID);

//	dbus_g_proxy_connect_signal(proxy2, "CallStatus",
//		G_CALLBACK(call_status_cb), conn, 0);
	
	/*
	dbus_error_init(&error2);
	conn2 = dbus_bus_get(DBUS_BUS_SYSTEM, &error2);
	if (!conn2)
	{
		g_warning ("Failed to connect to the D-BUS daemon: %s", error2.message);
		dbus_error_free (&error2);
	}
	dbus_connection_setup_with_g_main (conn2, NULL);
	*/
	/* listening to messages from all objects as no path is specified */
	/*
	dbus_bus_add_match (conn2, "type='signal', interface='" DBUS_GSM_CALL_NAME "'", &error2);
	dbus_connection_add_filter (conn2, signal_filter, loop, 0);
	*/

	g_print("Listening for signals on: '%s'\n", DBUS_SERVICE_NAME);
	
	g_main_loop_run(loop);
	
	return 0;
}
Esempio n. 23
0
static gboolean
gsm_consolekit_ensure_ck_connection (GsmConsolekit  *manager,
                                     GError        **error)
{
        GError  *connection_error;
        gboolean is_connected;

        connection_error = NULL;

        if (manager->priv->dbus_connection == NULL) {
                DBusConnection *connection;

                manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM,
                                                                 &connection_error);

                if (manager->priv->dbus_connection == NULL) {
                        g_propagate_error (error, connection_error);
                        is_connected = FALSE;
                        goto out;
                }

                connection = dbus_g_connection_get_connection (manager->priv->dbus_connection);
                dbus_connection_set_exit_on_disconnect (connection, FALSE);
                dbus_connection_add_filter (connection,
                                            gsm_consolekit_dbus_filter,
                                            manager, NULL);
        }

        if (manager->priv->bus_proxy == NULL) {
                manager->priv->bus_proxy =
                        dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection,
                                                         DBUS_SERVICE_DBUS,
                                                         DBUS_PATH_DBUS,
                                                         DBUS_INTERFACE_DBUS,
                                                         &connection_error);

                if (manager->priv->bus_proxy == NULL) {
                        g_propagate_error (error, connection_error);
                        is_connected = FALSE;
                        goto out;
                }

                dbus_g_proxy_add_signal (manager->priv->bus_proxy,
                                         "NameOwnerChanged",
                                         G_TYPE_STRING,
                                         G_TYPE_STRING,
                                         G_TYPE_STRING,
                                         G_TYPE_INVALID);

                dbus_g_proxy_connect_signal (manager->priv->bus_proxy,
                                             "NameOwnerChanged",
                                             G_CALLBACK (gsm_consolekit_on_name_owner_changed),
                                             manager, NULL);
        }

        if (manager->priv->ck_proxy == NULL) {
                manager->priv->ck_proxy =
                        dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection,
                                                         "org.freedesktop.ConsoleKit",
                                                         "/org/freedesktop/ConsoleKit/Manager",
                                                         "org.freedesktop.ConsoleKit.Manager",
                                                         &connection_error);

                if (manager->priv->ck_proxy == NULL) {
                        g_propagate_error (error, connection_error);
                        is_connected = FALSE;
                        goto out;
                }
        }

        is_connected = TRUE;

 out:
        if (manager->priv->is_connected != is_connected) {
                manager->priv->is_connected = is_connected;
                g_object_notify (G_OBJECT (manager), "is-connected");
        }

        if (!is_connected) {
                if (manager->priv->dbus_connection == NULL) {
                        if (manager->priv->bus_proxy != NULL) {
                                g_object_unref (manager->priv->bus_proxy);
                                manager->priv->bus_proxy = NULL;
                        }

                        if (manager->priv->ck_proxy != NULL) {
                                g_object_unref (manager->priv->ck_proxy);
                                manager->priv->ck_proxy = NULL;
                        }
                } else if (manager->priv->bus_proxy == NULL) {
                        if (manager->priv->ck_proxy != NULL) {
                                g_object_unref (manager->priv->ck_proxy);
                                manager->priv->ck_proxy = NULL;
                        }
                }
        }

        return is_connected;
}
static void
mnb_panel_oop_init_panel_oop_reply_cb (DBusGProxy *proxy,
                                       gchar      *name,
                                       guint       xid,
                                       gchar      *tooltip,
                                       gchar      *stylesheet,
                                       gchar      *button_style_id,
                                       guint       window_width,
                                       guint       window_height,
                                       GError     *error,
                                       gpointer    panel)
{
  MnbPanelOopPrivate *priv = MNB_PANEL_OOP (panel)->priv;

  if (error)
    {
      g_warning ("Could not initialize Panel %s: %s",
                 mnb_panel_oop_get_name ((MnbPanel*)panel), error->message);
      g_object_unref (panel);
      return;
    }

  priv->proxy_for_owner =
    dbus_g_proxy_new_for_name_owner (priv->dbus_conn,
                                     priv->dbus_name,
                                     priv->dbus_path,
                                     MPL_PANEL_DBUS_INTERFACE,
                                     &error);

  if (error)
    {
      g_warning ("Could not create owner-specif proxy for %s: %s",
                 priv->dbus_name, error->message);
      g_clear_error (&error);
    }
  else
    {
      g_object_weak_ref (G_OBJECT (priv->proxy_for_owner),
                         mnb_panel_oop_dbus_proxy_weak_notify_cb, panel);
    }

  /*
   * We duplicate the return values, because we need to be able to replace them
   * and using the originals we would need to use dbus_malloc() later on
   * to set them afresh.
   */
  g_free (priv->name);
  priv->name = g_strdup (name);

  g_free (priv->tooltip);
  priv->tooltip = g_strdup (tooltip);

  g_free (priv->stylesheet);
  priv->stylesheet = g_strdup (stylesheet);

  g_free (priv->button_style_id);
  priv->button_style_id = g_strdup (button_style_id);

  priv->xid = xid;

  g_free (priv->child_class);

  /*
   * Retrieve the WM_CLASS property for the child window (we have to do it the
   * hard way, because the WM_CLASS on the MetaWindowActor is coming from mutter,
   * not the application).
   *
   * (We use the wm-class to identify sub-windows.)
   */
  if (xid)
    {
      Atom r_type;
      int  r_fmt;
      unsigned long n_items;
      unsigned long r_after;
      char *r_prop;
      MetaPlugin *plugin = meego_netbook_get_plugin_singleton ();
      MetaDisplay *display;

      display = meta_screen_get_display (meta_plugin_get_screen (plugin));

      meta_error_trap_push (display);

      if (Success == XGetWindowProperty (gdk_x11_display_get_xdisplay(gdk_display_get_default ()), xid, XA_WM_CLASS,
                                         0, 8192,
                                         False, XA_STRING,
                                         &r_type, &r_fmt, &n_items, &r_after,
                                         (unsigned char **)&r_prop) &&
          r_type != 0)
        {
          if (r_prop)
            {
              /*
               * The property contains two strings separated by \0; we want the
               * second string.
               */
              gint len0 = strlen (r_prop);

              if (len0 == n_items)
                len0--;

              priv->child_class = g_strdup (r_prop + len0 + 1);

              XFree (r_prop);
            }
        }

      meta_error_trap_pop (display);
    }

  priv->dead = FALSE;
  priv->initialized = TRUE;

  if (priv->ready)
    g_signal_emit (panel, signals[READY], 0);

  dbus_free (name);
  dbus_free (tooltip);
  dbus_free (stylesheet);
  dbus_free (button_style_id);
}
Esempio n. 25
0
static DBusGProxy *dbus_connect (MoonshotError **error)
{
    DBusConnection  *dbconnection;
    DBusError        dbus_error;
    DBusGConnection *connection;
    DBusGProxy      *g_proxy;
    GError          *g_error = NULL;
    dbus_bool_t      name_has_owner;

    g_return_val_if_fail (*error == NULL, NULL);

    dbus_error_init (&dbus_error);

    /* Check for moonshot server and start the service if possible. We use
     * libdbus here because dbus-glib doesn't handle autostarting the service.
     * If/when we move to GDBus this code can become a one-liner.
     */

    if (is_setid()) {
        *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
	                             "Cannot use IPC while setid");
        return NULL;
    }
#ifdef IPC_DBUS_GLIB
    if (getenv("DISPLAY")==NULL) {
        connection = dbus_launch_moonshot();
        if (connection == NULL) {
            *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
                                         "Headless dbus launch failed");
            return NULL;
        }
    } else
#endif
    {
        connection = dbus_g_bus_get (DBUS_BUS_SESSION, &g_error);

        if (g_error_matches(g_error, DBUS_GERROR, DBUS_GERROR_NOT_SUPPORTED)) {
            /*Generally this means autolaunch failed because probably DISPLAY is unset*/
            connection = dbus_launch_moonshot();
            if (connection != NULL) {
                g_error_free(g_error);
                g_error = NULL;
            }
        }
        if (g_error != NULL) {
            *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
                                         "DBus error: %s",
                                         g_error->message);
            g_error_free (g_error);
            return NULL;
        }
    }


    dbconnection = dbus_g_connection_get_connection(connection);
    name_has_owner  = dbus_bus_name_has_owner (dbconnection,
                                               MOONSHOT_DBUS_NAME,
                                               &dbus_error);

    if (dbus_error_is_set (&dbus_error)) {
        *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
                                     "DBus error: %s",
                                     dbus_error.message);
        dbus_error_free (&dbus_error);
        return NULL;
    }

    if (! name_has_owner) {
        dbus_bus_start_service_by_name (dbconnection,
                                        MOONSHOT_DBUS_NAME,
                                        0,
                                        NULL,
                                        &dbus_error);

        if (dbus_error_is_set (&dbus_error)) {
            if (strcmp (dbus_error.name + 27, "ServiceUnknown") == 0) {
                /* Missing .service file; the moonshot-ui install is broken */
                *error = moonshot_error_new (MOONSHOT_ERROR_UNABLE_TO_START_SERVICE,
                                             "The Moonshot service was not found. "
                                             "Please make sure that moonshot-ui is "
                                             "correctly installed.");
            } else {
                *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
                                             "DBus error: %s",
                                             dbus_error.message);
            }
            dbus_error_free (&dbus_error);
            return NULL;
        }
    }

    /* Now the service should be running */
    g_error = NULL;

    g_proxy = dbus_g_proxy_new_for_name_owner (connection,
                                               MOONSHOT_DBUS_NAME,
                                               MOONSHOT_DBUS_PATH,
                                               MOONSHOT_DBUS_NAME,
                                               &g_error);

    if (g_error != NULL) {
        *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
                                     "DBus error: %s",
                                     g_error->message);
        g_error_free (g_error);
        return NULL;
    }

    return g_proxy; 
}
Esempio n. 26
0
void FcitxIMClientCreateICCallback(DBusGProxy *proxy,
                                   DBusGProxyCall *call_id,
                                   gpointer user_data)
{
    FcitxIMClient* client = (FcitxIMClient*) user_data;
    GError *error = NULL;

    guint arg1, arg2, arg3, arg4;
    int id = -1;
    dbus_g_proxy_end_call(proxy, call_id, &error,
                          G_TYPE_INT, &id,
                          G_TYPE_UINT, &arg1,
                          G_TYPE_UINT, &arg2,
                          G_TYPE_UINT, &arg3,
                          G_TYPE_UINT, &arg4,
                          G_TYPE_INVALID
                         );
    client->triggerkey[0].sym = arg1;
    client->triggerkey[0].state = arg2;
    client->triggerkey[1].sym = arg3;
    client->triggerkey[1].state = arg4;

    if (id >= 0)
        client->id = id;
    else
        return;

    sprintf(client->icname, FCITX_IC_DBUS_PATH, client->id);

    client->icproxy = dbus_g_proxy_new_for_name_owner(client->conn,
                      client->servicename,
                      client->icname,
                      FCITX_IC_DBUS_INTERFACE,
                      &error
                    );
    if (!client->icproxy)
        return;

    dbus_g_proxy_add_signal(client->icproxy, "EnableIM", G_TYPE_INVALID);
    dbus_g_proxy_add_signal(client->icproxy, "CloseIM", G_TYPE_INVALID);
    dbus_g_proxy_add_signal(client->icproxy, "CommitString", G_TYPE_STRING, G_TYPE_INVALID);

    dbus_g_object_register_marshaller(fcitx_marshall_VOID__STRING_STRING_STRING_STRING_STRING_INT,
                                      G_TYPE_NONE,
                                      G_TYPE_STRING,
                                      G_TYPE_STRING,
                                      G_TYPE_STRING,
                                      G_TYPE_STRING,
                                      G_TYPE_STRING,
                                      G_TYPE_INT,
                                      G_TYPE_INVALID);

    dbus_g_proxy_add_signal(client->icproxy, "UpdateClientSideUI",
                            G_TYPE_STRING,
                            G_TYPE_STRING,
                            G_TYPE_STRING,
                            G_TYPE_STRING,
                            G_TYPE_STRING,
                            G_TYPE_INT,
                            G_TYPE_INVALID);

    dbus_g_object_register_marshaller(fcitx_marshall_VOID__UINT_UINT_INT, G_TYPE_NONE, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);

    dbus_g_proxy_add_signal(client->icproxy, "ForwardKey", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
    client->connectcb(client, client->data);
}
static void
sw_client_item_view_constructed (GObject *object)
{
  SwClientItemViewPrivate *priv = GET_PRIVATE (object);
  GError *error = NULL;
  DBusConnection *conn;

  priv->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);

  if (!priv->connection)
  {
    g_critical (G_STRLOC ": Error getting DBUS connection: %s",
                error->message);
    g_clear_error (&error);
    return;
  }

  conn = dbus_g_connection_get_connection (priv->connection);

  priv->proxy = dbus_g_proxy_new_for_name_owner (priv->connection,
                                                 SW_SERVICE_NAME,
                                                 priv->object_path,
                                                 SW_SERVICE_ITEM_VIEW_INTERFACE,
                                                 &error);

  if (!priv->proxy)
  {
    g_critical (G_STRLOC ": Error setting up proxy for remote object: %s",
                error->message);
    g_clear_error (&error);
    return;
  }

  dbus_g_proxy_add_signal (priv->proxy,
                           "ItemsAdded",
                           _sw_items_get_container_type (),
                           NULL);
  dbus_g_proxy_connect_signal (priv->proxy,
                               "ItemsAdded",
                               (GCallback)_proxy_items_added_cb,
                               object,
                               NULL);

  dbus_g_proxy_add_signal (priv->proxy,
                           "ItemsChanged",
                           _sw_items_get_container_type (),
                           NULL);
  dbus_g_proxy_connect_signal (priv->proxy,
                               "ItemsChanged",
                               (GCallback)_proxy_items_changed_cb,
                               object,
                               NULL);

  dbus_g_proxy_add_signal (priv->proxy,
                           "ItemsRemoved",
                           _sw_items_removed_get_container_type (),
                           NULL);
  dbus_g_proxy_connect_signal (priv->proxy,
                               "ItemsRemoved",
                               (GCallback)_proxy_items_removed_cb,
                               object,
                               NULL);
}
static gboolean
panel_power_manager_ensure_gpm_connection (PanelPowerManager  *manager,
					   GError            **error)
{
	GError   *connection_error;
	gboolean  is_connected;

	connection_error = NULL;
	if (manager->priv->dbus_connection == NULL) {
		manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION,
								 &connection_error);

		if (manager->priv->dbus_connection == NULL) {
			g_propagate_error (error, connection_error);
			is_connected = FALSE;
			goto out;
		}
	}

	if (manager->priv->bus_proxy == NULL) {
		manager->priv->bus_proxy =
			dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection,
							 DBUS_SERVICE_DBUS,
							 DBUS_PATH_DBUS,
							 DBUS_INTERFACE_DBUS,
							 &connection_error);

		if (manager->priv->bus_proxy == NULL) {
			g_propagate_error (error, connection_error);
			is_connected = FALSE;
			goto out;
		}

		dbus_g_proxy_add_signal (manager->priv->bus_proxy,
					 "NameOwnerChanged",
					 G_TYPE_STRING,
					 G_TYPE_STRING,
					 G_TYPE_STRING,
					 G_TYPE_INVALID);
		dbus_g_proxy_connect_signal (manager->priv->bus_proxy,
					     "NameOwnerChanged",
					     G_CALLBACK (panel_power_manager_on_name_owner_changed),
					     manager, NULL);
	}

	if (manager->priv->gpm_proxy == NULL) {
		manager->priv->gpm_proxy =
			dbus_g_proxy_new_for_name_owner (
					manager->priv->dbus_connection,
					"org.gnome.PowerManager",
					"/org/gnome/PowerManager",
					"org.gnome.PowerManager",
					&connection_error);

		if (manager->priv->gpm_proxy == NULL) {
			g_propagate_error (error, connection_error);
			is_connected = FALSE;
			goto out;
		}
	}
	is_connected = TRUE;

out:
	if (manager->priv->is_connected != is_connected) {
		manager->priv->is_connected = is_connected;
		g_object_notify (G_OBJECT (manager), "is-connected");
	}

	if (!is_connected) {
		if (manager->priv->dbus_connection == NULL) {
			if (manager->priv->bus_proxy != NULL) {
				g_object_unref (manager->priv->bus_proxy);
				manager->priv->bus_proxy = NULL;
			}

			if (manager->priv->gpm_proxy != NULL) {
				g_object_unref (manager->priv->gpm_proxy);
				manager->priv->gpm_proxy = NULL;
			}
		} else if (manager->priv->bus_proxy == NULL) {
			if (manager->priv->gpm_proxy != NULL) {
				g_object_unref (manager->priv->gpm_proxy);
				manager->priv->gpm_proxy = NULL;
			}
		}
	}

	return is_connected;
}
Esempio n. 29
0
int
main (int argc, char **argv)
{
	DBusGConnection *session_bus;
	GError *error = NULL;
	RBShell *rb_shell;
	gboolean activated;
	gboolean autostarted;
	char *accel_map_file = NULL;
	char *desktop_file_path;

	GOptionContext *context;
	static const GOptionEntry options []  = {
		{ "debug",           'd', 0, G_OPTION_ARG_NONE,         &debug,           N_("Enable debug output"), NULL },
		{ "debug-match",     'D', 0, G_OPTION_ARG_STRING,       &debug_match,     N_("Enable debug output matching a specified string"), NULL },
		{ "no-update",	       0, 0, G_OPTION_ARG_NONE,         &no_update,       N_("Do not update the library with file changes"), NULL },
		{ "no-registration", 'n', 0, G_OPTION_ARG_NONE,         &no_registration, N_("Do not register the shell"), NULL },
		{ "dry-run",	       0, 0, G_OPTION_ARG_NONE,         &dry_run,         N_("Don't save any data permanently (implies --no-registration)"), NULL },
		{ "disable-plugins",   0, 0, G_OPTION_ARG_NONE,         &disable_plugins, N_("Disable loading of plugins"), NULL },
		{ "rhythmdb-file",     0, 0, G_OPTION_ARG_STRING,       &rhythmdb_file,   N_("Path for database file to use"), NULL },
		{ "playlists-file",    0, 0, G_OPTION_ARG_STRING,       &playlists_file,   N_("Path for playlists file to use"), NULL },
		{ "quit",	     'q', 0, G_OPTION_ARG_NONE,         &quit,            N_("Quit Rhythmbox"), NULL },
		{ G_OPTION_REMAINING,  0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args,  NULL, N_("[URI...]") },
		{ NULL }
	};

	g_thread_init (NULL);

	rb_profile_start ("starting rhythmbox");

	autostarted = (g_getenv ("DESKTOP_AUTOSTART_ID") != NULL);

#ifdef USE_UNINSTALLED_DIRS
	desktop_file_path = g_build_filename (SHARE_UNINSTALLED_BUILDDIR, "rhythmbox.desktop", NULL);

	g_setenv ("GSETTINGS_SCHEMA_DIR", SHARE_UNINSTALLED_BUILDDIR, TRUE);
#else
	desktop_file_path = g_build_filename (DATADIR, "applications", "rhythmbox.desktop", NULL);
#endif
	egg_set_desktop_file (desktop_file_path);
	g_free (desktop_file_path);

	context = g_option_context_new (NULL);
	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);

	rb_profile_start ("initializing gstreamer");
	g_option_context_add_group (context, gst_init_get_option_group ());
	rb_profile_end ("initializing gstreamer");

	g_option_context_add_group (context, egg_sm_client_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));

	setlocale (LC_ALL, NULL);

	rb_profile_start ("parsing command line options");
	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
			 error->message, argv[0]);
		g_error_free (error);
		g_option_context_free (context);
		exit (1);
	}
	g_option_context_free (context);
	rb_profile_end ("parsing command line options");

	g_random_set_seed (time (0));

#ifdef ENABLE_NLS
	/* initialize i18n */
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

	/* ask for utf-8 message text from GStreamer too,
	 * since it doesn't do that itself.
	 */
	bind_textdomain_codeset ("gstreamer-0.10", "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	if (!debug && debug_match)
		rb_debug_init_match (debug_match);
	else
		rb_debug_init (debug);
	rb_debug ("initializing Rhythmbox %s", VERSION);

#if defined(USE_UNINSTALLED_DIRS)
	g_irepository_prepend_search_path (SHARE_UNINSTALLED_BUILDDIR "/../bindings/gi");
#endif

	/* TODO: kill this function */
	rb_threads_init ();
	gdk_threads_enter ();

	activated = FALSE;

	rb_debug ("going to create DBus object");

	dbus_g_thread_init ();

	session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (session_bus == NULL) {
		g_warning ("couldn't connect to session bus: %s", (error) ? error->message : "(null)");
		g_clear_error (&error);
	} else if (!no_registration) {
		guint request_name_reply;
		int flags;
#ifndef DBUS_NAME_FLAG_DO_NOT_QUEUE
		flags = DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT;
#else
		flags = DBUS_NAME_FLAG_DO_NOT_QUEUE;
#endif

		DBusGProxy *bus_proxy;

		bus_proxy = dbus_g_proxy_new_for_name (session_bus,
						       "org.freedesktop.DBus",
						       "/org/freedesktop/DBus",
						       "org.freedesktop.DBus");

		if (!dbus_g_proxy_call (bus_proxy,
					"RequestName",
					&error,
					G_TYPE_STRING,
					"org.gnome.Rhythmbox",
					G_TYPE_UINT,
					flags,
					G_TYPE_INVALID,
					G_TYPE_UINT,
					&request_name_reply,
					G_TYPE_INVALID)) {
			g_warning ("Failed to invoke RequestName: %s",
				   error->message);
		}
		g_object_unref (bus_proxy);

		if (request_name_reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
		    || request_name_reply == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)
			activated = FALSE;
		else if (request_name_reply == DBUS_REQUEST_NAME_REPLY_EXISTS
			 || request_name_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE)
			activated = TRUE;
		else {
			g_warning ("Got unhandled reply %u from RequestName",
				   request_name_reply);
			activated = FALSE;
		}
	}

	if (!activated) {
		if (quit) {
			rb_debug ("was asked to quit, but no instance was running");
			gdk_notify_startup_complete ();
			exit (0);
		}
#ifdef WITH_RHYTHMDB_GDA
		gda_init (PACKAGE, VERSION, argc, argv);
#endif

		rb_refstring_system_init ();

#ifdef USE_UNINSTALLED_DIRS
		rb_file_helpers_init (TRUE);
#else
		rb_file_helpers_init (FALSE);
#endif

		/* XXX not sure what to do with this.  should we move it to
		 * the config dir, or leave it where it is?
		 */
		accel_map_file = g_build_filename (g_get_home_dir (),
						   ".gnome2",
						   "accels",
						   "rhythmbox",
						   NULL);
		gtk_accel_map_load (accel_map_file);


		rb_debug ("Going to create a new shell");

		rb_stock_icons_init ();

		g_setenv ("PULSE_PROP_media.role", "music", TRUE);

		rb_shell = rb_shell_new (no_registration, no_update, dry_run, autostarted, disable_plugins, rhythmdb_file, playlists_file);
		g_object_weak_ref (G_OBJECT (rb_shell), main_shell_weak_ref_cb, NULL);
		if (!no_registration && session_bus != NULL) {
			dbus_g_object_type_install_info (RB_TYPE_SHELL, &dbus_glib_rb_shell_object_info);
			dbus_g_connection_register_g_object (session_bus, "/org/gnome/Rhythmbox/Shell", G_OBJECT (rb_shell));

			g_signal_connect (G_OBJECT (rb_shell),
					  "database-load-complete",
					  G_CALLBACK (database_load_complete),
					  NULL);
		}
	} else if (!no_registration && session_bus != NULL) {
		DBusGProxy *shell_proxy;
		guint32 current_time;
		current_time = gdk_x11_display_get_user_time (gdk_display_get_default ());
		shell_proxy = dbus_g_proxy_new_for_name_owner (session_bus,
							       "org.gnome.Rhythmbox",
							       "/org/gnome/Rhythmbox/Shell",
							       "org.gnome.Rhythmbox.Shell",
							       &error);
		if (!shell_proxy) {
			g_warning ("Couldn't create proxy for Rhythmbox shell: %s",
				   error->message);
		} else {
			if (quit) {
				dbus_g_proxy_call_no_reply (shell_proxy, "quit",
							    G_TYPE_INVALID);
			} else {
				load_uri_args ((const char **) remaining_args, (GFunc) dbus_load_uri, shell_proxy);
				dbus_g_proxy_call_no_reply (shell_proxy, "present",
							    G_TYPE_UINT, current_time,
							    G_TYPE_INVALID);
			}
			g_object_unref (G_OBJECT (shell_proxy));
		}
	}

	if (activated) {
		gdk_notify_startup_complete ();
	} else {

		rb_profile_start ("mainloop");
#ifdef ENABLE_PYTHON
		if (rb_python_init_successful ()) {
			pyg_begin_allow_threads;
			gtk_main ();
			pyg_end_allow_threads;
		} else {
			gtk_main ();
		}
#else
		gtk_main ();
#endif
		rb_profile_end ("mainloop");

		rb_debug ("out of toplevel loop");

		rb_file_helpers_shutdown ();
		rb_stock_icons_shutdown ();
		rb_refstring_system_shutdown ();
	}

	gst_deinit ();

	rb_debug ("THE END");
	rb_profile_end ("starting rhythmbox");

	if (accel_map_file != NULL) {
		gtk_accel_map_save (accel_map_file);
	}

	gdk_threads_leave ();

	exit (0);
}
Esempio n. 30
0
static void
mojito_client_view_constructed (GObject *object)
{
  MojitoClientViewPrivate *priv = GET_PRIVATE (object);
  GError *error = NULL;
  DBusConnection *conn;
  DBusError derror;

  priv->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);

  if (!priv->connection)
  {
    g_critical (G_STRLOC ": Error getting DBUS connection: %s",
                error->message);
    g_clear_error (&error);
    return;
  }

  conn = dbus_g_connection_get_connection (priv->connection);
  dbus_error_init (&derror);
  if (!dbus_bus_start_service_by_name (conn,
                                       MOJITO_SERVICE_NAME,
                                       0, 
                                       NULL, 
                                       &derror))
  {
    g_critical (G_STRLOC ": Error starting mojito service: %s",
                derror.message);
    dbus_error_free (&derror);
    return;
  }

  priv->proxy = dbus_g_proxy_new_for_name_owner (priv->connection,
                                                 MOJITO_SERVICE_NAME,
                                                 priv->object_path,
                                                 MOJITO_SERVICE_VIEW_INTERFACE,
                                                 &error);

  if (!priv->proxy)
  {
    g_critical (G_STRLOC ": Error setting up proxy for remote object: %s",
                error->message);
    g_clear_error (&error);
    return;
  }

  dbus_g_proxy_add_signal (priv->proxy,
                           "ItemsAdded",
                           _mojito_items_get_container_type (),
                           NULL);
  dbus_g_proxy_connect_signal (priv->proxy,
                               "ItemsAdded",
                               (GCallback)_proxy_items_added_cb,
                               object,
                               NULL);

  dbus_g_proxy_add_signal (priv->proxy,
                           "ItemsChanged",
                           _mojito_items_get_container_type (),
                           NULL);
  dbus_g_proxy_connect_signal (priv->proxy,
                               "ItemsChanged",
                               (GCallback)_proxy_items_changed_cb,
                               object,
                               NULL);

  dbus_g_proxy_add_signal (priv->proxy,
                           "ItemsRemoved",
                           _mojito_items_removed_get_container_type (),
                           NULL);
  dbus_g_proxy_connect_signal (priv->proxy,
                               "ItemsRemoved",
                               (GCallback)_proxy_items_removed_cb,
                               object,
                               NULL);
}