AWS IoT Jobs v1.4.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 v1.4.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_COMMON_LENGTH( thingNameLength ) \
154 ( JOBS_API_PREFIX_LENGTH + ( thingNameLength ) + JOBS_API_BRIDGE_LENGTH )
155
164/* AWS IoT Jobs API topics. */
165#define JOBS_TOPIC_COMMON( thingName, jobId, jobsApi ) \
166 ( JOBS_API_PREFIX \
167 thingName \
168 JOBS_API_BRIDGE \
169 jobId \
170 jobsApi )
183#define JOBS_API_SUBSCRIBE_NEXTJOBCHANGED( thingName ) \
184 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_NEXTJOBCHANGED )
185
196#define JOBS_API_SUBSCRIBE_JOBSCHANGED( thingName ) \
197 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_JOBSCHANGED )
198
209#define JOBS_API_PUBLISH_STARTNEXT( thingName ) \
210 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_STARTNEXT )
211
222#define JOBS_API_PUBLISH_GETPENDING( thingName ) \
223 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_GETPENDING )
224
237#define JOBS_API_PUBLISH_DESCRIBENEXTJOB( thingName ) \
238 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NEXT JOBS_API_LEVEL_SEPARATOR, JOBS_API_DESCRIBE )
239
245#define JOBS_API_MAX_LENGTH( thingNameLength ) \
246 ( JOBS_API_COMMON_LENGTH( thingNameLength ) + \
247 JOBID_MAX_LENGTH + sizeof( '/' ) + JOBS_API_UPDATE_LENGTH + \
248 JOBS_API_SUCCESS_LENGTH + 1U )
249
254typedef enum
255{
256 JobsError = 0,
262
266typedef enum
267{
268 Queued,
269 InProgress,
270 Failed,
271 Succeeded,
272 Rejected
274
278typedef enum
279{
280 JobUpdateStatus_Accepted,
281 JobUpdateStatus_Rejected
283
300typedef enum
301{
302 JobsInvalidTopic = -1,
303 JobsJobsChanged,
304 JobsNextJobChanged,
305 JobsGetPendingSuccess,
306 JobsGetPendingFailed,
307 JobsStartNextSuccess,
308 JobsStartNextFailed,
309 /* Topics below use a job ID. */
310 JobsDescribeSuccess,
311 JobsDescribeFailed,
312 JobsUpdateSuccess,
313 JobsUpdateFailed,
314 JobsMaxTopic
316
317/*-----------------------------------------------------------*/
318
377/* @[declare_jobs_gettopic] */
378JobsStatus_t Jobs_GetTopic( char * buffer,
379 size_t length,
380 const char * thingName,
381 uint16_t thingNameLength,
382 JobsTopic_t api,
383 size_t * outLength );
384/* @[declare_jobs_gettopic] */
385
495/* @[declare_jobs_matchtopic] */
496JobsStatus_t Jobs_MatchTopic( char * topic,
497 size_t length,
498 const char * thingName,
499 uint16_t thingNameLength,
500 JobsTopic_t * outApi,
501 char ** outJobId,
502 uint16_t * outJobIdLength );
503/* @[declare_jobs_matchtopic] */
504
563/* @[declare_jobs_getpending] */
564JobsStatus_t Jobs_GetPending( char * buffer,
565 size_t length,
566 const char * thingName,
567 uint16_t thingNameLength,
568 size_t * outLength );
569/* @[declare_jobs_getpending] */
570
629/* @[declare_jobs_startnext] */
630JobsStatus_t Jobs_StartNext( char * buffer,
631 size_t length,
632 const char * thingName,
633 uint16_t thingNameLength,
634 size_t * outLength );
635/* @[declare_jobs_startnext] */
636
674/* @[declare_jobs_startnextmsg] */
675size_t Jobs_StartNextMsg( const char * clientToken,
676 size_t clientTokenLength,
677 char * buffer,
678 size_t bufferSize );
679/* @[declare_jobs_startnextmsg] */
680
751/* @[declare_jobs_describe] */
752JobsStatus_t Jobs_Describe( char * buffer,
753 size_t length,
754 const char * thingName,
755 uint16_t thingNameLength,
756 const char * jobId,
757 uint16_t jobIdLength,
758 size_t * outLength );
759/* @[declare_jobs_describe] */
760
828/* @[declare_jobs_update] */
829JobsStatus_t Jobs_Update( char * buffer,
830 size_t length,
831 const char * thingName,
832 uint16_t thingNameLength,
833 const char * jobId,
834 uint16_t jobIdLength,
835 size_t * outLength );
836/* @[declare_jobs_update] */
837
877/* @[declare_jobs_updatemsg] */
879 const char * expectedVersion,
880 size_t expectedVersionLength,
881 char * buffer,
882 size_t bufferSize );
883/* @[declare_jobs_updatemsg] */
884
916/* @[declare_jobs_getjobid] */
917size_t Jobs_GetJobId( const char * message,
918 size_t messageLength,
919 const char ** jobId );
920/* @[declare_jobs_getjobid] */
921
954/* @[declare_jobs_getjobdocument] */
955size_t Jobs_GetJobDocument( const char * message,
956 size_t messageLength,
957 const char ** jobDoc );
958/* @[declare_jobs_getjobdocument] */
959
971/* @[declare_jobs_isstartnextaccepted] */
972bool Jobs_IsStartNextAccepted( const char * topic,
973 const size_t topicLength,
974 const char * thingName,
975 const size_t thingNameLength );
976/* @[declare_jobs_isstartnextaccepted] */
977
991/* @[declare_jobs_isjobupdatestatus] */
992bool Jobs_IsJobUpdateStatus( const char * topic,
993 const size_t topicLength,
994 const char * jobId,
995 const size_t jobIdLength,
996 const char * thingName,
997 const size_t thingNameLength,
998 JobUpdateStatus_t expectedStatus );
999/* @[declare_jobs_isjobupdatestatus] */
1000
1001
1002/* *INDENT-OFF* */
1003#ifdef __cplusplus
1004 }
1005#endif
1006/* *INDENT-ON* */
1007
1008#endif /* ifndef JOBS_H_ */
JobsTopic_t
Topic values for subscription requests.
Definition: jobs.h:301
JobsStatus_t
Return codes from jobs functions.
Definition: jobs.h:255
@ JobsNoMatch
The buffer does not contain a jobs topic.
Definition: jobs.h:258
@ JobsBufferTooSmall
The buffer write was truncated.
Definition: jobs.h:260
@ JobsSuccess
The buffer was properly written or a match was found.
Definition: jobs.h:257
@ JobsBadParameter
A function parameter was NULL or has an illegal value.
Definition: jobs.h:259
JobCurrentStatus_t
Status codes for jobs.
Definition: jobs.h:267
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:887
size_t Jobs_UpdateMsg(JobCurrentStatus_t status, const char *expectedVersion, size_t expectedVersionLength, char *buffer, size_t bufferSize)
Populate a message string for an UpdateJobExecution request.
Definition: jobs.c:807
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:772
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:847
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:648
JobUpdateStatus_t
Status codes for job update status.
Definition: jobs.h:279
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:855
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:709
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:681
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:731
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:588
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:910
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:267