proton  0
reactor.h
Go to the documentation of this file.
1 #ifndef PROTON_REACTOR_H
2 #define PROTON_REACTOR_H 1
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include <proton/import_export.h>
26 #include <proton/type_compat.h>
27 #include <proton/event.h>
28 #include <proton/selectable.h>
29 #include <proton/ssl.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  * @file
37  *
38  * Reactor API for proton.
39  *
40  * @defgroup reactor Reactor
41  * @{
42  */
43 
44 typedef struct pn_reactor_t pn_reactor_t;
46 typedef struct pn_timer_t pn_timer_t;
47 typedef struct pn_task_t pn_task_t;
48 
50 PN_EXTERN pn_handler_t *pn_handler_new(void (*dispatch)(pn_handler_t *, pn_event_t *, pn_event_type_t), size_t size,
51  void (*finalize)(pn_handler_t *));
53 PN_EXTERN void *pn_handler_mem(pn_handler_t *handler);
54 PN_EXTERN void pn_handler_add(pn_handler_t *handler, pn_handler_t *child);
57 
74 PN_EXTERN void pn_reactor_update(pn_reactor_t *reactor, pn_selectable_t *selectable);
75 PN_EXTERN pn_acceptor_t *pn_reactor_acceptor(pn_reactor_t *reactor, const char *host, const char *port,
76  pn_handler_t *handler);
77 
78 
79 /**
80  * Create an outgoing connection that will be managed by the reactor.
81  *
82  * The reator's pn_iohandler will create a socket connection to the host
83  * once the connection is opened.
84  *
85  * @param[in] reactor the reactor that will own the connection.
86  * @param[in] host the address of the remote host. e.g. "localhost"
87  * @param[in] port the port to connect to. e.g. "5672"
88  * @param[in] handler the handler that will process all events generated by
89  * this connection.
90  * @return a connection object
91  */
93  const char *host,
94  const char *port,
95  pn_handler_t *handler);
96 
97 /**
98  * Create an outgoing connection that will be managed by the reactor.
99  *
100  * The host address for the connection must be set via
101  * ::pn_reactor_set_connection_host() prior to opening the connection.
102  * Typically this can be done by the handler when processing the
103  * ::PN_CONNECTION_INIT event.
104  *
105  * @param[in] reactor the reactor that will own the connection.
106  * @param[in] handler the handler that will process all events generated by
107  * this connection.
108  * @return a connection object
109  * @deprecated Use ::pn_reactor_connection_to_host() instead.
110  */
112  pn_handler_t *handler);
113 
114 /**
115  * Change the host address used by an outgoing reactor connection.
116  *
117  * The address is used by the reactor's iohandler to create an outgoing socket
118  * connection. This must be set prior to (re)opening the connection.
119  *
120  * @param[in] reactor the reactor that owns the connection.
121  * @param[in] connection the connection created by the reactor.
122  * @param[in] host the network address or DNS name of the host to connect to.
123  * @param[in] port the network port to use. Optional - default is "5672"
124  */
126  pn_connection_t *connection,
127  const char *host,
128  const char *port);
129 /**
130  * Retrieve the peer host address for a reactor connection.
131  *
132  * This may be used to retrieve the host address used by the reactor to
133  * establish the outgoing socket connection. In the case of an accepted
134  * connection the returned value is the address of the remote.
135  *
136  * @note Note that the returned address may be in numeric IP format.
137  *
138  * The pointer returned by this operation is valid until either the address is
139  * changed via ::pn_reactor_set_connection_host() or the connection object
140  * is freed.
141  *
142  * @param[in] reactor the reactor that owns the connection.
143  * @param[in] connection the reactor connection
144  * @return a C string containing the address in URL format or NULL if no
145  * address available. ::pn_url_parse() may be used to create a Proton pn_url_t
146  * instance from the returned value.
147  */
149  pn_connection_t *connection);
150 
155 PN_EXTERN void pn_reactor_stop(pn_reactor_t *reactor);
156 PN_EXTERN void pn_reactor_run(pn_reactor_t *reactor);
157 PN_EXTERN pn_task_t *pn_reactor_schedule(pn_reactor_t *reactor, int delay, pn_handler_t *handler);
158 
159 
163 
169 
172 
173 PN_EXTERN pn_reactor_t *pn_class_reactor(const pn_class_t *clazz, void *object);
176 
179 
180 /** @}
181  */
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* reactor.h */
PN_EXTERN void pn_reactor_run(pn_reactor_t *reactor)
PN_EXTERN void pn_reactor_set_connection_host(pn_reactor_t *reactor, pn_connection_t *connection, const char *host, const char *port)
Change the host address used by an outgoing reactor connection.
PN_EXTERN void pn_handler_free(pn_handler_t *handler)
PN_EXTERN pn_list_t * pn_reactor_children(pn_reactor_t *reactor)
pn_event_type_t
An event type.
Definition: event.h:82
PN_EXTERN pn_connection_t * pn_reactor_connection(pn_reactor_t *reactor, pn_handler_t *handler)
Create an outgoing connection that will be managed by the reactor.
PN_EXTERN pn_timestamp_t pn_timer_deadline(pn_timer_t *timer)
PN_EXTERN pn_selectable_t * pn_reactor_selectable(pn_reactor_t *reactor)
uint32_t pn_millis_t
Definition: types.h:47
struct pn_record_t pn_record_t
Definition: object.h:46
The selectable API provides an interface for integration with third party event loops.
PN_EXTERN int pn_timer_tasks(pn_timer_t *timer)
PN_EXTERN void pn_reactor_set_global_handler(pn_reactor_t *reactor, pn_handler_t *handler)
PN_EXTERN pn_reactor_t * pn_reactor(void)
PN_EXTERN void pn_handler_clear(pn_handler_t *handler)
struct pn_acceptor_t pn_acceptor_t
Definition: reactor.h:45
struct pn_reactor_t pn_reactor_t
Definition: reactor.h:44
struct pn_io_t pn_io_t
A pn_io_t manages IO for a group of pn_socket_t handles.
Definition: io.h:82
PN_EXTERN pn_acceptor_t * pn_reactor_acceptor(pn_reactor_t *reactor, const char *host, const char *port, pn_handler_t *handler)
PN_EXTERN bool pn_reactor_process(pn_reactor_t *reactor)
PN_EXTERN void pn_task_cancel(pn_task_t *task)
PN_EXTERN pn_io_t * pn_reactor_io(pn_reactor_t *reactor)
PN_EXTERN void pn_handler_dispatch(pn_handler_t *handler, pn_event_t *event, pn_event_type_t type)
#define PN_EXTERN
Definition: import_export.h:53
struct pn_collector_t pn_collector_t
An event collector.
Definition: types.h:250
PN_EXTERN pn_reactor_t * pn_class_reactor(const pn_class_t *clazz, void *object)
PN_EXTERN void pn_acceptor_close(pn_acceptor_t *acceptor)
PN_EXTERN pn_record_t * pn_reactor_attachments(pn_reactor_t *reactor)
PN_EXTERN pn_task_t * pn_timer_schedule(pn_timer_t *timer, pn_timestamp_t deadline)
PN_EXTERN void pn_record_set_handler(pn_record_t *record, pn_handler_t *handler)
PN_EXTERN bool pn_reactor_quiesced(pn_reactor_t *reactor)
PN_EXTERN int pn_reactor_wakeup(pn_reactor_t *reactor)
struct pn_list_t pn_list_t
Definition: object.h:41
PN_EXTERN void pn_reactor_update(pn_reactor_t *reactor, pn_selectable_t *selectable)
struct pn_timer_t pn_timer_t
Definition: reactor.h:46
PN_EXTERN pn_timer_t * pn_timer(pn_collector_t *collector)
struct pn_handler_t pn_handler_t
An event handler.
Definition: types.h:271
struct pn_ssl_domain_t pn_ssl_domain_t
Definition: ssl.h:76
PN_EXTERN void pn_reactor_yield(pn_reactor_t *reactor)
PN_EXTERN pn_connection_t * pn_reactor_connection_to_host(pn_reactor_t *reactor, const char *host, const char *port, pn_handler_t *handler)
Create an outgoing connection that will be managed by the reactor.
PN_EXTERN void pn_acceptor_set_ssl_domain(pn_acceptor_t *acceptor, pn_ssl_domain_t *domain)
PN_EXTERN void pn_timer_tick(pn_timer_t *timer, pn_timestamp_t now)
PN_EXTERN pn_record_t * pn_task_attachments(pn_task_t *task)
PN_EXTERN pn_handler_t * pn_handler_new(void(*dispatch)(pn_handler_t *, pn_event_t *, pn_event_type_t), size_t size, void(*finalize)(pn_handler_t *))
PN_EXTERN pn_handler_t * pn_record_get_handler(pn_record_t *record)
Definition: object.h:48
PN_EXTERN pn_task_t * pn_reactor_schedule(pn_reactor_t *reactor, int delay, pn_handler_t *handler)
PN_EXTERN void pn_reactor_stop(pn_reactor_t *reactor)
PN_EXTERN pn_millis_t pn_reactor_get_timeout(pn_reactor_t *reactor)
PN_EXTERN pn_handler_t * pn_reactor_get_global_handler(pn_reactor_t *reactor)
PN_EXTERN void pn_reactor_set_timeout(pn_reactor_t *reactor, pn_millis_t timeout)
PN_EXTERN pn_handler_t * pn_handler(void(*dispatch)(pn_handler_t *, pn_event_t *, pn_event_type_t))
Event API for the proton Engine.
int64_t pn_timestamp_t
Definition: types.h:51
struct pn_connection_t pn_connection_t
An AMQP Connection object.
Definition: types.h:118
PN_EXTERN void pn_reactor_set_handler(pn_reactor_t *reactor, pn_handler_t *handler)
PN_EXTERN void * pn_handler_mem(pn_handler_t *handler)
API for using SSL with the Transport Layer.
PN_EXTERN const char * pn_reactor_get_connection_address(pn_reactor_t *reactor, pn_connection_t *connection)
Retrieve the peer host address for a reactor connection.
PN_EXTERN pn_acceptor_t * pn_connection_acceptor(pn_connection_t *connection)
PN_EXTERN pn_reactor_t * pn_event_reactor(pn_event_t *event)
struct pn_task_t pn_task_t
Definition: reactor.h:47
PN_EXTERN pn_collector_t * pn_reactor_collector(pn_reactor_t *reactor)
PN_EXTERN void pn_reactor_free(pn_reactor_t *reactor)
PN_EXTERN pn_timestamp_t pn_reactor_now(pn_reactor_t *reactor)
PN_EXTERN pn_reactor_t * pn_object_reactor(void *object)
PN_EXTERN pn_timestamp_t pn_reactor_mark(pn_reactor_t *reactor)
PN_EXTERN void pn_reactor_start(pn_reactor_t *reactor)
PN_EXTERN pn_handler_t * pn_reactor_get_handler(pn_reactor_t *reactor)
struct pn_event_t pn_event_t
An event provides notification of a state change within the protocol engine&#39;s object model...
Definition: event.h:77
PN_EXTERN void pn_handler_add(pn_handler_t *handler, pn_handler_t *child)
struct pn_selectable_t pn_selectable_t
A selectable object provides an interface that can be used to incorporate proton&#39;s I/O into third par...
Definition: selectable.h:68