=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / Bug_2349_Regression / server.cpp
blobc74308883f82ef97016f170f0f53dc0abed4a244
1 #include "fooS.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'o':
17 ior_output_file = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-o <iorfile>"
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 class foo_i: public POA_foo
35 public:
36 foo_i (CORBA::ORB_ptr orb)
37 : orb_ (CORBA::ORB::_duplicate (orb)) {
40 //FUZZ: disable check_for_lack_ACE_OS
41 void shutdown ();
42 //FUZZ: enable check_for_lack_ACE_OS
44 void destroy ();
46 private:
47 CORBA::ORB_var orb_;
50 void
51 foo_i::shutdown ()
53 this->orb_->shutdown ();
56 void
57 foo_i::destroy ()
59 bool expected_exception_raised = false;
61 try
63 // This should case an BAD_INV_ORDER exception
64 this->orb_->destroy ();
66 catch (const CORBA::BAD_INV_ORDER& ex)
68 if ((ex.minor() & 0xFFFU) == 3)
70 expected_exception_raised = true;
74 if (!expected_exception_raised)
75 ACE_ERROR ((LM_ERROR, "ERROR: Caught incorrect exception\n"));
76 else
77 ACE_DEBUG ((LM_DEBUG, "Caught correct exception\n"));
81 int
82 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
84 try
86 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
88 if (parse_args (argc, argv) != 0)
89 return 1;
91 CORBA::Object_var poa_object =
92 orb->resolve_initial_references("RootPOA");
94 PortableServer::POA_var root_poa =
95 PortableServer::POA::_narrow (poa_object.in ());
97 if (CORBA::is_nil (root_poa.in ()))
98 ACE_ERROR_RETURN ((LM_ERROR,
99 " (%P|%t) Panic: nil RootPOA\n"),
102 PortableServer::POAManager_var poa_manager =
103 root_poa->the_POAManager ();
105 foo_i* server_impl = 0;
106 ACE_NEW_RETURN (server_impl,
107 foo_i (orb.in ()),
109 PortableServer::ServantBase_var owner_transfer(server_impl);
111 PortableServer::ObjectId_var id =
112 root_poa->activate_object (server_impl);
114 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
116 foo_var server = foo::_narrow (object.in ());
118 CORBA::String_var ior =
119 orb->object_to_string (server.in ());
121 // Output the IOR to the <ior_output_file>
122 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
123 if (output_file == 0)
124 ACE_ERROR_RETURN ((LM_ERROR,
125 "Cannot open output file for writing IOR: %s",
126 ior_output_file),
128 ACE_OS::fprintf (output_file, "%s", ior.in ());
129 ACE_OS::fclose (output_file);
131 poa_manager->activate ();
133 orb->run ();
135 root_poa->destroy (true, true);
136 orb->destroy ();
138 catch (const CORBA::Exception& ex)
140 ex._tao_print_exception ("CORBA::Exception");
143 return 0;