[166] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * collectserver.h --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[534] | 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.
|
---|
[166] | 9 | *
|
---|
[534] | 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 | *
|
---|
[1860] | 24 | * $Id: collectserver.h 1860 2001-01-25 18:26:45Z cs025 $
|
---|
| 25 | *
|
---|
[166] | 26 | *********************************************************************/
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | #ifndef COLLECTSERVER_H
|
---|
| 30 | #define COLLECTSERVER_H
|
---|
| 31 |
|
---|
[1860] | 32 | // Library header files
|
---|
[166] | 33 | #include "gsdlconf.h"
|
---|
| 34 | #include "text_t.h"
|
---|
| 35 | #include "comtypes.h"
|
---|
[226] | 36 | #include "filter.h"
|
---|
| 37 | #include "source.h"
|
---|
[804] | 38 | #include "cfgread.h"
|
---|
[1860] | 39 | #include "cnfgable.h"
|
---|
[166] | 40 |
|
---|
| 41 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 42 | # include <ospace\std\iostream>
|
---|
| 43 | #elif defined(GSDL_USE_IOS_H)
|
---|
| 44 | # include <iostream.h>
|
---|
| 45 | #else
|
---|
| 46 | # include <iostream>
|
---|
| 47 | #endif
|
---|
| 48 |
|
---|
| 49 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 50 | # include <ospace\std\map>
|
---|
| 51 | #elif defined(GSDL_USE_STL_H)
|
---|
| 52 | # include <map.h>
|
---|
| 53 | #else
|
---|
| 54 | # include <map>
|
---|
| 55 | #endif
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | struct colservrconf {
|
---|
| 59 | text_t gsdlhome;
|
---|
[804] | 60 | text_t gdbmhome;
|
---|
[166] | 61 | text_t collection;
|
---|
| 62 | text_t collectdir;
|
---|
| 63 | };
|
---|
| 64 |
|
---|
[191] | 65 |
|
---|
[1860] | 66 | class collectserver : public configurable {
|
---|
[166] | 67 | protected:
|
---|
| 68 | colservrconf configinfo;
|
---|
| 69 | ColInfoResponse_t collectinfo;
|
---|
[196] | 70 |
|
---|
[226] | 71 | filtermapclass filters;
|
---|
| 72 | sourcelistclass sources;
|
---|
| 73 |
|
---|
[166] | 74 | public:
|
---|
| 75 | collectserver ();
|
---|
| 76 | virtual ~collectserver ();
|
---|
| 77 |
|
---|
[226] | 78 | // add_filter makes another filter available to the collection server
|
---|
| 79 | // the filter remains the property of the calling code and that
|
---|
| 80 | // code should destroy the filter after the collection server has been
|
---|
| 81 | // destroyed.
|
---|
| 82 | void add_filter (filterclass *thefilter) {filters.addfilter(thefilter);}
|
---|
| 83 | filtermapclass *get_filtermap_ptr () {return &filters;}
|
---|
| 84 |
|
---|
| 85 | // add_source makes another source available to the collection server
|
---|
| 86 | // the source remains the property of the calling code and that
|
---|
| 87 | // code should destroy the source after the collection server has been
|
---|
| 88 | // destroyed.
|
---|
| 89 | void add_source (sourceclass *thesource) {sources.addsource(thesource);}
|
---|
| 90 | sourcelistclass *get_sourcelist_ptr () {return &sources;}
|
---|
| 91 |
|
---|
[166] | 92 | // configure should be called for each line in the
|
---|
| 93 | // configuration files to configure the collection server and everything
|
---|
| 94 | // it contains. The configuration should take place just before initialisation.
|
---|
| 95 | virtual void configure (const text_t &key, const text_tarray &cfgline);
|
---|
| 96 | void configure (const text_t &key, const text_t &value);
|
---|
| 97 | const colservrconf &get_configinfo () {return configinfo;}
|
---|
| 98 | text_t get_collection_name () {return configinfo.collection;}
|
---|
| 99 |
|
---|
| 100 | // init should be called after the collection name has been set and
|
---|
| 101 | // all initialisation is done. init returns true if the initialisation
|
---|
| 102 | // was successful, if false is returned then no other functions
|
---|
| 103 | // should be called (without producing meaningless output).
|
---|
| 104 | virtual bool init (ostream &logout);
|
---|
| 105 |
|
---|
[186] | 106 | void get_collectinfo (ColInfoResponse_t &reponse,
|
---|
| 107 | comerror_t &err, ostream &logout);
|
---|
| 108 |
|
---|
[220] | 109 | virtual void get_filterinfo (InfoFiltersResponse_t &response,
|
---|
| 110 | comerror_t &err, ostream &logout);
|
---|
| 111 |
|
---|
| 112 | virtual void get_filteroptions (const InfoFilterOptionsRequest_t &request,
|
---|
| 113 | InfoFilterOptionsResponse_t &response,
|
---|
[186] | 114 | comerror_t &err, ostream &logout);
|
---|
| 115 |
|
---|
[249] | 116 | virtual void filter (FilterRequest_t &request,
|
---|
[186] | 117 | FilterResponse_t &response,
|
---|
| 118 | comerror_t &err, ostream &logout);
|
---|
[259] | 119 |
|
---|
| 120 |
|
---|
| 121 | virtual void get_document (const DocumentRequest_t &request,
|
---|
| 122 | DocumentResponse_t &response,
|
---|
| 123 | comerror_t &err, ostream &logout);
|
---|
| 124 |
|
---|
[166] | 125 | };
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | // The collectserverptr function does not 'own' the collectserver. The
|
---|
| 129 | // collectserver should be deleted by the code which created it.
|
---|
| 130 | class collectserverptr {
|
---|
| 131 | public:
|
---|
| 132 | collectserver *c;
|
---|
| 133 |
|
---|
| 134 | collectserverptr () {c=NULL;}
|
---|
[492] | 135 | ~collectserverptr () {}
|
---|
[166] | 136 | };
|
---|
| 137 |
|
---|
[492] | 138 | bool operator==(const collectserverptr &x, const collectserverptr &y);
|
---|
| 139 | bool operator<(const collectserverptr &x, const collectserverptr &y);
|
---|
| 140 |
|
---|
[166] | 141 | typedef map<text_t, collectserverptr, lttext_t> collectserverptrmap;
|
---|
| 142 |
|
---|
| 143 | // contains a list of collectservers indexed by their name
|
---|
| 144 | class collectservermapclass {
|
---|
| 145 | protected:
|
---|
| 146 | collectserverptrmap collectserverptrs;
|
---|
| 147 |
|
---|
| 148 | public:
|
---|
| 149 | // type support for collectserverptrmap
|
---|
| 150 | typedef collectserverptrmap::iterator iterator;
|
---|
| 151 | typedef collectserverptrmap::const_iterator const_iterator;
|
---|
| 152 | typedef collectserverptrmap::reference reference;
|
---|
| 153 | typedef collectserverptrmap::const_reference const_reference;
|
---|
| 154 | typedef collectserverptrmap::size_type size_type;
|
---|
| 155 |
|
---|
| 156 | typedef collectserverptrmap::difference_type difference_type;
|
---|
| 157 | typedef collectserverptrmap::const_reverse_iterator const_reverse_iterator;
|
---|
| 158 | typedef collectserverptrmap::reverse_iterator reverse_iterator;
|
---|
| 159 |
|
---|
| 160 | // basic container support
|
---|
| 161 | iterator begin () {return collectserverptrs.begin();}
|
---|
| 162 | const_iterator begin () const {return collectserverptrs.begin();}
|
---|
| 163 | iterator end () {return collectserverptrs.end();}
|
---|
| 164 | const_iterator end () const {return collectserverptrs.end();}
|
---|
| 165 |
|
---|
| 166 | void erase(iterator pos) {collectserverptrs.erase(pos);}
|
---|
| 167 | void erase(iterator first, iterator last) {collectserverptrs.erase(first, last);}
|
---|
| 168 | collectservermapclass &operator=(const collectservermapclass &x)
|
---|
| 169 | {collectserverptrs=x.collectserverptrs;return *this;}
|
---|
| 170 |
|
---|
| 171 | bool empty () const {return collectserverptrs.empty();}
|
---|
| 172 | size_type size() const {return collectserverptrs.size();}
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | // added functionality
|
---|
| 176 | void clear () {collectserverptrs.erase(collectserverptrs.begin(),collectserverptrs.end());}
|
---|
| 177 |
|
---|
| 178 | // thecollectserver remains the property of the calling code but
|
---|
| 179 | // should not be deleted until it is removed from this list.
|
---|
| 180 | void addcollectserver (collectserver *thecollectserver);
|
---|
| 181 |
|
---|
| 182 | // getcollectserver will return NULL if the collectserver could not be found
|
---|
| 183 | collectserver *getcollectserver (const text_t &collection);
|
---|
| 184 | };
|
---|
| 185 |
|
---|
| 186 |
|
---|
| 187 | #endif
|
---|