AWS IoT Jobs v1.3.0
Client library for AWS IoT Jobs
jobs.h
Go to the documentation of this file.
1/*
2 * AWS IoT Jobs v1.3.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 <stddef.h>
36#include <stdint.h>
37
38/* *INDENT-OFF* */
39#ifdef __cplusplus
40 extern "C" {
41#endif
42/* *INDENT-ON* */
43
48#define JOBS_THINGNAME_MAX_LENGTH 128U /* per AWS IoT API Reference */
49
54#define JOBS_JOBID_MAX_LENGTH 64U /* per AWS IoT API Reference */
55
56#ifndef THINGNAME_MAX_LENGTH
57
63 #define THINGNAME_MAX_LENGTH JOBS_THINGNAME_MAX_LENGTH
64#endif
65
66#ifndef JOBID_MAX_LENGTH
67
73 #define JOBID_MAX_LENGTH JOBS_JOBID_MAX_LENGTH
74#endif
75
76#if ( THINGNAME_MAX_LENGTH > JOBS_THINGNAME_MAX_LENGTH )
77 #error "The value of THINGNAME_MAX_LENGTH exceeds the AWS IoT Jobs Service limit."
78#endif
79
80#if ( JOBID_MAX_LENGTH > JOBS_JOBID_MAX_LENGTH )
81 #error "The value of JOBID_MAX_LENGTH exceeds the AWS IoT Jobs Service limit."
82#endif
83
89#define JOBS_API_PREFIX "$aws/things/"
90#define JOBS_API_PREFIX_LENGTH ( sizeof( JOBS_API_PREFIX ) - 1U )
91
92#define JOBS_API_BRIDGE "/jobs/"
93#define JOBS_API_BRIDGE_LENGTH ( sizeof( JOBS_API_BRIDGE ) - 1U )
94
95#define JOBS_API_SUCCESS "/accepted"
96#define JOBS_API_SUCCESS_LENGTH ( sizeof( JOBS_API_SUCCESS ) - 1U )
97
98#define JOBS_API_FAILURE "/rejected"
99#define JOBS_API_FAILURE_LENGTH ( sizeof( JOBS_API_FAILURE ) - 1U )
100
101#define JOBS_API_JOBSCHANGED "notify"
102#define JOBS_API_JOBSCHANGED_LENGTH ( sizeof( JOBS_API_JOBSCHANGED ) - 1U )
103
104#define JOBS_API_NEXTJOBCHANGED "notify-next"
105#define JOBS_API_NEXTJOBCHANGED_LENGTH ( sizeof( JOBS_API_NEXTJOBCHANGED ) - 1U )
106
107#define JOBS_API_GETPENDING "get"
108#define JOBS_API_GETPENDING_LENGTH ( sizeof( JOBS_API_GETPENDING ) - 1U )
109
110#define JOBS_API_STARTNEXT "start-next"
111#define JOBS_API_STARTNEXT_LENGTH ( sizeof( JOBS_API_STARTNEXT ) - 1U )
112
113#define JOBS_API_DESCRIBE "get"
114#define JOBS_API_DESCRIBE_LENGTH ( sizeof( JOBS_API_DESCRIBE ) - 1U )
115
116#define JOBS_API_UPDATE "update"
117#define JOBS_API_UPDATE_LENGTH ( sizeof( JOBS_API_UPDATE ) - 1U )
118
119#define JOBS_API_JOBID_NEXT "$next"
120#define JOBS_API_JOBID_NEXT_LENGTH ( sizeof( JOBS_API_JOBID_NEXT ) - 1U )
121
122#define JOBS_API_JOBID_NULL ""
123#define JOBS_API_LEVEL_SEPARATOR "/"
124
125#define JOBS_API_COMMON_LENGTH( thingNameLength ) \
126 ( JOBS_API_PREFIX_LENGTH + ( thingNameLength ) + JOBS_API_BRIDGE_LENGTH )
127
136/* AWS IoT Jobs API topics. */
137#define JOBS_TOPIC_COMMON( thingName, jobId, jobsApi ) \
138 ( JOBS_API_PREFIX \
139 thingName \
140 JOBS_API_BRIDGE \
141 jobId \
142 jobsApi )
155#define JOBS_API_SUBSCRIBE_NEXTJOBCHANGED( thingName ) \
156 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_NEXTJOBCHANGED )
157
168#define JOBS_API_SUBSCRIBE_JOBSCHANGED( thingName ) \
169 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_JOBSCHANGED )
170
181#define JOBS_API_PUBLISH_STARTNEXT( thingName ) \
182 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_STARTNEXT )
183
194#define JOBS_API_PUBLISH_GETPENDING( thingName ) \
195 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_GETPENDING )
196
209#define JOBS_API_PUBLISH_DESCRIBENEXTJOB( thingName ) \
210 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NEXT JOBS_API_LEVEL_SEPARATOR, JOBS_API_DESCRIBE )
211
217#define JOBS_API_MAX_LENGTH( thingNameLength ) \
218 ( JOBS_API_COMMON_LENGTH( thingNameLength ) + \
219 JOBID_MAX_LENGTH + sizeof( '/' ) + JOBS_API_UPDATE_LENGTH + \
220 JOBS_API_SUCCESS_LENGTH + 1U )
221
226typedef enum
227{
228 JobsError = 0,
234
251typedef enum
252{
253 JobsInvalidTopic = -1,
254 JobsJobsChanged,
255 JobsNextJobChanged,
256 JobsGetPendingSuccess,
257 JobsGetPendingFailed,
258 JobsStartNextSuccess,
259 JobsStartNextFailed,
260 /* Topics below use a job ID. */
261 JobsDescribeSuccess,
262 JobsDescribeFailed,
263 JobsUpdateSuccess,
264 JobsUpdateFailed,
265 JobsMaxTopic
267
268/*-----------------------------------------------------------*/
269
328/* @[declare_jobs_gettopic] */
329JobsStatus_t Jobs_GetTopic( char * buffer,
330 size_t length,
331 const char * thingName,
332 uint16_t thingNameLength,
333 JobsTopic_t api,
334 size_t * outLength );
335/* @[declare_jobs_gettopic] */
336
446/* @[declare_jobs_matchtopic] */
447JobsStatus_t Jobs_MatchTopic( char * topic,
448 size_t length,
449 const char * thingName,
450 uint16_t thingNameLength,
451 JobsTopic_t * outApi,
452 char ** outJobId,
453 uint16_t * outJobIdLength );
454/* @[declare_jobs_matchtopic] */
455
514/* @[declare_jobs_getpending] */
515JobsStatus_t Jobs_GetPending( char * buffer,
516 size_t length,
517 const char * thingName,
518 uint16_t thingNameLength,
519 size_t * outLength );
520/* @[declare_jobs_getpending] */
521
580/* @[declare_jobs_startnext] */
581JobsStatus_t Jobs_StartNext( char * buffer,
582 size_t length,
583 const char * thingName,
584 uint16_t thingNameLength,
585 size_t * outLength );
586/* @[declare_jobs_startnext] */
587
658/* @[declare_jobs_describe] */
659JobsStatus_t Jobs_Describe( char * buffer,
660 size_t length,
661 const char * thingName,
662 uint16_t thingNameLength,
663 const char * jobId,
664 uint16_t jobIdLength,
665 size_t * outLength );
666/* @[declare_jobs_describe] */
667
735/* @[declare_jobs_update] */
736JobsStatus_t Jobs_Update( char * buffer,
737 size_t length,
738 const char * thingName,
739 uint16_t thingNameLength,
740 const char * jobId,
741 uint16_t jobIdLength,
742 size_t * outLength );
743/* @[declare_jobs_update] */
744
745/* *INDENT-OFF* */
746#ifdef __cplusplus
747 }
748#endif
749/* *INDENT-ON* */
750
751#endif /* ifndef JOBS_H_ */
JobsTopic_t
Topic values for subscription requests.
Definition: jobs.h:252
JobsStatus_t
Return codes from jobs functions.
Definition: jobs.h:227
@ JobsNoMatch
The buffer does not contain a jobs topic.
Definition: jobs.h:230
@ JobsBufferTooSmall
The buffer write was truncated.
Definition: jobs.h:232
@ JobsSuccess
The buffer was properly written or a match was found.
Definition: jobs.h:229
@ JobsBadParameter
A function parameter was NULL or has an illegal value.
Definition: jobs.h:231
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:714
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:606
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:639
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:673
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:546
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:266