1 | // standard headers
|
---|
2 | #include <iostream.h>
|
---|
3 | #include <fstream.h>
|
---|
4 |
|
---|
5 | // protocol headers
|
---|
6 | #include "corbaiface.h"
|
---|
7 |
|
---|
8 | #include "corbaconv_text_t.h"
|
---|
9 |
|
---|
10 | // library headers
|
---|
11 | #include "fileutil.h"
|
---|
12 | #include "gsdlhome.h"
|
---|
13 |
|
---|
14 | // greenstone headers
|
---|
15 | #include "comtypes.h"
|
---|
16 | #include "recptproto.h"
|
---|
17 | #include "nullproto.h"
|
---|
18 |
|
---|
19 | // local headers
|
---|
20 | #include "corbatext_t.h"
|
---|
21 |
|
---|
22 | void corbatext_setToCorbaArray(text_tset set, corbatext_tset *cset);
|
---|
23 | void corbatext_corbaArrayToSet(corbatext_tset cset, text_tset *set);
|
---|
24 | void corbatext_mapToCorbaMap(text_tmap map, corbatext_tmap *tm);
|
---|
25 | void corbaresponse_resultDocInfoToCorba(ResultDocInfo_tarray docinfo, corbaResultDocInfo_array &corbainfo);
|
---|
26 |
|
---|
27 | void corbaresponse_termInfoToCorba(TermInfo_tarray terminfo, corbaTermInfo_array &corbainfo)
|
---|
28 | {
|
---|
29 | TermInfo_tarray::iterator here = terminfo.begin();
|
---|
30 | TermInfo_tarray::iterator end = terminfo.end();
|
---|
31 | unsigned int i;
|
---|
32 |
|
---|
33 | i = 0;
|
---|
34 |
|
---|
35 | while (here != end)
|
---|
36 | {
|
---|
37 | corbainfo.length(i+1);
|
---|
38 |
|
---|
39 | corbainfo[i].frequency = here->freq;
|
---|
40 | corbaconv_text_t::getCorbatext(here->term,corbainfo[i].term);
|
---|
41 | corbatext_arrayToCorbaArray(here->matchTerms, &corbainfo[i].matchTerms);
|
---|
42 |
|
---|
43 | i ++;
|
---|
44 | here ++;
|
---|
45 | }
|
---|
46 | cout << "Terminfo " << i << endl;
|
---|
47 | }
|
---|
48 |
|
---|
49 | void corbatext_optionValueArrayToC(corbaOptionValue_array corba, OptionValue_tarray &array)
|
---|
50 | {
|
---|
51 | unsigned int i = 0;
|
---|
52 | OptionValue_t option;
|
---|
53 |
|
---|
54 | for (i = 0; i < corba.length(); i ++)
|
---|
55 | {
|
---|
56 | corbaconv_text_t::setCorbatext(option.name,corba[i].name);
|
---|
57 | corbaconv_text_t::setCorbatext(option.value,corba[i].value);
|
---|
58 |
|
---|
59 | // cout << corbatext_string(corba[i].name) << "?" << option
|
---|
60 |
|
---|
61 | array.push_back(option);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | class corbaServer : virtual public corbaiface_skel
|
---|
66 | {
|
---|
67 | private:
|
---|
68 | text_tarray collections;
|
---|
69 | recptproto *protocol;
|
---|
70 | public:
|
---|
71 | corbaServer(recptproto *protocol)
|
---|
72 | {
|
---|
73 | cout << GSDL_GSDLHOME << endl;
|
---|
74 | if (!read_dir (GSDL_GSDLHOME "/collect", collections)) exit (1);
|
---|
75 | cout << "Constructing set list server" << endl;
|
---|
76 | this->protocol = protocol;
|
---|
77 | }
|
---|
78 |
|
---|
79 | CORBA::Boolean init()
|
---|
80 | {
|
---|
81 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
82 | int reply;
|
---|
83 |
|
---|
84 | reply = protocol->init(logout);
|
---|
85 | logout.close();
|
---|
86 | return (reply != 0 ? 1 : 0);
|
---|
87 | }
|
---|
88 |
|
---|
89 | void configure(const corbatext_t &corbaKey, const corbatext_tarray &corbaCfgline)
|
---|
90 | {
|
---|
91 | text_t key;
|
---|
92 | text_tarray cfgline;
|
---|
93 |
|
---|
94 | corbaconv_text_t::setCorbatext(key,corbaKey);
|
---|
95 | corbatext_corbaArrayToArray(corbaCfgline, &cfgline);
|
---|
96 |
|
---|
97 | protocol->configure(key, cfgline);
|
---|
98 | }
|
---|
99 |
|
---|
100 | void hasCollection(const corbatext_t &corbaCollect, CORBA::Boolean &has,
|
---|
101 | corbaComError &error) {
|
---|
102 | // do nowt!
|
---|
103 | corbaconv_text_t *cct;
|
---|
104 | bool _has;
|
---|
105 | comerror_t err;
|
---|
106 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
107 |
|
---|
108 | cct = new corbaconv_text_t(corbaCollect);
|
---|
109 |
|
---|
110 | cout << "Collection: " << cct->getcstr() << endl;
|
---|
111 |
|
---|
112 | protocol->has_collection(*cct, _has, err, logout); // 'cct' typecast to text_t
|
---|
113 | if (_has)
|
---|
114 | {
|
---|
115 | has = 1;
|
---|
116 | }
|
---|
117 | else
|
---|
118 | {
|
---|
119 | has = 0;
|
---|
120 | }
|
---|
121 |
|
---|
122 | cout << " " << has << endl;
|
---|
123 |
|
---|
124 | delete cct;
|
---|
125 |
|
---|
126 | error = corbaNoError;
|
---|
127 | logout.close();
|
---|
128 | }
|
---|
129 |
|
---|
130 | CORBA::Boolean ping(const struct corbatext_t &corbaCollect, corbaComError &corbaError)
|
---|
131 | {
|
---|
132 | text_t collection;
|
---|
133 | bool success;
|
---|
134 | comerror_t error;
|
---|
135 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
136 |
|
---|
137 |
|
---|
138 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
139 | protocol->ping(collection, success, error, logout);
|
---|
140 |
|
---|
141 | corbaError = (corbaComError) error;
|
---|
142 | logout.close();
|
---|
143 |
|
---|
144 | return success;
|
---|
145 | }
|
---|
146 |
|
---|
147 | void filter(const struct corbatext_t &corbaCollect,
|
---|
148 | const struct corbaFilterRequest &corbaRequest,
|
---|
149 | struct corbaFilterResponse &corbaResponse,
|
---|
150 | corbaComError &corbaError)
|
---|
151 | {
|
---|
152 | // variables for action
|
---|
153 | FilterRequest_t request;
|
---|
154 | FilterResponse_t response;
|
---|
155 | comerror_t error = noError;
|
---|
156 | text_t collection;
|
---|
157 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
158 |
|
---|
159 | // copy collection id
|
---|
160 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
161 |
|
---|
162 | // copy request values
|
---|
163 | corbaconv_text_t::setCorbatext(request.filterName,corbaRequest.filter);
|
---|
164 | corbatext_optionValueArrayToC(corbaRequest.filterOptions, request.filterOptions);
|
---|
165 | corbatext_corbaArrayToArray(corbaRequest.docSet, &request.docSet);
|
---|
166 | request.filterResultOptions = corbaRequest.filterResultOptions;
|
---|
167 | corbaconv_text_t::setCorbatext(request.requestParams,corbaRequest.requestParams);
|
---|
168 | corbaconv_text_t::setCorbatext(request.refParams,corbaRequest.refParams);
|
---|
169 | corbatext_corbaArrayToSet(corbaRequest.fields, &request.fields);
|
---|
170 | request.getParents = corbaRequest.getParents;
|
---|
171 |
|
---|
172 | protocol->filter(collection, request, response, error, logout);
|
---|
173 |
|
---|
174 | // copy response values
|
---|
175 | corbaResponse.numDocs = response.numDocs;
|
---|
176 | corbaResponse.isApprox = response.isApprox;
|
---|
177 | corbaresponse_termInfoToCorba(response.termInfo, corbaResponse.termInfo);
|
---|
178 | corbaresponse_resultDocInfoToCorba(response.docInfo, corbaResponse.docInfo);
|
---|
179 |
|
---|
180 | // tidy up variables
|
---|
181 | logout.close();
|
---|
182 | corbaError = (corbaComError) error;
|
---|
183 | cout << "Filter prepared" << corbaResponse.docInfo.length() << "," << corbaResponse.numDocs << endl;
|
---|
184 | }
|
---|
185 |
|
---|
186 | void getCollectInfo(const struct corbatext_t &corbaCollect,
|
---|
187 | corbaColInfoResponse &corbaResponse,
|
---|
188 | corbaComError &corbaError)
|
---|
189 | {
|
---|
190 | ColInfoResponse_t response;
|
---|
191 | comerror_t error;
|
---|
192 | text_t collection;
|
---|
193 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
194 |
|
---|
195 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
196 | protocol->get_collectinfo(collection, response, error, logout);
|
---|
197 |
|
---|
198 | corbaResponse.isPublic = response.isPublic;
|
---|
199 | corbaResponse.isBeta = response.isBeta;
|
---|
200 | corbaResponse.buildDate = response.buildDate;
|
---|
201 | corbatext_arrayToCorbaArray(response.languages, &corbaResponse.languages);
|
---|
202 | corbaResponse.numDocs = response.numDocs;
|
---|
203 | corbaResponse.numBytes = response.numWords;
|
---|
204 | corbaResponse.numWords = response.numBytes;
|
---|
205 |
|
---|
206 | corbatext_mapToCorbaMap(response.collectionmeta, &corbaResponse.collectionMeta);
|
---|
207 | corbatext_mapToCorbaMap(response.format, &corbaResponse.format);
|
---|
208 | corbatext_mapToCorbaMap(response.building, &corbaResponse.building);
|
---|
209 | corbaconv_text_t::getCorbatext(response.receptionist,corbaResponse.receptionist);
|
---|
210 |
|
---|
211 | logout.close();
|
---|
212 | corbaError = (corbaComError) error;
|
---|
213 | }
|
---|
214 |
|
---|
215 | void getFilterOptions(const struct corbatext_t &corbaCollect,
|
---|
216 | const struct corbatext_t &corbaFilterName,
|
---|
217 | struct corbaFilterOptionsResponse &corbaResponse,
|
---|
218 | enum corbaComError &corbaError)
|
---|
219 | {
|
---|
220 | text_t collection;
|
---|
221 | InfoFilterOptionsRequest_t request;
|
---|
222 | InfoFilterOptionsResponse_t response;
|
---|
223 | comerror_t error;
|
---|
224 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
225 | unsigned int i;
|
---|
226 |
|
---|
227 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
228 | corbaconv_text_t::setCorbatext(request.filterName,corbaFilterName);
|
---|
229 | protocol->get_filteroptions(collection, request, response, error, logout);
|
---|
230 |
|
---|
231 | // decode filters back into corba format
|
---|
232 | FilterOption_tmap::iterator here = response.filterOptions.begin();
|
---|
233 | FilterOption_tmap::iterator end = response.filterOptions.end();
|
---|
234 | i = 0;
|
---|
235 | while (here != end)
|
---|
236 | {
|
---|
237 | // set array for name/options to be one bigger
|
---|
238 | corbaResponse.names.length(i+1);
|
---|
239 | corbaResponse.options.length(i+1);
|
---|
240 |
|
---|
241 | // get left-hand side of map
|
---|
242 | corbaconv_text_t::getCorbatext((*here).first,corbaResponse.names[i]);
|
---|
243 |
|
---|
244 | // get right-hand side of map
|
---|
245 | corbaconv_text_t::getCorbatext((*here).second.name,corbaResponse.options[i].name);
|
---|
246 | corbaResponse.options[i].type = (*here).second.type;
|
---|
247 | corbaResponse.options[i].repeatable = (*here).second.repeatable;
|
---|
248 | corbaconv_text_t::getCorbatext((*here).second.defaultValue,corbaResponse.options[i].defaultValue);
|
---|
249 | corbatext_arrayToCorbaArray((*here).second.validValues, &corbaResponse.options[i].validValues);
|
---|
250 |
|
---|
251 | // take next iterators
|
---|
252 | i++;
|
---|
253 | here ++;
|
---|
254 | }
|
---|
255 |
|
---|
256 | logout.close();
|
---|
257 | corbaError = (corbaComError) error;
|
---|
258 | }
|
---|
259 |
|
---|
260 | void getFilterInfo(const struct corbatext_t &corbaCollect,
|
---|
261 | corbatext_tarray &filterNames,
|
---|
262 | enum corbaComError &corbaError)
|
---|
263 | { text_tarray ta;
|
---|
264 | comerror_t error = noError;
|
---|
265 | text_t collection;
|
---|
266 | InfoFiltersResponse_t response;
|
---|
267 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
268 |
|
---|
269 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
270 | cout << collection.getcstr() << endl;
|
---|
271 |
|
---|
272 | protocol->get_filterinfo(collection, response, error, logout);
|
---|
273 | corbatext_setToCorbaArray(response.filterNames, &filterNames);
|
---|
274 |
|
---|
275 | corbaError = (corbaComError) error;
|
---|
276 | logout.close();
|
---|
277 | }
|
---|
278 |
|
---|
279 | void getDocument(const struct corbatext_t &corbaCollection, struct corbaDocRequest &corbaRequest,
|
---|
280 | struct corbaDocResponse &corbaResponse, enum corbaComError &corbaError)
|
---|
281 | { DocumentRequest_t request;
|
---|
282 | DocumentResponse_t response;
|
---|
283 | comerror_t error = noError;
|
---|
284 | text_t collection;
|
---|
285 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
286 |
|
---|
287 | // set up request
|
---|
288 | corbaconv_text_t::setCorbatext(collection,corbaCollection);
|
---|
289 | corbaconv_text_t::setCorbatext(request.OID,corbaRequest.OID);
|
---|
290 | corbaconv_text_t::setCorbatext(request.docType,corbaRequest.docType);
|
---|
291 | corbaconv_text_t::setCorbatext(request.docFormat,corbaRequest.docFormat);
|
---|
292 |
|
---|
293 | // do actual get document
|
---|
294 | protocol->get_document(collection, request, response, error, logout);
|
---|
295 | corbaconv_text_t::getCorbatext(response.doc,corbaResponse.doc);
|
---|
296 |
|
---|
297 | // decode response
|
---|
298 | corbaError = (corbaComError) error;
|
---|
299 |
|
---|
300 | logout.close();
|
---|
301 | }
|
---|
302 |
|
---|
303 | void collectionList(corbatext_tarray &corbalist)
|
---|
304 | {
|
---|
305 | /* stringSeq *reply;
|
---|
306 | unsigned int i;
|
---|
307 | char *istring; */
|
---|
308 |
|
---|
309 | text_tarray collist;
|
---|
310 | comerror_t err;
|
---|
311 | ofstream logout(GSDL_GSDLHOME "/etc/corbaout.txt");
|
---|
312 |
|
---|
313 | protocol->get_collection_list(collist, err, logout);
|
---|
314 |
|
---|
315 | /* reply = new stringSeq(collections.size());
|
---|
316 |
|
---|
317 | (*reply).length(collections.size());
|
---|
318 | for (i = 0; i < collections.size(); i ++)
|
---|
319 | {
|
---|
320 | istring = collections[i].getcstr();
|
---|
321 | (*reply)[i] = CORBA::string_dup(istring);
|
---|
322 | delete istring;
|
---|
323 | }
|
---|
324 |
|
---|
325 | return reply;
|
---|
326 | */
|
---|
327 |
|
---|
328 | // cout << "Replying " << collist.size() << endl;
|
---|
329 |
|
---|
330 | corbatext_arrayToCorbaArray(collist, &corbalist);
|
---|
331 | cout << "Replying " << collist.size() << endl;
|
---|
332 |
|
---|
333 | logout.close();
|
---|
334 | // CORBA::string_dup(_listString);
|
---|
335 | }
|
---|
336 | };
|
---|
337 |
|
---|
338 | int main (int argc, char *argv[])
|
---|
339 | {
|
---|
340 | nullproto protocol;
|
---|
341 | collectset *cservers;
|
---|
342 | text_t gsdlhome;
|
---|
343 |
|
---|
344 | cservers = new collectset(gsdlhome);
|
---|
345 | protocol.set_collectset(cservers);
|
---|
346 |
|
---|
347 | cout << "Started Corba ..." << endl;
|
---|
348 |
|
---|
349 | // ORB initialization
|
---|
350 | CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "mico-local-orb" );
|
---|
351 | CORBA::BOA_var boa = orb->BOA_init( argc, argv, "mico-local-boa" );
|
---|
352 |
|
---|
353 | cout << "Initialised ORB and BOA" << endl;
|
---|
354 |
|
---|
355 | corbaServer* server = new corbaServer(&protocol);
|
---|
356 | CORBA::String_var ref = orb->object_to_string( server );
|
---|
357 |
|
---|
358 | cout << "Mapped Corba object to string" << endl;
|
---|
359 |
|
---|
360 | // write id to "naming service"
|
---|
361 | ofstream out ("/tmp/localcorba.objid");
|
---|
362 | out << ref << endl;
|
---|
363 | out.close ();
|
---|
364 |
|
---|
365 | // indicate readiness and run
|
---|
366 | boa->impl_is_ready( CORBA::ImplementationDef::_nil() );
|
---|
367 | orb->run ();
|
---|
368 | CORBA::release( server );
|
---|
369 | return 0;
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|