summaryrefslogtreecommitdiff
path: root/TAO/examples/Persistent_Grid/Simple_util.h
blob: 2a3c74738253d3e07e6315372f64f235960eed34 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

//=============================================================================
/**
 *  @file    Simple_util.h
 *
 *  The classe define the templates for the client and server.
 *
 *  @author Balachandran Natarajan <bala@cs.wustl.edu>
 */
//=============================================================================


#ifndef TAO_UTIL_H
#define TAO_UTIL_H

#include "tao/Utils/ORB_Manager.h"
#include "ace/Get_Opt.h"
#include "ace/Read_Buffer.h"

/**
 * @class Server
 *
 * @brief A set of useful class Templates for using the TAO CORBA
 * implementation.
 *
 * A template server definition. This template can be used by
 * single server/client projects for definition of their
 * server/clients.  See the directories time, bank, echo for
 * further details of implemenatation.
 */
template <class Servant>
class Server
{
public:
  /// Constructor.
  Server (void);

  /// Destructor.
  ~Server (void);

  /// Initialize the Server state - parsing arguments and waiting.
  /// interface_name is the name used to register the Servant.
  int init (const char *servant_name,
            int argc,
            ACE_TCHAR *argv[]);

  // int register_name (void);
  // After calling <init>, this method will register the server with
  // the TAO Naming Service using the servant_name passed to <init>.

  /// Run the orb.
  int run (void);

 protected:
  /// Servant class
  Servant servant_;

  /// name of the servant to be used for TAO Naming Service
  const char *name;

  /// Parses the commandline arguments.
  int parse_args (void);

  /// The ORB manager - a helper class for accessing the POA and
  /// registering objects.
  TAO_ORB_Manager orb_manager_;

  /// File where the IOR of the server object is stored.
  FILE *ior_output_file_;

  /// Memory pool name that stores the state
  ACE_TCHAR* mem_pool_name_;

  /// Number of command line arguments.
  int argc_;

  /// The command line arguments.
  ACE_TCHAR **argv_;

};


// Client Class starts here

/**
 * @class Client
 *
 * @brief Template Client class
 *
 * A template client implementation for a single server/client
 * model. The example usage of these usage can be found in the
 * sub-directories below
 */
template <class InterfaceObj, class Var>
class Client
{
public:
  /// Constructor.
  Client (void);

  /// Destructor.
  ~Client (void);

  /// Initialize the client communication endpoint with server.
  int init (const char *name,int argc, ACE_TCHAR *argv[]);

  /// Return the interface object pointer.
  InterfaceObj *operator-> () { return server_.in ();};

  /// Returns the shutdown flag.
  int shutdown ();

  /// Fills in the shutdwon flag.
  void shutdown (int);

  /// Initialize naming service
  int obtain_initial_references (void);

protected:
  /// Function to read the server IOR from a file.
  int read_ior (ACE_TCHAR *filename);

  /// Parses the arguments passed on the command line.
  int parse_args (void);

  /// Remember our orb.
  CORBA::ORB_var orb_;

  /// # of arguments on the command line.
  int argc_;

  /// arguments from command line.
  ACE_TCHAR **argv_;

  /// IOR of the obj ref of the server.
  char *ior_;

  /// Flag to use the naming service
  int naming_;

  /// Flag for shutting down the server
  int shutdown_;

  /// Server object
  Var server_;
};

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "Simple_util.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Simple_util.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#endif /* TAO_UTIL_H */