AWS Greengrass Core SDK for C
greengrasssdk.h
Go to the documentation of this file.
1 
7 #ifndef _GREENGRASS_SDK_H_
8 #define _GREENGRASS_SDK_H_
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <stdlib.h>
15 #include <stdint.h>
16 #include <sys/types.h>
17 
18 /***************************************
19 ** Greengrass Types **
20 ***************************************/
21 
27 typedef enum gg_error {
40 
41  GGE_RESERVED_MAX,
42  GGE_RESERVED_PAD = 0x7FFFFFFF
43 } gg_error;
44 
45 typedef struct _gg_request *gg_request;
46 
53 typedef enum gg_request_status {
64 
65  GG_REQUEST_RESERVED_MAX,
66  GG_REQUEST_RESERVED_PAD = 0x7FFFFFFF
68 
73 typedef struct gg_request_result {
77 
83 typedef struct gg_lambda_context {
84  const char *function_arn;
85  const char *client_context;
87 
91 typedef enum gg_invoke_type {
96 
97  GG_INVOKE_RESERVED_MAX,
98  GG_INVOKE_RESERVED_PAD = 0x7FFFFFFF
100 
104 typedef enum gg_runtime_opt {
107  GG_RT_OPT_RESERVED_PAD = 0x7FFFFFFF
109 
120 typedef struct gg_invoke_options {
121  const char *function_arn;
122  const char *customer_context;
123  const char *qualifier;
124  gg_invoke_type type;
125  const void *payload;
126  size_t payload_size;
128 
139 
140  GG_QUEUE_FULL_POLICY_RESERVED_MAX,
141  GG_QUEUE_FULL_POLICY_RESERVED_PAD = 0x7FFFFFFF
143 
144 typedef struct _gg_publish_options *gg_publish_options;
145 
149 typedef enum gg_log_level {
150  GG_LOG_RESERVED_NOTSET,
151 
162 
163  GG_LOG_RESERVED_MAX,
164  GG_LOG_RESERVED_PAD = 0x7FFFFFFF
165 } gg_log_level;
166 
167 /***************************************
168 ** Global Methods **
169 ***************************************/
170 
171 
182 gg_error gg_global_init(uint32_t opt);
183 
184 /***************************************
185 ** Logging Methods **
186 ***************************************/
187 
195 gg_error gg_log(gg_log_level level, const char *format, ...);
196 
197 /***************************************
198 ** gg_request Methods **
199 ***************************************/
200 
207 gg_error gg_request_init(gg_request *ggreq);
208 
214 gg_error gg_request_close(gg_request ggreq);
215 
226 gg_error gg_request_read(gg_request ggreq, void *buffer, size_t buffer_size,
227  size_t *amount_read);
228 
229 /***************************************
230 ** Runtime Methods **
231 ***************************************/
232 
238 typedef void (*gg_lambda_handler)(const gg_lambda_context *cxt);
239 
247 gg_error gg_runtime_start(gg_lambda_handler handler, uint32_t opt);
248 
259 gg_error gg_lambda_handler_read(void *buffer, size_t buffer_size,
260  size_t *amount_read);
261 
269 gg_error gg_lambda_handler_write_response(const void *response,
270  size_t response_size);
271 
280 gg_error gg_lambda_handler_write_error(const char *error_message);
281 
282 /***************************************
283 ** AWS Secrets Manager Methods **
284 ***************************************/
285 
295 gg_error gg_get_secret_value(gg_request ggreq, const char *secret_id,
296  const char *version_id, const char *version_stage,
297  gg_request_result *result);
298 
299 /***************************************
300 ** Lambda Methods **
301 ***************************************/
302 
310 gg_error gg_invoke(gg_request ggreq, const gg_invoke_options *opts,
311  gg_request_result *result);
312 
313 /***************************************
314 ** AWS IoT Methods **
315 ***************************************/
316 
323 gg_error gg_publish_options_init(gg_publish_options *opts);
324 
330 gg_error gg_publish_options_free(gg_publish_options opts);
331 
338 gg_error gg_publish_options_set_queue_full_policy(gg_publish_options opts,
340 
351 gg_error gg_publish_with_options(gg_request ggreq, const char *topic,
352  const void *payload, size_t payload_size, const gg_publish_options opts,
353  gg_request_result *result);
354 
365 gg_error gg_publish(gg_request ggreq, const char *topic, const void *payload,
366  size_t payload_size, gg_request_result *result);
367 
375 gg_error gg_get_thing_shadow(gg_request ggreq, const char *thing_name,
376  gg_request_result *result);
377 
386 gg_error gg_update_thing_shadow(gg_request ggreq, const char *thing_name,
387  const char *update_payload,
388  gg_request_result *result);
389 
398 gg_error gg_delete_thing_shadow(gg_request ggreq, const char *thing_name,
399  gg_request_result *result);
400 
401 #ifdef __cplusplus
402 }
403 #endif
404 
405 #endif /* #ifndef _GREENGRASS_SDK_H_ */
gg_error gg_log(gg_log_level level, const char *format,...)
Log message to Greengrass Core using similar syntax to printf.
gg_error gg_lambda_handler_write_error(const char *error_message)
Write error message to the invoker of the lambda.
Definition: greengrasssdk.h:93
Definition: greengrasssdk.h:153
Definition: greengrasssdk.h:33
gg_error gg_lambda_handler_read(void *buffer, size_t buffer_size, size_t *amount_read)
Read the data from the invoker of the lambda. This method should be called till amount_read is zero...
Describes the options to invoke a target lambda.
Definition: greengrasssdk.h:120
gg_error gg_lambda_handler_write_response(const void *response, size_t response_size)
Write response to the invoker of the lambda.
gg_runtime_opt
Flags set for the gg_runtime_start)(.., opt)
Definition: greengrasssdk.h:104
gg_error gg_update_thing_shadow(gg_request ggreq, const char *thing_name, const char *update_payload, gg_request_result *result)
Update thing shadow for thing name.
void(* gg_lambda_handler)(const gg_lambda_context *cxt)
Handler signature that will be called whenever a subscribed message is received.
Definition: greengrasssdk.h:238
gg_error gg_request_close(gg_request ggreq)
Close a request context that was created by gg_request_init.
gg_error gg_invoke(gg_request ggreq, const gg_invoke_options *opts, gg_request_result *result)
Invoke a lambda with an optional payload.
gg_error gg_publish(gg_request ggreq, const char *topic, const void *payload, size_t payload_size, gg_request_result *result)
Publish a payload to a topic.
Definition: greengrasssdk.h:95
Definition: greengrasssdk.h:39
gg_error gg_publish_options_free(gg_publish_options opts)
Free a publish options that was created by gg_publish_options_init.
struct gg_request_result gg_request_result
Describes result metadata after request is made.
Definition: greengrasssdk.h:37
gg_error gg_get_secret_value(gg_request ggreq, const char *secret_id, const char *version_id, const char *version_stage, gg_request_result *result)
Get secret value for the given secret.
Definition: greengrasssdk.h:55
Definition: greengrasssdk.h:159
Definition: greengrasssdk.h:29
gg_queue_full_policy_options
Describes the policy options to take when Greengrass's queue is full.
Definition: greengrasssdk.h:132
gg_error gg_global_init(uint32_t opt)
Initialize Greengrass internal global variables.
Definition: greengrasssdk.h:57
Definition: greengrasssdk.h:31
Describes context when lambda handler is called.
Definition: greengrasssdk.h:83
Definition: greengrasssdk.h:61
gg_error gg_publish_options_init(gg_publish_options *opts)
Initialize the publish options.
gg_error gg_get_thing_shadow(gg_request ggreq, const char *thing_name, gg_request_result *result)
Get thing shadow for thing name.
Definition: greengrasssdk.h:157
Definition: greengrasssdk.h:59
gg_invoke_type
Describes invocation type for lambda function.
Definition: greengrasssdk.h:91
gg_error gg_publish_options_set_queue_full_policy(gg_publish_options opts, gg_queue_full_policy_options policy)
Sets the queue full policy on a publish options.
Definition: greengrasssdk.h:106
Definition: greengrasssdk.h:161
gg_error gg_runtime_start(gg_lambda_handler handler, uint32_t opt)
Registers the lambda handler and start Greengrass lambda runtime.
gg_error gg_publish_with_options(gg_request ggreq, const char *topic, const void *payload, size_t payload_size, const gg_publish_options opts, gg_request_result *result)
Publish a payload to a topic.
gg_error gg_request_init(gg_request *ggreq)
Initialize the context for managing the request.
gg_error
Greengrass SDK error enum.
Definition: greengrasssdk.h:27
gg_error gg_delete_thing_shadow(gg_request ggreq, const char *thing_name, gg_request_result *result)
Delete thing shadow for thing name.
Definition: greengrasssdk.h:134
Definition: greengrasssdk.h:35
Definition: greengrasssdk.h:155
gg_request_status
Greengrass SDK request status enum.
Definition: greengrasssdk.h:53
Definition: greengrasssdk.h:63
struct gg_invoke_options gg_invoke_options
Describes the options to invoke a target lambda.
Describes result metadata after request is made.
Definition: greengrasssdk.h:73
gg_log_level
Describes log levels could used in gg_log()
Definition: greengrasssdk.h:149
struct gg_lambda_context gg_lambda_context
Describes context when lambda handler is called.
gg_error gg_request_read(gg_request ggreq, void *buffer, size_t buffer_size, size_t *amount_read)
Read the data from a request. This method should be called till amount_read is zero.
gg_request_status request_status
Definition: greengrasssdk.h:75
Definition: greengrasssdk.h:138