Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Collocation_Oneway_Tests / Collocated_Test.cpp
blobe95f9c20d581227b009bd6c1f06bd02e8a605673
1 #include "Server_Task.h"
2 #include "Client_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Argv_Type_Converter.h"
5 #include "ace/SString.h"
6 #include "ace/Manual_Event.h"
8 const ACE_TCHAR *output = ACE_TEXT("test.ior");
9 const ACE_TCHAR *input = ACE_TEXT("file://test.ior");
10 const ACE_TCHAR *mode = ACE_TEXT("SYNC_NONE");
12 Client_Task::ClientSyncModeEnum syncMode = Client_Task::MODE_NONE;
14 // static int named_orbs = 0;
15 ACE_CString server_orb;
16 ACE_CString client_orb;
17 int
18 parse_args (int argc, ACE_TCHAR *argv[])
20 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n:m:"));
21 int c;
23 while ((c = get_opts ()) != -1)
24 switch (c)
26 case 'o':
27 output = get_opts.opt_arg ();
28 break;
29 case 'k':
30 input = get_opts.opt_arg ();
31 break;
32 case 'n':
33 // named_orbs = 1;
34 server_orb.set ("server_orb");
35 client_orb.set ("client_orb");
36 break;
37 case 'm':
38 mode = get_opts.opt_arg ();
39 // cout << "mode = " << mode << endl;
40 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - mode set to <%C> for collocated oneway test\n", mode));
41 if(mode) {
42 if(!ACE_OS::strcmp(ACE_TEXT("none"), mode)) {
43 syncMode = Client_Task::MODE_NONE;
45 else if (!ACE_OS::strcmp(ACE_TEXT("transport"), mode)) {
46 syncMode = Client_Task::MODE_TRANSPORT;
48 else if (!ACE_OS::strcmp(ACE_TEXT("server"), mode)) {
49 syncMode = Client_Task::MODE_SERVER;
51 else if (!ACE_OS::strcmp(ACE_TEXT("target"), mode)) {
52 syncMode = Client_Task::MODE_TARGET;
55 else {
56 // same hack used in original test!
57 return 0;
59 break;
60 case '?':
61 default:
62 // This is a hack but that is okay!
63 return 0;
65 // Indicates successful parsing of the command line
66 return 0;
69 int
70 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
72 if (parse_args (argc,
73 argv) == -1)
74 return -1;
76 try
78 ACE_Argv_Type_Converter satc (argc, argv);
79 CORBA::ORB_var sorb =
80 CORBA::ORB_init (satc.get_argc (),
81 satc.get_TCHAR_argv (),
82 server_orb.c_str ());
84 ACE_Manual_Event me;
85 Server_Task server_task (output,
86 sorb.in (),
87 me,
88 ACE_Thread_Manager::instance ());
90 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE,
92 1) == -1)
94 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
97 // Wait for the server thread to do some processing
98 me.wait ();
100 ACE_Argv_Type_Converter catc (argc, argv);
101 CORBA::ORB_var corb =
102 CORBA::ORB_init (catc.get_argc (),
103 catc.get_TCHAR_argv (),
104 client_orb.c_str ());
106 Client_Task client_task (input,
107 corb.in (),
108 syncMode,
109 ACE_Thread_Manager::instance ());
111 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE,
113 1) == -1)
115 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
118 ACE_Thread_Manager::instance ()->wait ();
120 catch (const CORBA::Exception&)
122 // Ignore exceptions..
124 return 0;