=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / Big_Request_Muxing / client.cpp
blobb12c3d046bc8ea0d291daef1a5887f65417a9f08
1 #include "Client_Task.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/Messaging/Messaging.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 namespace
9 // There are 3 clients so the server should expect:
10 // 3 * NUM_MSGS * NUM_THRDS total messages.
11 const int NUM_MSGS = 100;
12 const int NUM_THRDS = 2;
13 const int MSG_SIZE = 4096;
16 int
17 parse_args (int argc, ACE_TCHAR *argv[])
19 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
20 int c;
22 while ((c = get_opts ()) != -1)
23 switch (c)
25 case 'k':
26 ior = get_opts.opt_arg ();
27 break;
29 case '?':
30 default:
31 ACE_ERROR_RETURN ((LM_ERROR,
32 "usage: %s "
33 "-k <ior>"
34 "\n",
35 argv [0]),
36 -1);
38 // Indicates successful parsing of the command line
39 return 0;
42 int
43 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
45 ACE_DEBUG ((LM_DEBUG, "(%P) Starting client\n"));
47 try
49 CORBA::ORB_var orb =
50 CORBA::ORB_init (argc, argv);
52 if (parse_args (argc, argv) != 0)
54 return 1;
57 CORBA::Object_var tmp =
58 orb->string_to_object(ior);
60 Test::Payload_Receiver_var payload_receiver =
61 Test::Payload_Receiver::_narrow(tmp.in ());
63 if (CORBA::is_nil (payload_receiver.in ()))
65 ACE_ERROR_RETURN ((LM_DEBUG,
66 "(%P) Nil coordinator reference <%s>\n",
67 ior),
68 1);
71 Client_Task task0 (ACE_Thread_Manager::instance (),
72 payload_receiver.in (),
73 NUM_MSGS,
74 MSG_SIZE,
75 orb.in (),
76 Messaging::SYNC_WITH_TARGET,
77 ACE_CString("Sync_With_Target"));
78 Client_Task task1 (ACE_Thread_Manager::instance (),
79 payload_receiver.in (),
80 NUM_MSGS,
81 MSG_SIZE,
82 orb.in (),
83 Messaging::SYNC_WITH_TRANSPORT,
84 ACE_CString("Sync_With_Transport"));
85 Client_Task task2 (ACE_Thread_Manager::instance (),
86 payload_receiver.in (),
87 NUM_MSGS,
88 MSG_SIZE,
89 orb.in (),
90 Messaging::SYNC_NONE,
91 ACE_CString("Sync_None"));
93 if (TAO_debug_level > 0)
95 ACE_DEBUG ((LM_DEBUG, "(%P) Client: Activating threads\n"));
97 if (task0.activate (THR_NEW_LWP | THR_JOINABLE, NUM_THRDS, 1) == -1)
99 ACE_ERROR ((LM_ERROR, "(%P) Client: Error activating %s task\n", task0.ID ()));
101 if (task1.activate (THR_NEW_LWP | THR_JOINABLE, NUM_THRDS, 1) == -1)
103 ACE_ERROR ((LM_ERROR, "(%P) Client: Error activating %s task\n", task1.ID ()));
105 if (task2.activate (THR_NEW_LWP | THR_JOINABLE, NUM_THRDS, 1) == -1)
107 ACE_ERROR ((LM_ERROR, "(%P) Client: Error activating %s task\n", task2.ID ()));
110 ACE_Time_Value end_time = ACE_OS::gettimeofday() + ACE_Time_Value(30);
111 while (ACE_OS::gettimeofday() < end_time)
113 ACE_Time_Value tv (0, 100 * 1000);
114 orb->run (tv);
115 if (task0.done() && task1.done() && task2.done())
116 break;
119 ACE_Thread_Manager::instance ()->wait ();
120 if (TAO_debug_level > 0)
122 ACE_DEBUG ((LM_DEBUG, "(%P) Client: Threads finished posting\n"));
125 while (orb->work_pending())
127 ACE_Time_Value tv(0, 100 * 1000);
128 orb->run(tv);
131 if (TAO_debug_level > 0)
133 ACE_DEBUG ((LM_DEBUG, "(%P) Client: work finished\n"));
136 // Allow time for the server to process messages at the other end
137 // of the tcpip link before we destroy the sockets and rip down
138 // any pending messages it may have buffered up. Note this is ONLY
139 // for the benifit of the SYNC_NONE and SYNC_WITH_TRANSPORT messages.
140 ACE_Time_Value tv (4, 0);
141 orb->run (tv);
142 orb->destroy ();
144 catch (const CORBA::Exception& ex)
146 ACE_DEBUG ((LM_DEBUG, "(%P) Client: "));
147 ex._tao_print_exception ("CORBA Exception caught:");
148 return 1;
150 catch (...)
152 ACE_DEBUG ((LM_DEBUG, "(%P) Client caught unknown exception\n"));
153 return 1;
156 ACE_DEBUG ((LM_DEBUG, "(%P) Ending client (result 0)\n"));
158 return 0;