#include <ltt/ltt.h>
#include <ltt/event.h>
-#define AVERAGE_EXPRESSION_LENGTH 6
-#define MAX_FACTOR 1.5
/* A filter expression consists in nested AND, OR and NOT expressions
involving boolean relation (>, >=, =, !=, <, <=) between event fields and
*/
-extern GQuark
+/**
+ * @enum LttvFieldType
+ * @brief Structures and their fields
+ *
+ * the LttvFieldType enum consists on
+ * all the hardcoded structures and
+ * their appropriate fields on which
+ * filters can be applied.
+ */
+enum _LttvFieldType {
LTTV_FILTER_TRACE,
LTTV_FILTER_TRACESET,
LTTV_FILTER_TRACEFILE,
LTTV_FILTER_EX_MODE,
LTTV_FILTER_EX_SUBMODE,
LTTV_FILTER_P_STATUS,
- LTTV_FILTER_CPU;
+ LTTV_FILTER_CPU
+} LttvFieldType;
/**
- * @enum lttv_expression_op
+ * @enum LttvExpressionOp
*/
-typedef enum _lttv_expression_op
+typedef enum _LttvExpressionOp
{
- LTTV_FIELD_EQ, /** equal */
- LTTV_FIELD_NE, /** not equal */
- LTTV_FIELD_LT, /** lower than */
- LTTV_FIELD_LE, /** lower or equal */
- LTTV_FIELD_GT, /** greater than */
- LTTV_FIELD_GE /** greater or equal */
-} lttv_expression_op;
-
-typedef enum _lttv_expression_type
-{
- LTTV_EXPRESSION,
- LTTV_SIMPLE_EXPRESSION,
- LTTV_EXPRESSION_OP,
- LTTV_UNDEFINED_EXPRESSION
-} lttv_expression_type;
-
-typedef enum _lttv_tree_element {
- LTTV_TREE_IDLE,
- LTTV_TREE_NODE,
- LTTV_TREE_LEAF
-} lttv_tree_element;
-
-typedef struct _lttv_simple_expression
+ LTTV_FIELD_EQ, /** equal */
+ LTTV_FIELD_NE, /** not equal */
+ LTTV_FIELD_LT, /** lower than */
+ LTTV_FIELD_LE, /** lower or equal */
+ LTTV_FIELD_GT, /** greater than */
+ LTTV_FIELD_GE /** greater or equal */
+} LttvExpressionOp;
+
+/**
+ * @enum LttvTreeElement
+ * @brief element types for the tree nodes
+ *
+ * LttvTreeElement defines the possible
+ * types of nodes which build the LttvFilterTree.
+ */
+typedef enum _LttvTreeElement {
+ LTTV_TREE_IDLE, /** this node does nothing */
+ LTTV_TREE_NODE, /** this node contains a logical operator */
+ LTTV_TREE_LEAF /** this node is a leaf and contains a simple expression */
+} LttvTreeElement;
+
+/**
+ * @enum LttvSimpleExpression
+ * @brief simple expression structure
+ *
+ * An LttvSimpleExpression is the base
+ * of all filtering operations. It also
+ * populates the leaves of the
+ * LttvFilterTree. Each expression
+ * consists basically in a structure
+ * field, an operator and a specific
+ * value.
+ */
+typedef struct _LttvSimpleExpression
{
char *field_name;
- lttv_expression_op op;
+// LttvExpressionOp op;
+ gboolean (*op)();
char *value;
-} lttv_simple_expression;
+} LttvSimpleExpression;
-typedef enum _lttv_logical_op {
+/**
+ * @enum LttvLogicalOp
+ * @brief logical operators
+ *
+ * Contains the possible values taken
+ * by logical operator used to link
+ * simple expression. Values are
+ * AND, OR, XOR or NOT
+ */
+typedef enum _LttvLogicalOp {
LTTV_LOGICAL_OR = 1, /* 1 */
LTTV_LOGICAL_AND = 1<<1, /* 2 */
LTTV_LOGICAL_NOT = 1<<2, /* 4 */
LTTV_LOGICAL_XOR = 1<<3 /* 8 */
-} lttv_logical_op;
+} LttvLogicalOp;
-/*
- * Ah .. that's my tree
+/**
+ * @struct LttvFilterTree
+ * The filtering tree is used to represent the
+ * expression string in its entire hierarchy
+ * composed of simple expressions and logical
+ * operators
*/
-//typedef struct _lttv_expression
-//{
-// gboolean simple_expression;
-// int op;
-// lttv_expression_type type;
-// union {
-// struct lttv_expression *e;
- // lttv_field_relation *se; /* --> simple expression */
-// } e;
-//} lttv_expression;
-
-typedef struct _lttv_expression {
- lttv_expression_type type;
- union {
- lttv_simple_expression *se;
- int op;
- } e;
-} lttv_expression;
-
-typedef struct _lttv_filter_tree {
-// lttv_expression* node;
- int node;
- lttv_tree_element left;
- lttv_tree_element right;
+typedef struct _LttvFilterTree {
+ int node; /** value of LttvLogicalOp */
+ LttvTreeElement left;
+ LttvTreeElement right;
union {
- struct lttv_filter_tree* t;
- lttv_simple_expression* leaf;
+ struct LttvFilter* t;
+ LttvSimpleExpression* leaf;
} l_child;
union {
- struct lttv_filter_tree* t;
- lttv_simple_expression* leaf;
+ struct LttvFilter* t;
+ LttvSimpleExpression* leaf;
} r_child;
-} lttv_filter_tree;
+} LttvFilterTree;
/**
* @struct lttv_filter
- * ( will later contain a binary tree of filtering options )
+ * Contains a binary tree of filtering options along
+ * with the expression itself.
+ */
+typedef struct _LttvFilter {
+ char *expression;
+ LttvFilterTree *head;
+} LttvFilter;
+
+/*
+ * General Data Handling functions
*/
-typedef struct _lttv_filter_t {
- lttv_filter_tree* tree;
-} lttv_filter_t;
+LttvSimpleExpression* lttv_simple_expression_new();
-lttv_simple_expression* lttv_simple_expression_new();
+void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilterTree* subtree, LttvLogicalOp op);
-lttv_filter_tree* lttv_filter_tree_new();
+gboolean parse_field_path(GPtrArray* fp);
-void lttv_filter_tree_destroy(lttv_filter_tree* tree);
+gboolean parse_simple_expression(GString* expression);
-lttv_filter* lttv_filter_clone(lttv_filter* tree);
+/*
+ * Logical operators functions
+ */
-void lttv_filter_tree_add_node(GPtrArray* stack, lttv_filter_tree* subtree, lttv_logical_op op);
+gboolean lttv_apply_op_eq_uint64();
+gboolean lttv_apply_op_eq_uint32();
+gboolean lttv_apply_op_eq_uint16();
+gboolean lttv_apply_op_eq_double();
+gboolean lttv_apply_op_eq_string();
+
+gboolean lttv_apply_op_ne_uint64();
+gboolean lttv_apply_op_ne_uint32();
+gboolean lttv_apply_op_ne_uint16();
+gboolean lttv_apply_op_ne_double();
+gboolean lttv_apply_op_ne_string();
+
+gboolean lttv_apply_op_lt_uint64();
+gboolean lttv_apply_op_lt_uint32();
+gboolean lttv_apply_op_lt_uint16();
+gboolean lttv_apply_op_lt_double();
+
+gboolean lttv_apply_op_le_uint64();
+gboolean lttv_apply_op_le_uint32();
+gboolean lttv_apply_op_le_uint16();
+gboolean lttv_apply_op_le_double();
+
+gboolean lttv_apply_op_gt_uint64();
+gboolean lttv_apply_op_gt_uint32();
+gboolean lttv_apply_op_gt_uint16();
+gboolean lttv_apply_op_gt_double();
+
+gboolean lttv_apply_op_ge_uint64();
+gboolean lttv_apply_op_ge_uint32();
+gboolean lttv_apply_op_ge_uint16();
+gboolean lttv_apply_op_ge_double();
-/* Parse field path contained in list */
-gboolean parse_field_path(GPtrArray* fp);
+/*
+ * Cloning
+ */
-gboolean parse_simple_expression(GString* expression);
+LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree* tree);
-/* Compile the filter expression into an efficient data structure */
-lttv_filter_tree *lttv_filter_new(char *expression, LttvTraceState *tfs);
+LttvFilter* lttv_filter_clone(LttvFilter* filter);
-void lttv_filter_destroy(lttv_filter* filter);
+/*
+ * Constructors/Destructors
+ */
+
+/* LttvFilter */
+LttvFilter *lttv_filter_new(char *expression, LttvTraceState *tfs);
+
+void lttv_filter_destroy(LttvFilter* filter);
+
+/* LttvFilterTree */
+LttvFilterTree* lttv_filter_tree_new();
+
+void lttv_filter_tree_destroy(LttvFilterTree* tree);
+
+
+/*
+ * Hook functions
+ *
+ * These hook functions will be the one called when filtering
+ * an event, a trace, a state, etc.
+ */
/* Check if the tracefile or event satisfies the filter. The arguments are
declared as void * to allow these functions to be used as hooks. */
-gboolean lttv_filter_tracefile(lttv_filter_tree *filter, LttTracefile *tracefile);
+gboolean lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile);
-gboolean lttv_filter_tracestate(lttv_filter_t *filter, LttvTraceState *tracestate);
+gboolean lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate);
-gboolean lttv_filter_event(lttv_filter_t *filter, LttEvent *event);
+gboolean lttv_filter_event(LttvFilter *filter, LttEvent *event);
#endif // FILTER_H