2 * SimpleNamingService.cpp
3 * This is part of the regression test against bug #2130.
4 * See CollocationLockup.cpp for a description of the test.
7 #include "SimpleNamingServiceS.h"
9 #include "ace/String_Base.h"
10 #include "ace/streams.h"
11 #include "ace/Get_Opt.h"
13 #include "ace/Event_Handler.h"
14 #include "ace/Sig_Handler.h"
16 class TestShutdown
: public ACE_Event_Handler
19 TestShutdown (CORBA::ORB_ptr orb
)
20 : orb_(CORBA::ORB::_duplicate (orb
))
22 #if !defined(ACE_LACKS_UNIX_SIGNALS)
23 this->shutdown_
.register_handler (SIGTERM
, this);
24 this->shutdown_
.register_handler (SIGINT
, this);
25 #elif defined(ACE_WIN32)
26 this->shutdown_
.register_handler (SIGINT
, this);
32 #if !defined(ACE_LACKS_UNIX_SIGNALS)
33 this->shutdown_
.remove_handler (SIGTERM
);
34 this->shutdown_
.remove_handler (SIGINT
);
35 #elif defined(ACE_WIN32)
36 this->shutdown_
.remove_handler (SIGINT
);
40 virtual int handle_signal (int, siginfo_t
*, ucontext_t
*)
42 this->orb_
->shutdown ();
49 ACE_Sig_Handler shutdown_
;
54 const ACE_TCHAR
* iorFileName
= ACE_TEXT("SimpleNamingService.ior");
57 class SimpleNamingService_i
: public virtual POA_SimpleNamingService
60 //FUZZ: disable check_for_lack_ACE_OS
61 virtual void bind (CORBA::Object_ptr obj
)
63 obj_
= CORBA::Object::_duplicate (obj
);
65 //FUZZ: enable check_for_lack_ACE_OS
68 virtual CORBA::Object_ptr
resolve ()
70 return CORBA::Object::_duplicate (obj_
.in ());
74 CORBA::Object_var obj_
;
78 parse_args (int argc
, ACE_TCHAR
*argv
[])
80 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
83 while ((c
= get_opts ()) != -1)
87 iorFileName
= get_opts
.opt_arg ();
92 ACE_ERROR_RETURN ((LM_ERROR
,
99 // Indicates successful parsing of the command line
105 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
109 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
111 TestShutdown
killer (orb
.in ());
113 if (parse_args (argc
, argv
) != 0)
116 CORBA::Object_var pPoaObj
=
117 orb
->resolve_initial_references ("RootPOA");
118 PortableServer::POA_var poa
=
119 PortableServer::POA::_narrow (pPoaObj
.in ());
120 PortableServer::POAManager_var pMgr
= poa
->the_POAManager ();
123 SimpleNamingService_i
* servant
= new SimpleNamingService_i
;
124 PortableServer::ObjectId_var oid
= poa
->activate_object (servant
);
125 CORBA::Object_var obj
= poa
->id_to_reference (oid
.in ());
126 CORBA::String_var str
= orb
->object_to_string (obj
.in ());
128 FILE *output_file
= ACE_OS::fopen (iorFileName
, "w");
129 if (output_file
== 0)
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 "Cannot open output file for writing IOR: %s\n",
134 ACE_OS::fprintf (output_file
, "%s", str
.in ());
135 ACE_OS::fclose (output_file
);
139 catch (const CORBA::Exception
& ex
)
141 ACE_DEBUG ((LM_ERROR
, "Corba Exception: %s\n", ex
._info ().c_str ()));