Naimad
2009-07-20 16:58:36 UTC
Hi,
I'm trying to compilation my first program at Corba OmniORB.
I build file with idl:
interface Calc {
double Sum(in double a, in double b);
long Counter();
};
I build client file:
#include <iostream>
#include <iomanip>
#include "calc.hh"
using namespace std;
//-----------------------------------------------------------------------------
int
main(int argc, char * argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Check arguments
if (argc != 2) {
cerr << "Usage: client IOR_string" << endl;
throw 0;
}
// Destringify argv[1]
CORBA::Object_var obj = orb->string_to_object(argv[1]);
if (CORBA::is_nil(obj)) {
cerr << "Nil Time reference" << endl;
throw 0;
}
// Narrow
Calc_var calc= Calc::_narrow(obj);
if (CORBA::is_nil(calc)) {
cerr << "Argument is not a Time reference" << endl;
throw 0;
}
// Get time
cout << "2 + 3 = " << calc->Sum(2,3) << endl;
}
catch (const CORBA::Exception &) {
cerr << "Uncaught CORBA exception" << endl;
return 1;
}
catch (...) {
return 1;
}
return 0;
}
and I build server file:
#include <calc.h>
#include <iostream>
#include "calc.hh"
using namespace std;
class Calc_impl : virtual public Calc_skel {
private:
CORBA::Long __counter;
public:
Calc_impl() { __counter = 0; }
CORBA::Double Sum(CORBA::Double a, CORBA::Double b) { __counter++;
return a+b;}
};
//--------------------------------------------------------
int
main(int argc, char * argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Get reference to Root POA.
CORBA::Object_var obj
= orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj);
// Activate POA manager
PortableServer::POAManager_var mgr
= poa->the_POAManager();
mgr->activate();
// Create an object
Calc_impl calc_servant;
// Write its stringified reference to stdout
Calc_var server = calc_servant._this();
CORBA::String_var str= orb->object_to_string(server);
cout << str << endl;
// Accept requests
orb->run();
}
catch (const CORBA::Exception &) {
cerr << "Uncaught CORBA exception" << endl;
return 1;
}
return 0;
}
With compilation calc.idl and client I don't have problems, but I have
problems with compilation server. At first I have many errors but now
I have only one or two. Here they are:
server.cc:1:18: error: calc.h: Nie ma takiego pliku ani katalogu
server.cc:6: error: expected class-name before ‘{’ token
server.cc: In function ‘int main(int, char**)’:
server.cc:38: error: ‘class Calc_impl’ has no member named ‘_this’
make: *** [server.o] Błąd 1
What is wrong?
This example I take from polish book about CORBA, but it was to MICO
CORBA. I tried to change it to OmniORB. For base I take example who
work at my Debian with OmniORB (I think you are know this example from
book "Advanced CORBA Programming with C++")
I am very grateful for your help. Sorry for my English but I still
learn it.
I'm trying to compilation my first program at Corba OmniORB.
I build file with idl:
interface Calc {
double Sum(in double a, in double b);
long Counter();
};
I build client file:
#include <iostream>
#include <iomanip>
#include "calc.hh"
using namespace std;
//-----------------------------------------------------------------------------
int
main(int argc, char * argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Check arguments
if (argc != 2) {
cerr << "Usage: client IOR_string" << endl;
throw 0;
}
// Destringify argv[1]
CORBA::Object_var obj = orb->string_to_object(argv[1]);
if (CORBA::is_nil(obj)) {
cerr << "Nil Time reference" << endl;
throw 0;
}
// Narrow
Calc_var calc= Calc::_narrow(obj);
if (CORBA::is_nil(calc)) {
cerr << "Argument is not a Time reference" << endl;
throw 0;
}
// Get time
cout << "2 + 3 = " << calc->Sum(2,3) << endl;
}
catch (const CORBA::Exception &) {
cerr << "Uncaught CORBA exception" << endl;
return 1;
}
catch (...) {
return 1;
}
return 0;
}
and I build server file:
#include <calc.h>
#include <iostream>
#include "calc.hh"
using namespace std;
class Calc_impl : virtual public Calc_skel {
private:
CORBA::Long __counter;
public:
Calc_impl() { __counter = 0; }
CORBA::Double Sum(CORBA::Double a, CORBA::Double b) { __counter++;
return a+b;}
};
//--------------------------------------------------------
int
main(int argc, char * argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Get reference to Root POA.
CORBA::Object_var obj
= orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj);
// Activate POA manager
PortableServer::POAManager_var mgr
= poa->the_POAManager();
mgr->activate();
// Create an object
Calc_impl calc_servant;
// Write its stringified reference to stdout
Calc_var server = calc_servant._this();
CORBA::String_var str= orb->object_to_string(server);
cout << str << endl;
// Accept requests
orb->run();
}
catch (const CORBA::Exception &) {
cerr << "Uncaught CORBA exception" << endl;
return 1;
}
return 0;
}
With compilation calc.idl and client I don't have problems, but I have
problems with compilation server. At first I have many errors but now
I have only one or two. Here they are:
server.cc:1:18: error: calc.h: Nie ma takiego pliku ani katalogu
server.cc:6: error: expected class-name before ‘{’ token
server.cc: In function ‘int main(int, char**)’:
server.cc:38: error: ‘class Calc_impl’ has no member named ‘_this’
make: *** [server.o] Błąd 1
What is wrong?
This example I take from polish book about CORBA, but it was to MICO
CORBA. I tried to change it to OmniORB. For base I take example who
work at my Debian with OmniORB (I think you are know this example from
book "Advanced CORBA Programming with C++")
I am very grateful for your help. Sorry for my English but I still
learn it.