Microsoft Azure IoT Gateway SDK  1.0.8
The Microsoft Azure IoT Gateway SDK contains the infrastructure and modules to create IoT gateway solutions.
gateway.h
Go to the documentation of this file.
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 
11 #ifndef GATEWAY_H
12 #define GATEWAY_H
13 
14 #include "azure_c_shared_utility/macro_utils.h"
15 #include "azure_c_shared_utility/vector.h"
16 
17 #include "nanomsg/nn.h"
18 
19 #include "module.h"
20 #include "module_loader.h"
21 #include "gateway_export.h"
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27 
28 #define GATEWAY_CONNECTION_ID_MAX NN_SOCKADDR_MAX
29 #define GATEWAY_MESSAGE_VERSION_1 0x01
30 #define GATEWAY_MESSAGE_VERSION_CURRENT GATEWAY_MESSAGE_VERSION_1
31 
32 #define GATEWAY_ADD_LINK_RESULT_VALUES \
33  GATEWAY_ADD_LINK_SUCCESS, \
34  GATEWAY_ADD_LINK_ERROR, \
35  GATEWAY_ADD_LINK_INVALID_ARG
36 
39 DEFINE_ENUM(GATEWAY_ADD_LINK_RESULT, GATEWAY_ADD_LINK_RESULT_VALUES);
40 
41 #define GATEWAY_START_RESULT_VALUES \
42  GATEWAY_START_SUCCESS, \
43  GATEWAY_START_INVALID_ARGS
44 
47 DEFINE_ENUM(GATEWAY_START_RESULT, GATEWAY_START_RESULT_VALUES);
48 
49 #define GATEWAY_UPDATE_FROM_JSON_RESULT_VALUES \
50  GATEWAY_UPDATE_FROM_JSON_SUCCESS, \
51  GATEWAY_UPDATE_FROM_JSON_ERROR, \
52  GATEWAY_UPDATE_FROM_JSON_INVALID_ARG, \
53  GATEWAY_UPDATE_FROM_JSON_MEMORY
54 
57 DEFINE_ENUM(GATEWAY_UPDATE_FROM_JSON_RESULT, GATEWAY_UPDATE_FROM_JSON_RESULT_VALUES);
58 
59 
61 typedef struct GATEWAY_LINK_ENTRY_TAG
62 {
64  const char* module_source;
65 
67  const char* module_sink;
69 
71 typedef struct GATEWAY_HANDLE_DATA_TAG* GATEWAY_HANDLE;
72 
77 {
82 
85  void* entrypoint;
87 
91 {
93  const char* module_name;
94 
97 
99  const void* module_configuration;
101 
107 {
109  VECTOR_HANDLE gateway_modules;
110 
112  VECTOR_HANDLE gateway_links;
114 
165 GATEWAY_EXPORT GATEWAY_HANDLE Gateway_CreateFromJson(const char* file_path);
166 
167 
168 
178 GATEWAY_EXPORT GATEWAY_UPDATE_FROM_JSON_RESULT Gateway_UpdateFromJson(GATEWAY_HANDLE gw, const char* json_content);
179 
188 GATEWAY_EXPORT GATEWAY_HANDLE Gateway_Create(const GATEWAY_PROPERTIES* properties);
189 
196 GATEWAY_EXPORT GATEWAY_START_RESULT Gateway_Start(GATEWAY_HANDLE gw);
197 
202 GATEWAY_EXPORT void Gateway_Destroy(GATEWAY_HANDLE gw);
203 
213 GATEWAY_EXPORT MODULE_HANDLE Gateway_AddModule(GATEWAY_HANDLE gw, const GATEWAY_MODULES_ENTRY* entry);
214 
221 GATEWAY_EXPORT void Gateway_StartModule(GATEWAY_HANDLE gw, MODULE_HANDLE module);
222 
223 
231 GATEWAY_EXPORT void Gateway_RemoveModule(GATEWAY_HANDLE gw, MODULE_HANDLE module);
232 
242 GATEWAY_EXPORT int Gateway_RemoveModuleByName(GATEWAY_HANDLE gw, const char *module_name);
243 
253 GATEWAY_EXPORT GATEWAY_ADD_LINK_RESULT Gateway_AddLink(GATEWAY_HANDLE gw, const GATEWAY_LINK_ENTRY* entryLink);
254 
262 GATEWAY_EXPORT void Gateway_RemoveLink(GATEWAY_HANDLE gw, const GATEWAY_LINK_ENTRY* entryLink);
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif // GATEWAY_H
const MODULE_LOADER * loader
Pointer to the module loader to be used for loading this module.
Definition: gateway.h:81
Struct representing the loader and entrypoint to be used for a specific module.
Definition: gateway.h:76
GATEWAY_EXPORT void Gateway_StartModule(GATEWAY_HANDLE gw, MODULE_HANDLE module)
Tells a module that the gateway is ready for it to start.
GATEWAY_EXPORT GATEWAY_UPDATE_FROM_JSON_RESULT Gateway_UpdateFromJson(GATEWAY_HANDLE gw, const char *json_content)
Updates a gateway using a JSON configuration string as input which describes each module...
enum GATEWAY_ADD_LINK_RESULT_TAG GATEWAY_ADD_LINK_RESULT
Enumeration describing the result of Gateway_AddLink.
void * MODULE_HANDLE
Represents a module instance.
Definition: module.h:25
const char * module_source
The name of the module which is going to send messages.
Definition: gateway.h:64
GATEWAY_EXPORT GATEWAY_ADD_LINK_RESULT Gateway_AddLink(GATEWAY_HANDLE gw, const GATEWAY_LINK_ENTRY *entryLink)
Adds a link to a gateway message broker.
GATEWAY_EXPORT void Gateway_RemoveLink(GATEWAY_HANDLE gw, const GATEWAY_LINK_ENTRY *entryLink)
Remove a link from a gateway message broker.
GATEWAY_EXPORT int Gateway_RemoveModuleByName(GATEWAY_HANDLE gw, const char *module_name)
Removes module by its unique name.
GATEWAY_MODULE_LOADER_INFO module_loader_info
The module loader information for this module.
Definition: gateway.h:96
GATEWAY_EXPORT MODULE_HANDLE Gateway_AddModule(GATEWAY_HANDLE gw, const GATEWAY_MODULES_ENTRY *entry)
Creates a new module based on the GATEWAY_MODULES_ENTRY*.
struct GATEWAY_MODULE_LOADER_INFO_TAG GATEWAY_MODULE_LOADER_INFO
Struct representing the loader and entrypoint to be used for a specific module.
struct GATEWAY_HANDLE_DATA_TAG * GATEWAY_HANDLE
Struct representing a particular gateway.
Definition: gateway.h:71
struct GATEWAY_LINK_ENTRY_TAG GATEWAY_LINK_ENTRY
Struct representing a single link for a gateway.
void * entrypoint
Pointer to the entrypoint for this module.
Definition: gateway.h:85
Struct representing the properties that should be used when creating a module; each entry of the VECT...
Definition: gateway.h:106
struct GATEWAY_MODULES_ENTRY_TAG GATEWAY_MODULES_ENTRY
Struct representing a single entry of the GATEWAY_PROPERTIES.
GATEWAY_EXPORT void Gateway_RemoveModule(GATEWAY_HANDLE gw, MODULE_HANDLE module)
Removes the provided module from the gateway and all links that involves this module.
VECTOR_HANDLE gateway_modules
Vector of GATEWAY_MODULES_ENTRY objects.
Definition: gateway.h:109
Struct representing a single link for a gateway.
Definition: gateway.h:61
GATEWAY_EXPORT GATEWAY_HANDLE Gateway_CreateFromJson(const char *file_path)
Creates a gateway using a JSON configuration file as input which describes each module. Each module described in the configuration must support Module_CreateFromJson.
struct GATEWAY_PROPERTIES_DATA_TAG GATEWAY_PROPERTIES
Struct representing the properties that should be used when creating a module; each entry of the VECT...
Definition of the functions and structures that must be implemented by a gateway module loader...
Definition: module_loader.h:119
const char * module_name
The (possibly NULL) name of the module.
Definition: gateway.h:93
GATEWAY_EXPORT void Gateway_Destroy(GATEWAY_HANDLE gw)
Destroys the gateway and disposes of all associated data.
GATEWAY_EXPORT GATEWAY_START_RESULT Gateway_Start(GATEWAY_HANDLE gw)
Tell the Gateway it's ready to start.
const void * module_configuration
The user-defined configuration object for the module.
Definition: gateway.h:99
Struct representing a single entry of the GATEWAY_PROPERTIES.
Definition: gateway.h:90
enum GATEWAY_START_RESULT_TAG GATEWAY_START_RESULT
Enumeration describing the result of Gateway_Start.
const char * module_sink
The name of the module which is going to receive messages.
Definition: gateway.h:67
VECTOR_HANDLE gateway_links
Vector of GATEWAY_LINK_ENTRY objects.
Definition: gateway.h:112
Interface for modules which communicate with other modules via a message broker.
enum GATEWAY_UPDATE_FROM_JSON_RESULT_TAG GATEWAY_UPDATE_FROM_JSON_RESULT
Enumeration describing the result of Gateway_UpdateFromJson.
GATEWAY_EXPORT GATEWAY_HANDLE Gateway_Create(const GATEWAY_PROPERTIES *properties)
Creates a new gateway using the provided GATEWAY_PROPERTIES.