diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-02-17 17:36:50 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-17 17:36:50 -0500 |
commit | 961e1f62d24469a0dce5768d683c35a255ab1a69 (patch) | |
tree | b101942f0e09b35fa48fd967e72419a1218202a3 | |
parent | 85da60357f4b515af1c7be362cf0465f65672fd6 (diff) |
parse-events: Add pevent_filter_copy()
Add pevent_filter_copy() to be able to copy one filter onto another.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | parse-events.h | 2 | ||||
-rw-r--r-- | parse-filter.c | 68 |
2 files changed, 68 insertions, 2 deletions
diff --git a/parse-events.h b/parse-events.h index 88b471b..6b69b26 100644 --- a/parse-events.h +++ b/parse-events.h | |||
@@ -615,4 +615,6 @@ int pevent_filter_event_has_trivial(struct event_filter *filter, | |||
615 | int event_id, | 615 | int event_id, |
616 | enum filter_trivial_type type); | 616 | enum filter_trivial_type type); |
617 | 617 | ||
618 | int pevent_filter_copy(struct event_filter *dest, struct event_filter *source); | ||
619 | |||
618 | #endif /* _PARSE_EVENTS_H */ | 620 | #endif /* _PARSE_EVENTS_H */ |
diff --git a/parse-filter.c b/parse-filter.c index c00aa7c..cabc181 100644 --- a/parse-filter.c +++ b/parse-filter.c | |||
@@ -853,6 +853,72 @@ void pevent_filter_free(struct event_filter *filter) | |||
853 | free(filter); | 853 | free(filter); |
854 | } | 854 | } |
855 | 855 | ||
856 | static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg); | ||
857 | |||
858 | static int copy_filter_type(struct event_filter *filter, | ||
859 | struct event_filter *source, | ||
860 | struct filter_type *filter_type) | ||
861 | { | ||
862 | struct filter_arg *arg; | ||
863 | struct event_format *event; | ||
864 | const char *sys; | ||
865 | const char *name; | ||
866 | char *str; | ||
867 | |||
868 | /* Can't assume that the pevent's are the same */ | ||
869 | sys = filter_type->event->system; | ||
870 | name = filter_type->event->name; | ||
871 | event = pevent_find_event_by_name(filter->pevent, sys, name); | ||
872 | if (!event) | ||
873 | return -1; | ||
874 | |||
875 | str = arg_to_str(source, filter_type->filter); | ||
876 | if (!str) | ||
877 | return -1; | ||
878 | |||
879 | if (strcmp(str, "TRUE") == 0 || strcmp(str, "FALSE") == 0) { | ||
880 | /* Add trivial event */ | ||
881 | arg = allocate_arg(); | ||
882 | arg->type = FILTER_ARG_BOOLEAN; | ||
883 | if (strcmp(str, "TRUE") == 0) | ||
884 | arg->bool.value = 1; | ||
885 | else | ||
886 | arg->bool.value = 0; | ||
887 | |||
888 | filter_type = add_filter_type(filter, event->id); | ||
889 | filter_type->filter = arg; | ||
890 | |||
891 | free(str); | ||
892 | return 0; | ||
893 | } | ||
894 | |||
895 | filter_event(filter, event, str, NULL); | ||
896 | free(str); | ||
897 | |||
898 | return 0; | ||
899 | } | ||
900 | |||
901 | /** | ||
902 | * pevent_filter_copy - copy a filter using another filter | ||
903 | * @dest - the filter to copy to | ||
904 | * @source - the filter to copy from | ||
905 | * | ||
906 | * Returns 0 on success and -1 if not all filters were copied | ||
907 | */ | ||
908 | int pevent_filter_copy(struct event_filter *dest, struct event_filter *source) | ||
909 | { | ||
910 | int i; | ||
911 | int ret = 0; | ||
912 | |||
913 | pevent_filter_reset(dest); | ||
914 | |||
915 | for (i = 0; i < source->filters; i++) { | ||
916 | if (copy_filter_type(dest, source, &source->event_filters[i])) | ||
917 | ret = -1; | ||
918 | } | ||
919 | return ret; | ||
920 | } | ||
921 | |||
856 | /** | 922 | /** |
857 | * pevent_filter_clear_trivial - clear TRUE and FALSE filters | 923 | * pevent_filter_clear_trivial - clear TRUE and FALSE filters |
858 | * @filter: the filter to remove trivial filters from | 924 | * @filter: the filter to remove trivial filters from |
@@ -1138,8 +1204,6 @@ int pevent_filter_match(struct event_filter *filter, | |||
1138 | FILTER_MATCH : FILTER_MISS; | 1204 | FILTER_MATCH : FILTER_MISS; |
1139 | } | 1205 | } |
1140 | 1206 | ||
1141 | static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg); | ||
1142 | |||
1143 | static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) | 1207 | static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) |
1144 | { | 1208 | { |
1145 | char *str = NULL; | 1209 | char *str = NULL; |