=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / Bug_2417_Regression / server.cpp
blobb9fa51e3b41d74549fdf8c421b52b049b2bb6ad3
1 #include "publisher_impl.h"
2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/Task.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT ("ior.out");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 class ThreadPool : public ACE_Task_Base
37 public:
38 ThreadPool (CORBA::ORB_ptr orb);
39 virtual int svc ();
40 private:
41 CORBA::ORB_var orb_;
44 int
45 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
47 try
49 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
51 if (parse_args (argc, argv) != 0)
52 return 1;
54 CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA");
56 if (CORBA::is_nil (poa_object.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR,
58 " (%P|%t) Unable to initialize the POA.\n"),
59 1);
61 PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ());
62 PortableServer::POAManager_var poa_manager =
63 root_poa->the_POAManager();
65 Publisher_impl publisher(orb.in ());
66 PortableServer::ObjectId_var id = root_poa->activate_object (&publisher);
68 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
70 Publisher_var publisher_var = Publisher::_narrow (object.in ());
72 CORBA::String_var ior = orb->object_to_string(publisher_var.in());
73 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in()));
75 // output the ior
76 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
77 if (output_file == 0)
78 ACE_ERROR_RETURN ((LM_ERROR,
79 "Cannot open output file for writing IOR: %s\n",
80 ior_output_file),
81 1);
82 ACE_OS::fprintf (output_file, "%s", ior.in ());
83 ACE_OS::fclose (output_file);
85 poa_manager->activate();
87 const CORBA::Object_var pmobj (orb->resolve_initial_references("ORBPolicyManager" ));
88 CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(pmobj.in());
90 CORBA::Any orb_level;
91 orb_level <<= Messaging::SYNC_NONE;
92 CORBA::PolicyList policy_list;
93 policy_list.length(1);
94 policy_list[0] = orb->create_policy(Messaging::SYNC_SCOPE_POLICY_TYPE,
95 orb_level);
96 policy_manager->set_policy_overrides(policy_list,
97 CORBA::SET_OVERRIDE);
99 ThreadPool pool (orb.in ());
100 if (pool.activate(THR_NEW_LWP | THR_JOINABLE, 5) != 0)
101 ACE_ERROR_RETURN ((LM_ERROR,
102 "Cannot activate client threads\n"),
105 pool.thr_mgr ()->wait ();
107 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
109 catch (const CORBA::Exception& ex)
111 ex._tao_print_exception ("Exception caught:");
112 return 1;
115 return 0;
118 // ****************************************************************
120 ThreadPool::ThreadPool(CORBA::ORB_ptr orb)
121 : orb_(CORBA::ORB::_duplicate (orb))
125 int ThreadPool::svc ()
129 this->orb_->run ();
131 catch (...)
134 return 0;