Exemple #1
0
static gboolean
get_metadata (TrackerExtractTask *task)
{
	TrackerExtractInfo *info;
	TrackerSparqlBuilder *preupdate, *postupdate, *statements;
	gchar *where = NULL;

	preupdate = postupdate = statements = NULL;

#ifdef THREAD_ENABLE_TRACE
	g_debug ("Thread:%p --> File:'%s' - Extracted",
	         g_thread_self (),
	         task->file);
#endif /* THREAD_ENABLE_TRACE */

	if (task->cancellable &&
	    g_cancellable_is_cancelled (task->cancellable)) {
		g_simple_async_result_set_error ((GSimpleAsyncResult *) task->res,
		                                 TRACKER_DBUS_ERROR, 0,
		                                 "Extraction of '%s' was cancelled",
		                                 task->file);

		g_simple_async_result_complete_in_idle ((GSimpleAsyncResult *) task->res);
		extract_task_free (task);
		return FALSE;
	}

	if (!filter_module (task->extract, task->cur_module) &&
	    get_file_metadata (task, &info)) {
		g_simple_async_result_set_op_res_gpointer ((GSimpleAsyncResult *) task->res,
		                                           info,
		                                           (GDestroyNotify) tracker_extract_info_unref);

		g_simple_async_result_complete_in_idle ((GSimpleAsyncResult *) task->res);
		extract_task_free (task);
	} else {
		if (preupdate) {
			g_object_unref (preupdate);
		}

		if (postupdate) {
			g_object_unref (postupdate);
		}

		if (statements) {
			g_object_unref (statements);
		}

		g_free (where);

		/* Reinject the task into the main thread
		 * queue, so the next module kicks in.
		 */
		g_idle_add ((GSourceFunc) dispatch_task_cb, task);
	}

	return FALSE;
}
/* A callback function to catch loading and unloading of module. 
 * Sets target_module pointer among other things. */
static int 
detector_notifier_call(struct notifier_block *nb,
	unsigned long mod_state, void *vmod)
{
	struct module* mod = (struct module *)vmod;
	BUG_ON(mod == NULL);
	
	if (mutex_lock_interruptible(&controller_mutex) != 0)
	{
		KEDR_MSG(COMPONENT_STRING
			"failed to lock controller_mutex\n");
		return 0;
	}
	
	if (handle_module_notifications)
	{
		/* handle module state change */
		switch(mod_state)
		{
		case MODULE_STATE_COMING: /* the module has just loaded */
			if(!filter_module(module_name(mod))) break;
			
			BUG_ON(target_module != NULL);
			target_module = mod;
			on_module_load(mod);
			break;
		
		case MODULE_STATE_GOING: /* the module is going to unload */
		/* if the target module has already been unloaded, 
		 * target_module is NULL, so (mod != target_module) will
		 * be true. */
			if(mod != target_module) break;
			
			on_module_unload(mod);
			target_module = NULL;
		}
	}

	mutex_unlock(&controller_mutex);
	return 0;
}
Exemple #3
0
void
tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
                                         const gchar    *uri,
                                         const gchar    *mime)
{
	GError *error = NULL;
	TrackerExtractPrivate *priv;
	TrackerExtractTask *task;
	TrackerExtractInfo *info;
	gboolean no_modules = TRUE;

	priv = TRACKER_EXTRACT_GET_PRIVATE (object);
	priv->disable_summary_on_finalize = TRUE;

	g_return_if_fail (uri != NULL);

	task = extract_task_new (object, uri, mime, NULL, NULL, NULL, &error);

	if (error) {
		g_printerr ("Extraction failed, %s\n", error->message);
		g_error_free (error);

		return;
	}

	task->mimetype_handlers = tracker_extract_module_manager_get_mimetype_handlers (task->mimetype);
	task->cur_module = tracker_mimetype_info_get_module (task->mimetype_handlers, &task->cur_func, NULL);

	while (task->cur_module && task->cur_func) {
		if (!filter_module (object, task->cur_module) &&
		    get_file_metadata (task, &info)) {
			const gchar *preupdate_str, *postupdate_str, *statements_str, *where;
			TrackerSparqlBuilder *builder;

			no_modules = FALSE;
			preupdate_str = statements_str = postupdate_str = NULL;

			builder = tracker_extract_info_get_metadata_builder (info);

			if (tracker_sparql_builder_get_length (builder) > 0) {
				statements_str = tracker_sparql_builder_get_result (builder);
			}

			builder = tracker_extract_info_get_preupdate_builder (info);

			if (tracker_sparql_builder_get_length (builder) > 0) {
				preupdate_str = tracker_sparql_builder_get_result (builder);
			}

			builder = tracker_extract_info_get_postupdate_builder (info);

			if (tracker_sparql_builder_get_length (builder) > 0) {
				postupdate_str = tracker_sparql_builder_get_result (builder);
			}

			where = tracker_extract_info_get_where_clause (info);

			g_print ("\n");

			g_print ("SPARQL pre-update:\n--\n%s--\n\n",
			         preupdate_str ? preupdate_str : "");
			g_print ("SPARQL item:\n--\n%s--\n\n",
			         statements_str ? statements_str : "");
			g_print ("SPARQL where clause:\n--\n%s--\n\n",
			         where ? where : "");
			g_print ("SPARQL post-update:\n--\n%s--\n\n",
			         postupdate_str ? postupdate_str : "");

			tracker_extract_info_unref (info);
			break;
		} else {
			if (!tracker_mimetype_info_iter_next (task->mimetype_handlers)) {
				break;
			}

			task->cur_module = tracker_mimetype_info_get_module (task->mimetype_handlers,
			                                                     &task->cur_func,
			                                                     NULL);
		}
	}

	if (no_modules) {
		g_print ("No modules found to handle metadata extraction\n\n");
	}

	extract_task_free (task);
}