Skip to content

Commit 0e58049

Browse files
AWSSteveHaGordon Wang
authored andcommitted
Add Jobs support
1 parent 9ad74d8 commit 0e58049

31 files changed

+3118
-61
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ The Device SDK provides functionality to create and maintain a mutually authenti
1616
### Thing Shadow
1717
The Device SDK implements the specific protocol for Thing Shadows to retrieve, update and delete Thing Shadows adhering to the protocol that is implemented to ensure correct versioning and support for client tokens. It abstracts the necessary MQTT topic subscriptions by automatically subscribing to and unsubscribing from the reserved topics as needed for each API call. Inbound state change requests are automatically signalled via a configurable callback.
1818

19+
### Jobs
20+
The Device SDK implements features to facilitate use of the AWS Jobs service. The Jobs service can be used for device management tasks such as updating program files, rotating device certificates, or running other maintenance tasks such are restoring device settings or restarting devices.
21+
1922
## Design Goals of this SDK
2023
The embedded C SDK was specifically designed for resource constrained devices (running on micro-controllers and RTOS).
2124

include/aws_iot_error.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -151,6 +151,12 @@ typedef enum {
151151
MUTEX_UNLOCK_ERROR = -48,
152152
/** Mutex destroy failed */
153153
MUTEX_DESTROY_ERROR = -49,
154+
/** Input argument exceeded the allowed maximum size */
155+
MAX_SIZE_ERROR = -50,
156+
/** Some limit has been exceeded, e.g. the maximum number of subscriptions has been reached */
157+
LIMIT_EXCEEDED_ERROR = -51,
158+
/** Invalid input topic type */
159+
INVALID_TOPIC_TYPE_ERROR = -52
154160
} IoT_Error_t;
155161

156162
#ifdef __cplusplus

include/aws_iot_jobs_interface.h

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
/*
2+
* Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
/**
17+
* @file aws_iot_jobs_interface.h
18+
* @brief An interface for interacting with the AWS IoT Jobs system.
19+
*
20+
* This file defines utility functions for interacting with the AWS IoT jobs
21+
* APIs over MQTT. It provides functions for managing subscriptions to job
22+
* related topics and for sending queries and updates requests for jobs.
23+
* Callers are responsible for managing the subscriptions and associating
24+
* responses with the queries and update messages.
25+
*/
26+
#ifndef AWS_IOT_JOBS_INTERFACE_H_
27+
#define AWS_IOT_JOBS_INTERFACE_H_
28+
29+
#ifdef DISABLE_IOT_JOBS
30+
#error "Jobs API is disabled"
31+
#endif
32+
33+
/**
34+
* @file aws_iot_jobs_interface.h
35+
* @brief Functions for interacting with the AWS IoT Jobs system.
36+
*/
37+
#include "aws_iot_mqtt_client_interface.h"
38+
#include "aws_iot_jobs_topics.h"
39+
#include "aws_iot_jobs_types.h"
40+
#include "aws_iot_error.h"
41+
#include "aws_iot_json_utils.h"
42+
43+
#ifdef __cplusplus
44+
extern "C" {
45+
#endif
46+
47+
/**
48+
* @brief Subscribe to jobs messages for the given thing and/or jobs.
49+
*
50+
* The function can be used to subscribe to all job related messages. To subscribe
51+
* to messages not related to a job the jobId passed should be null. The jobId
52+
* can also be "+" to subscribe to messages related to any job, or "$next" to
53+
* indicate the next pending job.
54+
*
55+
* See also #aws_iot_jobs_subscribe_to_all_job_messages to subscribe to all possible
56+
* messages in one operation.
57+
*
58+
* \note Subscribing with the same thing, job and topic type more than
59+
* once is undefined.
60+
*
61+
* \param pClient the client to use
62+
* \param qos the qos to use
63+
* \param thingName the name of the thing to subscribe to
64+
* \param jobId the job id to subscribe to. To subscribe to messages not related to
65+
* a job the jobId passed should be null. The jobId can also be "+" to subscribe to
66+
* messages related to any job, or "$next" to indicate the next pending job.
67+
* \param topicType the topic type to subscribe to
68+
* \param replyType the reply topic type to subscribe to
69+
* \param pApplicationHandler the callback handler
70+
* \param pApplicationHandlerData the callback context data. This must remain valid at least until
71+
* aws_iot_jobs_unsubscribe_from_job_messages is called.
72+
* \param topicBuffer. A buffer to use to hold the topic name for the subscription. This buffer
73+
* must remain valid at least until aws_iot_jobs_unsubscribe_from_job_messages is called.
74+
* \param topicBufferSize the size of the topic buffer. The function will fail
75+
* with LIMIT_EXCEEDED_ERROR if this is too small.
76+
* \return the result of subscribing to the topic (see aws_iot_mqtt_subscribe)
77+
*/
78+
IoT_Error_t aws_iot_jobs_subscribe_to_job_messages(
79+
AWS_IoT_Client *pClient, QoS qos,
80+
const char *thingName,
81+
const char *jobId,
82+
AwsIotJobExecutionTopicType topicType,
83+
AwsIotJobExecutionTopicReplyType replyType,
84+
pApplicationHandler_t pApplicationHandler,
85+
void *pApplicationHandlerData,
86+
char *topicBuffer,
87+
uint16_t topicBufferSize);
88+
89+
/**
90+
* @brief Subscribe to all job messages.
91+
*
92+
* Subscribe to all job messages for the given thing.
93+
*
94+
* \note Subscribing with the same thing more than once is undefined.
95+
*
96+
* \param pClient the client to use
97+
* \param qos the qos to use
98+
* \param thingName the name of the thing to subscribe to
99+
* \param pApplicationHandler the callback handler
100+
* \param pApplicationHandlerData the callback context data. This must remain valid at least until
101+
* aws_iot_jobs_unsubscribe_from_job_messages is called.
102+
* \param topicBuffer. A buffer to use to hold the topic name for the subscription. This buffer
103+
* must remain valid at least until aws_iot_jobs_unsubscribe_from_job_messages is called.
104+
* \param topicBufferSize the size of the topic buffer. The function will fail
105+
* with LIMIT_EXCEEDED_ERROR if this is too small.
106+
* \return the result of subscribing to the topic (see aws_iot_mqtt_subscribe)
107+
*/
108+
IoT_Error_t aws_iot_jobs_subscribe_to_all_job_messages(
109+
AWS_IoT_Client *pClient, QoS qos,
110+
const char *thingName,
111+
pApplicationHandler_t pApplicationHandler,
112+
void *pApplicationHandlerData,
113+
char *topicBuffer,
114+
uint16_t topicBufferSize);
115+
116+
/**
117+
* @brief Unsubscribe from a job subscription
118+
*
119+
* Remove the subscription created using #aws_iot_jobs_subscribe_to_job_messages or
120+
* #aws_iot_jobs_subscribe_to_all_job_messages.
121+
*
122+
* \param pClient the client to use
123+
* \param topicBuffer the topic buffer passed to #aws_iot_jobs_subscribe_to_job_messages or
124+
* #aws_iot_jobs_subscribe_to_all_job_messages when the subscription was created.
125+
* \return #SUCCESS or the first error encountered.
126+
*/
127+
IoT_Error_t aws_iot_jobs_unsubscribe_from_job_messages(
128+
AWS_IoT_Client *pClient,
129+
char *topicBuffer);
130+
131+
/**
132+
* @brief Send a query to one of the job query APIs.
133+
*
134+
* Send a query to one of the job query APIs. If jobId is null this
135+
* requests a list of pending jobs for the thing. If jobId is
136+
* not null then it sends a query for the details of that job.
137+
* If jobId is $next then it sends a query for the details for
138+
* the next pending job.
139+
*
140+
* \param pClient the client to use
141+
* \param qos the qos to use
142+
* \param thingName the thing name to query for
143+
* \param jobId the id of the job to query for. If null a list
144+
* of all pending jobs for the thing is requested.
145+
* \param clientToken the client token to use for the query.
146+
* If null no clientToken is sent resulting in an empty message.
147+
* \param topicBuffer the topic buffer to use. This may be discarded
148+
* as soon as this function returns
149+
* \param topicBufferSize the size of topicBuffer
150+
* \param messageBuffer the message buffer to use. May be NULL
151+
* if clientToken is NULL
152+
* \param messageBufferSize the size of messageBuffer
153+
* \param topicType the topic type to publish query to
154+
* \return LIMIT_EXCEEDED_ERROR if the topic buffer or
155+
* message buffer is too small, NULL_VALUE_ERROR if the any of
156+
* the required inputs are NULL, otherwise the result
157+
* of the mqtt publish
158+
*/
159+
IoT_Error_t aws_iot_jobs_send_query(
160+
AWS_IoT_Client *pClient, QoS qos,
161+
const char *thingName,
162+
const char *jobId,
163+
const char *clientToken,
164+
char *topicBuffer,
165+
uint16_t topicBufferSize,
166+
char *messageBuffer,
167+
size_t messageBufferSize,
168+
AwsIotJobExecutionTopicType topicType);
169+
170+
/**
171+
* @brief Send a start next command to the job start-next API.
172+
*
173+
* Send a start next command to the job start-next API.
174+
*
175+
* \param pClient the client to use
176+
* \param qos the qos to use
177+
* \param thingName the thing name to query for
178+
* \param startNextRequest the start-next request to send
179+
* \param topicBuffer the topic buffer to use. This may be discarded
180+
* as soon as this function returns
181+
* \param topicBufferSize the size of topicBuffer
182+
* \param messageBuffer the message buffer to use. May be NULL
183+
* if clientToken is NULL
184+
* \param messageBufferSize the size of messageBuffer
185+
* \return LIMIT_EXCEEDED_ERROR if the topic buffer or
186+
* message buffer is too small, NULL_VALUE_ERROR if the any of
187+
* the required inputs are NULL, otherwise the result
188+
* of the mqtt publish
189+
*/
190+
IoT_Error_t aws_iot_jobs_start_next(
191+
AWS_IoT_Client *pClient, QoS qos,
192+
const char *thingName,
193+
const AwsIotStartNextPendingJobExecutionRequest *startNextRequest,
194+
char *topicBuffer,
195+
uint16_t topicBufferSize,
196+
char *messageBuffer,
197+
size_t messageBufferSize);
198+
199+
/**
200+
* @brief Send a describe job query to the job query API.
201+
*
202+
* Send a describe job query to the job query API. If jobId is null this
203+
* requests a list of pending jobs for the thing. If jobId is
204+
* not null then it sends a query for the details of that job.
205+
*
206+
* \param pClient the client to use
207+
* \param qos the qos to use
208+
* \param thingName the thing name to query for
209+
* \param jobId the id of the job to query for. If null a list
210+
* of all pending jobs for the thing is requested.
211+
* \param describeRequest the describe request to send
212+
* \param topicBuffer the topic buffer to use. This may be discarded
213+
* as soon as this function returns
214+
* \param topicBufferSize the size of topicBuffer
215+
* \param messageBuffer the message buffer to use. May be NULL
216+
* if clientToken is NULL
217+
* \param messageBufferSize the size of messageBuffer
218+
* \return LIMIT_EXCEEDED_ERROR if the topic buffer or
219+
* message buffer is too small, NULL_VALUE_ERROR if the any of
220+
* the required inputs are NULL, otherwise the result
221+
* of the mqtt publish
222+
*/
223+
IoT_Error_t aws_iot_jobs_describe(
224+
AWS_IoT_Client *pClient, QoS qos,
225+
const char *thingName,
226+
const char *jobId,
227+
const AwsIotDescribeJobExecutionRequest *describeRequest,
228+
char *topicBuffer,
229+
uint16_t topicBufferSize,
230+
char *messageBuffer,
231+
size_t messageBufferSize);
232+
233+
/**
234+
* @brief Send an update about a job execution.
235+
*
236+
* Send an update about a job execution.
237+
*
238+
* \param pClient the client to use
239+
* \param qos the qos to use
240+
* \param thingName the thing name to send the update for
241+
* \param jobId the id of the job to send the update for
242+
* \param updateRequest the update request to send
243+
* \param topicBuffer the topic buffer to use. This may be discarded
244+
* as soon as this function returns
245+
* \param topicBufferSize the size of topicBuffer
246+
* \param messageBuffer the message buffer to use.
247+
* \param messageBufferSize the size of messageBuffer
248+
* \return LIMIT_EXCEEDED_ERROR if the topic buffer or
249+
* message buffer is too small, NULL_VALUE_ERROR if the any of
250+
* the required inputs are NULL, otherwise the result
251+
* of the mqtt publish
252+
*/
253+
IoT_Error_t aws_iot_jobs_send_update(
254+
AWS_IoT_Client *pClient, QoS qos,
255+
const char *thingName,
256+
const char *jobId,
257+
const AwsIotJobExecutionUpdateRequest *updateRequest,
258+
char *topicBuffer,
259+
uint16_t topicBufferSize,
260+
char *messageBuffer,
261+
size_t messageBufferSize);
262+
263+
#ifdef __cplusplus
264+
}
265+
#endif
266+
267+
#endif /* AWS_IOT_JOBS_INTERFACE_H_ */

0 commit comments

Comments
 (0)