static void decorator_cache_next_items (TrackerDecorator *decorator) { TrackerDecoratorPrivate *priv = decorator->priv; if (priv->querying || g_hash_table_size (priv->tasks) > 0 || !g_queue_is_empty (&priv->item_cache)) return; priv->querying = TRUE; if (priv->n_remaining_items == 0) { decorator_query_remaining_items (decorator); } else { TrackerSparqlConnection *sparql_conn; gchar *query; sparql_conn = tracker_miner_get_connection (TRACKER_MINER (decorator)); query = create_remaining_items_query (decorator); tracker_sparql_connection_query_async (sparql_conn, query, NULL, decorator_cache_items_cb, decorator); g_free (query); } }
static void decorator_query_remaining_items (TrackerDecorator *decorator) { gchar *query, *clauses[] = { "COUNT(?urn)", NULL }; TrackerSparqlConnection *sparql_conn; query = create_query_string (decorator, clauses, FALSE); if (query) { sparql_conn = tracker_miner_get_connection (TRACKER_MINER (decorator)); tracker_sparql_connection_query_async (sparql_conn, query, NULL, decorator_query_remaining_items_cb, decorator); g_free (query); } else { decorator_notify_empty (decorator); } }
static gboolean miner_applications_initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { TrackerMinerFS *fs; GError *inner_error = NULL; TrackerIndexingTree *indexing_tree; fs = TRACKER_MINER_FS (initable); indexing_tree = tracker_miner_fs_get_indexing_tree (fs); /* Set up files filter, deny every file, but * those with a .desktop/directory extension */ tracker_indexing_tree_set_default_policy (indexing_tree, TRACKER_FILTER_FILE, TRACKER_FILTER_POLICY_DENY); tracker_indexing_tree_add_filter (indexing_tree, TRACKER_FILTER_FILE, "*.desktop"); tracker_indexing_tree_add_filter (indexing_tree, TRACKER_FILTER_FILE, "*.directory"); /* Chain up parent's initable callback before calling child's one */ if (!miner_applications_initable_parent_iface->init (initable, cancellable, &inner_error)) { g_propagate_error (error, inner_error); return FALSE; } g_signal_connect (fs, "finished", G_CALLBACK (miner_finished_cb), NULL); miner_applications_add_directories (fs); /* If the locales changed, we need to reset things first */ detect_locale_changed (TRACKER_MINER (fs)); return TRUE; }
static gboolean decorator_commit_info (TrackerDecorator *decorator) { TrackerSparqlConnection *sparql_conn; TrackerDecoratorPrivate *priv; GPtrArray *array; gint i; priv = decorator->priv; if (!priv->sparql_buffer || priv->sparql_buffer->len == 0) return FALSE; if (priv->commit_buffer) return FALSE; /* Move sparql buffer to commit buffer */ priv->commit_buffer = priv->sparql_buffer; priv->sparql_buffer = NULL; array = g_ptr_array_new (); for (i = 0; i < priv->commit_buffer->len; i++) { SparqlUpdate *update; update = &g_array_index (priv->commit_buffer, SparqlUpdate, i); g_ptr_array_add (array, update->sparql); } sparql_conn = tracker_miner_get_connection (TRACKER_MINER (decorator)); tracker_sparql_connection_update_array_async (sparql_conn, (gchar **) array->pdata, array->len, G_PRIORITY_DEFAULT, NULL, decorator_commit_cb, decorator); decorator_update_state (decorator, NULL, TRUE); g_ptr_array_unref (array); return TRUE; }
static void decorator_update_state (TrackerDecorator *decorator, const gchar *message, gboolean estimate_time) { TrackerDecoratorPrivate *priv; gint remaining_time = -1; gdouble progress = 1; gsize total_items; priv = decorator->priv; remaining_time = 0; total_items = priv->n_remaining_items + priv->n_processed_items; if (priv->n_remaining_items > 0) progress = ((gdouble) priv->n_processed_items / total_items); if (priv->timer && estimate_time && !tracker_miner_is_paused (TRACKER_MINER (decorator))) { gdouble elapsed; /* FIXME: Quite naive calculation */ elapsed = g_timer_elapsed (priv->timer, NULL); if (priv->n_processed_items > 0) remaining_time = (priv->n_remaining_items * elapsed) / priv->n_processed_items; } g_object_set (decorator, "progress", progress, "remaining-time", remaining_time, NULL); if (message) g_object_set (decorator, "status", message, NULL); }
int main (int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; TrackerExtract *extract; TrackerDecorator *decorator; TrackerExtractController *controller; gchar *log_filename = NULL; GMainLoop *my_main_loop; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Translators: this message will appear immediately after the */ /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */ context = g_option_context_new (_("- Extract file meta data")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, &error); if (!filename && mime_type) { gchar *help; g_printerr ("%s\n\n", _("Filename and mime type must be provided together")); help = g_option_context_get_help (context, TRUE, NULL); g_option_context_free (context); g_printerr ("%s", help); g_free (help); return EXIT_FAILURE; } g_option_context_free (context); if (version) { g_print ("\n" ABOUT "\n" LICENSE "\n"); return EXIT_SUCCESS; } g_set_application_name ("tracker-extract"); setlocale (LC_ALL, ""); config = tracker_config_new (); /* Set conditions when we use stand alone settings */ if (filename) { return run_standalone (config); } /* Initialize subsystems */ initialize_directories (); /* Extractor command line arguments */ if (verbosity > -1) { tracker_config_set_verbosity (config, verbosity); } tracker_log_init (tracker_config_get_verbosity (config), &log_filename); if (log_filename != NULL) { g_message ("Using log file:'%s'", log_filename); g_free (log_filename); } sanity_check_option_values (config); /* This makes sure we don't steal all the system's resources */ initialize_priority_and_scheduling (tracker_config_get_sched_idle (config), tracker_db_manager_get_first_index_done () == FALSE); extract = tracker_extract_new (TRUE, force_module); if (!extract) { g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } decorator = tracker_extract_decorator_new (extract, NULL, &error); if (error) { g_critical ("Could not start decorator: %s\n", error->message); g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } #ifdef THREAD_ENABLE_TRACE g_debug ("Thread:%p (Main) --- Waiting for extract requests...", g_thread_self ()); #endif /* THREAD_ENABLE_TRACE */ tracker_locale_init (); controller = tracker_extract_controller_new (decorator); tracker_miner_start (TRACKER_MINER (decorator)); /* Main loop */ main_loop = g_main_loop_new (NULL, FALSE); initialize_signal_handler (); g_main_loop_run (main_loop); my_main_loop = main_loop; main_loop = NULL; g_main_loop_unref (my_main_loop); tracker_miner_stop (TRACKER_MINER (decorator)); /* Shutdown subsystems */ tracker_locale_shutdown (); g_object_unref (extract); g_object_unref (decorator); g_object_unref (controller); tracker_log_shutdown (); g_object_unref (config); return EXIT_SUCCESS; }
int main (int argc, char **argv) { gchar *log_filename; GMainLoop *loop; GOptionContext *context; TrackerMinerRSS *miner; GError *error = NULL; const gchar *error_message; g_type_init(); setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); tzset (); /* Translators: this messagge will apper immediately after the * usage string - Usage: COMMAND <THIS_MESSAGE> */ context = g_option_context_new (_("- start the feeds indexer")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, NULL); if ((add_feed && !title) || (!add_feed && title)) { error_message = _("Adding a feed requires --add-feed and --title"); } else { error_message = NULL; } if (error_message) { gchar *help; g_printerr ("%s\n\n", error_message); help = g_option_context_get_help (context, TRUE, NULL); g_option_context_free (context); g_printerr ("%s", help); g_free (help); return EXIT_FAILURE; } g_option_context_free (context); /* Command line stuff doesn't use logging, so we're using g_print*() */ if (add_feed && title) { TrackerSparqlConnection *connection; const gchar *query; g_print ("Adding feed:\n" " title:'%s'\n" " url:'%s'\n", title, add_feed); connection = tracker_sparql_connection_get (NULL, &error); if (!connection) { g_printerr ("%s: %s\n", _("Could not establish a connection to Tracker"), error ? error->message : _("No error given")); g_clear_error (&error); return EXIT_FAILURE; } /* FIXME: Make interval configurable */ query = g_strdup_printf ("INSERT {" " _:FeedSettings a mfo:FeedSettings ;" " mfo:updateInterval 20 ." " _:Feed a nie:DataObject, mfo:FeedChannel ;" " mfo:feedSettings _:FeedSettings ;" " nie:url \"%s\" ;" " nie:title \"%s\" . " "}", add_feed, title); tracker_sparql_connection_update (connection, query, G_PRIORITY_DEFAULT, NULL, &error); if (error) { g_printerr ("%s, %s\n", _("Could not add feed"), error->message); g_error_free (error); g_object_unref (connection); return EXIT_FAILURE; } g_print ("Done\n"); return EXIT_SUCCESS; } tracker_log_init (verbosity, &log_filename); if (log_filename != NULL) { g_message ("Using log file:'%s'", log_filename); g_free (log_filename); } miner = tracker_miner_rss_new (&error); if (!miner) { g_critical ("Could not create new RSS miner: '%s', exiting...\n", error ? error->message : "unknown error"); return EXIT_FAILURE; } tracker_miner_start (TRACKER_MINER (miner)); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); tracker_log_shutdown (); g_main_loop_unref (loop); g_object_unref (miner); return EXIT_SUCCESS; }