Beispiel #1
0
static int
can_set (Cache *cache, const gchar *method_name)
{
  guint64 now = g_get_monotonic_time ();

  if (now - cache->stamp > (CACHE_VALIDITY_SEC * 1000000))
    {
      if (!cache->in_progress)
        {
          GDBusConnection *system_bus = get_system_bus (NULL);

          if (system_bus != NULL)
            g_dbus_connection_call (system_bus, MECHANISM_BUS_NAME,
                                    MECHANISM_OBJECT_PATH, MECHANISM_INTERFACE,
                                    method_name, NULL, G_VARIANT_TYPE ("(i)"),
                                    G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                                    can_set_call_finished, cache);

          /* Even if the system bus was NULL, we want to set this in
           * order to effectively wedge ourselves from ever trying
           * again.
           */
          cache->in_progress = TRUE;
        }
    }

  return cache->value;
}
Beispiel #2
0
void
set_system_timezone_async (const gchar         *tz,
                           GAsyncReadyCallback  callback,
                           gpointer             user_data)
{
  GDBusConnection *system_bus;
  GError *error = NULL;

  system_bus = get_system_bus (&error);

  if (system_bus == NULL)
    {
      GSimpleAsyncResult *simple;

      simple = g_simple_async_result_new (NULL, callback, user_data,
                                          set_system_timezone_async);
      g_simple_async_result_set_from_error (simple, error);
      g_simple_async_result_complete_in_idle (simple);
      g_object_unref (simple);
      g_error_free (error);
    }

  g_dbus_connection_call (system_bus, MECHANISM_BUS_NAME,
                          MECHANISM_OBJECT_PATH, MECHANISM_INTERFACE,
                          "SetTimezone", g_variant_new ("(s)", tz),
                          NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                          callback, user_data);
}
static void
set_time_async (SetTimeCallbackData *data)
{
        DBusGConnection *bus;
        DBusGProxy      *proxy;
	GError          *err = NULL;

        bus = get_system_bus (&err);
        if (bus == NULL) {
		if (err) {
			if (data->callback)
				data->callback (data->data, err);
			g_clear_error (&err);
		}
		return;
	}

	proxy = dbus_g_proxy_new_for_name (bus,
					   "org.gnome.SettingsDaemon.DateTimeMechanism",
					   "/",
					   "org.gnome.SettingsDaemon.DateTimeMechanism");

	data->ref_count++;
	if (strcmp (data->call, "SetTime") == 0)
		dbus_g_proxy_begin_call_with_timeout (proxy,
						      "SetTime",
						      set_time_notify,
						      data, free_data,
						      INT_MAX,
						      /* parameters: */
						      G_TYPE_INT64, data->time,
						      G_TYPE_INVALID,
						      /* return values: */
						      G_TYPE_INVALID);
	else if (strcmp (data->call, "SetTimezone") == 0)
		dbus_g_proxy_begin_call_with_timeout (proxy,
						      "SetTimezone",
						      set_time_notify,
						      data, free_data,
						      INT_MAX,
						      /* parameters: */
						      G_TYPE_STRING, data->tz,
						      G_TYPE_INVALID,
						      /* return values: */
						      G_TYPE_INVALID);
	else if (strcmp (data->call, "SetUsingNtp") == 0)
		dbus_g_proxy_begin_call_with_timeout (proxy,
						      "SetUsingNtp",
						      set_time_notify,
						      data, free_data,
						      INT_MAX,
						      /* parameters: */
						      G_TYPE_BOOLEAN, data->using_ntp,
						      G_TYPE_INVALID,
						      /* return values: */
						      G_TYPE_INVALID);
}
int
main (int argc, char **argv)
{
        GMainLoop             *loop;
        GsdDatetimeMechanism  *mechanism;
        DBusGProxy            *bus_proxy;
        DBusGConnection       *connection;
        int                    ret;

        ret = 1;

        if (! g_thread_supported ()) {
                g_thread_init (NULL);
        }
        dbus_g_thread_init ();
        g_type_init ();

        connection = get_system_bus ();
        if (connection == NULL) {
                goto out;
        }

        bus_proxy = get_bus_proxy (connection);
        if (bus_proxy == NULL) {
                g_warning ("Could not construct bus_proxy object; bailing out");
                goto out;
        }

        if (!acquire_name_on_proxy (bus_proxy) ) {
                g_warning ("Could not acquire name; bailing out");
                goto out;
        }

        mechanism = gsd_datetime_mechanism_new ();

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

        loop = g_main_loop_new (NULL, FALSE);

        g_main_loop_run (loop);

        g_object_unref (mechanism);
        g_main_loop_unref (loop);
        ret = 0;

out:
        return ret;
}
void
get_system_timezone_async (GetTimezoneFunc callback,
			   gpointer        user_data,
			   GDestroyNotify  notify)
{
	DBusGConnection *bus;
	DBusGProxy      *proxy;
	GetTimezoneData *data;
	GError          *error = NULL;

	bus = get_system_bus (&error);
	if (bus == NULL) {
		if (error) {
			if (callback)
				callback (user_data, NULL, error);
			g_clear_error (&error);
		}
		return;

        }

	data = g_new0 (GetTimezoneData, 1);
	data->data = user_data;
	data->notify = notify;
	data->callback = callback;

	proxy = dbus_g_proxy_new_for_name (bus,
					   "org.gnome.SettingsDaemon.DateTimeMechanism",
					   "/",
					   "org.gnome.SettingsDaemon.DateTimeMechanism");

	dbus_g_proxy_begin_call (proxy,
				 "GetTimezone",
				 get_timezone_notify,
				 data,
				 (GDestroyNotify) get_timezone_destroy_notify,
				 /* parameters: */
				 G_TYPE_INVALID,
				 /* return values: */
				 G_TYPE_STRING,
				 G_TYPE_INVALID);

}
int
main (int argc, char **argv)
{
        GMainLoop          *main_loop;
        DBusGConnection    *connection;
        DBusGProxy         *bus_proxy;

        g_type_init ();

        connection = get_system_bus ();
        if (connection == NULL) {
                goto out;
        }

        bus_proxy = get_bus_proxy (connection);
        if (bus_proxy == NULL) {
                g_warning ("Could not construct bus_proxy object; bailing out");
                goto out;
        }

        if (! acquire_name_on_proxy (bus_proxy) ) {
                g_warning ("Could not acquire name; bailing out");
                goto out;
        }

        settings = gdm_settings_new ();
        if (settings == NULL) {
                g_warning ("Unable to initialize settings");
                exit (1);
        }

        main_loop = g_main_loop_new (NULL, FALSE);
        g_main_loop_run (main_loop);

        g_main_loop_unref (main_loop);

        g_object_unref (settings);

 out:
        return 0;
}
static void
refresh_can_do (const gchar *action, CanDoFunc callback)
{
        DBusGConnection *bus;
        DBusGProxy      *proxy;

        bus = get_system_bus ();
        if (bus == NULL)
                return;

	proxy = dbus_g_proxy_new_for_name (bus,
					   "org.mate.SettingsDaemon.DateTimeMechanism",
					   "/",
					   "org.mate.SettingsDaemon.DateTimeMechanism");

	dbus_g_proxy_begin_call_with_timeout (proxy,
					      action,
					      notify_can_do,
					      callback, NULL,
					      INT_MAX,
					      G_TYPE_INVALID);
}
static void
set_time_async (SetTimeCallbackData *data)
{
        DBusGConnection *bus;
        DBusGProxy      *proxy;

        bus = get_system_bus ();
        if (bus == NULL)
                return;

	proxy = dbus_g_proxy_new_for_name (bus,
					   "org.mate.SettingsDaemon.DateTimeMechanism",
					   "/",
					   "org.mate.SettingsDaemon.DateTimeMechanism");

	data->ref_count++;
	if (strcmp (data->call, "SetTime") == 0)
		dbus_g_proxy_begin_call_with_timeout (proxy, 
						      "SetTime",
						      set_time_notify,
						      data, free_data,
						      INT_MAX,
						      /* parameters: */
						      G_TYPE_INT64, data->time,
						      G_TYPE_INVALID,
						      /* return values: */
						      G_TYPE_INVALID);
	else 
		dbus_g_proxy_begin_call_with_timeout (proxy, 
						      "SetTimezone",
						      set_time_notify,
						      data, free_data,
						      INT_MAX,
						      /* parameters: */
						      G_TYPE_STRING, data->filename,
						      G_TYPE_INVALID,
						      /* return values: */
						      G_TYPE_INVALID);
}
gboolean
get_using_ntp (void)
{
	static gboolean is_using_cache = FALSE;
	static time_t   last_refreshed = 0;
	time_t          now;
        DBusGConnection *bus;
        DBusGProxy      *proxy;

	time (&now);
	if (ABS (now - last_refreshed) > CACHE_VALIDITY_SEC) {
		gboolean cu, iu;
		bus = get_system_bus (NULL);
		if (bus == NULL)
			return FALSE;

		proxy = dbus_g_proxy_new_for_name (bus,
						   "org.gnome.SettingsDaemon.DateTimeMechanism",
						   "/",
						   "org.gnome.SettingsDaemon.DateTimeMechanism");


		if (dbus_g_proxy_call (proxy,
				       "GetUsingNtp",
				       NULL,
				       G_TYPE_INVALID,
				       G_TYPE_BOOLEAN, &cu,
				       G_TYPE_BOOLEAN, &iu,
				       G_TYPE_INVALID)) {
			is_using_cache = iu;
			last_refreshed = now;
		}
	}

	return is_using_cache;
}
Beispiel #10
0
gboolean
set_system_timezone_finish (GAsyncResult  *result,
                            GError       **error)
{
  GDBusConnection *system_bus = get_system_bus (NULL);
  GVariant *reply;

  /* detect if we set an error due to being unable to get the system bus */
  if (g_simple_async_result_is_valid (result, NULL, set_system_timezone_async))
    {
      g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
                                             error);
      return FALSE;
    }

  g_assert (system_bus != NULL);

  reply = g_dbus_connection_call_finish (system_bus, result, error);

  if (reply != NULL)
    g_variant_unref (reply);

  return reply != NULL;
}
int
main (int    argc,
      char **argv)
{
    GMainLoop        *main_loop;
    GOptionContext   *context;
    DBusGConnection  *connection;
    MdmSlave         *slave;
    static char      *display_id = NULL;
    MdmSignalHandler *signal_handler;
    static GOptionEntry entries []   = {
        { "display-id", 0, 0, G_OPTION_ARG_STRING, &display_id, N_("Display ID"), N_("ID") },
        { NULL }
    };

    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
    textdomain (GETTEXT_PACKAGE);
    setlocale (LC_ALL, "");

    mdm_set_fatal_warnings_if_unstable ();

    g_type_init ();

    context = g_option_context_new (_("MATE Display Manager Slave"));
    g_option_context_add_main_entries (context, entries, NULL);

    g_option_context_parse (context, &argc, &argv, NULL);
    g_option_context_free (context);

    connection = get_system_bus ();
    if (connection == NULL) {
        goto out;
    }

    mdm_xerrors_init ();
    mdm_log_init ();

    settings = mdm_settings_new ();
    if (settings == NULL) {
        g_warning ("Unable to initialize settings");
        goto out;
    }

    if (! mdm_settings_direct_init (settings, DATADIR "/mdm/mdm.schemas", "/")) {
        g_warning ("Unable to initialize settings");
        goto out;
    }

    mdm_log_set_debug (is_debug_set ());

    if (display_id == NULL) {
        g_critical ("No display ID set");
        exit (1);
    }

    main_loop = g_main_loop_new (NULL, FALSE);

    signal_handler = mdm_signal_handler_new ();
    mdm_signal_handler_set_fatal_func (signal_handler,
                                       (GDestroyNotify)g_main_loop_quit,
                                       main_loop);
    mdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGILL, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGBUS, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGFPE, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGSEGV, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGABRT, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
    mdm_signal_handler_add (signal_handler, SIGUSR2, signal_cb, NULL);

    slave = mdm_product_slave_new (display_id);
    if (slave == NULL) {
        goto out;
    }
    g_signal_connect (slave,
                      "stopped",
                      G_CALLBACK (on_slave_stopped),
                      main_loop);
    mdm_slave_start (slave);

    g_main_loop_run (main_loop);

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

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

    if (main_loop != NULL) {
        g_main_loop_unref (main_loop);
    }

out:

    g_debug ("Slave finished");

    return mdm_return_code;
}
int
main (int    argc,
      char **argv)
{
        GMainLoop        *main_loop;
        GOptionContext   *context;
        GDBusConnection  *connection;
        GdmSlave         *slave;
        static char      *display_id = NULL;
        static GOptionEntry entries []   = {
                { "display-id", 0, 0, G_OPTION_ARG_STRING, &display_id, N_("Display ID"), N_("ID") },
                { NULL }
        };

        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
        textdomain (GETTEXT_PACKAGE);
        setlocale (LC_ALL, "");

        context = g_option_context_new (_("GNOME Display Manager Slave"));
        g_option_context_add_main_entries (context, entries, NULL);

        g_option_context_parse (context, &argc, &argv, NULL);
        g_option_context_free (context);

        /* For debugging */
        /*sleep (10);*/

        connection = get_system_bus ();
        if (connection == NULL) {
                goto out;
        }

        gdm_xerrors_init ();
        gdm_log_init ();

        settings = gdm_settings_new ();
        if (settings == NULL) {
                g_warning ("Unable to initialize settings");
                goto out;
        }

        if (! gdm_settings_direct_init (settings, DATADIR "/gdm/gdm.schemas", "/")) {
                g_warning ("Unable to initialize settings");
                goto out;
        }

        gdm_log_set_debug (is_debug_set ());

        if (display_id == NULL) {
                g_critical ("No display ID set");
                exit (1);
        }

        if (! gdm_settings_client_init (DATADIR "/gdm/gdm.schemas", "/")) {
                g_critical ("Unable to initialize settings client");
                exit (1);
        }

        main_loop = g_main_loop_new (NULL, FALSE);

        g_unix_signal_add (SIGTERM, on_shutdown_signal_cb, main_loop);
        g_unix_signal_add (SIGINT, on_shutdown_signal_cb, main_loop);
        g_unix_signal_add (SIGUSR2, on_sigusr2_cb, NULL);

        slave = gdm_simple_slave_new (display_id);
        if (slave == NULL) {
                goto out;
        }
        g_signal_connect (slave,
                          "stopped",
                          G_CALLBACK (on_slave_stopped),
                          main_loop);
        gdm_slave_start (slave);

        g_main_loop_run (main_loop);

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

        g_main_loop_unref (main_loop);

 out:
        g_debug ("Slave finished");

        g_object_unref (connection);

        return gdm_return_code;
}
Beispiel #13
0
int
main (int argc, char **argv)
{
        GMainLoop           *loop;
        GConfDefaults       *mechanism;
        DBusGProxy          *bus_proxy;
        DBusGConnection     *connection;
        int                  ret;
	GOptionContext      *options;
	GError              *error = NULL;

        ret = 1;

        if (! g_thread_supported ()) {
                g_thread_init (NULL);
        }
        dbus_g_thread_init ();

	options = g_option_context_new (NULL);
	g_option_context_add_main_entries (options, entries, NULL);
	if (!g_option_context_parse (options, &argc, &argv, &error)) {
		g_warning ("Failed to parse options: %s\n", error->message);
		g_error_free (error);
	}
	g_option_context_free (options);

	g_log_set_default_handler (log_default_handler, NULL);
	if (debug) {
		log_levels = log_levels | G_LOG_LEVEL_DEBUG;
	}

        connection = get_system_bus ();
        if (connection == NULL) {
                g_warning ("Could not get system bus connection; bailing out");
                goto out;
        }

        bus_proxy = get_bus_proxy (connection);
        if (bus_proxy == NULL) {
                g_warning ("Could not construct bus_proxy object; bailing out");
                goto out;
        }

        mechanism = gconf_defaults_new ();

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

        if (!acquire_name_on_proxy (bus_proxy)) {
                g_warning ("Could not acquire name; bailing out");
                goto out;
        }

        loop = g_main_loop_new (NULL, FALSE);

        g_main_loop_run (loop);

        g_object_unref (mechanism);
        g_main_loop_unref (loop);
        ret = 0;

out:
        return ret;
}