| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/mqtt/client.h> |
| 7 |
#include <aws/mqtt/private/client_impl_shared.h> |
| 8 |
|
| 9 |
struct aws_mqtt_client_connection *aws_mqtt_client_connection_acquire(struct aws_mqtt_client_connection *connection) { |
| 10 |
if (connection != NULL) { |
| 11 |
return (*connection->vtable->acquire_fn)(connection->impl); |
| 12 |
} |
| 13 |
|
| 14 |
return NULL; |
| 15 |
} |
| 16 |
|
| 17 |
void aws_mqtt_client_connection_release(struct aws_mqtt_client_connection *connection) { |
| 18 |
if (connection != NULL) { |
| 19 |
(*connection->vtable->release_fn)(connection->impl); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
int aws_mqtt_client_connection_set_will( |
| 24 |
struct aws_mqtt_client_connection *connection, |
| 25 |
const struct aws_byte_cursor *topic, |
| 26 |
enum aws_mqtt_qos qos, |
| 27 |
bool retain, |
| 28 |
const struct aws_byte_cursor *payload) { |
| 29 |
|
| 30 |
return (*connection->vtable->set_will_fn)(connection->impl, topic, qos, retain, payload); |
| 31 |
} |
| 32 |
|
| 33 |
int aws_mqtt_client_connection_set_login( |
| 34 |
struct aws_mqtt_client_connection *connection, |
| 35 |
const struct aws_byte_cursor *username, |
| 36 |
const struct aws_byte_cursor *password) { |
| 37 |
|
| 38 |
return (*connection->vtable->set_login_fn)(connection->impl, username, password); |
| 39 |
} |
| 40 |
|
| 41 |
int aws_mqtt_client_connection_use_websockets( |
| 42 |
struct aws_mqtt_client_connection *connection, |
| 43 |
aws_mqtt_transform_websocket_handshake_fn *transformer, |
| 44 |
void *transformer_ud, |
| 45 |
aws_mqtt_validate_websocket_handshake_fn *validator, |
| 46 |
void *validator_ud) { |
| 47 |
|
| 48 |
return (*connection->vtable->use_websockets_fn)( |
| 49 |
connection->impl, transformer, transformer_ud, validator, validator_ud); |
| 50 |
} |
| 51 |
|
| 52 |
int aws_mqtt_client_connection_set_http_proxy_options( |
| 53 |
struct aws_mqtt_client_connection *connection, |
| 54 |
struct aws_http_proxy_options *proxy_options) { |
| 55 |
|
| 56 |
return (*connection->vtable->set_http_proxy_options_fn)(connection->impl, proxy_options); |
| 57 |
} |
| 58 |
|
| 59 |
int aws_mqtt_client_connection_set_host_resolution_options( |
| 60 |
struct aws_mqtt_client_connection *connection, |
| 61 |
const struct aws_host_resolution_config *host_resolution_config) { |
| 62 |
|
| 63 |
return (*connection->vtable->set_host_resolution_options_fn)(connection->impl, host_resolution_config); |
| 64 |
} |
| 65 |
|
| 66 |
int aws_mqtt_client_connection_set_reconnect_timeout( |
| 67 |
struct aws_mqtt_client_connection *connection, |
| 68 |
uint64_t min_timeout, |
| 69 |
uint64_t max_timeout) { |
| 70 |
|
| 71 |
return (*connection->vtable->set_reconnect_timeout_fn)(connection->impl, min_timeout, max_timeout); |
| 72 |
} |
| 73 |
|
| 74 |
int aws_mqtt_client_connection_set_connection_result_handlers( |
| 75 |
struct aws_mqtt_client_connection *connection, |
| 76 |
aws_mqtt_client_on_connection_success_fn *on_connection_success, |
| 77 |
void *on_connection_success_ud, |
| 78 |
aws_mqtt_client_on_connection_failure_fn *on_connection_failure, |
| 79 |
void *on_connection_failure_ud) { |
| 80 |
|
| 81 |
return (*connection->vtable->set_connection_result_handlers)( |
| 82 |
connection->impl, |
| 83 |
on_connection_success, |
| 84 |
on_connection_success_ud, |
| 85 |
on_connection_failure, |
| 86 |
on_connection_failure_ud); |
| 87 |
} |
| 88 |
|
| 89 |
int aws_mqtt_client_connection_set_connection_interruption_handlers( |
| 90 |
struct aws_mqtt_client_connection *connection, |
| 91 |
aws_mqtt_client_on_connection_interrupted_fn *on_interrupted, |
| 92 |
void *on_interrupted_ud, |
| 93 |
aws_mqtt_client_on_connection_resumed_fn *on_resumed, |
| 94 |
void *on_resumed_ud) { |
| 95 |
|
| 96 |
return (*connection->vtable->set_connection_interruption_handlers_fn)( |
| 97 |
connection->impl, on_interrupted, on_interrupted_ud, on_resumed, on_resumed_ud); |
| 98 |
} |
| 99 |
|
| 100 |
int aws_mqtt_client_connection_set_connection_closed_handler( |
| 101 |
struct aws_mqtt_client_connection *connection, |
| 102 |
aws_mqtt_client_on_connection_closed_fn *on_closed, |
| 103 |
void *on_closed_ud) { |
| 104 |
|
| 105 |
return (*connection->vtable->set_connection_closed_handler_fn)(connection->impl, on_closed, on_closed_ud); |
| 106 |
} |
| 107 |
|
| 108 |
int aws_mqtt_client_connection_set_on_any_publish_handler( |
| 109 |
struct aws_mqtt_client_connection *connection, |
| 110 |
aws_mqtt_client_publish_received_fn *on_any_publish, |
| 111 |
void *on_any_publish_ud) { |
| 112 |
|
| 113 |
return (*connection->vtable->set_on_any_publish_handler_fn)(connection->impl, on_any_publish, on_any_publish_ud); |
| 114 |
} |
| 115 |
|
| 116 |
int aws_mqtt_client_connection_set_connection_termination_handler( |
| 117 |
struct aws_mqtt_client_connection *connection, |
| 118 |
aws_mqtt_client_on_connection_termination_fn *on_termination, |
| 119 |
void *on_termination_ud) { |
| 120 |
|
| 121 |
return (*connection->vtable->set_connection_termination_handler_fn)( |
| 122 |
connection->impl, on_termination, on_termination_ud); |
| 123 |
} |
| 124 |
|
| 125 |
int aws_mqtt_client_connection_connect( |
| 126 |
struct aws_mqtt_client_connection *connection, |
| 127 |
const struct aws_mqtt_connection_options *connection_options) { |
| 128 |
|
| 129 |
return (*connection->vtable->connect_fn)(connection->impl, connection_options); |
| 130 |
} |
| 131 |
|
| 132 |
int aws_mqtt_client_connection_reconnect( |
| 133 |
struct aws_mqtt_client_connection *connection, |
| 134 |
aws_mqtt_client_on_connection_complete_fn *on_connection_complete, |
| 135 |
void *userdata) { |
| 136 |
|
| 137 |
return (*connection->vtable->reconnect_fn)(connection->impl, on_connection_complete, userdata); |
| 138 |
} |
| 139 |
|
| 140 |
int aws_mqtt_client_connection_disconnect( |
| 141 |
struct aws_mqtt_client_connection *connection, |
| 142 |
aws_mqtt_client_on_disconnect_fn *on_disconnect, |
| 143 |
void *userdata) { |
| 144 |
|
| 145 |
return (*connection->vtable->disconnect_fn)(connection->impl, on_disconnect, userdata); |
| 146 |
} |
| 147 |
|
| 148 |
uint16_t aws_mqtt_client_connection_subscribe_multiple( |
| 149 |
struct aws_mqtt_client_connection *connection, |
| 150 |
const struct aws_array_list *topic_filters, |
| 151 |
aws_mqtt_suback_multi_fn *on_suback, |
| 152 |
void *on_suback_ud) { |
| 153 |
|
| 154 |
return (*connection->vtable->subscribe_multiple_fn)(connection->impl, topic_filters, on_suback, on_suback_ud); |
| 155 |
} |
| 156 |
|
| 157 |
uint16_t aws_mqtt_client_connection_subscribe( |
| 158 |
struct aws_mqtt_client_connection *connection, |
| 159 |
const struct aws_byte_cursor *topic_filter, |
| 160 |
enum aws_mqtt_qos qos, |
| 161 |
aws_mqtt_client_publish_received_fn *on_publish, |
| 162 |
void *on_publish_ud, |
| 163 |
aws_mqtt_userdata_cleanup_fn *on_ud_cleanup, |
| 164 |
aws_mqtt_suback_fn *on_suback, |
| 165 |
void *on_suback_ud) { |
| 166 |
|
| 167 |
return (*connection->vtable->subscribe_fn)( |
| 168 |
connection->impl, topic_filter, qos, on_publish, on_publish_ud, on_ud_cleanup, on_suback, on_suback_ud); |
| 169 |
} |
| 170 |
|
| 171 |
uint16_t aws_mqtt_resubscribe_existing_topics( |
| 172 |
struct aws_mqtt_client_connection *connection, |
| 173 |
aws_mqtt_suback_multi_fn *on_suback, |
| 174 |
void *on_suback_ud) { |
| 175 |
|
| 176 |
return (*connection->vtable->resubscribe_existing_topics_fn)(connection->impl, on_suback, on_suback_ud); |
| 177 |
} |
| 178 |
|
| 179 |
uint16_t aws_mqtt_client_connection_unsubscribe( |
| 180 |
struct aws_mqtt_client_connection *connection, |
| 181 |
const struct aws_byte_cursor *topic_filter, |
| 182 |
aws_mqtt_op_complete_fn *on_unsuback, |
| 183 |
void *on_unsuback_ud) { |
| 184 |
|
| 185 |
return (*connection->vtable->unsubscribe_fn)(connection->impl, topic_filter, on_unsuback, on_unsuback_ud); |
| 186 |
} |
| 187 |
|
| 188 |
uint16_t aws_mqtt_client_connection_publish( |
| 189 |
struct aws_mqtt_client_connection *connection, |
| 190 |
const struct aws_byte_cursor *topic, |
| 191 |
enum aws_mqtt_qos qos, |
| 192 |
bool retain, |
| 193 |
const struct aws_byte_cursor *payload, |
| 194 |
aws_mqtt_op_complete_fn *on_complete, |
| 195 |
void *userdata) { |
| 196 |
|
| 197 |
return (*connection->vtable->publish_fn)(connection->impl, topic, qos, retain, payload, on_complete, userdata); |
| 198 |
} |
| 199 |
|
| 200 |
int aws_mqtt_client_connection_get_stats( |
| 201 |
struct aws_mqtt_client_connection *connection, |
| 202 |
struct aws_mqtt_connection_operation_statistics *stats) { |
| 203 |
|
| 204 |
return (*connection->vtable->get_stats_fn)(connection->impl, stats); |
| 205 |
} |
| 206 |
|
| 207 |
enum aws_mqtt311_impl_type aws_mqtt_client_connection_get_impl_type( |
| 208 |
const struct aws_mqtt_client_connection *connection) { |
| 209 |
return (*connection->vtable->get_impl_type)(connection->impl); |
| 210 |
} |
| 211 |
|
| 212 |
uint64_t aws_mqtt_hash_uint16_t(const void *item) { |
| 213 |
return *(uint16_t *)item; |
| 214 |
} |
| 215 |
|
| 216 |
bool aws_mqtt_compare_uint16_t_eq(const void *a, const void *b) { |
| 217 |
return *(uint16_t *)a == *(uint16_t *)b; |
| 218 |
} |
| 219 |
|
| 220 |
uint64_t aws_mqtt_hash_uint64_t(const void *item) { |
| 221 |
return *(uint64_t *)item; |
| 222 |
} |
| 223 |
|
| 224 |
bool aws_mqtt_compare_uint64_t_eq(const void *a, const void *b) { |
| 225 |
return *(uint64_t *)a == *(uint64_t *)b; |
| 226 |
} |
| 227 |
|
| 228 |
bool aws_mqtt_byte_cursor_hash_equality(const void *a, const void *b) { |
| 229 |
const struct aws_byte_cursor *a_cursor = a; |
| 230 |
const struct aws_byte_cursor *b_cursor = b; |
| 231 |
|
| 232 |
return aws_byte_cursor_eq(a_cursor, b_cursor); |
| 233 |
} |
| 234 |
|
| 235 |
struct aws_event_loop *aws_mqtt_client_connection_get_event_loop(const struct aws_mqtt_client_connection *connection) { |
| 236 |
return (*connection->vtable->get_event_loop)(connection->impl); |
| 237 |
} |