Update NEWS
[ACE_TAO.git] / ACE / netsvcs / lib / Name_Handler.h
blob355646a741b9cb1ecf976f50290e429db538527f
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Name_Handler.h
7 * @author Prashant Jain
8 * @author Gerhard Lenzer
9 * @author and Douglas C. Schmidt
11 //=============================================================================
14 #ifndef ACE_NAME_HANDLER_H
15 #define ACE_NAME_HANDLER_H
17 #include "ace/Acceptor.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/SOCK_Acceptor.h"
24 #include "ace/SString.h"
25 #include "ace/Svc_Handler.h"
26 #include "ace/Naming_Context.h"
27 #include "ace/Name_Request_Reply.h"
28 #include "ace/Null_Mutex.h"
29 #include "ace/svc_export.h"
32 #if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT
33 template class ACE_Svc_Export ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>;
34 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */
36 /**
37 * @class ACE_Name_Handler
39 * @brief Product object created by <ACE_Name_Acceptor>. An
40 * <ACE_Name_Handler> exchanges messages with a <ACE_Name_Proxy>
41 * object on the client-side.
43 * This class is the main workhorse of the <ACE_Name_Server>. It
44 * handles client requests to bind, rebind, resolve, and unbind
45 * names. It also schedules and handles timeouts that are used to
46 * support "timed waits." Clients used timed waits to bound the
47 * amount of time they block trying to get a name.
49 class ACE_Svc_Export ACE_Name_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
51 public:
52 /// Pointer to a member function of ACE_Name_Handler returning int
53 typedef int (ACE_Name_Handler::*OPERATION) (void);
55 /// Pointer to a member function of ACE_Naming_Context returning int
56 typedef int (ACE_Naming_Context::*LIST_OP) (ACE_PWSTRING_SET &, const ACE_NS_WString &);
58 /// Pointer to a member function of ACE_Name_Handler returning ACE_Name_Request
59 typedef ACE_Name_Request (ACE_Name_Handler::*REQUEST) (ACE_NS_WString *);
61 /// Default constructor.
62 ACE_Name_Handler (ACE_Thread_Manager * = 0);
64 /// Activate this instance of the <ACE_Name_Handler> (called by the
65 /// <ACE_Strategy_Acceptor>).
66 virtual int open (void * = 0);
68 protected:
69 // = Helper routines for the operations exported to clients.
71 /// Give up waiting (e.g., when a timeout occurs or a client shuts
72 /// down unexpectedly).
73 virtual int abandon (void);
75 // = Low level routines for framing requests, dispatching
76 // operations, and returning replies.
78 /// Receive, frame, and decode the client's request.
79 virtual int recv_request (void);
81 /// Dispatch the appropriate operation to handle the client's
82 /// request.
83 virtual int dispatch (void);
85 /// Create and send a reply to the client.
86 virtual int send_reply (ACE_INT32 status,
87 ACE_UINT32 errnum = 0);
89 /// Special kind of reply
90 virtual int send_request (ACE_Name_Request &);
92 // = Demultiplexing hooks.
93 /// Return the underlying <ACE_HANDLE>.
94 virtual ACE_HANDLE get_handle (void) const;
96 /// Callback method invoked by the <ACE_Reactor> when client events
97 /// arrive.
98 virtual int handle_input (ACE_HANDLE);
100 // = Timer hook.
101 /// Enable clients to limit the amount of time they wait for a name.
102 virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg);
104 /// Ensure dynamic allocation...
105 ~ACE_Name_Handler (void);
107 private:
109 /// Table of pointers to member functions
110 OPERATION op_table_[ACE_Name_Request::MAX_ENUM];
112 struct LIST_ENTRY
114 LIST_OP operation_;
115 // A member function pointer that performs the appropriate
116 // operation (e.g., LIST_NAMES, LIST_VALUES, or LIST_TYPES).
118 REQUEST request_factory_;
119 // A member function pointer that serves as a factory to create a
120 // request that is passed back to the client.
122 const char *description_;
123 // Name of the operation we're dispatching (used for debugging).
126 /// This is the table of pointers to functions that we use to
127 /// simplify the handling of list requests.
128 LIST_ENTRY list_table_[ACE_Name_Request::MAX_LIST];
130 /// Cache request from the client.
131 ACE_Name_Request name_request_;
133 /// Special kind of reply for resolve and listnames.
134 ACE_Name_Request name_request_back_;
136 /// Cache reply to the client.
137 ACE_Name_Reply name_reply_;
139 /// Address of client we are connected with.
140 ACE_INET_Addr addr_;
142 /// Naming Context
143 ACE_Naming_Context *naming_context_;
145 ACE_Naming_Context *naming_context (void);
147 /// Handle binds.
148 int bind (void);
150 /// Handle rebinds.
151 int rebind (void);
153 /// Handle binds and rebinds.
154 int shared_bind (int rebind);
156 /// Handle find requests.
157 int resolve (void);
159 /// Handle unbind requests.
160 int unbind (void);
162 /// Handle LIST_NAMES, LIST_VALUES, and LIST_TYPES requests.
163 int lists (void);
165 /// Handle LIST_NAME_ENTRIES, LIST_VALUE_ENTRIES, and
166 /// LIST_TYPE_ENTRIES requests.
167 int lists_entries (void);
169 /// Create a name request.
170 ACE_Name_Request name_request (ACE_NS_WString *one_name);
172 /// Create a value request.
173 ACE_Name_Request value_request (ACE_NS_WString *one_name);
175 /// Create a type request.
176 ACE_Name_Request type_request (ACE_NS_WString *one_name);
180 * @class ACE_Name_Acceptor
182 * @brief This class contains the service-specific methods that can't
183 * easily be factored into the <ACE_Strategy_Acceptor>.
185 class ACE_Name_Acceptor : public ACE_Strategy_Acceptor<ACE_Name_Handler, ACE_SOCK_ACCEPTOR>
187 public:
188 /// Dynamic linking hook.
189 virtual int init (int argc, ACE_TCHAR *argv[]);
191 /// Parse svc.conf arguments.
192 int parse_args (int argc, ACE_TCHAR *argv[]);
194 /// Naming context for acceptor /for the listening port/
195 ACE_Naming_Context *naming_context (void);
197 private:
198 /// The scheduling strategy is designed for Reactive services.
199 ACE_Schedule_All_Reactive_Strategy<ACE_Name_Handler> scheduling_strategy_;
201 /// The Naming Context
202 ACE_Naming_Context naming_context_;
205 ACE_SVC_FACTORY_DECLARE (ACE_Name_Acceptor)
208 #endif /* ACE_NAME_HANDLER_H */