source: trunk/gsdl/src/recpt/nullproto.cpp@ 1474

Last change on this file since 1474 was 1459, checked in by sjboddie, 24 years ago

Did some tidying up of destructor functions as a result of a few hours
spent playing with ccmalloc

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/**********************************************************************
2 *
3 * nullproto.cpp --
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#include "nullproto.h"
27#include "colservrconfig.h"
28#include <assert.h>
29
30nullproto::~nullproto() {
31 collectservermapclass::iterator here = cservers.begin();
32 collectservermapclass::iterator end = cservers.end();
33
34 while (here != end) {
35 if ((*here).second.c != NULL) {
36 delete (*here).second.c;
37 }
38 here ++;
39 }
40 cservers.clear();
41}
42
43// this configure will configure each of the collection servers
44void nullproto::configure (const text_t &key, const text_tarray &cfgline) {
45 // the naming of the collection should not be done here,
46 // it should be done just after the collection server has been
47 // created
48 if (key == "collection" || key == "collectdir") return;
49
50 collectservermapclass::iterator here = cservers.begin();
51 collectservermapclass::iterator end = cservers.end();
52
53 while (here != end) {
54 assert ((*here).second.c != NULL);
55 if ((*here).second.c != NULL) {
56 if (key == "collectinfo") {
57 if ((*here).first == cfgline[0]) {
58 (*here).second.c->configure ("gsdlhome", cfgline[1]);
59 (*here).second.c->configure ("gdbmhome", cfgline[2]);
60 }
61 } else {
62 (*here).second.c->configure (key, cfgline);
63 }
64 }
65
66 here++;
67 }
68}
69
70// this init will configure and init each of the collection servers
71bool nullproto::init (ostream &logout) {
72 collectservermapclass::iterator here = cservers.begin();
73 collectservermapclass::iterator end = cservers.end();
74
75 while (here != end) {
76 assert ((*here).second.c != NULL);
77 if ((*here).second.c != NULL) {
78 const colservrconf &configinfo = (*here).second.c->get_configinfo ();
79 bool failed = false;
80
81 // configure this collection server
82
83 // note that we read build.cfg before collect.cfg so that the indexmaps
84 // are available to decode defaultindex, defaultsubcollection, and
85 // defaultlanguage
86 if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
87 configinfo.collection)) {
88 outconvertclass text_t2ascii;
89 logout << text_t2ascii
90 << "Warning: couldn't read build.cfg file for collection \"" //****
91 << configinfo.collection << "\", gsdlhome=\""
92 << configinfo.gsdlhome << "\"\n";
93 failed = true;
94 }
95
96 if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
97 configinfo.collection)) {
98 outconvertclass text_t2ascii;
99 logout << text_t2ascii
100 << "Warning: couldn't read collect.cfg file for collection \""
101 << configinfo.collection << "\", gsdlhome=\""
102 << configinfo.gsdlhome << "\"\n";
103 failed = true;
104 }
105
106 // don't bother initializing if one of the config files
107 // wasn't read correctly
108 if (!failed) {
109 if (!(*here).second.c->init (logout)) return false;
110 }
111 }
112 here++;
113 }
114
115 return true;
116}
117
118text_t nullproto::get_protocol_name () {
119 return "nullproto";
120}
121
122
123void nullproto::get_collection_list (text_tarray &collist, comerror_t &err,
124 ostream &/*logout*/) {
125 collist.erase(collist.begin(),collist.end());
126 err = noError;
127
128 collectservermapclass::iterator here = cservers.begin();
129 collectservermapclass::iterator end = cservers.end();
130 while (here != end) {
131 assert ((*here).second.c != NULL);
132 if ((*here).second.c != NULL) {
133 collist.push_back ((*here).second.c->get_collection_name());
134 }
135 here++;
136 }
137}
138
139void nullproto::has_collection (const text_t &collection, bool &hascollection,
140 comerror_t &err, ostream &/*logout*/) {
141 hascollection = (cservers.getcollectserver(collection) != NULL);
142 err = noError;
143}
144
145void nullproto::ping (const text_t &collection, bool &wassuccess,
146 comerror_t &err, ostream &/*logout*/) {
147 wassuccess = (cservers.getcollectserver(collection) != NULL);
148 err = noError;
149}
150
151void nullproto::get_collectinfo (const text_t &collection,
152 ColInfoResponse_t &collectinfo,
153 comerror_t &err, ostream &logout) {
154 collectserver *cserver = cservers.getcollectserver (collection);
155 if (cserver != NULL) cserver->get_collectinfo (collectinfo, err, logout);
156 else err = protocolError;
157}
158
159
160void nullproto::get_filterinfo (const text_t &collection,
161 InfoFiltersResponse_t &response,
162 comerror_t &err, ostream &logout) {
163 collectserver *cserver = cservers.getcollectserver (collection);
164 if (cserver != NULL) cserver->get_filterinfo (response, err, logout);
165 else err = protocolError;
166}
167
168void nullproto::get_filteroptions (const text_t &collection,
169 const InfoFilterOptionsRequest_t &request,
170 InfoFilterOptionsResponse_t &response,
171 comerror_t &err, ostream &logout) {
172 collectserver *cserver = cservers.getcollectserver (collection);
173 if (cserver != NULL) cserver->get_filteroptions (request, response, err, logout);
174 else err = protocolError;
175}
176
177void nullproto::filter (const text_t &collection,
178 FilterRequest_t &request,
179 FilterResponse_t &response,
180 comerror_t &err, ostream &logout) {
181 collectserver *cserver = cservers.getcollectserver (collection);
182 if (cserver != NULL) cserver->filter (request, response, err, logout);
183 else err = protocolError;
184}
185
186void nullproto::get_document (const text_t &collection,
187 const DocumentRequest_t &request,
188 DocumentResponse_t &response,
189 comerror_t &err, ostream &logout) {
190 collectserver *cserver = cservers.getcollectserver (collection);
191 if (cserver != NULL) cserver->get_document (request, response, err, logout);
192 else err = protocolError;
193}
Note: See TracBrowser for help on using the repository browser.