Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TAO_UTILS_SERVER_MAIN_T_CPP
00016 #define TAO_UTILS_SERVER_MAIN_T_CPP
00017
00018 #include "tao/Utils/Server_Main.h"
00019
00020 #include "tao/ORB.h"
00021
00022 #include "ace/Argv_Type_Converter.h"
00023 #include "ace/Log_Msg.h"
00024 #include "ace/Time_Value.h"
00025
00026
00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00028
00029 template <typename SERVANT>
00030 TAO::Utils::Server_Main<SERVANT>::Server_Main (const char * name)
00031 : name_(name)
00032 {
00033 }
00034
00035 template <typename SERVANT>
00036 TAO::Utils::Server_Main<SERVANT>::~Server_Main ()
00037 {
00038 }
00039
00040 template <typename SERVANT>
00041 int
00042 TAO::Utils::Server_Main<SERVANT>::run (int argc, ACE_TCHAR *argv[])
00043 {
00044 int result = 0;
00045
00046 ACE_Argv_Type_Converter command_line (argc, argv);
00047
00048 ACE_TCHAR ** asciiArgv = command_line.get_TCHAR_argv ();
00049
00050 try
00051 {
00052
00053
00054 CORBA::ORB_var orb =
00055 CORBA::ORB_init (argc, asciiArgv, name_);
00056
00057 if (! ::CORBA::is_nil(orb.in ()))
00058 {
00059
00060
00061 SERVANT servant;
00062 result = servant.parse_args (argc, asciiArgv);
00063 if (result == 0)
00064 {
00065
00066
00067 result = servant.init (orb.in ());
00068
00069 if (result == 0)
00070 {
00071 ACE_ERROR ((LM_INFO,
00072 "%T %s (%P|%t) Ready %s\n", name_, servant.identity ()
00073 ));
00074
00075
00076
00077
00078 ACE_Time_Value tv (1,0);
00079 orb->run (tv);
00080
00081
00082 int quit = 0;
00083 while (result == 0 && ! quit )
00084 {
00085 ACE_Time_Value work_tv (1,0);
00086 orb->perform_work(work_tv);
00087 quit = servant.idle (result);
00088 }
00089 servant.fini ();
00090
00091 orb->shutdown (1);
00092
00093 ACE_ERROR ((LM_INFO,
00094 "%T %s (%P|%t) Terminated normally. %s\n",
00095 name_,
00096 servant.identity ()
00097 ));
00098 }
00099 else
00100 {
00101 ACE_ERROR ((LM_ERROR,
00102 "%T %s (%P|%t) Registration failed: %m\n", name_
00103 ));
00104 result = -1;
00105 }
00106 }
00107 else
00108 {
00109 ACE_ERROR ((LM_ERROR,
00110 "%T %s (%P|%t) ORB manager init failed\n", name_
00111 ));
00112 result = -1;
00113 }
00114 }
00115 }
00116 catch (const ::CORBA::Exception& ex)
00117 {
00118 ex._tao_print_exception (name_);
00119 result = -1;
00120 }
00121 return result;
00122 }
00123
00124 TAO_END_VERSIONED_NAMESPACE_DECL
00125
00126 #endif //TAO_UTILS_SERVER_MAIN_T_CPP