More tests update
[ACE_TAO.git] / TAO / tests / CollocationLockup / SimpleNamingService.cpp
blob97aab729a417f1ccbaa4352451c90a1094cdc357
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 (void)
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:
61 //FUZZ: disable check_for_lack_ACE_OS
62 virtual void bind (CORBA::Object_ptr obj)
64 obj_ = CORBA::Object::_duplicate (obj);
66 //FUZZ: enable check_for_lack_ACE_OS
69 virtual CORBA::Object_ptr resolve ()
71 return CORBA::Object::_duplicate (obj_.in ());
74 private:
76 CORBA::Object_var obj_;
80 int
81 parse_args (int argc, ACE_TCHAR *argv[])
83 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
84 int c;
86 while ((c = get_opts ()) != -1)
87 switch (c)
89 case 'o':
90 iorFileName = get_opts.opt_arg ();
91 break;
93 case '?':
94 default:
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "usage: %s "
97 "-o <iorfile>"
98 "\n",
99 argv [0]),
100 -1);
102 // Indicates successful parsing of the command line
103 return 0;
108 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
112 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
114 TestShutdown killer (orb.in ());
116 if (parse_args (argc, argv) != 0)
117 return 1;
119 CORBA::Object_var pPoaObj =
120 orb->resolve_initial_references ("RootPOA");
121 PortableServer::POA_var poa =
122 PortableServer::POA::_narrow (pPoaObj.in ());
123 PortableServer::POAManager_var pMgr = poa->the_POAManager ();
124 pMgr->activate ();
126 SimpleNamingService_i* servant = new SimpleNamingService_i;
127 PortableServer::ObjectId_var oid = poa->activate_object (servant);
128 CORBA::Object_var obj = poa->id_to_reference (oid.in ());
129 CORBA::String_var str = orb->object_to_string (obj.in ());
131 FILE *output_file= ACE_OS::fopen (iorFileName, "w");
132 if (output_file == 0)
133 ACE_ERROR_RETURN ((LM_ERROR,
134 "Cannot open output file for writing IOR: %s\n",
135 iorFileName),
137 ACE_OS::fprintf (output_file, "%s", str.in ());
138 ACE_OS::fclose (output_file);
140 orb->run ();
142 catch (const CORBA::Exception& ex)
144 ACE_DEBUG ((LM_ERROR, "Corba Exception: %s\n", ex._info ().c_str ()));
145 return 1;
148 return 0;