1 | // Standard headers
|
---|
2 | #include <iostream.h>
|
---|
3 | #include <fstream.h>
|
---|
4 |
|
---|
5 | // protocol headers
|
---|
6 | #include "corbaiface.h"
|
---|
7 | using namespace gsdlInterface;
|
---|
8 |
|
---|
9 | #include "corbaconv_text_t.h"
|
---|
10 |
|
---|
11 | // library headers
|
---|
12 | #include "fileutil.h"
|
---|
13 | //#include "gsdlhome.h"
|
---|
14 |
|
---|
15 | // greenstone headers
|
---|
16 | #include "comtypes.h"
|
---|
17 | #include "recptproto.h"
|
---|
18 | #include "nullproto.h"
|
---|
19 |
|
---|
20 | // local headers
|
---|
21 | #include "corbatext_t.h"
|
---|
22 |
|
---|
23 | void corbatext_setToCorbaArray(text_tset set, corbatext_tset *cset);
|
---|
24 | void corbatext_corbaArrayToSet(corbatext_tset cset, text_tset *set);
|
---|
25 | void corbatext_mapToCorbaMap(text_tmap map, corbatext_tmap *tm);
|
---|
26 | void corbaresponse_resultDocInfoToCorba(ResultDocInfo_tarray docinfo, corbaResultDocInfo_array &corbainfo);
|
---|
27 |
|
---|
28 | void corbaresponse_termInfoToCorba(TermInfo_tarray terminfo, corbaTermInfo_array &corbainfo) {
|
---|
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 | text_t gsdlhome;
|
---|
71 |
|
---|
72 | void openLogfile(text_t extension, ofstream &out)
|
---|
73 | {
|
---|
74 | char *cfilename;
|
---|
75 | text_t filename;
|
---|
76 |
|
---|
77 | filename = filename_cat(gsdlhome, extension);
|
---|
78 | cfilename = filename.getcstr();
|
---|
79 |
|
---|
80 | out.open(cfilename);
|
---|
81 | delete cfilename;
|
---|
82 | }
|
---|
83 |
|
---|
84 | public:
|
---|
85 | corbaServer(recptproto *protocol, text_t home)
|
---|
86 | {
|
---|
87 | text_t dirname;
|
---|
88 | char * cdirname;
|
---|
89 |
|
---|
90 | cout << "CorbaServer: gsdlhome = " << home << endl;
|
---|
91 |
|
---|
92 | this->gsdlhome = home;
|
---|
93 | cout << gsdlhome.getcstr() << endl;
|
---|
94 | dirname = filename_cat(gsdlhome, "/collect");
|
---|
95 | cdirname = dirname.getcstr();
|
---|
96 | if (!read_dir (cdirname, collections)) {
|
---|
97 | cout << "Unable to read the gsdl directory; terminating" << endl;
|
---|
98 | exit (1);
|
---|
99 | }
|
---|
100 | delete cdirname;
|
---|
101 |
|
---|
102 | cout << "Constructing set list server" << endl;
|
---|
103 | this->protocol = protocol;
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 | CORBA::Boolean initialise(corbaComError &err)
|
---|
108 | {
|
---|
109 | ofstream logout;
|
---|
110 | int reply;
|
---|
111 | comerror_t error = noError;
|
---|
112 |
|
---|
113 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
114 | reply = protocol->init(error, logout);
|
---|
115 | logout.close();
|
---|
116 | return (reply != 0 ? 1 : 0);
|
---|
117 | }
|
---|
118 |
|
---|
119 | void configure(const corbatext_t &corbaKey, const corbatext_tarray &corbaCfgline,corbaComError &err)
|
---|
120 | {
|
---|
121 | text_t key;
|
---|
122 | text_tarray cfgline;
|
---|
123 | comerror_t error = noError;
|
---|
124 |
|
---|
125 | corbaconv_text_t::setCorbatext(key,corbaKey);
|
---|
126 | corbatext_corbaArrayToArray(corbaCfgline, &cfgline);
|
---|
127 |
|
---|
128 |
|
---|
129 | // ****
|
---|
130 | cout << "Recieved " << key << " = ";
|
---|
131 | for (int unsigned i=0; i<cfgline.size(); i++)
|
---|
132 | {
|
---|
133 | cout << cfgline[i] << " ";
|
---|
134 | }
|
---|
135 | cout << endl;
|
---|
136 |
|
---|
137 | // DB // ****
|
---|
138 | if (key=="gsdlhome")
|
---|
139 | {
|
---|
140 | text_tarray cfgline;
|
---|
141 | cfgline.push_back (gsdlhome);
|
---|
142 | cout << "Changing gsdlhome to " << gsdlhome << endl;
|
---|
143 | protocol->configure(key, cfgline, error);
|
---|
144 | }
|
---|
145 | else if (key=="httpdomain")
|
---|
146 | {
|
---|
147 | // Only let gsdlhome through !!!! // ****
|
---|
148 | cout << "Supressing httpdomain" << endl;
|
---|
149 | }
|
---|
150 | else if (key=="httpprefix")
|
---|
151 | {
|
---|
152 | cout << "Supressing httpprefix" << endl;
|
---|
153 | }
|
---|
154 | else
|
---|
155 | {
|
---|
156 | protocol->configure(key, cfgline,error);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | void hasCollection(const corbatext_t &corbaCollect, CORBA::Boolean &has,
|
---|
161 | corbaComError &error) {
|
---|
162 | // do nowt!
|
---|
163 | corbaconv_text_t *cct;
|
---|
164 | bool _has;
|
---|
165 | comerror_t err = noError;
|
---|
166 | ofstream logout;
|
---|
167 |
|
---|
168 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
169 |
|
---|
170 | cct = new corbaconv_text_t(corbaCollect);
|
---|
171 |
|
---|
172 | cout << "Collection: " << cct->getcstr() << endl;
|
---|
173 |
|
---|
174 | protocol->has_collection(*cct, _has, err, logout); // 'cct' typecast to text_t
|
---|
175 | if (_has)
|
---|
176 | {
|
---|
177 | has = 1;
|
---|
178 | }
|
---|
179 | else
|
---|
180 | {
|
---|
181 | has = 0;
|
---|
182 | }
|
---|
183 |
|
---|
184 | // cout << " " << has << endl;
|
---|
185 |
|
---|
186 | delete cct;
|
---|
187 |
|
---|
188 | error = corbaNoError;
|
---|
189 | logout.close();
|
---|
190 | }
|
---|
191 |
|
---|
192 | void ping(const struct corbatext_t &corbaCollect, CORBA::Boolean &wasSuccess, corbaComError &corbaError)
|
---|
193 | {
|
---|
194 | text_t collection;
|
---|
195 | bool success;
|
---|
196 | comerror_t error = noError;
|
---|
197 | ofstream logout;
|
---|
198 |
|
---|
199 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
200 |
|
---|
201 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
202 | protocol->ping(collection, success, error, logout);
|
---|
203 |
|
---|
204 | corbaError = (corbaComError) error;
|
---|
205 | wasSuccess = (CORBA::Boolean) success;
|
---|
206 | logout.close();
|
---|
207 | }
|
---|
208 |
|
---|
209 | void filter(const struct corbatext_t &corbaCollect,
|
---|
210 | const struct corbaFilterRequest &corbaRequest,
|
---|
211 | struct corbaFilterResponse &corbaResponse,
|
---|
212 | corbaComError &corbaError)
|
---|
213 | {
|
---|
214 | // variables for action
|
---|
215 | FilterRequest_t request;
|
---|
216 | FilterResponse_t response;
|
---|
217 | comerror_t error = noError;
|
---|
218 | text_t collection;
|
---|
219 | ofstream logout;
|
---|
220 |
|
---|
221 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
222 |
|
---|
223 | // copy collection id
|
---|
224 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
225 |
|
---|
226 | // copy request values
|
---|
227 | corbaconv_text_t::setCorbatext(request.filterName,corbaRequest.filter);
|
---|
228 | corbatext_optionValueArrayToC(corbaRequest.filterOptions, request.filterOptions);
|
---|
229 | corbatext_corbaArrayToArray(corbaRequest.docSet, &request.docSet);
|
---|
230 | request.filterResultOptions = corbaRequest.filterResultOptions;
|
---|
231 | corbaconv_text_t::setCorbatext(request.requestParams,corbaRequest.requestParams);
|
---|
232 | corbaconv_text_t::setCorbatext(request.refParams,corbaRequest.refParams);
|
---|
233 | corbatext_corbaArrayToSet(corbaRequest.fields, &request.fields);
|
---|
234 | request.getParents = corbaRequest.getParents;
|
---|
235 |
|
---|
236 | protocol->filter(collection, request, response, error, logout);
|
---|
237 |
|
---|
238 | // copy response values
|
---|
239 | corbaResponse.numDocs = response.numDocs;
|
---|
240 | corbaResponse.isApprox = (::gsdlInterface::corbaIsApprox) response.isApprox;
|
---|
241 | corbaresponse_termInfoToCorba(response.termInfo, corbaResponse.termInfo);
|
---|
242 | corbaresponse_resultDocInfoToCorba(response.docInfo, corbaResponse.docInfo);
|
---|
243 |
|
---|
244 | // tidy up variables
|
---|
245 | logout.close();
|
---|
246 | corbaError = (corbaComError) error;
|
---|
247 | cout << "Filter prepared" << corbaResponse.docInfo.length() << "," << corbaResponse.numDocs << endl;
|
---|
248 | }
|
---|
249 |
|
---|
250 | void getCollectInfo(const struct corbatext_t &corbaCollect,
|
---|
251 | corbaColInfoResponse &corbaResponse,
|
---|
252 | corbaComError &corbaError)
|
---|
253 | {
|
---|
254 | ColInfoResponse_t response;
|
---|
255 | comerror_t error = noError;
|
---|
256 | text_t collection;
|
---|
257 | ofstream logout;
|
---|
258 |
|
---|
259 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
260 |
|
---|
261 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
262 | protocol->get_collectinfo(collection, response, error, logout);
|
---|
263 |
|
---|
264 | cout << "IsPublic = " << ((response.isPublic)?"True":"False") << endl;
|
---|
265 | cout << "IsBeta = " << ((response.isBeta) ?"True":"False") << endl;
|
---|
266 | cout << "BuildDate = " << response.buildDate << endl;
|
---|
267 | cout << "NumDocs = " << response.numDocs << endl;
|
---|
268 | cout << "NumBytes = " << response.numBytes << endl;
|
---|
269 | cout << "NumWords = " << response.numWords << endl;
|
---|
270 |
|
---|
271 | corbaResponse.isPublic = response.isPublic;
|
---|
272 | corbaResponse.isBeta = response.isBeta;
|
---|
273 | corbaResponse.buildDate = response.buildDate;
|
---|
274 | corbatext_arrayToCorbaArray(response.languages, &corbaResponse.languages);
|
---|
275 | corbatext_arrayToCorbaArray(response.ccsCols, &corbaResponse.ccsCols);
|
---|
276 | corbaResponse.numDocs = response.numDocs;
|
---|
277 | corbaResponse.numBytes = response.numBytes;
|
---|
278 | corbaResponse.numWords = response.numWords;
|
---|
279 |
|
---|
280 | corbatext_mapToCorbaMap(response.collectionmeta, &corbaResponse.collectionMeta);
|
---|
281 | corbatext_mapToCorbaMap(response.format, &corbaResponse.format);
|
---|
282 | corbatext_mapToCorbaMap(response.building, &corbaResponse.building);
|
---|
283 | corbaconv_text_t::getCorbatext(response.httpdomain,corbaResponse.httpdomain);
|
---|
284 |
|
---|
285 | corbaconv_text_t::getCorbatext(response.httpprefix,corbaResponse.httpprefix);
|
---|
286 | corbaconv_text_t::getCorbatext(response.receptionist,corbaResponse.receptionist);
|
---|
287 |
|
---|
288 | /* text_tmap::iterator f_here = response.format.begin();
|
---|
289 | text_tmap::iterator f_end = response.format.end();
|
---|
290 | while (f_here!=f_end)
|
---|
291 | {
|
---|
292 | cout << "**** format: " << f_here->first << " = " << f_here->second << endl;
|
---|
293 | f_here++;
|
---|
294 | }
|
---|
295 | */ // ****
|
---|
296 |
|
---|
297 | logout.close();
|
---|
298 | corbaError = (corbaComError) error;
|
---|
299 | }
|
---|
300 |
|
---|
301 | void getFilterOptions(const struct corbatext_t &corbaCollect,
|
---|
302 | const struct corbatext_t &corbaFilterName,
|
---|
303 | struct corbaFilterOptionsResponse &corbaResponse,
|
---|
304 | enum corbaComError &corbaError)
|
---|
305 | {
|
---|
306 | text_t collection;
|
---|
307 | InfoFilterOptionsRequest_t request;
|
---|
308 | InfoFilterOptionsResponse_t response;
|
---|
309 | comerror_t error = noError;
|
---|
310 | unsigned int i;
|
---|
311 | ofstream logout;
|
---|
312 |
|
---|
313 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
314 |
|
---|
315 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
316 | corbaconv_text_t::setCorbatext(request.filterName,corbaFilterName);
|
---|
317 | protocol->get_filteroptions(collection, request, response, error, logout);
|
---|
318 |
|
---|
319 | // decode filters back into corba format
|
---|
320 | FilterOption_tmap::iterator here = response.filterOptions.begin();
|
---|
321 | FilterOption_tmap::iterator end = response.filterOptions.end();
|
---|
322 | i = 0;
|
---|
323 | while (here != end)
|
---|
324 | {
|
---|
325 | // set array for name/options to be one bigger
|
---|
326 | corbaResponse.names.length(i+1);
|
---|
327 | corbaResponse.options.length(i+1);
|
---|
328 |
|
---|
329 | // get left-hand side of map
|
---|
330 | corbaconv_text_t::getCorbatext((*here).first,corbaResponse.names[i]);
|
---|
331 |
|
---|
332 | // get right-hand side of map
|
---|
333 | corbaconv_text_t::getCorbatext((*here).second.name,corbaResponse.options[i].name);
|
---|
334 | corbaResponse.options[i].type =
|
---|
335 | (::gsdlInterface::corbaFilterType)(*here).second.type;
|
---|
336 | corbaResponse.options[i].repeatable =
|
---|
337 | (::gsdlInterface::corbaFilterRepeatable)(*here).second.repeatable;
|
---|
338 | corbaconv_text_t::getCorbatext((*here).second.defaultValue,corbaResponse.options[i].defaultValue);
|
---|
339 | corbatext_arrayToCorbaArray((*here).second.validValues, &corbaResponse.options[i].validValues);
|
---|
340 |
|
---|
341 | // take next iterators
|
---|
342 | i++;
|
---|
343 | here ++;
|
---|
344 | }
|
---|
345 |
|
---|
346 | logout.close();
|
---|
347 | corbaError = (corbaComError) error;
|
---|
348 | }
|
---|
349 |
|
---|
350 | void getFilterInfo(const struct corbatext_t &corbaCollect,
|
---|
351 | corbatext_tarray &filterNames,
|
---|
352 | enum corbaComError &corbaError)
|
---|
353 | { text_tarray ta;
|
---|
354 | comerror_t error = noError;
|
---|
355 | text_t collection;
|
---|
356 | InfoFiltersResponse_t response;
|
---|
357 | ofstream logout;
|
---|
358 |
|
---|
359 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
360 |
|
---|
361 | corbaconv_text_t::setCorbatext(collection,corbaCollect);
|
---|
362 | cout << collection.getcstr() << endl;
|
---|
363 |
|
---|
364 | protocol->get_filterinfo(collection, response, error, logout);
|
---|
365 | corbatext_setToCorbaArray(response.filterNames, &filterNames);
|
---|
366 |
|
---|
367 | corbaError = (corbaComError) error;
|
---|
368 | logout.close();
|
---|
369 | }
|
---|
370 |
|
---|
371 | void getDocument(const struct corbatext_t &corbaCollection, struct corbaDocRequest &corbaRequest,
|
---|
372 | struct corbaDocResponse &corbaResponse, enum corbaComError &corbaError)
|
---|
373 | { DocumentRequest_t request;
|
---|
374 | DocumentResponse_t response;
|
---|
375 | comerror_t error = noError;
|
---|
376 | text_t collection;
|
---|
377 | ofstream logout;
|
---|
378 |
|
---|
379 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
380 |
|
---|
381 | // set up request
|
---|
382 | corbaconv_text_t::setCorbatext(collection,corbaCollection);
|
---|
383 | corbaconv_text_t::setCorbatext(request.OID,corbaRequest.OID);
|
---|
384 | corbaconv_text_t::setCorbatext(request.docType,corbaRequest.docType);
|
---|
385 | corbaconv_text_t::setCorbatext(request.docFormat,corbaRequest.docFormat);
|
---|
386 |
|
---|
387 | // do actual get document
|
---|
388 | protocol->get_document(collection, request, response, error, logout);
|
---|
389 | corbaconv_text_t::getCorbatext(response.doc,corbaResponse.doc);
|
---|
390 |
|
---|
391 | // decode response
|
---|
392 | corbaError = (corbaComError) error;
|
---|
393 |
|
---|
394 | logout.close();
|
---|
395 | }
|
---|
396 |
|
---|
397 | void collectionList(corbatext_tarray &corbalist, corbaComError &error)
|
---|
398 | {
|
---|
399 | /* stringSeq *reply;
|
---|
400 | unsigned int i;
|
---|
401 | char *istring; */
|
---|
402 |
|
---|
403 | text_tarray collist;
|
---|
404 | comerror_t err;
|
---|
405 | ofstream logout;
|
---|
406 |
|
---|
407 | cout << "Received collection list request" << endl;
|
---|
408 |
|
---|
409 | this->openLogfile("/etc/corbaout.txt", logout);
|
---|
410 |
|
---|
411 | protocol->get_collection_list(collist, err, logout);
|
---|
412 |
|
---|
413 | /* reply = new stringSeq(collections.size());
|
---|
414 |
|
---|
415 | (*reply).length(collections.size());
|
---|
416 | for (i = 0; i < collections.size(); i ++)
|
---|
417 | {
|
---|
418 | istring = collections[i].getcstr();
|
---|
419 | (*reply)[i] = CORBA::string_dup(istring);
|
---|
420 | delete istring;
|
---|
421 | }
|
---|
422 |
|
---|
423 | return reply;
|
---|
424 | */
|
---|
425 |
|
---|
426 | corbatext_arrayToCorbaArray(collist, &corbalist);
|
---|
427 | cout << "Replying " << collist.size() << ": " << endl;
|
---|
428 |
|
---|
429 | for (int unsigned i = 0; i < collist.size(); i ++)
|
---|
430 | {
|
---|
431 | cout << collist[i];
|
---|
432 | if (i<collist.size()-1) cout << ", ";
|
---|
433 | }
|
---|
434 | cout << endl;
|
---|
435 |
|
---|
436 | logout.close();
|
---|
437 | // CORBA::string_dup(_listString);
|
---|
438 | }
|
---|
439 | };
|
---|
440 |
|
---|
441 | int main (int argc, char *argv[])
|
---|
442 | {
|
---|
443 | nullproto protocol;
|
---|
444 | collectset *cservers;
|
---|
445 | text_t gsdlhome;
|
---|
446 |
|
---|
447 | cservers = new collectset(gsdlhome);
|
---|
448 | protocol.set_collectset(cservers);
|
---|
449 |
|
---|
450 | cout << "Started Corba ..." << endl;
|
---|
451 |
|
---|
452 | // ORB initialization
|
---|
453 | CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "mico-local-orb" );
|
---|
454 | CORBA::BOA_var boa = orb->BOA_init( argc, argv, "mico-local-boa" );
|
---|
455 |
|
---|
456 | cout << "Initialised ORB and BOA" << endl;
|
---|
457 |
|
---|
458 | corbaServer* server = new corbaServer(&protocol, gsdlhome);
|
---|
459 |
|
---|
460 | cout << "Initialised server" << endl;
|
---|
461 |
|
---|
462 | CORBA::String_var ref = orb->object_to_string( server );
|
---|
463 |
|
---|
464 | cout << "Mapped Corba object to string" << endl;
|
---|
465 |
|
---|
466 | // write id to "naming service"
|
---|
467 | ofstream out ("/tmp/localcorba.objid");
|
---|
468 | if (out.is_open()) {
|
---|
469 | out << ref << endl;
|
---|
470 | if (out.fail() || out.bad()) {
|
---|
471 | cout << "Failed " << endl;
|
---|
472 | }
|
---|
473 | out.close ();
|
---|
474 | }
|
---|
475 | else {
|
---|
476 | cout << "Unable to write string to file /tmp/localcorba.objid" << endl;
|
---|
477 | cout << "Please check the file permissions/ownership" << endl;
|
---|
478 | return 0;
|
---|
479 | }
|
---|
480 | cout << "Corba string is " << ref << endl;
|
---|
481 |
|
---|
482 | // indicate readiness and run
|
---|
483 | boa->impl_is_ready( CORBA::ImplementationDef::_nil() );
|
---|
484 | orb->run ();
|
---|
485 | CORBA::release( server );
|
---|
486 | return 0;
|
---|
487 | }
|
---|
488 |
|
---|
489 |
|
---|