source: branches/corba/gsdl/src/recpt/corbaproto.mpp@ 1074

Last change on this file since 1074 was 1074, checked in by cs025, 24 years ago

Corba improvements; tidied client initialisation in corbaproto and also
added a number of changes to the main trunk which somehow had not made
it into the corba branch via update before its instantiation.

Also the dated use of the GSDL_GSDLHOME macro was removed, at the expense
of some particularly poor code in corbaserver where log file creation is
now nowhere near so elegant.

  • Property svn:keywords set to Author Date Id Revision
File size: 18.1 KB
Line 
1/**********************************************************************
2 *
3 * corbaproto.cpp --
4 * Copyright (C) 2000 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 * $Id: corbaproto.mpp 1074 2000-04-06 11:11:40Z cs025 $
25 *
26 *********************************************************************/
27
28#include <iostream.h>
29#include <fstream.h>
30
31// protocol headers for CORBA
32#include "corbaiface.h"
33
34// greenstone library headers
35#include "corbaconv_text_t.h"
36
37// greenstone local headers
38#include "corbatext_t.h"
39
40#include "corbaproto.h"
41#include "colservrconfig.h"
42
43// default headers
44#include <assert.h>
45
46void corbatext_optionValueArrayToCorba(OptionValue_tarray array, corbaOptionValue_array &corba)
47{
48 unsigned int i = 0;
49 OptionValue_tarray::iterator here = array.begin();
50 OptionValue_tarray::iterator end = array.end();
51
52 while (here != end)
53 {
54 corba.length(i+1);
55
56 corbaconv_text_t::getCorbatext(here->name,corba[i].name);
57 corbaconv_text_t::getCorbatext(here->value,corba[i].value);
58
59 i ++;
60 here ++;
61 }
62 // cout << "Options " << i << endl;
63}
64
65void corbaresponse_resultMetadataToCorba(MetadataInfo_t &meta, corbaMetadataInfo &corbaMeta)
66{
67 corbaconv_text_t::getCorbatext(meta.params,corbaMeta.params);
68 corbatext_arrayToCorbaArray(meta.values, &corbaMeta.values);
69 corbaMeta.isRef = meta.isRef;
70}
71
72void corbaresponse_resultMetadataToC(const corbaMetadataInfo &corbaMeta, MetadataInfo_t &meta)
73{
74 corbaconv_text_t::setCorbatext(meta.params,corbaMeta.params);
75 corbatext_corbaArrayToArray(corbaMeta.values, &meta.values);
76 meta.isRef = corbaMeta.isRef;
77}
78
79int corbaresponse_resultMetaParentToCorba(MetadataInfo_t *parent, corbaMetadataInfo_array &corbaparent)
80{
81 int reply = -1, pid = -1;
82
83 // extend for new parent
84 reply = corbaparent.length();
85 corbaparent.length(reply+1);
86
87 // copy content into new array element
88 corbaresponse_resultMetadataToCorba(*parent, corbaparent[reply]);
89
90 // deal with our own parent
91 if (parent->parent != NULL)
92 {
93 // get offset of new parent and extend parent vector
94
95 pid = corbaresponse_resultMetaParentToCorba(parent->parent, corbaparent);
96 }
97 corbaparent[reply].parentid = pid;
98
99 // return the parent id from here
100 return reply;
101}
102
103MetadataInfo_t *corbaresponse_resultMetaParentToC(corbaMetadataInfo_array &corbaparent, int pid)
104{
105 MetadataInfo_t *reply;
106
107 reply = new MetadataInfo_t;
108
109 corbaresponse_resultMetadataToC(corbaparent[pid], *reply);
110
111 // deal with our own parent
112 if (corbaparent[pid].parentid >= 0)
113 {
114 // get offset of new parent and extend parent vector
115
116 reply->parent = corbaresponse_resultMetaParentToC(corbaparent, corbaparent[pid].parentid);
117 }
118 else
119 {
120 reply->parent = NULL;
121 }
122
123 // return the parent id from here
124 return reply;
125}
126
127void corbaresponse_resultDocInfoToCorba(ResultDocInfo_tarray docinfo, corbaResultDocInfo_array &corbainfo)
128{
129 ResultDocInfo_tarray::iterator here = docinfo.begin();
130 ResultDocInfo_tarray::iterator end = docinfo.end();
131 unsigned int i;
132
133 i = 0;
134 while (here != end)
135 {
136 corbainfo.length(i+1);
137
138 // copy the easy bits
139 corbaconv_text_t::getCorbatext(here->OID,corbainfo[i].OID);
140
141 corbainfo[i].resultNum = here->result_num;
142 corbainfo[i].ranking = here->ranking;
143 corbainfo[i].termsMatched = here->num_terms_matched;
144 corbainfo[i].phraseMatched = here->num_phrase_match;
145
146 // copy the docFreq array
147 vector<int>::iterator fhere = here->docFreq.begin();
148 vector<int>::iterator fend = here->docFreq.end();
149 unsigned int fi = 0;
150
151 while (fhere != fend)
152 {
153 corbainfo[i].docFreq.length(fi+1);
154
155 corbainfo[i].docFreq[fi] = *fhere;
156
157 fhere ++;
158 fi ++;
159 }
160
161 // copy the MetadataInfo map
162 MetadataInfo_tmap::iterator mhere = here->metadata.begin();
163 MetadataInfo_tmap::iterator mend = here->metadata.end();
164 unsigned int mi = 0;
165
166 while (mhere != mend)
167 {
168 corbainfo[i].metadata.names.length(mi+1);
169 corbainfo[i].metadata.values.length(mi+1);
170
171 // copy name
172 corbaconv_text_t::getCorbatext((*mhere).first,corbainfo[i].metadata.names[mi]);
173
174 // copy metadata
175 corbaresponse_resultMetadataToCorba((*mhere).second, corbainfo[i].metadata.values[mi]);
176 if (mhere->second.parent != NULL)
177 {
178 int pid;
179
180 pid = corbaresponse_resultMetaParentToCorba(mhere->second.parent,
181 corbainfo[i].metaparents);
182 corbainfo[i].metadata.values[mi].parentid = pid;
183 }
184 else
185 {
186 corbainfo[i].metadata.values[mi].parentid = -1;
187 }
188
189 cout << "Parent " << mi << " " << (int) &mhere->second << " " << (int) mhere->second.parent << endl;
190
191 mhere ++;
192 mi ++;
193 }
194
195 // Copy the classifier variables
196 corbaconv_text_t::getCorbatext(here->classifier_metadata_type, corbainfo[i].classifierMetadataType);
197 corbainfo[i].classifierMetadataOffset = here->classifier_metadata_offset;
198
199 // Get next Docinfo item
200 i++;
201 here ++;
202 }
203}
204
205void corbaresponse_resultDocInfoToC(corbaResultDocInfo_array corbainfo, ResultDocInfo_tarray &docinfo)
206{
207 unsigned int i;
208 ResultDocInfo_t doc;
209
210 for (i = 0; i < corbainfo.length(); i++)
211 {
212 corbaconv_text_t::setCorbatext(doc.OID,corbainfo[i].OID);
213 doc.result_num = corbainfo[i].resultNum;
214 doc.ranking = corbainfo[i].ranking;
215 doc.num_terms_matched = corbainfo[i].termsMatched;
216 doc.num_phrase_match = corbainfo[i].phraseMatched;
217
218 // copy the doc freq array
219 unsigned int fi;
220 for (fi = 0; fi < corbainfo[i].docFreq.length(); fi ++)
221 {
222 doc.docFreq.push_back(corbainfo[i].docFreq[fi]);
223 }
224
225 // copy the MetadataInfomap
226 unsigned int mi;
227 text_t mname;
228 MetadataInfo_t mdata;
229
230 doc.metadata.clear();
231 for (mi = 0; mi < corbainfo[i].metadata.names.length(); mi ++)
232 {
233 // get name
234 corbaconv_text_t::setCorbatext(mname,corbainfo[i].metadata.names[mi]);
235
236 // get metadata
237 corbaresponse_resultMetadataToC(corbainfo[i].metadata.values[mi], mdata);
238
239 if (corbainfo[i].metadata.values[mi].parentid >= 0)
240 {
241 mdata.parent =
242 corbaresponse_resultMetaParentToC(corbainfo[i].metaparents,
243 corbainfo[i].metadata.values[mi].parentid);
244 }
245
246 doc.metadata.insert(make_pair(mname, mdata));
247 }
248
249 // GRB: sort out parent data
250 for (mi = 0; mi < corbainfo[i].metadata.names.length(); mi ++)
251 {
252 if (corbainfo[i].metadata.values[mi].parentid != 0)
253 {
254 int pi;
255
256 for (pi = 0; pi < corbainfo[i].metadata.names.length(); pi ++)
257 {
258 if (pi != mi &&
259 corbainfo[i].metadata.values[mi].parentid ==
260 corbainfo[i].metadata.values[pi].id)
261 {
262 doc.metadata[mi].parent = &doc.metadata[pi];
263 }
264 }
265 }
266 }
267 // doc.metadata
268
269 // convert metadata classifer information
270 corbaconv_text_t::setCorbatext(doc.classifier_metadata_type,corbainfo[i].classifierMetadataType);
271 doc.classifier_metadata_offset = corbainfo[i].classifierMetadataOffset;
272
273 docinfo.push_back(doc);
274 }
275}
276
277corbaproto::corbaproto()
278{ char *dummyv[1] = {""};
279 int dummyc = 0;
280 /* // CORBA variables
281 static CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
282 static CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
283
284 // Get ref from "naming service"
285 ifstream in ("/tmp/account.objid");
286 char ref[1000];
287 in >> ref;
288 in.close ();
289
290 // startup corba
291 static CORBA::Object_var obj = orb->string_to_object (ref);
292
293 client = corbaiface::_narrow( obj );*/
294 client = NULL;
295}
296
297corbaiface_var corbaproto::getCorbaClient()
298{
299 char *dummyv[1] = {""};
300 int dummyc = 0;
301 // CORBA variables
302 static CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
303 static CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
304
305 // Get ref from "naming service"
306 ifstream in ("/tmp/account.objid");
307 char ref[1000];
308 in >> ref;
309 in.close ();
310
311 // startup corba
312 static CORBA::Object_var obj = orb->string_to_object (ref);
313
314 return corbaiface::_narrow( obj );
315}
316
317
318// this configure will configure each of the collection servers
319void corbaproto::configure (const text_t &key, const text_tarray &cfgline) {
320 // the naming of the collection should not be done here,
321 // it should be done just after the collection server has been
322 // created
323
324 // cout << "Corbaproto::Configure" << endl;
325 corbatext_t corbaKey;
326 corbatext_tarray corbaCfgline;
327
328 // get the corba client reference
329 corbaiface_var lclient = this->getCorbaClient();
330
331 // convert all the requisite structures into their CORBA form
332 corbaconv_text_t::getCorbatext(key,corbaKey);
333 corbatext_arrayToCorbaArray(cfgline, &corbaCfgline);
334
335 // execute the corba transaction
336 lclient->configure(corbaKey, corbaCfgline);
337}
338
339// this init will configure and init each of the collection servers
340bool corbaproto::init (ostream &logout) {
341// cout << "Corbaproto::Init" << endl;
342
343 // get the corba client reference
344 corbaiface_var lclient = this->getCorbaClient();
345
346 // execute the corba transaction
347 return lclient->init();
348}
349
350text_t corbaproto::get_protocol_name () {
351 return "corbaproto";
352}
353
354
355void corbaproto::get_collection_list (text_tarray &collist, comerror_t &err,
356 ostream &/*logout*/) {
357
358 cout << "Corbaproto::Collection list" << endl;
359
360 corbatext_tarray corba_collist;
361 text_tarray tcollist;
362
363 // get the corba client reference
364 corbaiface_var lclient = this->getCorbaClient();
365
366 // execute the corba transaction
367 lclient->collectionList(corba_collist);
368
369 // convert the response back to normal form
370 corbatext_corbaArrayToArray(corba_collist, &tcollist);
371 collist = tcollist;
372
373 err = noError;
374}
375
376void corbaproto::has_collection (const text_t &collection, bool &hascollection,
377 comerror_t &err, ostream &/*logout*/) {
378 // cout << "Corbaproto::Has collection" << endl;
379
380 corbatext_t corbaCollection;
381 corbaComError corbaError;
382 CORBA::Boolean corbaHas;
383
384 // get the corba client reference
385 corbaiface_var lclient = this->getCorbaClient();
386
387 // convert all the requisite structures into their CORBA form
388 corbaconv_text_t::getCorbatext(collection,corbaCollection);
389
390 // execute the corba transaction
391 lclient->hasCollection(corbaCollection, corbaHas, corbaError);
392
393 // convert the response back to normal form
394 hascollection = (corbaHas != 0);
395 err = noError;
396}
397
398void corbaproto::ping (const text_t &collection, bool &wassuccess,
399 comerror_t &err, ostream &/*logout*/) {
400 // cout << "Corbaproto::Ping" << endl;
401
402 corbatext_t corbaCollect;
403 corbaComError corbaError;
404 bool success;
405
406 // get the corba client reference
407 corbaiface_var lclient = this->getCorbaClient();
408
409 // convert all the requisite structures into their CORBA form
410 corbaconv_text_t::getCorbatext(collection,corbaCollect);
411
412 // execute the corba transaction
413 success = lclient->ping(corbaCollect, corbaError);
414
415 // convert the response back to normal form
416 wassuccess = (success != 0);
417}
418
419void corbaproto::get_collectinfo (const text_t &collection,
420 ColInfoResponse_t &collectinfo,
421 comerror_t &err, ostream &logout) {
422 // cout << "Corbaproto::Collectinfo" << endl;
423
424 corbatext_t corbaCollection;
425 corbaComError corbaError;
426 corbaColInfoResponse corbaCollectInfo;
427
428 // get the corba client reference
429 corbaiface_var lclient = this->getCorbaClient();
430
431 // convert all the requisite structures into their CORBA form
432 corbaconv_text_t::getCorbatext(collection,corbaCollection);
433
434 // execute the corba transaction
435 lclient->getCollectInfo(corbaCollection, corbaCollectInfo, corbaError);
436
437 // convert the response back to normal form
438 collectinfo.isPublic = corbaCollectInfo.isPublic;
439 collectinfo.isBeta = corbaCollectInfo.isBeta;
440 collectinfo.buildDate = corbaCollectInfo.buildDate;
441 corbatext_corbaArrayToArray(corbaCollectInfo.ccsCols, &collectinfo.ccsCols);
442 corbatext_corbaArrayToArray(corbaCollectInfo.languages, &collectinfo.languages);
443 collectinfo.numDocs = corbaCollectInfo.numDocs;
444 collectinfo.numWords = corbaCollectInfo.numWords;
445 collectinfo.numBytes = corbaCollectInfo.numBytes;
446 corbatext_corbaMapToMap(corbaCollectInfo.collectionMeta, collectinfo.collectionmeta);
447 corbatext_corbaMapToMap(corbaCollectInfo.format, collectinfo.format);
448 corbatext_corbaMapToMap(corbaCollectInfo.building, collectinfo.building);
449 corbaconv_text_t::setCorbatext(collectinfo.receptionist,corbaCollectInfo.receptionist);
450
451 err = (comerror_t) corbaError;
452}
453
454
455void corbaproto::get_filterinfo (const text_t &collection,
456 InfoFiltersResponse_t &response,
457 comerror_t &err, ostream &logout) {
458 // cout << "Corbaproto::Filterinfo" << endl;
459
460 corbatext_t corbaCollection;
461 corbatext_tset corbaResponse;
462 corbaComError corbaError;
463
464 // get the corba client reference
465 corbaiface_var lclient = this->getCorbaClient();
466
467 // convert all the requisite structures into their CORBA form
468 corbaconv_text_t::getCorbatext(collection,corbaCollection);
469
470 // execute the corba transaction
471 lclient->getFilterInfo(corbaCollection, corbaResponse, corbaError);
472
473 // convert the response back to normal form
474 corbatext_corbaArrayToSet(corbaResponse, &response.filterNames);
475
476 err = (comerror_t) corbaError;
477}
478
479void corbaproto::get_filteroptions (const text_t &collection,
480 const InfoFilterOptionsRequest_t &request,
481 InfoFilterOptionsResponse_t &response,
482 comerror_t &err, ostream &logout) {
483 // cout << "Corbaproto::Filteroptions" << endl;
484
485 corbatext_t corbaCollection;
486 corbatext_t filterName;
487 corbaFilterOptionsResponse corbaResponse;
488 corbaComError corbaError;
489 unsigned int i;
490 corbaconv_text_t *cc_name;
491 FilterOption_t *option;
492
493 // get the corba client reference
494 corbaiface_var lclient = this->getCorbaClient();
495
496 // convert all the requisite structures into their CORBA form
497 corbaconv_text_t::getCorbatext(collection,corbaCollection);
498 corbaconv_text_t::getCorbatext(request.filterName,filterName);
499
500 // execute the corba transaction
501 lclient->getFilterOptions(corbaCollection, filterName, corbaResponse, corbaError);
502
503 // convert the response back to normal form
504 for (i = 0; i < corbaResponse.names.length(); i ++)
505 {
506 cc_name = new corbaconv_text_t(corbaResponse.names[i]);
507
508 option = new FilterOption_t;
509 corbaconv_text_t::setCorbatext(option->name,corbaResponse.options[i].name);
510 option->type = (FilterOption_t::type_t) corbaResponse.options[i].type;
511 option->repeatable = (FilterOption_t::repeatable_t) corbaResponse.options[i].repeatable;
512 corbaconv_text_t::setCorbatext(option->defaultValue,corbaResponse.options[i].defaultValue);
513 corbatext_corbaArrayToArray(corbaResponse.options[i].validValues, &option->validValues);
514
515 response.filterOptions.insert(make_pair(*cc_name, *option)); // typecast to text_t
516 }
517
518 err = (comerror_t) corbaError;
519}
520
521void corbaproto::filter (const text_t &collection,
522 FilterRequest_t &request,
523 FilterResponse_t &response,
524 comerror_t &err, ostream &logout) {
525 // cout << "Corbaproto::Filter" << endl;
526
527 corbaFilterRequest corbaRequest;
528 corbaFilterResponse corbaResponse;
529 corbatext_t corbaCollection;
530 corbaComError corbaError;
531
532 // get the corba client reference
533 corbaiface_var lclient = this->getCorbaClient();
534
535 // convert all the requisite structures into their CORBA form
536 corbaconv_text_t::getCorbatext(collection,corbaCollection);
537 corbaconv_text_t::getCorbatext(request.filterName,corbaRequest.filter);
538 corbatext_optionValueArrayToCorba(request.filterOptions, corbaRequest.filterOptions);
539 corbatext_arrayToCorbaArray(request.docSet, &corbaRequest.docSet);
540 corbaRequest.filterResultOptions = request.filterResultOptions;
541 corbaconv_text_t::getCorbatext(request.requestParams,corbaRequest.requestParams);
542 corbaconv_text_t::getCorbatext(request.refParams,corbaRequest.refParams);
543 corbaRequest.getParents = request.getParents;
544 corbatext_setToCorbaArray(request.fields, &corbaRequest.fields);
545
546 corbaResponse.numDocs = response.numDocs;
547 corbaresponse_resultDocInfoToCorba(response.docInfo, corbaResponse.docInfo);
548
549 // execute the corba transaction
550 lclient->filter (corbaCollection, corbaRequest, corbaResponse, corbaError);
551
552 // convert the response back to normal form
553 response.numDocs = corbaResponse.numDocs;
554 response.isApprox = corbaResponse.isApprox;
555 corbaresponse_resultDocInfoToC(corbaResponse.docInfo, response.docInfo);
556
557 err = (comerror_t) corbaError;
558 // cout << "Corbaproto::Filter" << endl;
559
560}
561
562void corbaproto::get_document (const text_t &collection,
563 const DocumentRequest_t &request,
564 DocumentResponse_t &response,
565 comerror_t &err, ostream &logout) {
566 // cout << "Corbaproto::Get Document" << endl;
567
568 corbatext_t corbaCollect;
569 corbaDocRequest corbaRequest;
570 corbaDocResponse corbaResponse;
571 corbaComError corbaError;
572
573 // get the corba client reference
574 corbaiface_var lclient = this->getCorbaClient();
575
576 // convert all the requisite structures into their CORBA form
577 corbaconv_text_t::getCorbatext(collection,corbaCollect);
578 corbaconv_text_t::getCorbatext(request.OID,corbaRequest.OID);
579 corbaconv_text_t::getCorbatext(request.docType,corbaRequest.docType);
580 corbaconv_text_t::getCorbatext(request.docFormat,corbaRequest.docFormat);
581
582 // execute the corba transaction
583 lclient->getDocument(corbaCollect, corbaRequest, corbaResponse, corbaError);
584
585 // convert the response back to normal form
586 corbaconv_text_t::setCorbatext(response.doc,corbaResponse.doc);
587
588 err = (comerror_t) corbaError;
589}
590
Note: See TracBrowser for help on using the repository browser.