1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
3 |
|
---|
4 | #ifndef MQTT_CLIENT_H
|
---|
5 | #define MQTT_CLIENT_H
|
---|
6 |
|
---|
7 | #include "azure_c_shared_utility/xio.h"
|
---|
8 | #include "azure_c_shared_utility/macro_utils.h"
|
---|
9 | #include "azure_umqtt_c/mqttconst.h"
|
---|
10 | #include "azure_umqtt_c/mqtt_message.h"
|
---|
11 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
12 |
|
---|
13 | #ifdef __cplusplus
|
---|
14 | #include <cstdint>
|
---|
15 | extern "C" {
|
---|
16 | #else
|
---|
17 | #include <stdint.h>
|
---|
18 | #endif // __cplusplus
|
---|
19 |
|
---|
20 |
|
---|
21 | typedef struct MQTT_CLIENT_TAG* MQTT_CLIENT_HANDLE;
|
---|
22 |
|
---|
23 | #define MQTT_CLIENT_EVENT_VALUES \
|
---|
24 | MQTT_CLIENT_ON_CONNACK, \
|
---|
25 | MQTT_CLIENT_ON_PUBLISH_ACK, \
|
---|
26 | MQTT_CLIENT_ON_PUBLISH_RECV, \
|
---|
27 | MQTT_CLIENT_ON_PUBLISH_REL, \
|
---|
28 | MQTT_CLIENT_ON_PUBLISH_COMP, \
|
---|
29 | MQTT_CLIENT_ON_SUBSCRIBE_ACK, \
|
---|
30 | MQTT_CLIENT_ON_UNSUBSCRIBE_ACK, \
|
---|
31 | MQTT_CLIENT_ON_PING_RESPONSE, \
|
---|
32 | MQTT_CLIENT_ON_DISCONNECT
|
---|
33 |
|
---|
34 | MU_DEFINE_ENUM(MQTT_CLIENT_EVENT_RESULT, MQTT_CLIENT_EVENT_VALUES);
|
---|
35 |
|
---|
36 | #define MQTT_CLIENT_EVENT_ERROR_VALUES \
|
---|
37 | MQTT_CLIENT_CONNECTION_ERROR, \
|
---|
38 | MQTT_CLIENT_PARSE_ERROR, \
|
---|
39 | MQTT_CLIENT_MEMORY_ERROR, \
|
---|
40 | MQTT_CLIENT_COMMUNICATION_ERROR, \
|
---|
41 | MQTT_CLIENT_NO_PING_RESPONSE, \
|
---|
42 | MQTT_CLIENT_UNKNOWN_ERROR
|
---|
43 |
|
---|
44 | MU_DEFINE_ENUM(MQTT_CLIENT_EVENT_ERROR, MQTT_CLIENT_EVENT_ERROR_VALUES);
|
---|
45 |
|
---|
46 | typedef void(*ON_MQTT_OPERATION_CALLBACK)(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_RESULT actionResult, const void* msgInfo, void* callbackCtx);
|
---|
47 | typedef void(*ON_MQTT_ERROR_CALLBACK)(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_ERROR error, void* callbackCtx);
|
---|
48 | typedef void(*ON_MQTT_MESSAGE_RECV_CALLBACK)(MQTT_MESSAGE_HANDLE msgHandle, void* callbackCtx);
|
---|
49 | typedef void(*ON_MQTT_DISCONNECTED_CALLBACK)(void* callbackCtx);
|
---|
50 |
|
---|
51 | MOCKABLE_FUNCTION(, MQTT_CLIENT_HANDLE, mqtt_client_init, ON_MQTT_MESSAGE_RECV_CALLBACK, msgRecv, ON_MQTT_OPERATION_CALLBACK, opCallback, void*, opCallbackCtx, ON_MQTT_ERROR_CALLBACK, onErrorCallBack, void*, errorCBCtx);
|
---|
52 | MOCKABLE_FUNCTION(, void, mqtt_client_deinit, MQTT_CLIENT_HANDLE, handle);
|
---|
53 |
|
---|
54 | MOCKABLE_FUNCTION(, int, mqtt_client_connect, MQTT_CLIENT_HANDLE, handle, XIO_HANDLE, xioHandle, MQTT_CLIENT_OPTIONS*, mqttOptions);
|
---|
55 | MOCKABLE_FUNCTION(, int, mqtt_client_disconnect, MQTT_CLIENT_HANDLE, handle, ON_MQTT_DISCONNECTED_CALLBACK, callback, void*, ctx);
|
---|
56 |
|
---|
57 | MOCKABLE_FUNCTION(, int, mqtt_client_subscribe, MQTT_CLIENT_HANDLE, handle, uint16_t, packetId, SUBSCRIBE_PAYLOAD*, subscribeList, size_t, count);
|
---|
58 | MOCKABLE_FUNCTION(, int, mqtt_client_unsubscribe, MQTT_CLIENT_HANDLE, handle, uint16_t, packetId, const char**, unsubscribeList, size_t, count);
|
---|
59 |
|
---|
60 | MOCKABLE_FUNCTION(, int, mqtt_client_publish, MQTT_CLIENT_HANDLE, handle, MQTT_MESSAGE_HANDLE, msgHandle);
|
---|
61 |
|
---|
62 | MOCKABLE_FUNCTION(, void, mqtt_client_dowork, MQTT_CLIENT_HANDLE, handle);
|
---|
63 |
|
---|
64 | MOCKABLE_FUNCTION(, void, mqtt_client_set_trace, MQTT_CLIENT_HANDLE, handle, bool, traceOn, bool, rawBytesOn);
|
---|
65 |
|
---|
66 | #ifdef __cplusplus
|
---|
67 | }
|
---|
68 | #endif // __cplusplus
|
---|
69 |
|
---|
70 | #endif // MQTTCLIENT_H
|
---|