summaryrefslogtreecommitdiff
path: root/TAO/tao/Utils/Server_Main.h
blob: c5d3ea2d8258ecc21ae757cbd7dfaa3d90a1ae2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Server_Main.h
 *
 *  $Id$
 *
 *  Declares a generic object that acts as "main" for a CORBA server.
 *  @author Dale Wilson <wilson_d@ociweb.com>
 *
 *  This object supports creation of a relatively simple CORBA server.
 *  The object implements "main" for a process.
 *  A single servant is created and initialized as the process begins
 *  execution.  The lifetime of this initial servant is the lifetime of
 *  the process.
 *  The servant is free to create other servants as necessary.
 *  The servant can capture command line options.
 *  A callback method in the ORB event loop allows the servant to act
 *  asynchronously if necessary.
 *  The callback method allows the servant to request process termination
 *  and specify the status to be returned from the process.
 *
 *  The application should create a C/C++ main that looks something like:
 *    #include <tao/Utils/Server_Main.h>
 *    #include "Xyzzy_i.h"
 *    int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
 *    {
 *      Server_Main<Xyzzy_i> servant ("Xyzzy");
 *      return servant.run(argc, argv);
 *    }
 *
 *  The servant implementation (Xyzzy_i in this case) must implement
 *  the following methods:
 *      Xyzzy_i (); // null constructor
 *      ~Xyzzy_i (); // destructor
 *      int parse_args (int argc, char * argv[]);
 *      int init (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL_WITH_DEFAULTS);
 *      int idle(int &result);
 *      int fini (ACE_ENV_SINGLE_ARG_DECL);
 *      const char * identity () const;
 *
 *      parse_args, self_register, self_unregister return 0 if ok, nonzero for error.
 *      idle returns 0 to continue execution; nonzero to exit -- returning "result" from the process
 *      identity provides a string to identify this servant in log messages.
 *
 */
//=============================================================================

#ifndef TAO_UTILS_SERVANTMAIN_H
#define TAO_UTILS_SERVANTMAIN_H

#include /**/ "ace/pre.h"

#include "ace/ACE.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/orbconf.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  namespace Utils
  {
    template <typename SERVANT>
    class Server_Main
    {
    public:
      Server_Main(const char * name);
      ~Server_Main();

      int run (int argc, ACE_TCHAR *argv[]);

    private:
      Server_Main( const Server_Main &);
      Server_Main & operator = (const Server_Main &);

    private:
      const char * name_;
    };
  } // namespace UTILS
} // namespace TAO

TAO_END_VERSIONED_NAMESPACE_DECL

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
# include "tao/Utils/Server_Main.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
# pragma implementation "Server_Main.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#include /**/ "ace/post.h"

#endif //TAO_UTILS_SERVANTMAIN_H