Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_3683_Regression / Simple_util.h
blobb76b6b9e42b69ae7b995e92601827b9b63582d9f
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 "ace/Get_Opt.h"
18 #include "ace/Read_Buffer.h"
19 #include "tao/Intrusive_Ref_Count_Handle_T.h"
21 /**
22 * @class Server
24 * @brief A set of useful class Templates for using the TAO CORBA
25 * implementation.
27 * A template server definition. This template can be used by
28 * single server/client projects for definition of their
29 * server/clients. See the directories time, bank, echo for
30 * further details of implementation.
32 template <class Servant>
33 class Server
35 public:
36 /// Constructor.
37 Server ();
39 /// Destructor.
40 ~Server ();
42 /// Initialize the Server state - parsing arguments and waiting.
43 /// interface_name is the name used to register the Servant.
44 int init (const char *servant_name,
45 int argc,
46 ACE_TCHAR *argv[]);
48 /// Run the orb.
49 int run ();
51 /// Ignore this method if you are not testing the InterOperable
52 /// Naming Service.
53 int test_for_ins (const char *ior);
55 private:
56 /// Parses the commandline arguments.
57 int parse_args ();
59 /// A holder of the servant that does ref counting for him.
60 typedef TAO_Intrusive_Ref_Count_Handle<Servant> Servant_var;
61 Servant_var servant_;
63 /// The ORB manager - a helper class for accessing the POA and
64 /// registering objects.
65 TAO_ORB_Manager orb_manager_;
67 /// File where the IOR of the server object is stored.
68 ACE_TCHAR *ior_output_file_;
70 /// Flag to indicate whether naming service could be used
71 int naming_;
73 /// Used test the INS.
74 ACE_TCHAR *ins_;
76 /// Number of command line arguments.
77 int argc_;
79 /// The command line arguments.
80 ACE_TCHAR **argv_;
83 /**
84 * @class Client
86 * @brief Template Client class
88 * A template client implementation for a single server/client
89 * model. The example usage of these usage can be found in the
90 * sub-directories below
92 template <class ServerInterface>
93 class Client
95 public:
96 /// Constructor.
97 Client ();
99 /// Destructor.
100 ~Client ();
102 /// Initialize the client communication endpoint with server.
103 int init (const char *name, int argc, ACE_TCHAR *argv[]);
105 /// Return the interface object pointer.
106 ServerInterface *operator-> () { return server_.in (); }
108 /// Returns the shutdown flag.
109 int do_shutdown ();
111 /// Fills in the shutdwon flag.
112 void do_shutdown (int);
114 /// Initialize naming service
115 int obtain_initial_references (const char *name);
117 CORBA::ORB_ptr orb ()
119 return CORBA::ORB::_duplicate (this->orb_.in ());
122 private:
123 /// Function to read the server IOR from a file.
124 int read_ior (ACE_TCHAR *filename);
126 /// Parses the arguments passed on the command line.
127 int parse_args ();
129 /// Remember our orb.
130 CORBA::ORB_var orb_;
132 /// # of arguments on the command line.
133 int argc_;
135 /// arguments from command line.
136 ACE_TCHAR **argv_;
138 /// IOR of the obj ref of the server.
139 ACE_CString ior_;
141 /// Server object
142 typedef TAO_Intrusive_Ref_Count_Handle<ServerInterface> ServerInterface_var;
143 ServerInterface_var server_;
145 /// Flag to use the naming service
146 int naming_;
148 /// Flag for shutting down the server
149 int do_shutdown_;
152 #include "Simple_util.cpp"
153 #endif /* TAO_UTIL_H */