Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Oneway_Send_Timeouts / Server_Task.h
blob7db4ed5e1cd53dd74caf294fb370846ed6c0a49b
1 #ifndef _SERVER_TASK_
2 #define _SERVER_TASK_
4 #include "Server.h"
6 #include "ace/ARGV.h"
7 #include "ace/Task.h"
9 #include <string>
11 class Server_Task : public ACE_Task_Base
13 public:
14 Server_Task (const std::string& args)
15 : args_ (args)
17 ~Server_Task () { this->force_shutdown (); }
19 virtual int svc ()
21 bool initializer = false;
23 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
24 if (!server_)
26 ACE_ARGV my_args (args_.c_str ());
28 // Initialize Server ORB in new thread
29 server_ = std::make_unique<Server> (my_args.argc (), my_args.argv ());
31 ACE_ASSERT (server_);
32 initializer = true;
36 if (initializer)
38 server_->run (false);
39 this->force_shutdown (); // servant thread is responsible for shutdown
41 else
43 server_->run (true);
46 return 0;
49 bool ready ()
51 if (server_)
53 return server_->init_;
56 return false;
59 void force_shutdown ()
61 if (server_)
63 server_->shutdown ();
67 private:
68 std::string args_;
69 std::unique_ptr<Server> server_;
70 TAO_SYNCH_MUTEX mutex_;
73 #endif //_SERVER_TASK_