source: gsdl/trunk/src/protocol/recptproto.h@ 15450

Last change on this file since 15450 was 15450, checked in by mdewsnip, 16 years ago

(Untangling colservr/recpt) Created a new src/protocol directory, and moved the recptproto and nullproto classes into it.

File size: 6.8 KB
Line 
1/**********************************************************************
2 *
3 * recptproto.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 *********************************************************************/
25
26
27#ifndef RECPTPROTO_H
28#define RECPTPROTO_H
29
30#include "gsdlconf.h"
31#include "text_t.h"
32#include "comtypes.h"
33
34#if defined(GSDL_USE_OBJECTSPACE)
35# include <ospace\std\vector>
36#elif defined(GSDL_USE_STL_H)
37# include <vector.h>
38#else
39# include <vector>
40#endif
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
51// recptproto is a generalisation of a protocol for communicating
52// with a collection server.
53class recptproto {
54public:
55
56 // add collection server to protocol
57 virtual void add_collection (const text_t &collection, void *recpt,
58 const text_t &gsdlhome, const text_t &gdbmhome);
59
60 virtual void remove_collection (const text_t &collection, ostream &logout);
61
62 // configure should be called for each line in the configuration file
63 virtual void configure (const text_t &key, const text_tarray &cfgline, comerror_t &err);
64
65 // init should be called after the configuration but before any other
66 // functions are called. If init returns false a message will be written
67 // out to the log file and no other output should be produced.
68 virtual bool init (comerror_t &err, ostream &logout);
69
70 // get_site_name should return the name of the site used.
71 // This is trivially empty in the case of a null protocol. If a remote
72 // connection to a site is being used then this should return the name
73 // used to label a site
74 virtual text_t get_site_name(comerror_t &err);
75
76 // get_protocol_name should return the name of this protocol (e.g. recptproto)
77 // that can be used to do run time type identification and display information
78 // about the protocol.
79 virtual text_t get_protocol_name (comerror_t &err);
80
81 // get_collection_list returns the list of collections that
82 // this protocol knows about
83 virtual void get_collection_list (text_tarray &collist, comerror_t &err,
84 ostream &logout);
85
86 // has_collection sets 'hascollection' to be true if the protocol
87 // can communicate with the collection (i.e. it is within its
88 // collection list). This function should be implemented in as
89 // efficient time as possible as it will be called for each page
90 // access and for each protocol.
91 virtual void has_collection (const text_t &collection, bool &hascollection,
92 comerror_t &err, ostream &logout);
93
94 // sets 'wassuccess' to be true if a successful ping was done to
95 // the given collection.
96 virtual void ping (const text_t &collection, bool &wassuccess,
97 comerror_t &err, ostream &logout);
98
99 // obtains general information about the collection
100 virtual void get_collectinfo (const text_t &collection,
101 ColInfoResponse_t &collectinfo,
102 comerror_t &err, ostream &logout);
103
104 // gets a list of all the filters
105 virtual void get_filterinfo (const text_t &collection,
106 InfoFiltersResponse_t &response,
107 comerror_t &err, ostream &logout);
108
109 // gets all the filter options for a particular filter
110 virtual void get_filteroptions (const text_t &collection,
111 const InfoFilterOptionsRequest_t &request,
112 InfoFilterOptionsResponse_t &response,
113 comerror_t &err, ostream &logout);
114
115 // filters (search or browse) a result set and returns information
116 // about the filtered set including term frequency information and
117 // metadata
118 virtual void filter (const text_t &collection,
119 FilterRequest_t &request,
120 FilterResponse_t &response,
121 comerror_t &err, ostream &logout);
122
123 // gets a document (duh!)
124 virtual void get_document (const text_t &collection,
125 const DocumentRequest_t &request,
126 DocumentResponse_t &response,
127 comerror_t &err, ostream &logout);
128
129 virtual void is_searchable (const text_t &collection, bool &issearchable,
130 comerror_t &err, ostream &logout);
131
132};
133
134
135// The recptprotoptr function does not 'own' the recptproto. The
136// recptproto should be deleted by the code which created it.
137class recptprotoptr {
138public:
139 recptproto *p;
140
141 recptprotoptr () {p=NULL;}
142 ~recptprotoptr () {}
143};
144
145typedef vector<recptprotoptr> recptprotoptrlist;
146
147
148// contains a list of recptprotos
149class recptprotolistclass {
150protected:
151 recptprotoptrlist recptprotoptrs;
152
153public:
154 // type support for recptprotolistclass
155 typedef recptprotoptrlist::iterator iterator;
156 typedef recptprotoptrlist::const_iterator const_iterator;
157 typedef recptprotoptrlist::reference reference;
158 typedef recptprotoptrlist::const_reference const_reference;
159 typedef recptprotoptrlist::size_type size_type;
160
161 typedef recptprotoptrlist::difference_type difference_type;
162 typedef recptprotoptrlist::const_reverse_iterator const_reverse_iterator;
163 typedef recptprotoptrlist::reverse_iterator reverse_iterator;
164
165 // basic container support
166 iterator begin () {return recptprotoptrs.begin();}
167 const_iterator begin () const {return recptprotoptrs.begin();}
168 iterator end () {return recptprotoptrs.end();}
169 const_iterator end () const {return recptprotoptrs.end();}
170
171 void erase(iterator pos) {recptprotoptrs.erase(pos);}
172 void erase(iterator first, iterator last) {recptprotoptrs.erase(first, last);}
173 recptprotolistclass &operator=(const recptprotolistclass &x)
174 {recptprotoptrs=x.recptprotoptrs;return *this;}
175
176 bool empty () const {return recptprotoptrs.empty();}
177 size_type size() const {return recptprotoptrs.size();}
178
179
180 // added functionality
181 void clear () {recptprotoptrs.erase(recptprotoptrs.begin(),recptprotoptrs.end());}
182
183 // therecptproto remains the property of the calling code but
184 // should not be deleted until it is removed from this list.
185 void addrecptproto (recptproto *therecptproto);
186
187 // getrecptproto will return NULL if a recptproto for the given collection
188 // could not be found
189 recptproto *getrecptproto (const text_t &collection, ostream &logout);
190};
191
192
193#endif
Note: See TracBrowser for help on using the repository browser.