AWS IoT Jobs v2.0.0
Client library for AWS IoT Jobs
 
Loading...
Searching...
No Matches
jobs.h
Go to the documentation of this file.
1/*
2 * AWS IoT Jobs v2.0.0
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
32#ifndef JOBS_H_
33#define JOBS_H_
34
35#include <stdbool.h>
36#include <stddef.h>
37#include <stdint.h>
38
39/* *INDENT-OFF* */
40#ifdef __cplusplus
41 extern "C" {
42#endif
43/* *INDENT-ON* */
44
49#define TOPIC_BUFFER_SIZE 256U
50
55#define START_JOB_MSG_LENGTH 147U
56
61#define UPDATE_JOB_MSG_LENGTH 48U
62
67#define JOBS_THINGNAME_MAX_LENGTH 128U /* per AWS IoT API Reference */
68
73#define JOBS_JOBID_MAX_LENGTH 64U /* per AWS IoT API Reference */
74
75#ifndef THINGNAME_MAX_LENGTH
76
82 #define THINGNAME_MAX_LENGTH JOBS_THINGNAME_MAX_LENGTH
83#endif
84
85#ifndef JOBID_MAX_LENGTH
86
92 #define JOBID_MAX_LENGTH JOBS_JOBID_MAX_LENGTH
93#endif
94
95#if ( THINGNAME_MAX_LENGTH > JOBS_THINGNAME_MAX_LENGTH )
96 #error "The value of THINGNAME_MAX_LENGTH exceeds the AWS IoT Jobs Service limit."
97#endif
98
99#if ( JOBID_MAX_LENGTH > JOBS_JOBID_MAX_LENGTH )
100 #error "The value of JOBID_MAX_LENGTH exceeds the AWS IoT Jobs Service limit."
101#endif
102
108#define JOBS_API_PREFIX "$aws/things/"
109#define JOBS_API_PREFIX_LENGTH ( sizeof( JOBS_API_PREFIX ) - 1U )
110
111#define JOBS_API_BRIDGE "/jobs/"
112#define JOBS_API_BRIDGE_LENGTH ( sizeof( JOBS_API_BRIDGE ) - 1U )
113
114#define JOBS_API_SUCCESS "/accepted"
115#define JOBS_API_SUCCESS_LENGTH ( sizeof( JOBS_API_SUCCESS ) - 1U )
116
117#define JOBS_API_FAILURE "/rejected"
118#define JOBS_API_FAILURE_LENGTH ( sizeof( JOBS_API_FAILURE ) - 1U )
119
120#define JOBS_API_JOBSCHANGED "notify"
121#define JOBS_API_JOBSCHANGED_LENGTH ( sizeof( JOBS_API_JOBSCHANGED ) - 1U )
122
123#define JOBS_API_NEXTJOBCHANGED "notify-next"
124#define JOBS_API_NEXTJOBCHANGED_LENGTH ( sizeof( JOBS_API_NEXTJOBCHANGED ) - 1U )
125
126#define JOBS_API_GETPENDING "get"
127#define JOBS_API_GETPENDING_LENGTH ( sizeof( JOBS_API_GETPENDING ) - 1U )
128
129#define JOBS_API_STARTNEXT "start-next"
130#define JOBS_API_STARTNEXT_LENGTH ( sizeof( JOBS_API_STARTNEXT ) - 1U )
131
132#define JOBS_API_DESCRIBE "get"
133#define JOBS_API_DESCRIBE_LENGTH ( sizeof( JOBS_API_DESCRIBE ) - 1U )
134
135#define JOBS_API_UPDATE "update"
136#define JOBS_API_UPDATE_LENGTH ( sizeof( JOBS_API_UPDATE ) - 1U )
137
138#define JOBS_API_JOBID_NEXT "$next"
139#define JOBS_API_JOBID_NEXT_LENGTH ( sizeof( JOBS_API_JOBID_NEXT ) - 1U )
140
141#define JOBS_API_JOBID_NULL ""
142#define JOBS_API_LEVEL_SEPARATOR "/"
143
144#define JOBS_API_CLIENTTOKEN "{\"clientToken\":\""
145#define JOBS_API_CLIENTTOKEN_LENGTH ( sizeof( JOBS_API_CLIENTTOKEN ) - 1U )
146
147#define JOBS_API_STATUS "{\"status\":\""
148#define JOBS_API_STATUS_LENGTH ( sizeof( JOBS_API_STATUS ) - 1U )
149
150#define JOBS_API_EXPECTED_VERSION "\",\"expectedVersion\":\""
151#define JOBS_API_EXPECTED_VERSION_LENGTH ( sizeof( JOBS_API_EXPECTED_VERSION ) - 1U )
152
153#define JOBS_API_STATUS_DETAILS "\",\"statusDetails\":"
154#define JOBS_API_STATUS_DETAILS_LENGTH ( sizeof( JOBS_API_STATUS_DETAILS ) - 1U )
155
156#define JOBS_API_COMMON_LENGTH( thingNameLength ) \
157 ( JOBS_API_PREFIX_LENGTH + ( thingNameLength ) + JOBS_API_BRIDGE_LENGTH )
158
167/* AWS IoT Jobs API topics. */
168#define JOBS_TOPIC_COMMON( thingName, jobId, jobsApi ) \
169 ( JOBS_API_PREFIX \
170 thingName \
171 JOBS_API_BRIDGE \
172 jobId \
173 jobsApi )
186#define JOBS_API_SUBSCRIBE_NEXTJOBCHANGED( thingName ) \
187 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_NEXTJOBCHANGED )
188
199#define JOBS_API_SUBSCRIBE_JOBSCHANGED( thingName ) \
200 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_JOBSCHANGED )
201
212#define JOBS_API_PUBLISH_STARTNEXT( thingName ) \
213 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_STARTNEXT )
214
225#define JOBS_API_PUBLISH_GETPENDING( thingName ) \
226 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_GETPENDING )
227
240#define JOBS_API_PUBLISH_DESCRIBENEXTJOB( thingName ) \
241 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NEXT JOBS_API_LEVEL_SEPARATOR, JOBS_API_DESCRIBE )
242
248#define JOBS_API_MAX_LENGTH( thingNameLength ) \
249 ( JOBS_API_COMMON_LENGTH( thingNameLength ) + \
250 JOBID_MAX_LENGTH + sizeof( '/' ) + JOBS_API_UPDATE_LENGTH + \
251 JOBS_API_SUCCESS_LENGTH + 1U )
252
257typedef enum
258{
259 JobsError = 0,
265
269typedef enum
270{
271 Queued,
272 InProgress,
273 Failed,
274 Succeeded,
275 Rejected
277
281typedef enum
282{
283 JobUpdateStatus_Accepted,
284 JobUpdateStatus_Rejected
286
303typedef enum
304{
305 JobsInvalidTopic = -1,
306 JobsJobsChanged,
307 JobsNextJobChanged,
308 JobsGetPendingSuccess,
309 JobsGetPendingFailed,
310 JobsStartNextSuccess,
311 JobsStartNextFailed,
312 /* Topics below use a job ID. */
313 JobsDescribeSuccess,
314 JobsDescribeFailed,
315 JobsUpdateSuccess,
316 JobsUpdateFailed,
317 JobsMaxTopic
319
337typedef struct
338{
340 const char * expectedVersion;
342 const char * statusDetails;
345
346/*-----------------------------------------------------------*/
347
406/* @[declare_jobs_gettopic] */
407JobsStatus_t Jobs_GetTopic( char * buffer,
408 size_t length,
409 const char * thingName,
410 uint16_t thingNameLength,
411 JobsTopic_t api,
412 size_t * outLength );
413/* @[declare_jobs_gettopic] */
414
524/* @[declare_jobs_matchtopic] */
525JobsStatus_t Jobs_MatchTopic( char * topic,
526 size_t length,
527 const char * thingName,
528 uint16_t thingNameLength,
529 JobsTopic_t * outApi,
530 char ** outJobId,
531 uint16_t * outJobIdLength );
532/* @[declare_jobs_matchtopic] */
533
592/* @[declare_jobs_getpending] */
593JobsStatus_t Jobs_GetPending( char * buffer,
594 size_t length,
595 const char * thingName,
596 uint16_t thingNameLength,
597 size_t * outLength );
598/* @[declare_jobs_getpending] */
599
658/* @[declare_jobs_startnext] */
659JobsStatus_t Jobs_StartNext( char * buffer,
660 size_t length,
661 const char * thingName,
662 uint16_t thingNameLength,
663 size_t * outLength );
664/* @[declare_jobs_startnext] */
665
703/* @[declare_jobs_startnextmsg] */
704size_t Jobs_StartNextMsg( const char * clientToken,
705 size_t clientTokenLength,
706 char * buffer,
707 size_t bufferSize );
708/* @[declare_jobs_startnextmsg] */
709
780/* @[declare_jobs_describe] */
781JobsStatus_t Jobs_Describe( char * buffer,
782 size_t length,
783 const char * thingName,
784 uint16_t thingNameLength,
785 const char * jobId,
786 uint16_t jobIdLength,
787 size_t * outLength );
788/* @[declare_jobs_describe] */
789
857/* @[declare_jobs_update] */
858JobsStatus_t Jobs_Update( char * buffer,
859 size_t length,
860 const char * thingName,
861 uint16_t thingNameLength,
862 const char * jobId,
863 uint16_t jobIdLength,
864 size_t * outLength );
865/* @[declare_jobs_update] */
866
909/* @[declare_jobs_updatemsg] */
910size_t Jobs_UpdateMsg( JobsUpdateRequest_t request,
911 char * buffer,
912 size_t bufferSize );
913/* @[declare_jobs_updatemsg] */
914
946/* @[declare_jobs_getjobid] */
947size_t Jobs_GetJobId( const char * message,
948 size_t messageLength,
949 const char ** jobId );
950/* @[declare_jobs_getjobid] */
951
984/* @[declare_jobs_getjobdocument] */
985size_t Jobs_GetJobDocument( const char * message,
986 size_t messageLength,
987 const char ** jobDoc );
988/* @[declare_jobs_getjobdocument] */
989
1001/* @[declare_jobs_isstartnextaccepted] */
1002bool Jobs_IsStartNextAccepted( const char * topic,
1003 const size_t topicLength,
1004 const char * thingName,
1005 const size_t thingNameLength );
1006/* @[declare_jobs_isstartnextaccepted] */
1007
1021/* @[declare_jobs_isjobupdatestatus] */
1022bool Jobs_IsJobUpdateStatus( const char * topic,
1023 const size_t topicLength,
1024 const char * jobId,
1025 const size_t jobIdLength,
1026 const char * thingName,
1027 const size_t thingNameLength,
1028 JobUpdateStatus_t expectedStatus );
1029/* @[declare_jobs_isjobupdatestatus] */
1030
1031
1032/* *INDENT-OFF* */
1033#ifdef __cplusplus
1034 }
1035#endif
1036/* *INDENT-ON* */
1037
1038#endif /* ifndef JOBS_H_ */
JobsTopic_t
Topic values for subscription requests.
Definition: jobs.h:304
JobsStatus_t
Return codes from jobs functions.
Definition: jobs.h:258
@ JobsNoMatch
The buffer does not contain a jobs topic.
Definition: jobs.h:261
@ JobsBufferTooSmall
The buffer write was truncated.
Definition: jobs.h:263
@ JobsSuccess
The buffer was properly written or a match was found.
Definition: jobs.h:260
@ JobsBadParameter
A function parameter was NULL or has an illegal value.
Definition: jobs.h:262
JobCurrentStatus_t
Status codes for jobs.
Definition: jobs.h:270
size_t Jobs_GetJobId(const char *message, size_t messageLength, const char **jobId)
Retrieves the job ID from a given message (if applicable)
Definition: jobs.c:963
size_t Jobs_UpdateMsg(JobsUpdateRequest_t request, char *buffer, size_t bufferSize)
Populate a message string for an UpdateJobExecution request.
Definition: jobs.c:882
JobsStatus_t Jobs_Update(char *buffer, size_t length, const char *thingName, uint16_t thingNameLength, const char *jobId, uint16_t jobIdLength, size_t *outLength)
Populate a topic string for an UpdateJobExecution request.
Definition: jobs.c:790
bool Jobs_IsStartNextAccepted(const char *topic, const size_t topicLength, const char *thingName, const size_t thingNameLength)
Checks if a message comes from the start-next/accepted reserved topic.
Definition: jobs.c:921
JobsStatus_t Jobs_GetPending(char *buffer, size_t length, const char *thingName, uint16_t thingNameLength, size_t *outLength)
Populate a topic string for a GetPendingJobExecutions request.
Definition: jobs.c:666
JobUpdateStatus_t
Status codes for job update status.
Definition: jobs.h:282
bool Jobs_IsJobUpdateStatus(const char *topic, const size_t topicLength, const char *jobId, const size_t jobIdLength, const char *thingName, const size_t thingNameLength, JobUpdateStatus_t expectedStatus)
Checks if a message comes from the update/accepted reserved topic.
Definition: jobs.c:929
size_t Jobs_StartNextMsg(const char *clientToken, size_t clientTokenLength, char *buffer, size_t bufferSize)
Populate a message string for a StartNextPendingJobExecution request.
Definition: jobs.c:727
JobsStatus_t Jobs_StartNext(char *buffer, size_t length, const char *thingName, uint16_t thingNameLength, size_t *outLength)
Populate a topic string for a StartNextPendingJobExecution request.
Definition: jobs.c:699
JobsStatus_t Jobs_Describe(char *buffer, size_t length, const char *thingName, uint16_t thingNameLength, const char *jobId, uint16_t jobIdLength, size_t *outLength)
Populate a topic string for a DescribeJobExecution request.
Definition: jobs.c:749
JobsStatus_t Jobs_MatchTopic(char *topic, size_t length, const char *thingName, uint16_t thingNameLength, JobsTopic_t *outApi, char **outJobId, uint16_t *outJobIdLength)
Output a topic value if a Jobs API topic string is present. Optionally, output a pointer to a jobID w...
Definition: jobs.c:606
size_t Jobs_GetJobDocument(const char *message, size_t messageLength, const char **jobDoc)
Retrieves the job document from a given message (if applicable)
Definition: jobs.c:986
JobsStatus_t Jobs_GetTopic(char *buffer, size_t length, const char *thingName, uint16_t thingNameLength, JobsTopic_t api, size_t *outLength)
Populate a topic string for a subscription request.
Definition: jobs.c:285
Structure for Jobs_UpdateMsg request parameters.
Definition: jobs.h:338
size_t expectedVersionLength
Definition: jobs.h:341
size_t statusDetailsLength
Definition: jobs.h:343
const char * statusDetails
Definition: jobs.h:342
JobCurrentStatus_t status
Definition: jobs.h:339
const char * expectedVersion
Definition: jobs.h:340