Xin Zhang / azure-iot-c-sdk-f767zi

Dependents:   samplemqtt

Committer:
XinZhangMS
Date:
Thu Aug 23 06:52:14 2018 +0000
Revision:
0:f7f1f0d76dd6
azure-c-sdk for mbed os supporting NUCLEO_F767ZI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
XinZhangMS 0:f7f1f0d76dd6 1 // Copyright (c) Microsoft. All rights reserved.
XinZhangMS 0:f7f1f0d76dd6 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
XinZhangMS 0:f7f1f0d76dd6 3
XinZhangMS 0:f7f1f0d76dd6 4 #ifndef CONNECTION_H
XinZhangMS 0:f7f1f0d76dd6 5 #define CONNECTION_H
XinZhangMS 0:f7f1f0d76dd6 6
XinZhangMS 0:f7f1f0d76dd6 7 #include <stddef.h>
XinZhangMS 0:f7f1f0d76dd6 8 #include <stdbool.h>
XinZhangMS 0:f7f1f0d76dd6 9 #include <stdint.h>
XinZhangMS 0:f7f1f0d76dd6 10 #include "azure_c_shared_utility/xio.h"
XinZhangMS 0:f7f1f0d76dd6 11 #include "azure_c_shared_utility/umock_c_prod.h"
XinZhangMS 0:f7f1f0d76dd6 12 #include "azure_uamqp_c/amqp_frame_codec.h"
XinZhangMS 0:f7f1f0d76dd6 13 #include "azure_uamqp_c/amqp_definitions_fields.h"
XinZhangMS 0:f7f1f0d76dd6 14 #include "azure_uamqp_c/amqp_definitions_milliseconds.h"
XinZhangMS 0:f7f1f0d76dd6 15 #include "azure_uamqp_c/amqp_definitions_error.h"
XinZhangMS 0:f7f1f0d76dd6 16 #include "azure_uamqp_c/amqpvalue.h"
XinZhangMS 0:f7f1f0d76dd6 17
XinZhangMS 0:f7f1f0d76dd6 18 #ifdef __cplusplus
XinZhangMS 0:f7f1f0d76dd6 19 extern "C" {
XinZhangMS 0:f7f1f0d76dd6 20 #endif /* __cplusplus */
XinZhangMS 0:f7f1f0d76dd6 21
XinZhangMS 0:f7f1f0d76dd6 22 typedef struct CONNECTION_INSTANCE_TAG* CONNECTION_HANDLE;
XinZhangMS 0:f7f1f0d76dd6 23 typedef struct ENDPOINT_INSTANCE_TAG* ENDPOINT_HANDLE;
XinZhangMS 0:f7f1f0d76dd6 24 typedef struct ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_TAG* ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE;
XinZhangMS 0:f7f1f0d76dd6 25
XinZhangMS 0:f7f1f0d76dd6 26 typedef enum CONNECTION_STATE_TAG
XinZhangMS 0:f7f1f0d76dd6 27 {
XinZhangMS 0:f7f1f0d76dd6 28 /* Codes_S_R_S_CONNECTION_01_039: [START In this state a connection exists, but nothing has been sent or received. This is the state an implementation would be in immediately after performing a socket connect or socket accept.] */
XinZhangMS 0:f7f1f0d76dd6 29 CONNECTION_STATE_START,
XinZhangMS 0:f7f1f0d76dd6 30
XinZhangMS 0:f7f1f0d76dd6 31 /* Codes_S_R_S_CONNECTION_01_040: [HDR RCVD In this state the connection header has been received from the peer but a connection header has not been sent.] */
XinZhangMS 0:f7f1f0d76dd6 32 CONNECTION_STATE_HDR_RCVD,
XinZhangMS 0:f7f1f0d76dd6 33
XinZhangMS 0:f7f1f0d76dd6 34 /* Codes_S_R_S_CONNECTION_01_041: [HDR SENT In this state the connection header has been sent to the peer but no connection header has been received.] */
XinZhangMS 0:f7f1f0d76dd6 35 CONNECTION_STATE_HDR_SENT,
XinZhangMS 0:f7f1f0d76dd6 36
XinZhangMS 0:f7f1f0d76dd6 37 /* Codes_S_R_S_CONNECTION_01_042: [HDR EXCH In this state the connection header has been sent to the peer and a connection header has been received from the peer.] */
XinZhangMS 0:f7f1f0d76dd6 38 CONNECTION_STATE_HDR_EXCH,
XinZhangMS 0:f7f1f0d76dd6 39
XinZhangMS 0:f7f1f0d76dd6 40 /* Codes_S_R_S_CONNECTION_01_043: [OPEN PIPE In this state both the connection header and the open frame have been sent but nothing has been received.] */
XinZhangMS 0:f7f1f0d76dd6 41 CONNECTION_STATE_OPEN_PIPE,
XinZhangMS 0:f7f1f0d76dd6 42
XinZhangMS 0:f7f1f0d76dd6 43 /* Codes_S_R_S_CONNECTION_01_044: [OC PIPE In this state, the connection header, the open frame, any pipelined connection traffic, and the close frame have been sent but nothing has been received.] */
XinZhangMS 0:f7f1f0d76dd6 44 CONNECTION_STATE_OC_PIPE,
XinZhangMS 0:f7f1f0d76dd6 45
XinZhangMS 0:f7f1f0d76dd6 46 /* Codes_S_R_S_CONNECTION_01_045: [OPEN RCVD In this state the connection headers have been exchanged. An open frame has been received from the peer but an open frame has not been sent.] */
XinZhangMS 0:f7f1f0d76dd6 47 CONNECTION_STATE_OPEN_RCVD,
XinZhangMS 0:f7f1f0d76dd6 48
XinZhangMS 0:f7f1f0d76dd6 49 /* Codes_S_R_S_CONNECTION_01_046: [OPEN SENT In this state the connection headers have been exchanged. An open frame has been sent to the peer but no open frame has yet been received.] */
XinZhangMS 0:f7f1f0d76dd6 50 CONNECTION_STATE_OPEN_SENT,
XinZhangMS 0:f7f1f0d76dd6 51
XinZhangMS 0:f7f1f0d76dd6 52 /* Codes_S_R_S_CONNECTION_01_047: [CLOSE PIPE In this state the connection headers have been exchanged. An open frame, any pipelined connection traffic, and the close frame have been sent but no open frame has yet been received from the peer.] */
XinZhangMS 0:f7f1f0d76dd6 53 CONNECTION_STATE_CLOSE_PIPE,
XinZhangMS 0:f7f1f0d76dd6 54
XinZhangMS 0:f7f1f0d76dd6 55 /* Codes_S_R_S_CONNECTION_01_048: [OPENED In this state the connection header and the open frame have been both sent and received.] */
XinZhangMS 0:f7f1f0d76dd6 56 CONNECTION_STATE_OPENED,
XinZhangMS 0:f7f1f0d76dd6 57
XinZhangMS 0:f7f1f0d76dd6 58 /* Codes_S_R_S_CONNECTION_01_049: [CLOSE RCVD In this state a close frame has been received indicating that the peer has initiated an AMQP close.] */
XinZhangMS 0:f7f1f0d76dd6 59 CONNECTION_STATE_CLOSE_RCVD,
XinZhangMS 0:f7f1f0d76dd6 60
XinZhangMS 0:f7f1f0d76dd6 61 /* Codes_S_R_S_CONNECTION_01_053: [CLOSE SENT In this state a close frame has been sent to the peer. It is illegal to write anything more onto the connection, however there could potentially still be incoming frames.] */
XinZhangMS 0:f7f1f0d76dd6 62 CONNECTION_STATE_CLOSE_SENT,
XinZhangMS 0:f7f1f0d76dd6 63
XinZhangMS 0:f7f1f0d76dd6 64 /* Codes_S_R_S_CONNECTION_01_055: [DISCARDING The DISCARDING state is a variant of the CLOSE SENT state where the close is triggered by an error.] */
XinZhangMS 0:f7f1f0d76dd6 65 CONNECTION_STATE_DISCARDING,
XinZhangMS 0:f7f1f0d76dd6 66
XinZhangMS 0:f7f1f0d76dd6 67 /* Codes_S_R_S_CONNECTION_01_057: [END In this state it is illegal for either endpoint to write anything more onto the connection. The connection can be safely closed and discarded.] */
XinZhangMS 0:f7f1f0d76dd6 68 CONNECTION_STATE_END,
XinZhangMS 0:f7f1f0d76dd6 69
XinZhangMS 0:f7f1f0d76dd6 70 /* Codes_S_R_S_CONNECTION_09_001: [ERROR In this state the connection has failed, most likely due to a socket error, and should not be reused.] */
XinZhangMS 0:f7f1f0d76dd6 71 CONNECTION_STATE_ERROR
XinZhangMS 0:f7f1f0d76dd6 72 } CONNECTION_STATE;
XinZhangMS 0:f7f1f0d76dd6 73
XinZhangMS 0:f7f1f0d76dd6 74 typedef void(*ON_ENDPOINT_FRAME_RECEIVED)(void* context, AMQP_VALUE performative, uint32_t frame_payload_size, const unsigned char* payload_bytes);
XinZhangMS 0:f7f1f0d76dd6 75 typedef void(*ON_CONNECTION_STATE_CHANGED)(void* context, CONNECTION_STATE new_connection_state, CONNECTION_STATE previous_connection_state);
XinZhangMS 0:f7f1f0d76dd6 76 typedef void(*ON_CONNECTION_CLOSE_RECEIVED)(void* context, ERROR_HANDLE error);
XinZhangMS 0:f7f1f0d76dd6 77 typedef bool(*ON_NEW_ENDPOINT)(void* context, ENDPOINT_HANDLE new_endpoint);
XinZhangMS 0:f7f1f0d76dd6 78
XinZhangMS 0:f7f1f0d76dd6 79 MOCKABLE_FUNCTION(, CONNECTION_HANDLE, connection_create, XIO_HANDLE, io, const char*, hostname, const char*, container_id, ON_NEW_ENDPOINT, on_new_endpoint, void*, callback_context);
XinZhangMS 0:f7f1f0d76dd6 80 MOCKABLE_FUNCTION(, CONNECTION_HANDLE, connection_create2, XIO_HANDLE, xio, const char*, hostname, const char*, container_id, ON_NEW_ENDPOINT, on_new_endpoint, void*, callback_context, ON_CONNECTION_STATE_CHANGED, on_connection_state_changed, void*, on_connection_state_changed_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
XinZhangMS 0:f7f1f0d76dd6 81 MOCKABLE_FUNCTION(, void, connection_destroy, CONNECTION_HANDLE, connection);
XinZhangMS 0:f7f1f0d76dd6 82 MOCKABLE_FUNCTION(, int, connection_open, CONNECTION_HANDLE, connection);
XinZhangMS 0:f7f1f0d76dd6 83 MOCKABLE_FUNCTION(, int, connection_listen, CONNECTION_HANDLE, connection);
XinZhangMS 0:f7f1f0d76dd6 84 MOCKABLE_FUNCTION(, int, connection_close, CONNECTION_HANDLE, connection, const char*, condition_value, const char*, description, AMQP_VALUE, info);
XinZhangMS 0:f7f1f0d76dd6 85 MOCKABLE_FUNCTION(, int, connection_set_max_frame_size, CONNECTION_HANDLE, connection, uint32_t, max_frame_size);
XinZhangMS 0:f7f1f0d76dd6 86 MOCKABLE_FUNCTION(, int, connection_get_max_frame_size, CONNECTION_HANDLE, connection, uint32_t*, max_frame_size);
XinZhangMS 0:f7f1f0d76dd6 87 MOCKABLE_FUNCTION(, int, connection_set_channel_max, CONNECTION_HANDLE, connection, uint16_t, channel_max);
XinZhangMS 0:f7f1f0d76dd6 88 MOCKABLE_FUNCTION(, int, connection_get_channel_max, CONNECTION_HANDLE, connection, uint16_t*, channel_max);
XinZhangMS 0:f7f1f0d76dd6 89 MOCKABLE_FUNCTION(, int, connection_set_idle_timeout, CONNECTION_HANDLE, connection, milliseconds, idle_timeout);
XinZhangMS 0:f7f1f0d76dd6 90 MOCKABLE_FUNCTION(, int, connection_get_idle_timeout, CONNECTION_HANDLE, connection, milliseconds*, idle_timeout);
XinZhangMS 0:f7f1f0d76dd6 91 MOCKABLE_FUNCTION(, int, connection_set_properties, CONNECTION_HANDLE, connection, fields, properties);
XinZhangMS 0:f7f1f0d76dd6 92 MOCKABLE_FUNCTION(, int, connection_get_properties, CONNECTION_HANDLE, connection, fields*, properties);
XinZhangMS 0:f7f1f0d76dd6 93 MOCKABLE_FUNCTION(, int, connection_get_remote_max_frame_size, CONNECTION_HANDLE, connection, uint32_t*, remote_max_frame_size);
XinZhangMS 0:f7f1f0d76dd6 94 MOCKABLE_FUNCTION(, int, connection_set_remote_idle_timeout_empty_frame_send_ratio, CONNECTION_HANDLE, connection, double, idle_timeout_empty_frame_send_ratio);
XinZhangMS 0:f7f1f0d76dd6 95 MOCKABLE_FUNCTION(, uint64_t, connection_handle_deadlines, CONNECTION_HANDLE, connection);
XinZhangMS 0:f7f1f0d76dd6 96 MOCKABLE_FUNCTION(, void, connection_dowork, CONNECTION_HANDLE, connection);
XinZhangMS 0:f7f1f0d76dd6 97 MOCKABLE_FUNCTION(, ENDPOINT_HANDLE, connection_create_endpoint, CONNECTION_HANDLE, connection);
XinZhangMS 0:f7f1f0d76dd6 98 MOCKABLE_FUNCTION(, int, connection_start_endpoint, ENDPOINT_HANDLE, endpoint, ON_ENDPOINT_FRAME_RECEIVED, on_frame_received, ON_CONNECTION_STATE_CHANGED, on_connection_state_changed, void*, context);
XinZhangMS 0:f7f1f0d76dd6 99 MOCKABLE_FUNCTION(, int, connection_endpoint_get_incoming_channel, ENDPOINT_HANDLE, endpoint, uint16_t*, incoming_channel);
XinZhangMS 0:f7f1f0d76dd6 100 MOCKABLE_FUNCTION(, void, connection_destroy_endpoint, ENDPOINT_HANDLE, endpoint);
XinZhangMS 0:f7f1f0d76dd6 101 MOCKABLE_FUNCTION(, int, connection_encode_frame, ENDPOINT_HANDLE, endpoint, AMQP_VALUE, performative, PAYLOAD*, payloads, size_t, payload_count, ON_SEND_COMPLETE, on_send_complete, void*, callback_context);
XinZhangMS 0:f7f1f0d76dd6 102 MOCKABLE_FUNCTION(, void, connection_set_trace, CONNECTION_HANDLE, connection, bool, trace_on);
XinZhangMS 0:f7f1f0d76dd6 103
XinZhangMS 0:f7f1f0d76dd6 104 MOCKABLE_FUNCTION(, ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE, connection_subscribe_on_connection_close_received, CONNECTION_HANDLE, connection, ON_CONNECTION_CLOSE_RECEIVED, on_connection_close_received, void*, context);
XinZhangMS 0:f7f1f0d76dd6 105 MOCKABLE_FUNCTION(, void, connection_unsubscribe_on_connection_close_received, ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE, event_subscription);
XinZhangMS 0:f7f1f0d76dd6 106
XinZhangMS 0:f7f1f0d76dd6 107 #ifdef __cplusplus
XinZhangMS 0:f7f1f0d76dd6 108 }
XinZhangMS 0:f7f1f0d76dd6 109 #endif /* __cplusplus */
XinZhangMS 0:f7f1f0d76dd6 110
XinZhangMS 0:f7f1f0d76dd6 111 #endif /* CONNECTION_H */