1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * collectserver.h --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | * $Id: collectserver.h 9929 2005-05-23 04:18:43Z kjdon $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 |
|
---|
29 | #ifndef COLLECTSERVER_H
|
---|
30 | #define COLLECTSERVER_H
|
---|
31 |
|
---|
32 | // Library header files
|
---|
33 | #include "gsdlconf.h"
|
---|
34 | #include "text_t.h"
|
---|
35 | #include "comtypes.h"
|
---|
36 | #include "filter.h"
|
---|
37 | #include "source.h"
|
---|
38 | #include "cfgread.h"
|
---|
39 | #include "cnfgable.h"
|
---|
40 | #include "maptools.h"
|
---|
41 |
|
---|
42 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
43 | # include <ospace\std\iostream>
|
---|
44 | #elif defined(GSDL_USE_IOS_H)
|
---|
45 | # include <iostream.h>
|
---|
46 | #else
|
---|
47 | # include <iostream>
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
51 | # include <ospace\std\map>
|
---|
52 | #elif defined(GSDL_USE_STL_H)
|
---|
53 | # include <map.h>
|
---|
54 | #else
|
---|
55 | # include <map>
|
---|
56 | #endif
|
---|
57 |
|
---|
58 |
|
---|
59 | struct colservrconf {
|
---|
60 | text_t gsdlhome;
|
---|
61 | text_t gdbmhome;
|
---|
62 | text_t collection;
|
---|
63 | text_t collectdir;
|
---|
64 | };
|
---|
65 |
|
---|
66 |
|
---|
67 | class collectserver : public configurable {
|
---|
68 | protected:
|
---|
69 | colservrconf configinfo;
|
---|
70 | ColInfoResponse_t collectinfo;
|
---|
71 |
|
---|
72 | filtermapclass filters;
|
---|
73 | sourcelistclass sources;
|
---|
74 |
|
---|
75 | // some stuff to remember while we are configuring
|
---|
76 | stringmap indexmap;
|
---|
77 |
|
---|
78 | public:
|
---|
79 | collectserver ();
|
---|
80 | virtual ~collectserver ();
|
---|
81 |
|
---|
82 | // add_filter makes another filter available to the collection server
|
---|
83 | // the filter remains the property of the calling code and that
|
---|
84 | // code should destroy the filter after the collection server has been
|
---|
85 | // destroyed.
|
---|
86 | void add_filter (filterclass *thefilter) {filters.addfilter(thefilter);}
|
---|
87 | filtermapclass *get_filtermap_ptr () {return &filters;}
|
---|
88 |
|
---|
89 | // add_source makes another source available to the collection server
|
---|
90 | // the source remains the property of the calling code and that
|
---|
91 | // code should destroy the source after the collection server has been
|
---|
92 | // destroyed.
|
---|
93 | void add_source (sourceclass *thesource) {sources.addsource(thesource);}
|
---|
94 | sourcelistclass *get_sourcelist_ptr () {return &sources;}
|
---|
95 |
|
---|
96 | // configure should be called for each line in the
|
---|
97 | // configuration files to configure the collection server and everything
|
---|
98 | // it contains. The configuration should take place just before initialisation.
|
---|
99 | virtual void configure (const text_t &key, const text_tarray &cfgline);
|
---|
100 | void configure (const text_t &key, const text_t &value);
|
---|
101 | const colservrconf &get_configinfo () {return configinfo;}
|
---|
102 | text_t get_collection_name () {return configinfo.collection;}
|
---|
103 |
|
---|
104 | // ping indicates whether the collection has appropriate data structures
|
---|
105 | // to be active or not
|
---|
106 | void ping(bool &wasSuccess, comerror_t &err, ostream &logout);
|
---|
107 |
|
---|
108 | // init should be called after the collection name has been set and
|
---|
109 | // all initialisation is done. init returns true if the initialisation
|
---|
110 | // was successful, if false is returned then no other functions
|
---|
111 | // should be called (without producing meaningless output).
|
---|
112 | virtual bool init (ostream &logout);
|
---|
113 |
|
---|
114 | void get_collectinfo (ColInfoResponse_t &reponse,
|
---|
115 | comerror_t &err, ostream &logout);
|
---|
116 |
|
---|
117 | virtual void get_filterinfo (InfoFiltersResponse_t &response,
|
---|
118 | comerror_t &err, ostream &logout);
|
---|
119 |
|
---|
120 | virtual void get_filteroptions (const InfoFilterOptionsRequest_t &request,
|
---|
121 | InfoFilterOptionsResponse_t &response,
|
---|
122 | comerror_t &err, ostream &logout);
|
---|
123 |
|
---|
124 | virtual void filter (FilterRequest_t &request,
|
---|
125 | FilterResponse_t &response,
|
---|
126 | comerror_t &err, ostream &logout);
|
---|
127 |
|
---|
128 |
|
---|
129 | virtual void get_document (const DocumentRequest_t &request,
|
---|
130 | DocumentResponse_t &response,
|
---|
131 | comerror_t &err, ostream &logout);
|
---|
132 |
|
---|
133 | virtual void is_searchable (bool &issearchable, comerror_t &err,
|
---|
134 | ostream &logout);
|
---|
135 |
|
---|
136 | };
|
---|
137 |
|
---|
138 |
|
---|
139 | // The collectserverptr function does not 'own' the collectserver. The
|
---|
140 | // collectserver should be deleted by the code which created it.
|
---|
141 | class collectserverptr {
|
---|
142 | public:
|
---|
143 | collectserver *c;
|
---|
144 |
|
---|
145 | collectserverptr () {c=NULL;}
|
---|
146 | ~collectserverptr () {}
|
---|
147 | };
|
---|
148 |
|
---|
149 | bool operator==(const collectserverptr &x, const collectserverptr &y);
|
---|
150 | bool operator<(const collectserverptr &x, const collectserverptr &y);
|
---|
151 |
|
---|
152 | typedef map<text_t, collectserverptr, lttext_t> collectserverptrmap;
|
---|
153 |
|
---|
154 | // contains a list of collectservers indexed by their name
|
---|
155 | class collectservermapclass {
|
---|
156 | protected:
|
---|
157 | collectserverptrmap collectserverptrs;
|
---|
158 |
|
---|
159 | public:
|
---|
160 | // type support for collectserverptrmap
|
---|
161 | typedef collectserverptrmap::iterator iterator;
|
---|
162 | typedef collectserverptrmap::const_iterator const_iterator;
|
---|
163 | typedef collectserverptrmap::reference reference;
|
---|
164 | typedef collectserverptrmap::const_reference const_reference;
|
---|
165 | typedef collectserverptrmap::size_type size_type;
|
---|
166 |
|
---|
167 | typedef collectserverptrmap::difference_type difference_type;
|
---|
168 | typedef collectserverptrmap::const_reverse_iterator const_reverse_iterator;
|
---|
169 | typedef collectserverptrmap::reverse_iterator reverse_iterator;
|
---|
170 |
|
---|
171 | // basic container support
|
---|
172 | iterator begin () {return collectserverptrs.begin();}
|
---|
173 | const_iterator begin () const {return collectserverptrs.begin();}
|
---|
174 | iterator end () {return collectserverptrs.end();}
|
---|
175 | const_iterator end () const {return collectserverptrs.end();}
|
---|
176 |
|
---|
177 | void erase(iterator pos) {collectserverptrs.erase(pos);}
|
---|
178 | void erase(iterator first, iterator last) {collectserverptrs.erase(first, last);}
|
---|
179 | collectservermapclass &operator=(const collectservermapclass &x)
|
---|
180 | {collectserverptrs=x.collectserverptrs;return *this;}
|
---|
181 |
|
---|
182 | bool empty () const {return collectserverptrs.empty();}
|
---|
183 | size_type size() const {return collectserverptrs.size();}
|
---|
184 |
|
---|
185 |
|
---|
186 | // added functionality
|
---|
187 | void clear () {collectserverptrs.erase(collectserverptrs.begin(),collectserverptrs.end());}
|
---|
188 |
|
---|
189 | // thecollectserver remains the property of the calling code but
|
---|
190 | // should not be deleted until it is removed from this list.
|
---|
191 | void addcollectserver (collectserver *thecollectserver);
|
---|
192 |
|
---|
193 | // getcollectserver will return NULL if the collectserver could not be found
|
---|
194 | collectserver *getcollectserver (const text_t &collection);
|
---|
195 | };
|
---|
196 |
|
---|
197 |
|
---|
198 | #endif
|
---|