コード例 #1
0
/**
 * main:
 **/
int
main (int argc, gchar **argv)
{
    GOptionContext *context;
    guint i;
    guint len;
    gboolean ret;
    gchar **codecs = NULL;
    gint xid = 0;
    const gchar *suffix;
    gchar *resource;
    _cleanup_error_free_ GError *error = NULL;
    _cleanup_free_ gchar *desktop_id = NULL;
    _cleanup_free_ gchar *interaction = NULL;
    _cleanup_free_ gchar *startup_id = NULL;
    _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
    _cleanup_strv_free_ gchar **resources = NULL;

    const GOptionEntry options[] = {
        { "transient-for", '\0', 0, G_OPTION_ARG_INT, &xid, "The XID of the parent window", NULL },
        { "desktop-id", '\0', 0, G_OPTION_ARG_STRING, &desktop_id, "The desktop ID of the calling application", NULL },
        { "interaction", '\0', 0, G_OPTION_ARG_STRING, &interaction, "Interaction mode specifying which UI elements should be shown", NULL },
        { "startup-notification-id", '\0', 0, G_OPTION_ARG_STRING, &startup_id, "The startup notification ID for focus stealing prevention", NULL },
        { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL },
        { NULL }
    };

#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 35)
    g_type_init ();
#endif

    gst_init (&argc, &argv);

    context = g_option_context_new ("Install missing codecs");
    g_option_context_add_main_entries (context, options, NULL);

    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
                 error->message, argv[0]);
        return GST_INSTALL_PLUGINS_ERROR;
    }
    if (codecs == NULL) {
        g_print ("Missing codecs information\n");
        g_print ("Run 'with --help' to see a full list of available command line options.\n");
        return GST_INSTALL_PLUGINS_ERROR;
    }

    /* this is our parent window */
    g_message ("PackageKit: xid = %i", xid);
    g_message ("PackageKit: desktop_id = %s", desktop_id);

    /* use a ()(64bit) suffix for 64 bit */
    suffix = pk_gst_get_arch_suffix ();

    array = g_ptr_array_new_with_free_func (g_free);
    len = g_strv_length (codecs);

    /* process argv */
    for (i = 0; i < len; i++) {
        PkGstCodecInfo *info;
        gchar *type;
        const gchar *gstreamer_version;

        info = pk_gst_parse_codec (codecs[i]);
        if (info == NULL) {
            g_message ("skipping %s", codecs[i]);
            continue;
        }

        /* gstreamer1 is the provide name used for the
         * first version of the new release */
        if (g_strcmp0 (info->gstreamer_version, "1.0") == 0)
            gstreamer_version = "1";
        else
            gstreamer_version = info->gstreamer_version;

        g_message ("PackageKit: Codec nice name: %s", info->codec_name);
        if (info->structure != NULL) {
            _cleanup_free_ gchar *s = NULL;
            s = pk_gst_structure_to_provide (info->structure);
            type = g_strdup_printf ("gstreamer%s(%s-%s)%s%s",
                                    gstreamer_version,
                                    info->type_name,
                                    gst_structure_get_name (info->structure),
                                    s, suffix);
            g_message ("PackageKit: structure: %s", type);
        } else {
            type = g_strdup_printf ("gstreamer%s(%s)%s",
                                    gstreamer_version,
                                    info->type_name,
                                    suffix);
            g_message ("PackageKit: non-structure: %s", type);
        }

        /* "encode" */
        resource = g_strdup_printf ("%s|%s", info->codec_name, type);
        g_ptr_array_add (array, resource);

        /* free codec structure */
        pk_gst_codec_free (info);
    }

    /* nothing parsed */
    if (array->len == 0) {
        g_message ("no codec lines could be parsed");
        return GST_INSTALL_PLUGINS_ERROR;
    }

    /* convert to a GStrv */
    resources = pk_ptr_array_to_strv (array);

    /* first try the new interface */
    ret = pk_gst_dbus_install_resources (resources, desktop_id, startup_id, interaction, &error);
    if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
        /* ... and if that fails, fall back to the compat interface */
        g_clear_error (&error);
        g_message ("PackageKit: falling back to compat dbus interface");
        ret = pk_gst_dbus_install_resources_compat (resources, xid, &error);
    }
    if (!ret) {
        /* use the error string to return a good GStreamer exit code */
        g_message ("PackageKit: Did not install codec: %s", error->message);
        if (g_strrstr (error->message, "did not agree to search") != NULL)
            return GST_INSTALL_PLUGINS_USER_ABORT;
        if (g_strrstr (error->message, "not all codecs were installed") != NULL)
            return GST_INSTALL_PLUGINS_PARTIAL_SUCCESS;
        return GST_INSTALL_PLUGINS_NOT_FOUND;
    }
    return GST_INSTALL_PLUGINS_SUCCESS;
}
コード例 #2
0
ファイル: pk-gstreamer-install.c プロジェクト: afb/PackageKit
/**
 * main:
 **/
int
main (int argc, gchar **argv)
{
	GOptionContext *context;
	guint i;
	guint len;
	gchar **codecs = NULL;
	gint xid = 0;
	const gchar *suffix;
	gchar *resource;
	_cleanup_error_free_ GError *error = NULL;
	_cleanup_object_unref_ GDBusProxy *proxy = NULL;
	_cleanup_ptrarray_unref_ GPtrArray *array = NULL;
	_cleanup_strv_free_ gchar **resources = NULL;
	_cleanup_variant_unref_ GVariant *value = NULL;

	const GOptionEntry options[] = {
		{ "transient-for", '\0', 0, G_OPTION_ARG_INT, &xid, "The XID of the parent window", NULL },
		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL },
		{ NULL }
	};

#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 35)
	g_type_init ();
#endif

	gst_init (&argc, &argv);

	context = g_option_context_new ("Install missing codecs");
	g_option_context_add_main_entries (context, options, NULL);

	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
			 error->message, argv[0]);
		return GST_INSTALL_PLUGINS_ERROR;
	}
	if (codecs == NULL) {
		g_print ("Missing codecs information\n");
		g_print ("Run 'with --help' to see a full list of available command line options.\n");
		return GST_INSTALL_PLUGINS_ERROR;
	}

	/* this is our parent window */
	g_message ("PackageKit: xid = %i", xid);

	/* get proxy */
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
					       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
					       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
					       NULL,
					       "org.freedesktop.PackageKit",
					       "/org/freedesktop/PackageKit",
					       "org.freedesktop.PackageKit.Modify",
					       NULL,
					       &error);
	if (proxy == NULL) {
		g_warning ("Cannot connect to PackageKit session service: %s",
			   error->message);
		return GST_INSTALL_PLUGINS_ERROR;
	}

	/* use a ()(64bit) suffix for 64 bit */
	suffix = pk_gst_get_arch_suffix ();

	array = g_ptr_array_new_with_free_func (g_free);
	len = g_strv_length (codecs);

	/* process argv */
	for (i = 0; i < len; i++) {
		PkGstCodecInfo *info;
		gchar *type;
		const gchar *gstreamer_version;

		info = pk_gst_parse_codec (codecs[i]);
		if (info == NULL) {
			g_message ("skipping %s", codecs[i]);
			continue;
		}

		/* gstreamer1 is the provide name used for the
		 * first version of the new release */
		if (g_strcmp0 (info->gstreamer_version, "1.0") == 0)
			gstreamer_version = "1";
		else
			gstreamer_version = info->gstreamer_version;

		g_message ("PackageKit: Codec nice name: %s", info->codec_name);
		if (info->structure != NULL) {
			_cleanup_free_ gchar *s = NULL;
			s = pk_gst_structure_to_provide (info->structure);
			type = g_strdup_printf ("gstreamer%s(%s-%s)%s%s",
						gstreamer_version,
						info->type_name,
						gst_structure_get_name (info->structure),
						s, suffix);
			g_message ("PackageKit: structure: %s", type);
		} else {
			type = g_strdup_printf ("gstreamer%s(%s)%s",
						gstreamer_version,
						info->type_name,
						suffix);
			g_message ("PackageKit: non-structure: %s", type);
		}

		/* "encode" */
		resource = g_strdup_printf ("%s|%s", info->codec_name, type);
		g_ptr_array_add (array, resource);

		/* free codec structure */
		pk_gst_codec_free (info);
	}

	/* nothing parsed */
	if (array->len == 0) {
		g_message ("no codec lines could be parsed");
		return GST_INSTALL_PLUGINS_ERROR;
	}

	/* convert to a GStrv */
	resources = pk_ptr_array_to_strv (array);

	/* invoke the method */
	value = g_dbus_proxy_call_sync (proxy,
					"InstallGStreamerResources",
					g_variant_new ("(u^a&ss)",
						       xid,
						       resources,
						       "hide-finished"),
					G_DBUS_CALL_FLAGS_NONE,
					60 * 60 * 1000, /* 1 hour */
					NULL,
					&error);
	if (value == NULL) {
		/* use the error string to return a good GStreamer exit code */
		g_message ("PackageKit: Did not install codec: %s", error->message);
		if (g_strrstr (error->message, "did not agree to search") != NULL)
			return GST_INSTALL_PLUGINS_USER_ABORT;
		if (g_strrstr (error->message, "not all codecs were installed") != NULL)
			return GST_INSTALL_PLUGINS_PARTIAL_SUCCESS;
		return GST_INSTALL_PLUGINS_NOT_FOUND;
	}
	return GST_INSTALL_PLUGINS_SUCCESS;
}