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