[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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>omniORB: ERROR -- the application =
attempted to=20
invoke an operation<BR>&nbsp;on a nil pseudo-object =
reference.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</DIV><FONT size=3D2>
<DIV><FONT face=3DArial>#include &lt;gtk/gtk.h&gt; /* include gtk =
headers=20
*/</FONT></DIV>
<DIV><FONT face=3DArial>#include &lt;string.h&gt;</FONT></DIV>
<DIV><FONT face=3DArial>#include &lt;Comms.h&gt;</FONT></DIV>
<DIV><FONT face=3DArial>#include =
&lt;small_server_impl.h&gt;</FONT></DIV>
<DIV><FONT face=3DArial>#include &lt;unistd.h&gt;</FONT></DIV>
<DIV><FONT face=3DArial>#include &lt;pthread.h&gt;</FONT></DIV>
<DIV><FONT face=3DArial>#include &lt;iostream.h&gt;</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>&nbsp;&nbsp;&nbsp; =
server-&gt;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>&nbsp;&nbsp;&nbsp; GtkWidget =
*window,*table;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; GtkWidget =
*mybutton;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; try</FONT> </DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; gtk_init(&amp;argc, =
&amp;argv); /*=20
always needed */</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; orb=3DCORBA::ORB_init(argc,=20
argv,"omniORB3");&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; CORBA::Object_var obj =3D=20
orb-&gt;resolve_initial_references("RootPOA");</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; PortableServer::POA_var poa =
=3D=20
PortableServer::POA::_narrow(obj);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
//PortableServer::ObjectId_var=20
mysmall_server_iid =3D =
poa-&gt;activate_object(small_server_impl);</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; server =3D new=20
small_server_impl();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; CORBA::Object_var sref =3D=20
server-&gt;_this();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; CORBA::String_var ref =3D=20
orb-&gt;object_to_string( sref );</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
server-&gt;labels();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
server-&gt;textboxes();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
server-&gt;listboxes();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
server-&gt;buttons();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
server-&gt;entry_box();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp;=20
table=3Dserver-&gt;get_windows();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; mybutton =3D=20
gtk_button_new_with_label("Join");</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp;=20
gtk_signal_connect(GTK_OBJECT(mybutton),"clicked",GTK_SIGNAL_FUNC(client_=
connect),(ref));</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp;=20
gtk_table_attach_defaults(GTK_TABLE(table),mybutton,5,6,7,8);</FONT></DIV=
>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
gtk_widget_show(mybutton);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; pthread_t =
athread,bthread;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
pthread_create(&amp;athread,NULL,=20
(void*(*)(void*))gtk_run,NULL); /* always needed */</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
PortableServer::POAManager_var pman =3D=20
poa-&gt;the_POAManager();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
pman-&gt;activate();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; orb-&gt;run();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
orb-&gt;destroy();</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; return(0);</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>catch(CORBA::SystemException&amp;)</FONT> </DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; "Caught=20
CORBA::SystemException." &lt;&lt; endl;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>catch(CORBA::Exception&amp;)</FONT> </DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; "Caught=20
CORBA::Exception." &lt;&lt; endl;</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV>
<DIV><FONT face=3DArial>catch(omniORB::fatalException&amp; fe)</FONT> =
</DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; "Caught=20
omniORB::fatalException:" &lt;&lt; endl;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; " file: " =
&lt;&lt;=20
fe.file() &lt;&lt; endl;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; " line: " =
&lt;&lt;=20
fe.line() &lt;&lt; endl;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; " mesg: " =
&lt;&lt;=20
fe.errmsg() &lt;&lt; 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>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; "Caught unknown =

exception." &lt;&lt; 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>&nbsp;&nbsp;&nbsp; gint client_connect(GtkWidget =
*widget,=20
gpointer pointer)</FONT></DIV>
<DIV><FONT face=3DArial>{</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; int fault=3D1;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; char user[15];</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "I'm here =
in the=20
client connect function" &lt;&lt; endl;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; =
strcpy(user,"Warren");</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; CosNaming::NamingContext_var=20
rootContext;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; try</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; {</FONT> </DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
CORBA::Object_var=20
obj =3D orb-&gt;resolve_initial_references("NameService");</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
rootContext =3D=20
CosNaming::NamingContext::_narrow(obj);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
if(CORBA::is_nil(rootContext))</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
{</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
cerr &lt;&lt; "Failed to narrow the root naming context" &lt;&lt;=20
endl;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
exit(0);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; CosNaming::Name =
name;</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; name.length(2);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; name[0].id =3D (const char*)=20
"test";</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; name[0].kind =3D (const =
char*)=20
"my_context";</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; name[1].id =3D (const char*)=20
"Server";</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; name[1].kind =3D (const =
char*)=20
"Object";</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; try</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; {</FONT> </DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
CORBA::Object_var=20
nobj =3D rootContext-&gt;resolve(name);</FONT> </DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if=20
(!CORBA::is_nil(nobj))</FONT> </DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</FONT> =
</DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
Comms_var client =3D Comms::_narrow(nobj);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
if (client-&gt;connect((char*)user,(char*)pointer))</FONT> </DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
{</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; server-&gt;tell_server(client);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; gtk_widget_set_sensitive(widget,FALSE);</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
}</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else=20
server-&gt;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>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp;=20
catch(CosNaming::NamingContext::NotFound&amp; ex){ cerr &lt;&lt; =
"Context not=20
found" &lt;&lt; endl;}</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
catch(CORBA::ORB::InvalidName&amp; ex) { cerr &lt;&lt; "Service required =
is=20
invalid" &lt;&lt; endl;}</FONT></DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
catch(...){ cout=20
&lt;&lt; "You had another error dude" &lt;&lt; endl; }</FONT></DIV>
<DIV><FONT face=3DArial>}</FONT></DIV></FONT>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial><BR><FONT =
size=3D2></FONT></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0050_01C1B976.CF2E92E0--