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