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