Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_4080_Regression / server.cpp
blob189f408731fe65adaaa566da79644eb85aa71dcf
2 #include "ace/Task.h"
3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/PortableGroup/GOA.h"
5 #include "test_impl.h"
7 ACE_TCHAR const *uipmc_url =
8 ACE_TEXT ("corbaloc:miop:1.0@1.0-test-1/225.1.1.8:32158");
9 ACE_TCHAR const *ior_output_file = ACE_TEXT ("test.ior");
10 CORBA::ULong threads = 2u;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:u:t:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'o':
22 ior_output_file = get_opts.opt_arg ();
23 break;
25 case 'u':
26 uipmc_url = get_opts.opt_arg ();
27 break;
29 case 't':
30 threads = ACE_OS::strtoul (get_opts.opt_arg (), 0, 10);
31 break;
33 case '?':
34 default:
35 ACE_ERROR_RETURN ((LM_ERROR,
36 ACE_TEXT ("usage: %s ")
37 ACE_TEXT ("-o <iorfile> ")
38 ACE_TEXT ("-u <uipmc_url> ")
39 ACE_TEXT ("-t <threads> ")
40 ACE_TEXT ("\n"),
41 argv [0]),
42 -1);
44 // Indicates sucessful parsing of the command line.
45 return 0;
48 class OrbThread : public ACE_Task_Base
50 public:
51 OrbThread (CORBA::ORB_ptr orb)
52 : orb_ (CORBA::ORB::_duplicate (orb))
56 virtual int svc (void)
58 try
60 this->orb_->run ();
62 catch (const CORBA::Exception& ex)
64 ex._tao_print_exception ("Exception caught in OrbThread:");
65 return -1;
68 return 0;
71 private:
72 CORBA::ORB_var orb_;
75 int
76 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
78 try
80 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
82 if (parse_args (argc, argv) != 0)
83 ACE_ERROR_RETURN ((LM_ERROR,
84 ACE_TEXT ("ERROR: wrong arguments\n")),
85 -1);
87 CORBA::Object_var poa_object =
88 orb->resolve_initial_references("RootPOA");
90 PortableGroup::GOA_var root_goa =
91 PortableGroup::GOA::_narrow (poa_object.in ());
93 if (CORBA::is_nil (root_goa.in ()))
94 ACE_ERROR_RETURN ((LM_ERROR,
95 ACE_TEXT ("ERROR: nil RootPOA\n")),
96 -1);
98 PortableServer::POAManager_var poa_manager = root_goa->the_POAManager ();
100 // Create UIPMC reference.
101 CORBA::Object_var obj = orb->string_to_object (uipmc_url);
103 // Create id.
104 PortableServer::ObjectId_var id =
105 root_goa->create_id_for_reference (obj.in ());
107 // Activate UIPMC Object.
108 UIPMC_Object_Impl* uipmc_impl;
109 ACE_NEW_RETURN (uipmc_impl,
110 UIPMC_Object_Impl (orb.in (), threads),
111 -1);
112 PortableServer::ServantBase_var owner_transfer1 (uipmc_impl);
113 root_goa->activate_object_with_id (id.in (), uipmc_impl);
115 Test::UIPMC_Object_var uipmc_obj =
116 Test::UIPMC_Object::_unchecked_narrow (obj.in ());
118 if (CORBA::is_nil (uipmc_obj.in ()))
119 ACE_ERROR_RETURN ((LM_ERROR,
120 ACE_TEXT ("ERROR: nil Hello object\n")),
121 -1);
122 CORBA::String_var ior = orb->object_to_string (obj.in ());
124 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("MIOP object is <%C>\n"), ior.in ()));
126 //obj = hello_impl->_this ();
128 // If the ior_output_file exists, output the ior to it.
129 if (ior_output_file != 0)
131 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
133 if (output_file == 0)
135 ACE_ERROR_RETURN ((LM_ERROR,
136 ACE_TEXT ("Cannot open output file ")
137 ACE_TEXT ("for writing IOR: %s"),
138 ior_output_file),
139 -1);
142 ACE_OS::fprintf (output_file, "%s", ior.in ());
143 ACE_OS::fclose (output_file);
146 poa_manager->activate ();
149 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Starting %u thread, thread pool\n"), (unsigned) threads));
150 // start server thread pool
151 OrbThread orb_thr (orb.in ());
152 orb_thr.activate (THR_NEW_LWP | THR_JOINABLE, threads);
153 orb_thr.wait ();
154 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Stopping thread pool\n")));
157 root_goa->destroy (1, 1);
159 orb->destroy ();
161 catch (const CORBA::Exception& ex)
163 ex._tao_print_exception ("Exception caught in server main ():");
164 return -1;
167 ACE_DEBUG ((LM_DEBUG,
168 ACE_TEXT ("\nServer finished successfully.\n")));
169 return 0;