1 #include "Client_Task.h"
2 #include "Server_Task.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_strings.h"
14 MyMain (int argc
, ACE_TCHAR
* argv
[]);
21 bool init_server (const ACE_TCHAR
* args
);
22 bool init_client (const ACE_TCHAR
* args
);
24 std::unique_ptr
<Server_Task
> server_task_
;
25 std::unique_ptr
<Client_Task
> client_task_
;
31 void MyMain::print_usage ()
34 bool MyMain::init_server (const ACE_TCHAR
* args
)
36 std::string
my_args (ACE_TEXT_ALWAYS_CHAR (args
));
37 // main thread and extra thread for backdoor operations
40 server_task_
= std::make_unique
<Server_Task
> (my_args
);
42 ACE_ASSERT (server_task_
);
44 server_task_
->activate (THR_NEW_LWP
| THR_JOINABLE
| THR_INHERIT_SCHED
, thread_pool
);
46 int duration
= 4; // wait 3 seconds for initialization
47 ACE_Time_Value current
= ACE_High_Res_Timer::gettimeofday_hr ();
48 ACE_Time_Value timeout
= current
+ ACE_Time_Value (duration
);
50 while (current
< timeout
)
52 if (server_task_
->ready ())
56 ACE_Time_Value sleep_time
;
58 ACE_OS::sleep (sleep_time
);
59 current
+= sleep_time
;
62 if (!server_task_
->ready ())
64 server_task_
->force_shutdown ();
65 server_task_
->wait ();
66 server_task_
.reset ();
73 bool MyMain::init_client (const ACE_TCHAR
* args
)
75 std::string
my_args (ACE_TEXT_ALWAYS_CHAR (args
));
78 client_task_
= std::make_unique
<Client_Task
> (my_args
);
80 ACE_ASSERT (client_task_
);
82 client_task_
->activate (THR_NEW_LWP
| THR_JOINABLE
| THR_INHERIT_SCHED
, thread_pool
);
87 MyMain::MyMain (int argc
, ACE_TCHAR
* argv
[])
92 for (int p
= 1; p
<= argc
; p
++)
94 if (ACE_OS::strcmp (argv
[p
], ACE_TEXT ("-?")) == 0)
100 if (ACE_OS::strcasecmp (argv
[p
], ACE_TEXT ("-s")) == 0)
102 const ACE_TCHAR
* s_args
= (((p
+ 1) <= argc
) ? argv
[p
+ 1] : 0);
103 s_init_
= this->init_server (s_args
);
106 else if (ACE_OS::strcasecmp (argv
[p
], ACE_TEXT ("-c")) == 0)
108 const ACE_TCHAR
* s_args
= (((p
+ 1) <= argc
) ? argv
[p
+ 1] : 0);
111 this->init_client (s_args
);
122 server_task_
->wait ();
127 client_task_
->wait ();
141 int ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
143 MyMain
my_main (argc
, argv
);