filters in order.
eg,
f = composite_filter_create(2, regex_filter, persistent_filter);
ownership of the filters passes, they will be destroyed when f's
destroy method is called.
device/dev-cache.c \
device/dev-io.c \
device/device.c \
+ display/display.c \
+ filters/filter-composite.c \
filters/filter-persistent.c \
filters/filter-regex.c \
- display/display.c \
filters/filter.c \
format1/disk-rep.c \
format1/format1.c \
--- /dev/null
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#include "filter-composite.h"
+#include "dbg_malloc.h"
+#include "log.h"
+
+#include <stdarg.h>
+
+static int _and_p(struct dev_filter *f, struct device *dev)
+{
+ struct dev_filter **filters = (struct dev_filter **) f->private;
+
+ while (*filters) {
+ if (!(*filters)->passes_filter(*filters, dev))
+ return 0;
+ filters++;
+ }
+
+ return 1;
+}
+
+void _destroy(struct dev_filter *f)
+{
+ struct dev_filter **filters = (struct dev_filter **) f->private;
+
+ while (*filters) {
+ (*filters)->destroy(*filters);
+ filters++;
+ }
+
+ dbg_free(f->private);
+}
+
+
+struct dev_filter *composite_filter_create(int n, ...)
+{
+ struct dev_filter **filters = dbg_malloc(sizeof(*filters) * (n + 1));
+ struct dev_filter *cf;
+ va_list ap;
+ int i;
+
+ if (!filters) {
+ stack;
+ return NULL;
+ }
+
+ if (!(cf = dbg_malloc(sizeof(*cf)))) {
+ stack;
+ dbg_free(filters);
+ return NULL;
+ }
+
+ va_start(ap, n);
+ for (i = 0; i < n; i++) {
+ struct dev_filter *f = va_arg(ap, struct dev_filter *);
+ filters[i] = f;
+ }
+ filters[i] = NULL;
+ va_end(ap);
+
+ cf->passes_filter = _and_p;
+ cf->destroy = _destroy;
+ cf->private = filters;
+
+ return cf;
+}
--- /dev/null
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#ifndef _LVM_FILTER_COMPOSITE_H
+#define _LVM_FILTER_COMPOSITE_H
+
+#include "dev-cache.h"
+
+struct dev_filter *composite_filter_create(int n, ...);
+
+#endif
#define PF_UNCHECKED ((void *) 1)
#define PF_CHECKED ((void *) 2)
-int _init_hash(struct pfilter *pf)
+static int _init_hash(struct pfilter *pf)
{
if (pf->devices)
hash_destroy(pf->devices);
return pf ? 1 : 0;
}
-int _load(struct pfilter *pf)
+static int _load(struct pfilter *pf)
{
int r = 0;
struct config_file *cf;
return r;
}
-int _dump(struct pfilter *pf)
+static int _dump(struct pfilter *pf)
{
int first = 1;
struct hash_node *n;
return 1;
}
-int _check(const char *path)
+static int _check(const char *path)
{
int fd = open(path, O_RDONLY), r = 0;
return r;
}
-int _init_valid_p(struct dev_filter *f, struct device *dev)
+static int _init_valid_p(struct dev_filter *f, struct device *dev)
{
struct pfilter *pf = (struct pfilter *) f->private;
void *l = hash_lookup(pf->devices, dev->name);
return 0;
}
-int _valid_p(struct dev_filter *f, struct device *dev)
+static int _valid_p(struct dev_filter *f, struct device *dev)
{
struct pfilter *pf = (struct pfilter *) f->private;
void *l = hash_lookup(pf->devices, dev->name);
return 1;
}
-void _destroy(struct dev_filter *f)
+static void _destroy(struct dev_filter *f)
{
struct pfilter *pf = (struct pfilter *) f->private;
*/
#ifndef _LVM_FILTER_PERSISTENT_H
-#define _LVM_FILTER_PERSISTENT_h
+#define _LVM_FILTER_PERSISTENT_H
#include "dev-cache.h"