00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Server_Main.h 00006 * 00007 * $Id: Server_Main.h 76551 2007-01-24 13:42:44Z johnnyw $ 00008 * 00009 * Declares a generic object that acts as "main" for a CORBA server. 00010 * @author Dale Wilson <wilson_d@ociweb.com> 00011 * 00012 * This object supports creation of a relatively simple CORBA server. 00013 * The object implements "main" for a process. 00014 * A single servant is created and initialized as the process begins 00015 * execution. The lifetime of this initial servant is the lifetime of 00016 * the process. 00017 * The servant is free to create other servants as necessary. 00018 * The servant can capture command line options. 00019 * A callback method in the ORB event loop allows the servant to act 00020 * asynchronously if necessary. 00021 * The callback method allows the servant to request process termination 00022 * and specify the status to be returned from the process. 00023 * 00024 * The application should create a C/C++ main that looks something like: 00025 * #include <tao/Utils/Server_Main.h> 00026 * #include "Xyzzy_i.h" 00027 * int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) 00028 * { 00029 * Server_Main<Xyzzy_i> servant ("Xyzzy"); 00030 * return servant.run(argc, argv); 00031 * } 00032 * 00033 * The servant implementation (Xyzzy_i in this case) must implement 00034 * the following methods: 00035 * Xyzzy_i (); // null constructor 00036 * ~Xyzzy_i (); // destructor 00037 * int parse_args (int argc, char * argv[]); 00038 * int init (CORBA::ORB_ptr orb ); 00039 * int idle(int &result); 00040 * int fini (void); 00041 * const char * identity () const; 00042 * 00043 * parse_args, self_register, self_unregister return 0 if ok, nonzero for error. 00044 * idle returns 0 to continue execution; nonzero to exit -- returning "result" from the process 00045 * identity provides a string to identify this servant in log messages. 00046 * 00047 */ 00048 //============================================================================= 00049 00050 #ifndef TAO_UTILS_SERVANTMAIN_H 00051 #define TAO_UTILS_SERVANTMAIN_H 00052 00053 #include /**/ "ace/pre.h" 00054 00055 #include "ace/ACE.h" 00056 00057 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00058 # pragma once 00059 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00060 00061 #include "tao/orbconf.h" 00062 00063 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00064 00065 namespace TAO 00066 { 00067 namespace Utils 00068 { 00069 template <typename SERVANT> 00070 class Server_Main 00071 { 00072 public: 00073 Server_Main(const char * name); 00074 ~Server_Main(); 00075 00076 int run (int argc, ACE_TCHAR *argv[]); 00077 00078 private: 00079 Server_Main( const Server_Main &); 00080 Server_Main & operator = (const Server_Main &); 00081 00082 private: 00083 const char * name_; 00084 }; 00085 } // namespace UTILS 00086 } // namespace TAO 00087 00088 TAO_END_VERSIONED_NAMESPACE_DECL 00089 00090 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00091 # include "tao/Utils/Server_Main.cpp" 00092 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00093 00094 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00095 # pragma implementation "Server_Main.cpp" 00096 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00097 00098 #include /**/ "ace/post.h" 00099 00100 #endif //TAO_UTILS_SERVANTMAIN_H