filter core:
[lttv.git] / ltt / branches / poly / lttv / modules / text / textFilter.c
index 5729634e2e9a7de705ec325cbb637503d47c9d1f..f8a2ea4533ba92b25d09fbf317a39f9d114debac 100644 (file)
  *  - why does this module need dependency with batchAnalysis ?
  */
 
+/*
+ *  TODO
+ *  - specify wich hook function will be used to call the core filter
+ */
+
 static char 
   *a_file_name = NULL,
   *a_string = NULL;
 
-static GString
-  *a_filter_string = NULL;
-
-
 static LttvHooks
   *before_traceset,
   *event_hook;
 
 static FILE *a_file;
 
-
 /**
  * filters the file input from user
  * @param hook_data the hook data
@@ -68,27 +68,36 @@ void filter_analyze_file(void *hook_data) {
 
   g_print("textFilter::filter_analyze_file\n");
  
+  LttvAttributeValue value;
+
+  LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+
   /*
         *      User may specify filtering options through static file
         *      and/or command line string.  From these sources, an 
         *      option string is rebuilded and sent to the filter core
         */
-       a_file = fopen(a_file_name, "r"); 
+  GString* a_file_content = g_string_new("");
+  a_file = fopen(a_file_name, "r"); 
        if(a_file == NULL) { 
                g_warning("file %s does not exist", a_file_name);
     return;
   }
   
-  char* tmp;
-  fscanf(a_file,"%s",tmp);
-    
-  if(!a_filter_string->len) {
-    g_string_append(a_filter_string,tmp);
-  }
-  else {
-    g_string_append(a_filter_string,"&"); /*conjonction between expression*/
-    g_string_append(a_filter_string,tmp);
+  char* line = NULL;
+  size_t len = 0;
+
+  while(!feof(a_file)) {
+    len = getline(&line,&len,a_file);
+    g_string_append(a_file_content,line);
   }
+  free(line);
+  
+  g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
+      LTTV_POINTER, &value));
+
+  if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
+  g_string_append((GString*)*(value.v_pointer),a_file_content->str);
   
   fclose(a_file);
 }
@@ -102,33 +111,33 @@ void filter_analyze_string(void *hook_data) {
 
   g_print("textFilter::filter_analyze_string\n");
 
-  a_filter_string = g_string_new("");
+  LttvAttributeValue value;
+
+  LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+  
   /*
         *      User may specify filtering options through static file
         *      and/or command line string.  From these sources, an 
         *      option string is rebuilded and sent to the filter core
         */
-//  if(!a_filter_string->len) {
+/*  if(a_filter_string==NULL) {
+    a_filter_string = g_string_new("");
     g_string_append(a_filter_string,a_string);
-    lttv_filter_new(a_filter_string->str,NULL);
-//  }
-//  else {
-//    g_string_append(a_filter_string,"&"); /*conjonction between expression*/
-//    g_string_append(a_filter_string,a_string);
-//  }
-
-}
+  }
+  else {
+    g_string_append(a_filter_string,"&"); 
+    g_string_append(a_filter_string,a_string);
+  }
+*/
+  
+  g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
+      LTTV_POINTER, &value));
 
-/**
- * filter to current event depending on the 
- * filter options tree
- * @param hook_data the hook data
- * @param call_data the call data
- * @return success/error of operation
- */
-static gboolean filter_event_content(void *hook_data, void *call_data) {
+  if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
+  g_string_append((GString*)*(value.v_pointer),a_string);
 
-       g_print("textFilter::filter_event_content\n");  /* debug */
+//  LttvFilter* filter = lttv_filter_new();
+//  lttv_filter_append_expression(filter,a_string);
 }
 
 /**
@@ -138,16 +147,19 @@ static void init() {
   
   g_print("textFilter::init()\n");     /* debug */
 
-  a_filter_string = g_string_new("");
-  
   LttvAttributeValue value;
 
   LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
 
-  g_info("Init textFilter.c");
+  g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
+      LTTV_POINTER, &value));
   
+  *(value.v_pointer) = g_string_new("");
+
+  g_info("Init textFilter.c");
   a_string = NULL;
-  lttv_option_add("string", 's', 
+  lttv_option_add("expression", 'e', 
       "filters a string issued by the user on the command line", 
       "string", 
       LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL);
@@ -158,23 +170,7 @@ static void init() {
       "browse the filter options contained in specified file", 
       "file name", 
       LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL);
-  
-  /*
-   *   Note to myself !
-   *   LttvAttributeValue::v_pointer is a gpointer* --> void**
-   *   see union LttvAttributeValue for more info 
-   */
-  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
-      LTTV_POINTER, &value));
-  g_assert((event_hook = *(value.v_pointer)) != NULL);
-  lttv_hooks_add(event_hook, filter_event_content, NULL, LTTV_PRIO_DEFAULT);
-
-//  g_assert(lttv_iattribute_find_by_path(attributes,"hooks/trace/before",
-//     LTTV_POINTER, &value));
-//  g_assert((before_traceset = *(value.v_pointer)) != NULL);
-//  lttv_hooks_add(before_traceset, parse_filter_options, NULL, LTTV_PRIO_DEFAULT);
 
-  
 }
 
 /**
@@ -183,18 +179,23 @@ static void init() {
 static void destroy() {
   g_info("Destroy textFilter");
 
-  lttv_option_remove("string");
+  lttv_option_remove("expression");
 
   lttv_option_remove("filename");
 
-  lttv_hooks_remove_data(event_hook, filter_event_content, NULL);
+  LttvAttributeValue value;
+
+  LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
 
-//  lttv_hooks_remove_data(before_traceset, parse_filter_options, NULL);
+  g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
+      LTTV_POINTER, &value));
+  g_string_free((GString*)*(value.v_pointer),TRUE);
   
 }
 
 
 LTTV_MODULE("textFilter", "Filters traces", \
            "Filter the trace following commands issued by user input", \
-           init, destroy, "batchAnalysis", "option")
+           init, destroy, "option")
 
This page took 0.02521 seconds and 4 git commands to generate.