00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _SEARCH_HH_
00019 #define _SEARCH_HH_
00020
00021 #include <vos/corelibs/vos/vos.hh>
00022 #include <vos/metaobjects/property/property.hh>
00023 #include <vos/metaobjects/misc/cod.hh>
00024
00025 #if defined(HAVE_BOOST_REGEX_H) && defined(HAVE_LIBBOOST_REGEX)
00026 # define BOOST_REGEX_NO_LIB 1
00027 # include <boost/regex.h>
00028 #else
00029 extern "C" {
00030 # include <regex.h>
00031 }
00032 #endif
00033
00034 #if defined(_WIN32) && defined(_MSC_VER)
00035 # ifdef MISC_EXPORTS
00036 # define MISC_API __declspec(dllexport)
00037 # else
00038 # define MISC_API __declspec(dllimport)
00039 # endif
00040 #else
00041 # define MISC_API
00042 #endif
00043
00044 class MISC_API CatchUpdatesFilter : public MessageFilter
00045 {
00046 public:
00047 string nonce;
00048 MessageBlock* mb;
00049 bool savechildren;
00050
00051 CatchUpdatesFilter(const string& n) : nonce(n), mb(new MessageBlock()), savechildren(false) { }
00052 ~CatchUpdatesFilter() { mb->release(); }
00053 virtual bool checkMessage(Message* m) {
00054 if(m->getNonce().substr(0, nonce.size()) == nonce) {
00055 if(m->getMethod() != "core:set-child-update"
00056 && m->getMethod() != "core:insert-child-update")
00057 {
00058 mb->insertMessage(-1, m);
00059 } else savechildren = true;
00060 return false;
00061 } else return true;
00062 }
00063 };
00064
00065
00066
00067
00068
00069
00070 class MISC_API Search : public virtual MetaObject
00071 {
00072
00073
00074 protected:
00075 PropertyAccessControl* accessControl;
00076
00077
00078 public:
00079
00080
00081 Search(MetaObject* superobject);
00082
00083
00084 virtual ~Search();
00085
00086
00087 virtual const string getType();
00088
00089
00090 static void registerExtenders();
00091
00092
00093 virtual void setPropertyAccessControl(PropertyAccessControl* ac);
00094
00095
00096 virtual PropertyAccessControl* getPropertyAccessControl();
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 };
00111
00112
00113
00114
00115 class MISC_API LocalSearch : public virtual Search
00116 {
00117 public:
00118
00119 struct PatternRule
00120 {
00121 regex_t typepattern;
00122 bool typePatternEmpty;
00123 bool negateChild;
00124 vector<regex_t> childpattern;
00125 vector<string> actions;
00126 string plaintext;
00127 };
00128
00129
00130 LocalSearch(MetaObject* superobject);
00131
00132
00133 virtual ~LocalSearch();
00134
00135
00136 virtual void initialize(PropertyAccessControl* ac);
00137
00138
00139
00140
00141
00142
00143 virtual void initialize();
00144
00145
00146 static MetaObject* new_LocalSearch(MetaObject* superobject, const string& type);
00147
00148 deque<PatternRule*> makeRules(Message* rules);
00149
00150 bool doActions(Vobject* currentobject,
00151 const deque<PatternRule*>& rules,
00152 const PatternRule& thisrule,
00153 RemoteCOD* cod,
00154 list<Vobject*>& touchedObjects);
00155
00156 bool actOnChildren(Vobject* currentobject,
00157 const deque<PatternRule*>& rules,
00158 const PatternRule& thisrule,
00159 int patternpart,
00160 RemoteCOD* cod,
00161 list<Vobject*>& touchedObjects);
00162
00163 void search(Vobject* currentobject,
00164 const deque<PatternRule*>& rules,
00165 RemoteCOD* cod,
00166 list<Vobject*>& touchedObjects);
00167
00168 protected:
00169
00170
00171
00172
00173
00174 virtual void handleSearch(Message* m);
00175
00176
00177
00178 int calledregex;
00179
00180 };
00181
00182
00183 class MISC_API SearchListener {
00184 public:
00185 virtual ~SearchListener() {}
00186 virtual void notifySearchDone() = 0;
00187 };
00188
00189
00190 class MISC_API RemoteSearch : public virtual Search
00191 {
00192 private:
00193 set<string> searches;
00194 map<string, SearchListener*> listeners;
00195
00196 public:
00197
00198
00199 RemoteSearch(MetaObject* superobject);
00200
00201
00202 virtual ~RemoteSearch();
00203
00204
00205 static MetaObject* new_RemoteSearch(MetaObject* superobject, const string& type);
00206
00207
00208 void sendUpdateMessage(Message *m);
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 string doSearch(const deque<string>& objects, const deque<string>& rules, bool async = false, RemoteCOD** cod = 0);
00258
00259
00260
00261
00262
00263
00264 string doSearch(const deque<string>& objects, const deque<string>& rules, SearchListener* listener);
00265
00266
00267
00268
00269 protected:
00270
00271
00272
00273
00274
00275 virtual void handleSearchDone(Message* m);
00276
00277
00278
00279 };
00280
00281
00282
00283
00284
00285 class SearchRules : public deque<string> {
00286 public:
00287 inline void addRule(string type, string name, string actions) {
00288 this->push_back(type);
00289 this->push_back(name);
00290 this->push_back(actions);
00291 }
00292 };
00293
00294 #endif // #ifdef _SEARCH_HH_
00295