Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_3827_Regression / test.cpp
blob94b828523ba3206948897c3b4f05e583aaa6ee8d
1 #include "MessageC.h"
2 #include "ace/Task.h"
3 #include "ace/OS_NS_unistd.h"
5 int status = 0;
7 class ORB_Task : public ACE_Task_Base
9 public:
10 ORB_Task (CORBA::ORB_ptr orb)
11 : orb_ (CORBA::ORB::_duplicate (orb))
15 virtual int svc ()
17 try
19 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Event loop started\n"));
20 this->orb_->run ();
21 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Event loop finished\n"));
23 catch (const CORBA::Exception& )
26 return 0;
29 private:
30 CORBA::ORB_var orb_;
33 class Worker_Task : public ACE_Task_Base
35 public:
36 Worker_Task (CORBA::ORB_ptr orb)
37 : orb_ (CORBA::ORB::_duplicate (orb))
41 virtual int svc ()
43 try
45 Message_init *mi = new Message_init ();
46 CORBA::ValueFactoryBase_var safe (mi);
48 while (1)
50 CORBA::ValueFactoryBase_var tmp1 =
51 this->orb_->register_value_factory (mi->tao_repository_id (), mi);
53 CORBA::ValueFactoryBase_var tmp2 =
54 this->orb_->lookup_value_factory (mi->tao_repository_id ());
56 this->orb_->unregister_value_factory (mi->tao_repository_id ());
59 catch (const CORBA::BAD_INV_ORDER&)
61 // It's ok to ignore BAD_INV_ORDER which can be thrown after orb
62 // is shutdown from other thread.
64 catch (const CORBA::Exception&)
66 ACE_ERROR ((LM_ERROR,
67 ACE_TEXT ("ERROR: Unexpected exception.\n")));
68 status = 1;
70 return 0;
73 private:
74 CORBA::ORB_var orb_;
77 int
78 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
80 try
82 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
84 ORB_Task orb_runner (orb.in ());
85 if (orb_runner.activate (THR_NEW_LWP | THR_JOINABLE, 1) == -1)
87 ACE_ERROR_RETURN ((LM_ERROR,
88 "ERROR: Can not start ORB thread\n"),
89 -1);
92 ACE_OS::sleep (1);
94 Worker_Task work_runner (orb.in ());
95 if (work_runner.activate (THR_NEW_LWP | THR_JOINABLE, 10) == -1)
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "ERROR: Can not start work threads\n"),
99 -1);
102 ACE_OS::sleep (1);
104 ACE_DEBUG ((LM_DEBUG,
105 ACE_TEXT ("(%P|%t) Shutting down / destroying ORB\n")));
107 orb->shutdown (false);
109 ACE_Thread_Manager::instance ()->wait ();
111 orb->destroy ();
113 catch (const CORBA::Exception& ex)
115 ex._tao_print_exception ("Exception caught:");
116 return 1;
119 return status;