3 //=============================================================================
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)
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 */
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
>
52 /// Pointer to a member function of ACE_Name_Handler returning int
53 typedef int (ACE_Name_Handler::*OPERATION
) ();
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);
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 ();
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 ();
81 /// Dispatch the appropriate operation to handle the client's
83 virtual int dispatch ();
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 () const;
96 /// Callback method invoked by the <ACE_Reactor> when client events
98 virtual int handle_input (ACE_HANDLE
);
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 ();
108 /// Table of pointers to member functions
109 OPERATION op_table_
[ACE_Name_Request::MAX_ENUM
];
114 // A member function pointer that performs the appropriate
115 // operation (e.g., LIST_NAMES, LIST_VALUES, or LIST_TYPES).
117 REQUEST request_factory_
;
118 // A member function pointer that serves as a factory to create a
119 // request that is passed back to the client.
121 const char *description_
;
122 // Name of the operation we're dispatching (used for debugging).
125 /// This is the table of pointers to functions that we use to
126 /// simplify the handling of list requests.
127 LIST_ENTRY list_table_
[ACE_Name_Request::MAX_LIST
];
129 /// Cache request from the client.
130 ACE_Name_Request name_request_
;
132 /// Special kind of reply for resolve and listnames.
133 ACE_Name_Request name_request_back_
;
135 /// Cache reply to the client.
136 ACE_Name_Reply name_reply_
;
138 /// Address of client we are connected with.
142 ACE_Naming_Context
*naming_context_
;
144 ACE_Naming_Context
*naming_context ();
152 /// Handle binds and rebinds.
153 int shared_bind (int rebind
);
155 /// Handle find requests.
158 /// Handle unbind requests.
161 /// Handle LIST_NAMES, LIST_VALUES, and LIST_TYPES requests.
164 /// Handle LIST_NAME_ENTRIES, LIST_VALUE_ENTRIES, and
165 /// LIST_TYPE_ENTRIES requests.
166 int lists_entries ();
168 /// Create a name request.
169 ACE_Name_Request
name_request (ACE_NS_WString
*one_name
);
171 /// Create a value request.
172 ACE_Name_Request
value_request (ACE_NS_WString
*one_name
);
174 /// Create a type request.
175 ACE_Name_Request
type_request (ACE_NS_WString
*one_name
);
179 * @class ACE_Name_Acceptor
181 * @brief This class contains the service-specific methods that can't
182 * easily be factored into the <ACE_Strategy_Acceptor>.
184 class ACE_Name_Acceptor
: public ACE_Strategy_Acceptor
<ACE_Name_Handler
, ACE_SOCK_ACCEPTOR
>
187 /// Dynamic linking hook.
188 virtual int init (int argc
, ACE_TCHAR
*argv
[]);
190 /// Parse svc.conf arguments.
191 int parse_args (int argc
, ACE_TCHAR
*argv
[]);
193 /// Naming context for acceptor /for the listening port/
194 ACE_Naming_Context
*naming_context ();
197 /// The scheduling strategy is designed for Reactive services.
198 ACE_Schedule_All_Reactive_Strategy
<ACE_Name_Handler
> scheduling_strategy_
;
200 /// The Naming Context
201 ACE_Naming_Context naming_context_
;
204 ACE_SVC_FACTORY_DECLARE (ACE_Name_Acceptor
)
207 #endif /* ACE_NAME_HANDLER_H */