[omniORB] ni pseudo-object reference
Warren Brown
warren@scully.xfiles.za.org
Tue, 19 Feb 2002 18:54:07 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0050_01C1B976.CF2E92E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi
I'm using the nameservice to connect to my server.
Everything goes fine until I try to invoke a method on the server. Then =
I get the following error/
omniORB: ERROR -- the application attempted to invoke an operation
on a nil pseudo-object reference.
The snippet of code causing the problem is as follows:-
#include <gtk/gtk.h> /* include gtk headers */
#include <string.h>
#include <Comms.h>
#include <small_server_impl.h>
#include <unistd.h>
#include <pthread.h>
#include <iostream.h>
gint client_connect(GtkWidget *widget, gpointer pointer);
small_server_impl* server;
CORBA::ORB_var orb;
void gtk_run()
{
server->run();
}
int main(int argc, char** argv)
{
GtkWidget *window,*table;
GtkWidget *mybutton;
try=20
{
gtk_init(&argc, &argv); /* always needed */
orb=3DCORBA::ORB_init(argc, argv,"omniORB3"); =20
CORBA::Object_var obj =3D =
orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa =3D PortableServer::POA::_narrow(obj);
//PortableServer::ObjectId_var mysmall_server_iid =3D =
poa->activate_object(small_server_impl);
server =3D new small_server_impl();
CORBA::Object_var sref =3D server->_this();
CORBA::String_var ref =3D orb->object_to_string( sref );
server->labels();
server->textboxes();
server->listboxes();
server->buttons();
server->entry_box();
table=3Dserver->get_windows();
mybutton =3D gtk_button_new_with_label("Join");
=
gtk_signal_connect(GTK_OBJECT(mybutton),"clicked",GTK_SIGNAL_FUNC(client_=
connect),(ref));
gtk_table_attach_defaults(GTK_TABLE(table),mybutton,5,6,7,8);
gtk_widget_show(mybutton);
pthread_t athread,bthread;
pthread_create(&athread,NULL, (void*(*)(void*))gtk_run,NULL); /* =
always needed */
=20
PortableServer::POAManager_var pman =3D poa->the_POAManager();
pman->activate();
orb->run();
orb->destroy();
return(0);
}
catch(CORBA::SystemException&)=20
{
cerr << "Caught CORBA::SystemException." << endl;
}
catch(CORBA::Exception&)=20
{
cerr << "Caught CORBA::Exception." << endl;
}
catch(omniORB::fatalException& fe)=20
{
cerr << "Caught omniORB::fatalException:" << endl;
cerr << " file: " << fe.file() << endl;
cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl;
}
catch(...)=20
{
cerr << "Caught unknown exception." << endl;
}
return 0;
}
gint client_connect(GtkWidget *widget, gpointer pointer)
{
int fault=3D1;
char user[15];
std::cout << "I'm here in the client connect function" << endl;
strcpy(user,"Warren");
CosNaming::NamingContext_var rootContext;
try
{=20
CORBA::Object_var obj =3D =
orb->resolve_initial_references("NameService");
rootContext =3D CosNaming::NamingContext::_narrow(obj);
if(CORBA::is_nil(rootContext))
{
cerr << "Failed to narrow the root naming context" << endl;
exit(0);
}
CosNaming::Name name;
name.length(2);
name[0].id =3D (const char*) "test";
name[0].kind =3D (const char*) "my_context";
name[1].id =3D (const char*) "Server";
name[1].kind =3D (const char*) "Object";
try
{=20
CORBA::Object_var nobj =3D rootContext->resolve(name);=20
if (!CORBA::is_nil(nobj))=20
{=20
Comms_var client =3D Comms::_narrow(nobj);
if (client->connect((char*)user,(char*)pointer))=20
{
server->tell_server(client);
gtk_widget_set_sensitive(widget,FALSE);
}
}
else server->message_print("**** System Message ****","Can't =
connect to main server.\nEither the server is not running, or it can not =
resolve your hostname! ",user);
}
catch(CosNaming::NamingContext::NotFound& ex){ cerr << "Context not =
found" << endl;}
}
catch(CORBA::ORB::InvalidName& ex) { cerr << "Service required =
is invalid" << endl;}
catch(...){ cout << "You had another error dude" << endl; }
}
------=_NextPart_000_0050_01C1B976.CF2E92E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I'm using the nameservice to connect to =
my=20
server.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Everything goes fine until I try to =
invoke a method=20
on the server. Then I get the following error/</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>omniORB: ERROR -- the application =
attempted to=20
invoke an operation<BR> on a nil pseudo-object =
reference.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>The snippet of code causing the problem =
is as=20
follows:-</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV><FONT size=3D2>
<DIV><FONT face=3DArial>#include <gtk/gtk.h> /* include gtk =
headers=20
*/</FONT></DIV>
<DIV><FONT face=3DArial>#include <string.h></FONT></DIV>
<DIV><FONT face=3DArial>#include <Comms.h></FONT></DIV>
<DIV><FONT face=3DArial>#include =
<small_server_impl.h></FONT></DIV>
<DIV><FONT face=3DArial>#include <unistd.h></FONT></DIV>
<DIV><FONT face=3DArial>#include <pthread.h></FONT></DIV>
<DIV><FONT face=3DArial>#include <iostream.h></FONT></DIV>
<DIV><FONT face=3DArial>gint client_connect(GtkWidget *widget, gpointer=20
pointer);</FONT></DIV>
<DIV><FONT face=3DArial>small_server_impl* server;</FONT></DIV>
<DIV><FONT face=3DArial>CORBA::ORB_var orb;</FONT></DIV>
<DIV><FONT face=3DArial>void gtk_run()</FONT></DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial> =
server->run();</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>int main(int argc, char** argv)</FONT></DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial> GtkWidget =
*window,*table;</FONT></DIV>
<DIV><FONT face=3DArial> GtkWidget =
*mybutton;</FONT></DIV>
<DIV><FONT face=3DArial> try</FONT> </DIV>
<DIV><FONT face=3DArial> {</FONT></DIV>
<DIV><FONT face=3DArial> gtk_init(&argc, =
&argv); /*=20
always needed */</FONT></DIV>
<DIV><FONT face=3DArial> orb=3DCORBA::ORB_init(argc,=20
argv,"omniORB3"); </FONT></DIV>
<DIV><FONT face=3DArial> CORBA::Object_var obj =3D=20
orb->resolve_initial_references("RootPOA");</FONT></DIV>
<DIV><FONT face=3DArial> PortableServer::POA_var poa =
=3D=20
PortableServer::POA::_narrow(obj);</FONT></DIV>
<DIV><FONT face=3DArial> =
//PortableServer::ObjectId_var=20
mysmall_server_iid =3D =
poa->activate_object(small_server_impl);</FONT></DIV>
<DIV><FONT face=3DArial></FONT> </DIV>
<DIV><FONT face=3DArial> server =3D new=20
small_server_impl();</FONT></DIV>
<DIV><FONT face=3DArial> CORBA::Object_var sref =3D=20
server->_this();</FONT></DIV>
<DIV><FONT face=3DArial> CORBA::String_var ref =3D=20
orb->object_to_string( sref );</FONT></DIV>
<DIV><FONT face=3DArial></FONT> </DIV>
<DIV><FONT face=3DArial> =
server->labels();</FONT></DIV>
<DIV><FONT face=3DArial> =
server->textboxes();</FONT></DIV>
<DIV><FONT face=3DArial> =
server->listboxes();</FONT></DIV>
<DIV><FONT face=3DArial> =
server->buttons();</FONT></DIV>
<DIV><FONT face=3DArial> =
server->entry_box();</FONT></DIV>
<DIV><FONT face=3DArial> =20
table=3Dserver->get_windows();</FONT></DIV>
<DIV><FONT face=3DArial> mybutton =3D=20
gtk_button_new_with_label("Join");</FONT></DIV>
<DIV><FONT face=3DArial> =20
gtk_signal_connect(GTK_OBJECT(mybutton),"clicked",GTK_SIGNAL_FUNC(client_=
connect),(ref));</FONT></DIV>
<DIV><FONT face=3DArial> =20
gtk_table_attach_defaults(GTK_TABLE(table),mybutton,5,6,7,8);</FONT></DIV=
>
<DIV><FONT face=3DArial> =
gtk_widget_show(mybutton);</FONT></DIV>
<DIV><FONT face=3DArial> pthread_t =
athread,bthread;</FONT></DIV>
<DIV><FONT face=3DArial> =
pthread_create(&athread,NULL,=20
(void*(*)(void*))gtk_run,NULL); /* always needed */</FONT></DIV>
<DIV><FONT face=3DArial> </FONT></DIV>
<DIV><FONT face=3DArial> =
PortableServer::POAManager_var pman =3D=20
poa->the_POAManager();</FONT></DIV>
<DIV><FONT face=3DArial> =
pman->activate();</FONT></DIV>
<DIV><FONT face=3DArial> orb->run();</FONT></DIV>
<DIV><FONT face=3DArial> =
orb->destroy();</FONT></DIV>
<DIV><FONT face=3DArial> return(0);</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>catch(CORBA::SystemException&)</FONT> </DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial> cerr << "Caught=20
CORBA::SystemException." << endl;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>catch(CORBA::Exception&)</FONT> </DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial> cerr << "Caught=20
CORBA::Exception." << endl;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>catch(omniORB::fatalException& fe)</FONT> =
</DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial> cerr << "Caught=20
omniORB::fatalException:" << endl;</FONT></DIV>
<DIV><FONT face=3DArial> cerr << " file: " =
<<=20
fe.file() << endl;</FONT></DIV>
<DIV><FONT face=3DArial> cerr << " line: " =
<<=20
fe.line() << endl;</FONT></DIV>
<DIV><FONT face=3DArial> cerr << " mesg: " =
<<=20
fe.errmsg() << endl;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>catch(...)</FONT> </DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial> cerr << "Caught unknown =
exception." << endl;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>return 0;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial> gint client_connect(GtkWidget =
*widget,=20
gpointer pointer)</FONT></DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial> int fault=3D1;</FONT></DIV>
<DIV><FONT face=3DArial> char user[15];</FONT></DIV>
<DIV><FONT face=3DArial> std::cout << "I'm here =
in the=20
client connect function" << endl;</FONT></DIV>
<DIV><FONT face=3DArial> =
strcpy(user,"Warren");</FONT></DIV>
<DIV><FONT face=3DArial> CosNaming::NamingContext_var=20
rootContext;</FONT></DIV>
<DIV><FONT face=3DArial> try</FONT></DIV>
<DIV><FONT face=3DArial> {</FONT> </DIV>
<DIV><FONT face=3DArial> =
CORBA::Object_var=20
obj =3D orb->resolve_initial_references("NameService");</FONT></DIV>
<DIV><FONT face=3DArial> =
rootContext =3D=20
CosNaming::NamingContext::_narrow(obj);</FONT></DIV>
<DIV><FONT face=3DArial> =20
if(CORBA::is_nil(rootContext))</FONT></DIV>
<DIV><FONT face=3DArial> =
{</FONT></DIV>
<DIV><FONT face=3DArial> =
=20
cerr << "Failed to narrow the root naming context" <<=20
endl;</FONT></DIV>
<DIV><FONT face=3DArial> =20
exit(0);</FONT></DIV>
<DIV><FONT face=3DArial> }</FONT></DIV>
<DIV><FONT face=3DArial> CosNaming::Name =
name;</FONT></DIV>
<DIV><FONT face=3DArial> name.length(2);</FONT></DIV>
<DIV><FONT face=3DArial> name[0].id =3D (const char*)=20
"test";</FONT></DIV>
<DIV><FONT face=3DArial> name[0].kind =3D (const =
char*)=20
"my_context";</FONT></DIV>
<DIV><FONT face=3DArial> name[1].id =3D (const char*)=20
"Server";</FONT></DIV>
<DIV><FONT face=3DArial> name[1].kind =3D (const =
char*)=20
"Object";</FONT></DIV>
<DIV><FONT face=3DArial> try</FONT></DIV>
<DIV><FONT face=3DArial> {</FONT> </DIV>
<DIV><FONT face=3DArial> =
CORBA::Object_var=20
nobj =3D rootContext->resolve(name);</FONT> </DIV>
<DIV><FONT face=3DArial> if=20
(!CORBA::is_nil(nobj))</FONT> </DIV>
<DIV><FONT face=3DArial> {</FONT> =
</DIV>
<DIV><FONT face=3DArial> =
=20
Comms_var client =3D Comms::_narrow(nobj);</FONT></DIV>
<DIV><FONT face=3DArial> =
=20
if (client->connect((char*)user,(char*)pointer))</FONT> </DIV>
<DIV><FONT face=3DArial> =
=20
{</FONT></DIV>
<DIV><FONT face=3DArial> =
=20
server->tell_server(client);</FONT></DIV>
<DIV><FONT face=3DArial> =
=20
gtk_widget_set_sensitive(widget,FALSE);</FONT></DIV>
<DIV><FONT face=3DArial> =
=20
}</FONT></DIV>
<DIV><FONT face=3DArial> =
}</FONT></DIV>
<DIV><FONT face=3DArial> else=20
server->message_print("**** System Message ****","Can't connect to =
main=20
server.\nEither the server is not running, or it can not resolve your =
hostname!=20
",user);</FONT></DIV>
<DIV><FONT face=3DArial> }</FONT></DIV>
<DIV><FONT face=3DArial> =20
catch(CosNaming::NamingContext::NotFound& ex){ cerr << =
"Context not=20
found" << endl;}</FONT></DIV>
<DIV><FONT face=3DArial> }</FONT></DIV>
<DIV><FONT face=3DArial> =20
catch(CORBA::ORB::InvalidName& ex) { cerr << "Service required =
is=20
invalid" << endl;}</FONT></DIV>
<DIV><FONT face=3DArial> =
catch(...){ cout=20
<< "You had another error dude" << endl; }</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV></FONT>
<DIV> </DIV>
<DIV><FONT face=3DArial><BR><FONT =
size=3D2></FONT></FONT> </DIV></BODY></HTML>
------=_NextPart_000_0050_01C1B976.CF2E92E0--