Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_2417_Regression / client.cpp
blobc20afbb4460aa93730173030e555ec83586c46cc
1 #include "subscriber_impl.h"
2 #include "publisherC.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Task.h"
6 const ACE_TCHAR *ior = ACE_TEXT ("file://ior.out");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 ior = get_opts.opt_arg ();
19 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-k <ior> "
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 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 (
62 poa_object.in ());
63 PortableServer::POAManager_var poa_manager =
64 root_poa->the_POAManager();
66 Subscriber_impl subscriber(orb.in ());
67 PortableServer::ObjectId_var id =
68 root_poa->activate_object (&subscriber);
70 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
72 Subscriber_var subscriber_var = Subscriber::_narrow (object.in ());
74 object = orb->string_to_object(ior);
75 Publisher_var publisher = Publisher::_narrow(object.in());
77 publisher->subscribe(subscriber_var.in());
79 poa_manager->activate();
81 ThreadPool pool (orb.in ());
82 if (pool.activate(THR_NEW_LWP | THR_JOINABLE, 5) != 0)
83 ACE_ERROR_RETURN ((LM_ERROR,
84 "Cannot activate client threads\n"),
85 1);
87 pool.thr_mgr ()->wait ();
89 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
91 catch (const CORBA::Exception& ex)
93 ex._tao_print_exception ("Exception caught:");
94 return 1;
97 return 0;
100 // ****************************************************************
102 ThreadPool::ThreadPool(CORBA::ORB_ptr orb)
103 : orb_(CORBA::ORB::_duplicate (orb))
107 int ThreadPool::svc ()
111 this->orb_->run ();
113 catch (...)
116 return 0;