Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_2683_Regression / client.cpp
blobb2204a920f102082c94194f658d63ba62fdacf81
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task.h"
4 #include "ace/OS_NS_unistd.h"
6 class Pinger : public ACE_Task_Base
8 private:
9 const char * ior_;
10 CORBA::ORB_var orb_;
11 bool do_shutdown_;
12 bool stop_;
14 public:
15 Pinger (CORBA::ORB_var &orb, const char *ior)
16 : ior_ (ior),
17 orb_(orb),
18 do_shutdown_ (false),
19 stop_ (false)
23 int svc ()
25 bool keep_going = true;
26 while (keep_going && !this->stop_)
28 try
30 CORBA::Object_var tmp = this->orb_->string_to_object(this->ior_);
32 Test::IORTable_Shutdown_Race_var target =
33 Test::IORTable_Shutdown_Race::_narrow(tmp.in ());
34 if (CORBA::is_nil (target.in ()))
35 ACE_ERROR_RETURN ((LM_DEBUG,
36 "(%P|%t) Nil target reference <%s>\n",
37 this->ior_),
38 1);
39 target->ping();
40 if (this->do_shutdown_)
42 ACE_DEBUG ((LM_DEBUG,"(%P|%t) Calling shutdown\n"));
43 this->do_shutdown_ = false;
44 target->shutdown ();
47 catch (const CORBA::Exception &ex)
49 ACE_DEBUG ((LM_DEBUG,
50 "(%P|%t) caught an exception - %C\n",ex._name()));
51 keep_going = false;
54 return 0;
57 void killit()
59 do_shutdown_ = true;
62 void stop ()
64 stop_ = true;
68 int port = 0;
69 ACE_TCHAR const * target_host = ACE_TEXT("localhost");
71 int
72 parse_args (int argc, ACE_TCHAR *argv[])
74 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:h:"));
75 int c;
77 while ((c = get_opts ()) != -1)
78 switch (c)
80 case 'p':
81 port = ACE_OS::atoi (get_opts.opt_arg ());
82 break;
83 case 'h':
84 target_host = get_opts.opt_arg ();
85 break;
86 case '?':
87 default:
88 ACE_ERROR_RETURN ((LM_ERROR,
89 "usage: %s "
90 "-p <server_port> "
91 "\n",
92 argv [0]),
93 -1);
95 // Indicates successful parsing of the command line
96 return 0;
99 int
100 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
104 CORBA::ORB_var orb =
105 CORBA::ORB_init (argc, argv);
107 if (parse_args (argc, argv) != 0)
108 return 1;
110 char ior[100];
111 ACE_OS::sprintf (ior, "corbaloc::%s:%d/Racer",
112 ACE_TEXT_ALWAYS_CHAR (target_host), port);
114 Pinger pinger(orb, ior);
116 ACE_OS::sleep (1);
118 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client - starting client threads\n"));
120 pinger.activate (THR_NEW_LWP | THR_JOINABLE, 5);
122 ACE_OS::sleep (1);
124 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client - All running, time to shutdown server\n"));
125 pinger.killit();
127 ACE_OS::sleep (2);
129 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client - Stopping client threads\n"));
130 pinger.stop ();
132 pinger.wait();
133 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client done\n"));
135 catch (const CORBA::Exception &ex)
137 ACE_DEBUG ((LM_DEBUG,"Main caught %s\n",ex._name()));
138 return 1;
141 return 0;