Discussion:
[omniORB] problem when passing an interface in a function
risc risc
2010-01-20 21:24:41 UTC
Permalink
Hi All,

I have a problem, when i passing an interface object to a corbaobject i
have:

idl:

module prova
{
interface inter
{
attribute string name;
};

interface inter2
{
string func(in inter obj);
};

}


client:


CORBA::Object_var obj = orb->string_to_object(argv[1]);

inter2_var operation=inter2::_narrow(obj);

if( CORBA::is_nil(operation) ) {
cerr << "Can't narrow reference to type Echo (or it was nil)." <<
endl;
return 1;
}

obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
PortableServer::POAManager_var pman = poa->the_POAManager();
pman->activate();


prova_inter_impl * o=new prova_inter_impl ();

o->setName("RISC");

inter_ptr ok=o->_this();

operation->func(ok);

cout<<"FINE";

.....


server:

char * inter2::getName( prova::inter_ptr obj )
{
char *p=obj->name();

cout<<p<<endl

return p;
}


after a client run at the server print the name fine and after the client go
in segfault why?

Thanks lots
Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20100120/bbde6044/attachment.htm
Edward Lin
2010-01-21 20:31:26 UTC
Permalink
Hi,

At least I see one problem, you cannot "return p"; you must

char* inter2::getName( ... )
{
...
return CORBA::string_dup(p);
}

You can refer to omniORB 'echo' example.
Post by risc risc
char * inter2::getName( prova::inter_ptr obj )
{
char *p=obj->name();
cout<<p<<endl
return p;
}
risc risc
2010-01-21 20:57:11 UTC
Permalink
Thanks Edward,

i see the problem but i have the problem also if i have this function:

void inter2::getName( prova::inter_ptr obj )
{
char *p=obj->name();

cout<<p<<endl;
}
Post by Edward Lin
Hi,
At least I see one problem, you cannot "return p"; you must
char* inter2::getName( ... )
{
...
return CORBA::string_dup(p);
}
You can refer to omniORB 'echo' example.
Post by risc risc
char * inter2::getName( prova::inter_ptr obj )
{
char *p=obj->name();
cout<<p<<endl
return p;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20100121/4afc0304/attachment.htm
Edward Lin
2010-01-22 09:41:20 UTC
Permalink
Hi,

You've to be aware of CORBA memory marshaling, I guess it should be

CORBA::String_var p = obj->name();
Post by risc risc
Thanks Edward,
? void inter2::getName( prova::inter_ptr obj )
? {
? char *p=obj->name();
? cout<<p<<endl;
? }
Post by Edward Lin
Hi,
At least I see one problem, you cannot "return p"; you must
char* inter2::getName( ... )
{
? ?...
? ?return CORBA::string_dup(p);
}
You can refer to omniORB 'echo' example.
Post by risc risc
char * inter2::getName( prova::inter_ptr obj )
{
?char *p=obj->name();
?cout<<p<<endl
return p;
}
risc risc
2010-01-22 20:56:21 UTC
Permalink
Thanks Edward, so much!!! it's true :)

thanks bye
Post by Edward Lin
Hi,
You've to be aware of CORBA memory marshaling, I guess it should be
CORBA::String_var p = obj->name();
Post by risc risc
Thanks Edward,
void inter2::getName( prova::inter_ptr obj )
{
char *p=obj->name();
cout<<p<<endl;
}
Post by Edward Lin
Hi,
At least I see one problem, you cannot "return p"; you must
char* inter2::getName( ... )
{
...
return CORBA::string_dup(p);
}
You can refer to omniORB 'echo' example.
Post by risc risc
char * inter2::getName( prova::inter_ptr obj )
{
char *p=obj->name();
cout<<p<<endl
return p;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20100122/36de3303/attachment.htm
Loading...