Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Oneway_Send_Timeouts / Server_Task.h
blob08862f30111d72c8e197b07ea8f02ec3f0e069cf
1 #ifndef _SERVER_TASK_
2 #define _SERVER_TASK_
4 #include "Server.h"
6 #include "ace/Task.h"
7 #include "ace/ARGV.h"
8 #include "ace/Auto_Ptr.h"
10 class Server_Task : public ACE_Task_Base
12 public:
14 Server_Task (const std::string& args)
15 : args_ (args)
16 { }
17 ~Server_Task ()
19 this->force_shutdown ();
22 virtual int svc ()
24 bool initializer = false;
26 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
27 if (server_.get() == 0) {
28 ACE_ARGV my_args (args_.c_str());
30 // Initialize Server ORB in new thread
31 ACE_auto_ptr_reset (server_, new Server (my_args.argc(), my_args.argv()));
32 ACE_ASSERT (server_.get() != 0);
33 initializer = true;
37 if (initializer) {
38 server_->run (false);
39 this->force_shutdown (); // servant thread is responsible for shutdown
41 else {
42 server_->run (true);
45 return 0;
48 bool ready ()
50 if (server_.get() != 0) {
51 return server_->init_;
54 return false;
57 void force_shutdown ()
59 if (server_.get() != 0) {
60 server_->shutdown ();
64 private:
65 std::string args_;
66 std::auto_ptr<Server> server_;
67 TAO_SYNCH_MUTEX mutex_;
70 #endif //_SERVER_TASK_