no-OS
iot_sample_common.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
4 #ifndef IOT_SAMPLE_COMMON_H
5 #define IOT_SAMPLE_COMMON_H
6 
7 #include <stdbool.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 
13 #include <azure/az_core.h>
14 
15 //
16 // Logging
17 //
18 #define IOT_SAMPLE_LOG_ERROR(...) \
19  do \
20  { \
21  (void)fprintf(stderr, "ERROR:\t\t%s:%s():%d: ", __FILE__, __func__, __LINE__); \
22  (void)fprintf(stderr, __VA_ARGS__); \
23  (void)fprintf(stderr, "\n"); \
24  fflush(stdout); \
25  fflush(stderr); \
26  } while (0)
27 
28 #define IOT_SAMPLE_LOG_SUCCESS(...) \
29  do \
30  { \
31  (void)printf("SUCCESS:\t"); \
32  (void)printf(__VA_ARGS__); \
33  (void)printf("\n"); \
34  } while (0)
35 
36 #define IOT_SAMPLE_LOG(...) \
37  do \
38  { \
39  (void)printf("\t\t"); \
40  (void)printf(__VA_ARGS__); \
41  (void)printf("\n"); \
42  } while (0)
43 
44 typedef enum {
48 
49 /*
50  * @brief Builds an MQTT endpoint c-string for an Azure IoT Hub or provisioning service.
51  *
52  * @param[in] type The enumerated type of the sample.
53  * @param[out] endpoint A buffer with sufficient capacity to hold the built endpoint. If
54  * successful, contains a null-terminated string of the endpoint.
55  * @param[in] endpoint_size The size of \p out_endpoint in bytes.
56  */
58  iot_sample_type type,
59  char* endpoint,
60  size_t endpoint_size);
61 
62 #endif // IOT_SAMPLE_COMMON_H
PAHO_IOT_HUB
@ PAHO_IOT_HUB
Definition: iot_sample_common.h:45
iot_sample_common.h
PAHO_IOT_PROVISIONING
@ PAHO_IOT_PROVISIONING
Definition: iot_sample_common.h:46
iot_sample_create_mqtt_endpoint
void iot_sample_create_mqtt_endpoint(iot_sample_type type, char *out_endpoint, size_t endpoint_size)
Definition: iot_sample_common.c:31
IOT_SAMPLE_LOG_SUCCESS
#define IOT_SAMPLE_LOG_SUCCESS(...)
Definition: iot_sample_common.h:28
iot_sample_create_mqtt_endpoint
void iot_sample_create_mqtt_endpoint(iot_sample_type type, char *endpoint, size_t endpoint_size)
Definition: iot_sample_common.c:31
iot_sample_type
iot_sample_type
Definition: iot_sample_common.h:44
IOT_SAMPLE_LOG_ERROR
#define IOT_SAMPLE_LOG_ERROR(...)
Definition: iot_sample_common.h:18