Exemple #1
0
/* This is a somewhat hacky way to get FTP to almost work. The proper way to
 * get FTP to _really_ work involves hacking GIO to have APIs to handle
 * canoncial URLs.
 */
static GFile *
webkit_soup_request_file_ensure_file_ftp (SoupURI       *uri,
					  GCancellable  *cancellable,
					  GError       **error)
{
	SoupURI *host;
	char *s;
	GFile *file, *result;
	GMount *mount;

	host = soup_uri_copy_host (uri);
	s = soup_uri_to_string (host, FALSE);
	file = g_file_new_for_uri (s);
	soup_uri_free (host);
	g_free (s);

	mount = g_file_find_enclosing_mount (file, cancellable, error);
	if (mount == NULL && g_file_supports_thread_contexts (file)) {
		GMainContext *context = g_main_context_new ();
		GMainLoop *loop = g_main_loop_new (context, FALSE);

		g_clear_error (error);
		g_main_context_push_thread_default (context);
		g_file_mount_enclosing_volume (file,
					       G_MOUNT_MOUNT_NONE,
					       NULL, /* FIXME! */
					       cancellable,
					       webkit_soup_request_file_ftp_main_loop_quit,
					       loop);
		g_main_loop_run (loop);
		g_main_context_pop_thread_default (context);
		g_main_loop_unref (loop);
		g_main_context_unref (context);
		mount = g_file_find_enclosing_mount (file, cancellable, error);
	}
	if (mount == NULL)
		return NULL;
	g_object_unref (file);

	file = g_mount_get_default_location (mount);
	g_object_unref (mount);

	s = g_strdup (uri->path);
	if (strchr (s, ';'))
		*strchr (s, ';') = 0;

	result = g_file_resolve_relative_path (file, s);
	g_free (s);
	g_object_unref (file);

	return result;
}
Exemple #2
0
gboolean
shmdata_base_reader_start (shmdata_base_reader_t * reader, const char *socketPath)
{
    if (NULL == reader)
        return FALSE;
    g_mutex_lock (&reader->mutex_);
    destroy_polling_g_source (reader);
    if (reader->install_sync_handler_)
    {
        g_debug ("installing a sync handler");
        //looking for the bus, searching the top level
        GstElement *pipe = reader->bin_;

        while (pipe != NULL && !GST_IS_PIPELINE (pipe))
            pipe = GST_ELEMENT_PARENT (pipe);

        if( GST_IS_PIPELINE (pipe))
        {
            GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipe));

            gst_bus_set_sync_handler (bus, shmdata_base_reader_message_handler, NULL);
            gst_object_unref (bus);
        }
        else
        {
            g_warning ("no top level pipeline found when starting, cannot install sync_handler");
            g_mutex_unlock (&reader->mutex_);
            return FALSE;
        }
    }
    reader->socket_name_ = g_strdup (socketPath);
    //monitoring the shared memory file
    reader->shmfile_ = g_file_new_for_commandline_arg (reader->socket_name_);
    if (g_file_query_exists (reader->shmfile_, NULL))
    {
        g_debug ("existing shmdata, attaching (%s)",
                 reader->socket_name_);
        reader->initialized_ = TRUE;
        g_mutex_unlock (&reader->mutex_);//give hand to user
        reader->on_first_data_ (reader, reader->on_first_data_userData_);
        shmdata_base_reader_attach (reader); //attach is acquiring mutex
        g_mutex_lock (&reader->mutex_);//get hand back
    }
    else
        g_debug ("monitoring %s",
                 reader->socket_name_);
    //#ifdef HAVE_OSX
#if 1
    //directory monitoring is not working on osx, use polling :(
    /* g_timeout_add (500, */
    /*                shmdata_base_reader_poll_shmdata_path, */
    /* 		 reader); */
    //GSource *source;
    reader->polling_g_source_ = g_timeout_source_new (500);
    g_source_set_callback (reader->polling_g_source_,
                           shmdata_base_reader_poll_shmdata_path,
                           reader,
                           NULL);
    g_source_attach (reader->polling_g_source_,
                     reader->g_main_context_);
    g_source_unref (reader->polling_g_source_);
#else
    //FIXME fix monitoring with custom gmaincontext... find how to use "g_main_context_push_thread_default"...
    if (reader->g_main_context_ != NULL)
    {
        g_debug ("shmdata_base_reader_start: set a custom maincontext");
        g_main_context_push_thread_default (reader->g_main_context_);
    }
    GFile *dir = g_file_get_parent (reader->shmfile_);
    if (!g_file_supports_thread_contexts(dir))
        g_debug ("does not support thread_context");
    GError *error = NULL;
    reader->dirMonitor_ = g_file_monitor_directory (dir,
                          G_FILE_MONITOR_NONE,
                          NULL, &error);
    g_object_unref (dir);
    if (reader->dirMonitor_ == NULL)
    {
        g_warning ("monitor directory failled: %s",
                   error->message);
        g_error_free (error);
        g_mutex_unlock (&reader->mutex_);
        return FALSE;
    }
    g_signal_connect (reader->dirMonitor_,
                      "changed",
                      G_CALLBACK (shmdata_base_reader_file_system_monitor_change),
                      reader);
    if (reader->g_main_context_ != NULL)
        g_main_context_pop_thread_default (reader->g_main_context_);
#endif
    g_debug ("shmdata reader started (%s)", reader->socket_name_);
    g_mutex_unlock (&reader->mutex_);
    return TRUE;
}