1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * recptproto.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 "recptproto.h"
|
---|
27 | #include <assert.h>
|
---|
28 |
|
---|
29 |
|
---|
30 | // configure should be called for each line in the configuration file
|
---|
31 | void recptproto::configure (const text_t &/*key*/, const text_tarray &/*cfgline*/) {
|
---|
32 | }
|
---|
33 |
|
---|
34 | // init should be called after the configuration but before any other
|
---|
35 | // functions are called. If init returns false a message will be written
|
---|
36 | // out to the log file and no other output should be produced.
|
---|
37 | bool recptproto::init (ostream &/*logout*/) {
|
---|
38 | return true;
|
---|
39 | }
|
---|
40 |
|
---|
41 | // get_protocol_name should return the name of this protocol (e.g. recptproto)
|
---|
42 | // that can be used to do run time type identification and display information
|
---|
43 | // about the protocol.
|
---|
44 | text_t recptproto::get_protocol_name () {
|
---|
45 | return "recptproto";
|
---|
46 | }
|
---|
47 |
|
---|
48 | // get_collection_list returns the list of collections that
|
---|
49 | // this protocol knows about
|
---|
50 | void recptproto::get_collection_list (text_tarray &collist, comerror_t &err,
|
---|
51 | ostream &/*logout*/) {
|
---|
52 | collist.erase(collist.begin(),collist.end());
|
---|
53 | err = noError;
|
---|
54 | }
|
---|
55 |
|
---|
56 | // has_collection sets 'hascollection' to be true if the protocol
|
---|
57 | // can communicate with the collection (i.e. it is within its
|
---|
58 | // collection list). This function should be implemented in as
|
---|
59 | // efficient time as possible as it will be called for each page
|
---|
60 | // access and for each protocol.
|
---|
61 | void recptproto::has_collection (const text_t &/*collection*/, bool &hascollection,
|
---|
62 | comerror_t &err, ostream &/*logout*/) {
|
---|
63 | hascollection = false;
|
---|
64 | err = noError;
|
---|
65 | }
|
---|
66 |
|
---|
67 | // sets 'wassuccess' to be true if a successful ping was done to
|
---|
68 | // the given collection.
|
---|
69 | void recptproto::ping (const text_t &/*collection*/, bool &wassuccess,
|
---|
70 | comerror_t &err, ostream &/*logout*/) {
|
---|
71 | wassuccess = false; // no collections are supported by this class
|
---|
72 | err = noError;
|
---|
73 | }
|
---|
74 |
|
---|
75 | // obtains general information about the collection
|
---|
76 | void recptproto::get_collectinfo (const text_t &/*collection*/,
|
---|
77 | ColInfoResponse_t &/*collectinfo*/,
|
---|
78 | comerror_t &err, ostream &/*logout*/) {
|
---|
79 | err = protocolError;
|
---|
80 | }
|
---|
81 |
|
---|
82 | // gets a list of all the filters
|
---|
83 | void recptproto::get_filterinfo (const text_t &/*collection*/,
|
---|
84 | InfoFiltersResponse_t &/*reponse*/,
|
---|
85 | comerror_t &err, ostream &/*logout*/) {
|
---|
86 | err = protocolError;
|
---|
87 | }
|
---|
88 |
|
---|
89 | // gets all the filter options for a particular filter
|
---|
90 | void recptproto::get_filteroptions (const text_t &/*collection*/,
|
---|
91 | const InfoFilterOptionsRequest_t &/*request*/,
|
---|
92 | InfoFilterOptionsResponse_t &/*response*/,
|
---|
93 | comerror_t &err, ostream &/*logout*/) {
|
---|
94 | err = protocolError;
|
---|
95 | }
|
---|
96 |
|
---|
97 | // filters (search or browse) a result set
|
---|
98 | void recptproto::filter (const text_t &/*collection*/,
|
---|
99 | FilterRequest_t &/*request*/,
|
---|
100 | FilterResponse_t &/*response*/,
|
---|
101 | comerror_t &err, ostream &/*logout*/) {
|
---|
102 | err = protocolError;
|
---|
103 | }
|
---|
104 |
|
---|
105 | void recptproto::get_document (const text_t &/*collection*/,
|
---|
106 | const DocumentRequest_t &/*request*/,
|
---|
107 | DocumentResponse_t &/*response*/,
|
---|
108 | comerror_t &err, ostream &/*logout*/) {
|
---|
109 | err = protocolError;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | // therecptproto remains the property of the calling code but
|
---|
119 | // should not be deleted until it is removed from this list.
|
---|
120 | void recptprotolistclass::addrecptproto (recptproto *therecptproto) {
|
---|
121 | // can't add a protocol that doesn't exist
|
---|
122 | assert (therecptproto != NULL);
|
---|
123 | if (therecptproto == NULL) return;
|
---|
124 |
|
---|
125 | recptprotoptr rpp;
|
---|
126 | rpp.p = therecptproto;
|
---|
127 |
|
---|
128 | recptprotoptrs.push_back(rpp);
|
---|
129 | }
|
---|
130 |
|
---|
131 | // getrecptproto will return NULL if a recptproto for the given colelction
|
---|
132 | // could not be found
|
---|
133 | recptproto *recptprotolistclass::getrecptproto (const text_t &collection,
|
---|
134 | ostream &logout) {
|
---|
135 | iterator here = recptprotoptrs.begin ();
|
---|
136 | iterator end = recptprotoptrs.end ();
|
---|
137 | bool hascollection;
|
---|
138 | comerror_t err;
|
---|
139 |
|
---|
140 | while (here != end) {
|
---|
141 | assert ((*here).p != NULL);
|
---|
142 | if ((*here).p != NULL) {
|
---|
143 | (*here).p->has_collection (collection, hascollection, err, logout);
|
---|
144 | if ((err == noError) && (hascollection == true)) return (*here).p;
|
---|
145 | }
|
---|
146 |
|
---|
147 | here++;
|
---|
148 | }
|
---|
149 |
|
---|
150 | return NULL;
|
---|
151 | }
|
---|