Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / examples / Simple / Simple_util.h
blobd78ad81de959c9a6d2c0b68fc90a94f2838d9495
2 //=============================================================================
3 /**
4 * @file Simple_util.h
6 * The classe define the templates for the client and server.
8 * @author Balachandran Natarajan <bala@cs.wustl.edu>
9 */
10 //=============================================================================
13 #ifndef TAO_UTIL_H
14 #define TAO_UTIL_H
16 #include "tao/Utils/ORB_Manager.h"
17 #include "orbsvcs/Naming/Naming_Client.h"
18 #include "ace/Get_Opt.h"
19 #include "ace/Read_Buffer.h"
20 #include "tao/Intrusive_Ref_Count_Handle_T.h"
22 /**
23 * @class Server
25 * @brief A set of useful class Templates for using the TAO CORBA
26 * implementation.
28 * A template server definition. This template can be used by
29 * single server/client projects for definition of their
30 * server/clients. See the directories time, bank, echo for
31 * further details of implementation.
33 template <class Servant>
34 class Server
36 public:
37 /// Constructor.
38 Server ();
40 /// Destructor.
41 ~Server () = default;
43 /// Initialize the Server state - parsing arguments and waiting.
44 /// interface_name is the name used to register the Servant.
45 int init (const char *servant_name,
46 int argc,
47 ACE_TCHAR *argv[]);
49 /// After calling <init>, this method will register the server with
50 /// the TAO Naming Service using the name passed to this method.
51 int register_name (const char *name);
53 /// Run the orb.
54 int run ();
56 /// Ignore this method if you are not testing the InterOperable
57 /// Naming Service.
58 int test_for_ins (const char *ior);
60 private:
61 /// Parses the commandline arguments.
62 int parse_args ();
64 /// A holder of the servant that does ref counting for him.
65 typedef TAO_Intrusive_Ref_Count_Handle<Servant> Servant_var;
66 Servant_var servant_;
68 /// The ORB manager - a helper class for accessing the POA and
69 /// registering objects.
70 TAO_ORB_Manager orb_manager_;
72 /// helper class for getting access to Naming Service.
73 TAO_Naming_Client naming_client_;
75 /// File where the IOR of the server object is stored.
76 ACE_TCHAR *ior_output_file_;
78 /// Flag to indicate whether naming service could be used
79 int naming_;
81 /// Used test the INS.
82 ACE_TCHAR *ins_;
84 /// Number of command line arguments.
85 int argc_;
87 /// The command line arguments.
88 ACE_TCHAR **argv_;
91 /**
92 * @class Client
94 * @brief Template Client class
96 * A template client implementation for a single server/client
97 * model. The example usage of these usage can be found in the
98 * sub-directories below
100 template <class ServerInterface>
101 class Client
103 public:
104 /// Constructor.
105 Client ();
107 /// Destructor.
108 ~Client ();
110 /// Initialize the client communication endpoint with server.
111 int init (const char *name, int argc, ACE_TCHAR *argv[]);
113 /// Return the interface object pointer.
114 ServerInterface *operator-> () { return server_.in (); }
116 /// Returns the shutdown flag.
117 int do_shutdown ();
119 /// Fills in the shutdwon flag.
120 void do_shutdown (int);
122 /// Initialize naming service
123 int obtain_initial_references (const char *name);
125 CORBA::ORB_ptr orb ()
127 return CORBA::ORB::_duplicate (this->orb_.in ());
130 private:
131 /// Function to read the server IOR from a file.
132 int read_ior (ACE_TCHAR *filename);
134 /// Parses the arguments passed on the command line.
135 int parse_args ();
137 /// Remember our orb.
138 CORBA::ORB_var orb_;
140 /// helper class for getting access to Naming Service.
141 TAO_Naming_Client naming_client_;
143 /// # of arguments on the command line.
144 int argc_ {};
146 /// arguments from command line.
147 ACE_TCHAR **argv_ {};
149 /// IOR of the obj ref of the server.
150 ACE_CString ior_;
152 /// Server object
153 typedef TAO_Intrusive_Ref_Count_Handle<ServerInterface> ServerInterface_var;
154 ServerInterface_var server_;
156 /// Flag to use the naming service
157 int naming_;
159 /// Flag for shutting down the server
160 int do_shutdown_;
163 #include "Simple_util.cpp"
165 #endif /* TAO_UTIL_H */