Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / CollocationLockup / SimpleNamingService.cpp
blobe535dc43946081e3a043039c80e06e9bd23dc7c6
1 /**
2 * SimpleNamingService.cpp
3 * This is part of the regression test against bug #2130.
4 * See CollocationLockup.cpp for a description of the test.
5 */
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
18 public:
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);
27 #endif
30 ~TestShutdown ()
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);
37 #endif
40 virtual int handle_signal (int, siginfo_t*, ucontext_t*)
42 this->orb_->shutdown ();
43 return 0;
46 private:
47 CORBA::ORB_var orb_;
49 ACE_Sig_Handler shutdown_;
52 namespace
54 const ACE_TCHAR* iorFileName = ACE_TEXT("SimpleNamingService.ior");
57 class SimpleNamingService_i : public virtual POA_SimpleNamingService
59 public:
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 ());
73 private:
74 CORBA::Object_var obj_;
77 int
78 parse_args (int argc, ACE_TCHAR *argv[])
80 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
81 int c;
83 while ((c = get_opts ()) != -1)
84 switch (c)
86 case 'o':
87 iorFileName = get_opts.opt_arg ();
88 break;
90 case '?':
91 default:
92 ACE_ERROR_RETURN ((LM_ERROR,
93 "usage: %s "
94 "-o <iorfile>"
95 "\n",
96 argv [0]),
97 -1);
99 // Indicates successful parsing of the command line
100 return 0;
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)
114 return 1;
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 ();
121 pMgr->activate ();
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",
132 iorFileName),
134 ACE_OS::fprintf (output_file, "%s", str.in ());
135 ACE_OS::fclose (output_file);
137 orb->run ();
139 catch (const CORBA::Exception& ex)
141 ACE_DEBUG ((LM_ERROR, "Corba Exception: %s\n", ex._info ().c_str ()));
142 return 1;
145 return 0;