Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / Utils / Server_Main.h
blob00cccb31b1d0b0279eeb4314110d926251f49995
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Server_Main.h
7 * Declares a generic object that acts as "main" for a CORBA server.
8 * @author Dale Wilson <wilson_d@ociweb.com>
10 * This object supports creation of a relatively simple CORBA server.
11 * The object implements "main" for a process.
12 * A single servant is created and initialized as the process begins
13 * execution. The lifetime of this initial servant is the lifetime of
14 * the process.
15 * The servant is free to create other servants as necessary.
16 * The servant can capture command line options.
17 * A callback method in the ORB event loop allows the servant to act
18 * asynchronously if necessary.
19 * The callback method allows the servant to request process termination
20 * and specify the status to be returned from the process.
22 * The application should create a C/C++ main that looks something like:
23 * #include <tao/Utils/Server_Main.h>
24 * #include "Xyzzy_i.h"
25 * int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
26 * {
27 * Server_Main<Xyzzy_i> servant ("Xyzzy");
28 * return servant.run(argc, argv);
29 * }
31 * The servant implementation (Xyzzy_i in this case) must implement
32 * the following methods:
33 * Xyzzy_i (); // null constructor
34 * ~Xyzzy_i (); // destructor
35 * int parse_args (int argc, ACE_TCHAR * argv[]);
36 * int init (CORBA::ORB_ptr orb );
37 * int idle(int &result);
38 * int fini ();
39 * const char * identity () const;
41 * parse_args, self_register, self_unregister return 0 if ok, nonzero for error.
42 * idle returns 0 to continue execution; nonzero to exit -- returning "result" from the process
43 * identity provides a string to identify this servant in log messages.
45 //=============================================================================
47 #ifndef TAO_UTILS_SERVANTMAIN_H
48 #define TAO_UTILS_SERVANTMAIN_H
50 #include /**/ "ace/pre.h"
52 #include "ace/ACE.h"
54 #if !defined (ACE_LACKS_PRAGMA_ONCE)
55 # pragma once
56 #endif /* ACE_LACKS_PRAGMA_ONCE */
58 #include "tao/orbconf.h"
59 #include "ace/Copy_Disabled.h"
61 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
63 namespace TAO
65 namespace Utils
67 template <typename SERVANT>
68 class Server_Main : private ACE_Copy_Disabled
70 public:
71 Server_Main(const char * name);
72 ~Server_Main();
74 int run (int argc, ACE_TCHAR *argv[]);
76 private:
77 const char * name_;
79 } // namespace UTILS
80 } // namespace TAO
82 TAO_END_VERSIONED_NAMESPACE_DECL
84 #include "tao/Utils/Server_Main.cpp"
86 #include /**/ "ace/post.h"
88 #endif //TAO_UTILS_SERVANTMAIN_H