2
* filtertree.h - Filter tree topology and data propagation handling
3
* Copyright (C) 2011, D Haley
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
33
unsigned int cacheStrategy;
35
//!Maximum size for cache (percent of available ram).
36
float maxCachePercent;
38
//!Filters that provide and act upon datastreams.
39
tree<Filter *> filters;
42
//!Get the filter refresh seed points in tree, by examination of tree caches, block/emit of filters
44
void getFilterRefreshStarts(vector<tree<Filter *>::iterator > &propStarts) const;
47
//Retrieve the filter's pointer from its ID value
48
Filter* getFilterByIdNonConst(unsigned long long filterId) const;
51
//!Check that the output of filter refresh functions
52
void checkRefreshValidity(const vector< const FilterStreamData *> curData,
53
const Filter *refreshFilter) const;
57
//TODO: Move me to tree.hh
58
//!Returns true if the testChild is a child of testParent.
59
// returns false if testchild == testParent, or if the testParent
60
// is not a parent of testChild.
61
bool isChild(const tree<Filter *> &treeInst,
62
tree<Filter *>::iterator testParent,
63
tree<Filter *>::iterator testChild) const;
66
size_t countChildFilters(const tree<Filter *> &treeInst,
67
const vector<tree<Filter *>::iterator> &nodes) const;
72
FilterTree(const FilterTree &orig);
74
void swap(FilterTree &);
75
//Note that the = operator creates a *CLONE* of the orignal tree,
76
// not an exact duplicate. underlying pointers will not be the same
77
const FilterTree &operator=(const FilterTree &orig);
79
//Return iterator to tree contents begin.
80
tree<Filter *>::pre_order_iterator depthBegin() const { return filters.begin();};
81
//Return iterator to tree contents end
82
tree<Filter *>::pre_order_iterator depthEnd() const { return filters.end();}
83
//Return depth of a given iterator
84
size_t maxDepth() const;
86
size_t depth(const tree<Filter*>::pre_order_iterator &it) const
87
{ ASSERT(std::find(filters.begin(),filters.end(),*it)!=filters.end()); return filters.depth(it);};
89
//FIXME: REFACTOR: REMOVE ME
90
// We should NOT be granting this kind of access...
91
tree<Filter*> &getTree() { return filters;}
93
//!Return the number of filters
94
size_t size() const {return filters.size();};
96
//!Remove all tree contents
99
bool contains(const Filter *f) const;
103
//!Run the initialisation stage of the filter processing
104
void initFilterTree() const;
106
bool setFilterProperty(Filter *f, unsigned int set,
107
unsigned int key, const std::string &value, bool &needUpdate);
109
//!Refresh the entire filter tree. Whilst this is public, great care must be taken in
110
// deleting the filterstream data correctly. To do this, use the "safeDeleteFilterList" function.
111
unsigned int refreshFilterTree(
112
std::list<std::pair<Filter *, std::vector<const FilterStreamData * > > > &outData,
113
std::vector<SelectionDevice<Filter> *> &devices,std::vector<string> &consoleMessages,
114
ProgressData &curProg, bool (*callback)(bool));
116
//!Safely delete data generated by refreshFilterTree(...).
117
//a mask can be used to *prevent* STREAM_TYPE_blah from being deleted. Deleted items are removed from the list.
118
void safeDeleteFilterList(std::list<std::pair<Filter *, std::vector<const FilterStreamData * > > > &outData,
119
size_t typeMask, bool maskPrevents) const;
123
//!function for the loading of a filter tree from its XML representation
124
unsigned int loadXML(const xmlNodePtr &treeParent,
125
std::ostream &errStream, const std::string &stateDir);
128
//Write out the filters into their XML representation
129
bool saveXML(std::ofstream &f, std::map<string,string> &fileMapping,
130
bool writePackage, bool useRelativePaths, unsigned int minTabDepth=0) const;
133
//Topological alteration & examination functions
135
//!Remove an element and all sub elements from the tree,
136
void removeSubtree(Filter *f);
138
//!Add a new filter to the tree. Note that pointer will be released
139
// by filter destructor
140
void addFilter(Filter *f, const Filter *parent);
142
//!Add a new tree as a subtree to a node
143
void addFilterTree(FilterTree &f, const Filter *parent);
145
//!Move a branch of the tree to a new position
146
bool reparentFilter(Filter *f, const Filter *newParent);
147
//!Duplicate a branch of the tree to a new position. Do not copy cache,
148
bool copyFilter(Filter *id, const Filter *newParent);
150
//Obtain a copy of the filters in the specified subtree
151
void cloneSubtree(FilterTree &f,Filter *targetFilt) const;
155
//Filter alteration functions
157
//!Set the filter user text
158
bool setFilterString(Filter *, const std::string &s);
160
//!Invalidate the cache of a given Filter and all its children. set to 0 to clear all.
161
void clearCache(const Filter *filt);
164
//!Invalidate the cache of a given type of filter
165
// and all their children.
166
void clearCacheByType(unsigned int type);
168
//!Return all of a given type of filter from the filter tree
169
void getFiltersByType(std::vector<const Filter *> &filters, unsigned int type) const;
171
//!Make the filter system safe (non-hazardous)
172
void removeHazardousContents();
175
//!Used to remove potentially hazardous filters
176
//(filters that can do nasty things to computers, like executing commands)
177
//which may have come from unsafe sources
178
void stripHazardousContents();
180
//!return true if the tree contains hazardous filters
181
bool hasHazardousContents() const ;
183
//!Force a wipe of all caches in the filter tree
187
//!Returns true if any of the filters (incl. stash)
188
//return a state override (i.e. refer to external entities, such as files)
189
bool hasStateOverrides() const ;
191
bool hasUpdates() const ;
195
void setCachePercent(unsigned int newCache);