Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tao / Utils / Server_Main.cpp
blobb21ec16ebb89a38bcb36cd55b9c210ce8aa65b24
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Server_Main.cpp
7 * Implements a generic object that acts as "main" for a CORBA server.
9 * @author Dale Wilson <wilson_d@ociweb.com>
11 //=============================================================================
13 #ifndef TAO_UTILS_SERVER_MAIN_T_CPP
14 #define TAO_UTILS_SERVER_MAIN_T_CPP
16 #include "tao/Utils/Server_Main.h"
18 #include "tao/ORB.h"
20 #include "ace/Argv_Type_Converter.h"
21 #include "ace/Log_Msg.h"
22 #include "ace/Time_Value.h"
25 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
27 template <typename SERVANT>
28 TAO::Utils::Server_Main<SERVANT>::Server_Main (const char * name)
29 : name_(name)
33 template <typename SERVANT>
34 TAO::Utils::Server_Main<SERVANT>::~Server_Main ()
38 template <typename SERVANT>
39 int
40 TAO::Utils::Server_Main<SERVANT>::run (int argc, ACE_TCHAR *argv[])
42 int result = 0;
44 try
46 // Initialize the orb
48 CORBA::ORB_var orb =
49 CORBA::ORB_init (argc, argv, name_);
51 if (! ::CORBA::is_nil(orb.in ()))
53 // create an instance of the servant object and give it a
54 // chance at the arguments.
55 SERVANT servant;
56 result = servant.parse_args (argc, argv);
57 if (result == 0)
59 //////////////////////////////////
60 // let the servant register itself
61 result = servant.init (orb.in ());
63 if (result == 0)
65 TAOLIB_ERROR ((LM_INFO,
66 "%T %C (%P|%t) Ready %C\n", name_, servant.identity ()));
68 //////////////////////////////////
69 // Run the event loop for the ORB.
70 // Initial run to initialize the orb
71 ACE_Time_Value tv (1,0);
72 orb->run (tv);
74 // now run event loop
75 int quit = 0;
76 while (result == 0 && ! quit )
78 ACE_Time_Value work_tv (1,0);
79 orb->perform_work(work_tv);
80 quit = servant.idle (result);
82 servant.fini ();
84 orb->shutdown (true);
86 TAOLIB_ERROR ((LM_INFO,
87 "%T %C (%P|%t) Terminated normally. %C\n",
88 name_,
89 servant.identity ()));
91 else
93 TAOLIB_ERROR ((LM_ERROR,
94 "%T %C (%P|%t) Registration failed: %m\n", name_));
95 result = -1;
98 else
100 TAOLIB_ERROR ((LM_ERROR,
101 "%T %C (%P|%t) ORB manager init failed\n", name_));
102 result = -1;
106 catch (const ::CORBA::Exception& ex)
108 ex._tao_print_exception (name_);
109 result = -1;
111 return result;
114 TAO_END_VERSIONED_NAMESPACE_DECL
116 #endif //TAO_UTILS_SERVER_MAIN_T_CPP