Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit b1b1e45

Browse files
New Gateway_UpdateFromJson api, which enables to dynamically create Modules, Loaders and Links from JSON Content.
1 parent 1bab934 commit b1b1e45

File tree

12 files changed

+1167
-56
lines changed

12 files changed

+1167
-56
lines changed

core/devdoc/gateway_createfromjson_requirements.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern GATEWAY_HANDLE Gateway_CreateFromJson(const char* file_path);
6565
#endif
6666
```
6767

68-
##Gateway_CreateFromJson
68+
## Gateway_CreateFromJson
6969
```
7070
extern GATEWAY_HANDLE Gateway_CreateFromJson(const char* file_path);
7171
```
@@ -118,3 +118,30 @@ Gateway_CreateFromJson creates a new gateway using information contained within
118118
**SRS_GATEWAY_JSON_17_002: [** This function shall return `NULL` if starting the gateway fails. **]**
119119

120120
**SRS_GATEWAY_JSON_14_008: [** This function shall return `NULL` upon any memory allocation failure. **]**
121+
122+
123+
## Gateway_UpdateFromJson
124+
```
125+
extern int Gateway_UpdateFromJson(GATEWAY_HANDLE gw, const char* json_content);
126+
```
127+
Gateway_UpdateFromJson adds loades, modules or links based on a well-formed JSON configuration content.
128+
129+
**SRS_GATEWAY_JSON_04_003: [** If `json_content` is NULL the function shall return GATEWAY_UPDATE_FROM_JSON_ERROR. **]**
130+
131+
**SRS_GATEWAY_JSON_04_004: [** If `gw` is NULL the function shall return GATEWAY_UPDATE_FROM_JSON_ERROR.
132+
**]**
133+
134+
**SRS_GATEWAY_JSON_04_005: [** The function shall use *parson* to parse the JSON string to a *parson* `JSON_Value` structure. **]**
135+
136+
**SRS_GATEWAY_JSON_04_006: [** The function shall return NULL if the JSON content could not be parsed to a `JSON_Value`. **]**
137+
138+
**SRS_GATEWAY_JSON_04_007: [** The function shall traverse the `JSON_Value` object to initialize a `GATEWAY_PROPERTIES` instance. **]**
139+
140+
**SRS_GATEWAY_JSON_04_010: [** The function shall return NULL if the `JSON_Value` contains incomplete information. **]**
141+
142+
**SRS_GATEWAY_JSON_04_011: [** The function shall be able to add just `modules`, just `links` or both.
143+
**]**
144+
145+
**SRS_GATEWAY_JSON_04_009: [** The function shall be able to roll back previous operation if any `module` or `link` fails to be added. **]**
146+
147+
**SRS_GATEWAY_JSON_04_008: [** This function shall return GATEWAY_UPDATE_FROM_JSON_ERROR upon any memory allocation failure. **]**

core/inc/gateway.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ DEFINE_ENUM(GATEWAY_ADD_LINK_RESULT, GATEWAY_ADD_LINK_RESULT_VALUES);
4646
*/
4747
DEFINE_ENUM(GATEWAY_START_RESULT, GATEWAY_START_RESULT_VALUES);
4848

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+
55+
/** @brief Enumeration describing the result of ::Gateway_UpdateFromJson.
56+
*/
57+
DEFINE_ENUM(GATEWAY_UPDATE_FROM_JSON_RESULT, GATEWAY_UPDATE_FROM_JSON_RESULT_VALUES);
58+
59+
4960
/** @brief Struct representing a single link for a gateway. */
5061
typedef struct GATEWAY_LINK_ENTRY_TAG
5162
{
@@ -153,6 +164,19 @@ typedef struct GATEWAY_PROPERTIES_DATA_TAG
153164
*/
154165
GATEWAY_EXPORT GATEWAY_HANDLE Gateway_CreateFromJson(const char* file_path);
155166

167+
168+
169+
/** @brief Updates a gateway using a JSON configuration string as input
170+
* which describes each module.
171+
*
172+
* @param gw Pointer to a #GATEWAY_HANDLE from which to remove
173+
* the module.
174+
* @param json_content A JSON string with a list of Loaders, Modules and/or Links.
175+
*
176+
* @return A GATEWAY_UPDATE_FROM_JSON_RESULT with the operation result.
177+
*/
178+
GATEWAY_EXPORT GATEWAY_UPDATE_FROM_JSON_RESULT Gateway_UpdateFromJson(GATEWAY_HANDLE gw, const char* json_content);
179+
156180
/** @brief Creates a new gateway using the provided #GATEWAY_PROPERTIES.
157181
*
158182
* @param properties #GATEWAY_PROPERTIES structure containing

core/src/gateway_createfromjson.c

Lines changed: 320 additions & 52 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)