Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_4010_Regression / client.cpp
blobad27bb0f31cd8e529f344fbcd011c47a6cc40c18
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/ORB_Core.h"
4 #include "ace/Reactor.h"
5 #include "ace/Event_Handler.h"
7 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
8 int iterations = 3;
9 int timeout = 10;
10 int process_result = 1;
12 int parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:t:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
23 case 'i':
24 iterations = ACE_OS::atoi(get_opts.opt_arg ());
25 break;
26 case 't':
27 timeout = ACE_OS::atoi(get_opts.opt_arg ());
28 break;
30 case '?':
31 default:
32 ACE_ERROR_RETURN ((LM_ERROR,
33 "usage: %s "
34 "-k <ior> "
35 "-i <iterations> "
36 "-t <timeout> "
37 "\n",
38 argv [0]),
39 -1);
41 // Indicates successful parsing of the command line
42 return 0;
45 class PeriodicTask : public ACE_Event_Handler
47 public:
48 explicit PeriodicTask(CORBA::ORB_var orbIn)
49 : ACE_Event_Handler(),
50 orb(orbIn),
51 iterationsLeft(iterations),
52 successfulConnections(0)
56 virtual ~PeriodicTask()
60 virtual int handle_timeout(const ACE_Time_Value &, const void *)
62 --iterationsLeft;
64 try
66 ACE_DEBUG ((LM_DEBUG,
67 "\n(%P|%t) - handling timeout with %d iterations left\n",
68 iterationsLeft + 1));
69 CORBA::Object_var tmp = orb->string_to_object(ior);
71 Test::Hello_var hello = Test::Hello::_narrow(tmp.in ());
73 if (CORBA::is_nil (hello.in ()))
75 ACE_ERROR_RETURN ((LM_DEBUG,
76 "Nil Test::Hello reference <%s>\n",
77 ior),
78 1);
81 CORBA::String_var the_string = hello->get_string ();
83 ++successfulConnections;
84 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
85 the_string.in ()));
86 ACE_OS::sleep(2);
87 hello->shutdown ();
89 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - shutdown requested\n"));
91 catch (const CORBA::Exception& ex)
93 ex._tao_print_exception ("Exception caught:");
94 process_result = 1;
95 orb->shutdown();
98 if(successfulConnections == 2)
100 process_result = 0;
101 orb->shutdown();
104 return 0;
107 protected:
108 private:
109 PeriodicTask(const PeriodicTask &);
110 PeriodicTask & operator=(const PeriodicTask &);
111 CORBA::ORB_var orb;
112 int iterationsLeft;
113 int successfulConnections;
117 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
121 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
123 if (parse_args (argc, argv) != 0)
124 return 1;
126 PeriodicTask periodicTask(orb);
128 orb->orb_core()->reactor()->schedule_timer(&periodicTask, 0, ACE_Time_Value::zero, ACE_Time_Value(timeout));
130 orb->run();
132 orb->destroy ();
134 catch (const CORBA::Exception& ex)
136 ex._tao_print_exception ("Exception caught:");
137 return 1;
140 return process_result;