AWS IoT Jobs v1.2.0
Client library for AWS IoT Jobs
jobs.h
Go to the documentation of this file.
1/*
2 * AWS IoT Jobs v1.2.0
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
30#ifndef JOBS_H_
31#define JOBS_H_
32
33#include <stddef.h>
34#include <stdint.h>
35
36/* *INDENT-OFF* */
37#ifdef __cplusplus
38 extern "C" {
39#endif
40/* *INDENT-ON* */
41
46#define JOBS_THINGNAME_MAX_LENGTH 128U /* per AWS IoT API Reference */
47
52#define JOBS_JOBID_MAX_LENGTH 64U /* per AWS IoT API Reference */
53
54#ifndef THINGNAME_MAX_LENGTH
55
61 #define THINGNAME_MAX_LENGTH JOBS_THINGNAME_MAX_LENGTH
62#endif
63
64#ifndef JOBID_MAX_LENGTH
65
71 #define JOBID_MAX_LENGTH JOBS_JOBID_MAX_LENGTH
72#endif
73
74#if ( THINGNAME_MAX_LENGTH > JOBS_THINGNAME_MAX_LENGTH )
75 #error "The value of THINGNAME_MAX_LENGTH exceeds the AWS IoT Jobs Service limit."
76#endif
77
78#if ( JOBID_MAX_LENGTH > JOBS_JOBID_MAX_LENGTH )
79 #error "The value of JOBID_MAX_LENGTH exceeds the AWS IoT Jobs Service limit."
80#endif
81
87#define JOBS_API_PREFIX "$aws/things/"
88#define JOBS_API_PREFIX_LENGTH ( sizeof( JOBS_API_PREFIX ) - 1U )
89
90#define JOBS_API_BRIDGE "/jobs/"
91#define JOBS_API_BRIDGE_LENGTH ( sizeof( JOBS_API_BRIDGE ) - 1U )
92
93#define JOBS_API_SUCCESS "/accepted"
94#define JOBS_API_SUCCESS_LENGTH ( sizeof( JOBS_API_SUCCESS ) - 1U )
95
96#define JOBS_API_FAILURE "/rejected"
97#define JOBS_API_FAILURE_LENGTH ( sizeof( JOBS_API_FAILURE ) - 1U )
98
99#define JOBS_API_JOBSCHANGED "notify"
100#define JOBS_API_JOBSCHANGED_LENGTH ( sizeof( JOBS_API_JOBSCHANGED ) - 1U )
101
102#define JOBS_API_NEXTJOBCHANGED "notify-next"
103#define JOBS_API_NEXTJOBCHANGED_LENGTH ( sizeof( JOBS_API_NEXTJOBCHANGED ) - 1U )
104
105#define JOBS_API_GETPENDING "get"
106#define JOBS_API_GETPENDING_LENGTH ( sizeof( JOBS_API_GETPENDING ) - 1U )
107
108#define JOBS_API_STARTNEXT "start-next"
109#define JOBS_API_STARTNEXT_LENGTH ( sizeof( JOBS_API_STARTNEXT ) - 1U )
110
111#define JOBS_API_DESCRIBE "get"
112#define JOBS_API_DESCRIBE_LENGTH ( sizeof( JOBS_API_DESCRIBE ) - 1U )
113
114#define JOBS_API_UPDATE "update"
115#define JOBS_API_UPDATE_LENGTH ( sizeof( JOBS_API_UPDATE ) - 1U )
116
117#define JOBS_API_JOBID_NEXT "$next"
118#define JOBS_API_JOBID_NEXT_LENGTH ( sizeof( JOBS_API_JOBID_NEXT ) - 1U )
119
120#define JOBS_API_JOBID_NULL ""
121#define JOBS_API_LEVEL_SEPARATOR "/"
122
123#define JOBS_API_COMMON_LENGTH( thingNameLength ) \
124 ( JOBS_API_PREFIX_LENGTH + ( thingNameLength ) + JOBS_API_BRIDGE_LENGTH )
125
134/* AWS IoT Jobs API topics. */
135#define JOBS_TOPIC_COMMON( thingName, jobId, jobsApi ) \
136 ( JOBS_API_PREFIX \
137 thingName \
138 JOBS_API_BRIDGE \
139 jobId \
140 jobsApi )
153#define JOBS_API_SUBSCRIBE_NEXTJOBCHANGED( thingName ) \
154 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_NEXTJOBCHANGED )
155
166#define JOBS_API_SUBSCRIBE_JOBSCHANGED( thingName ) \
167 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_JOBSCHANGED )
168
179#define JOBS_API_PUBLISH_STARTNEXT( thingName ) \
180 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_STARTNEXT )
181
192#define JOBS_API_PUBLISH_GETPENDING( thingName ) \
193 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NULL, JOBS_API_GETPENDING )
194
207#define JOBS_API_PUBLISH_DESCRIBENEXTJOB( thingName ) \
208 JOBS_TOPIC_COMMON( thingName, JOBS_API_JOBID_NEXT JOBS_API_LEVEL_SEPARATOR, JOBS_API_DESCRIBE )
209
215#define JOBS_API_MAX_LENGTH( thingNameLength ) \
216 ( JOBS_API_COMMON_LENGTH( thingNameLength ) + \
217 JOBID_MAX_LENGTH + sizeof( '/' ) + JOBS_API_UPDATE_LENGTH + \
218 JOBS_API_SUCCESS_LENGTH + 1U )
219
224typedef enum
225{
226 JobsError = 0,
232
249typedef enum
250{
251 JobsInvalidTopic = -1,
252 JobsJobsChanged,
253 JobsNextJobChanged,
254 JobsGetPendingSuccess,
255 JobsGetPendingFailed,
256 JobsStartNextSuccess,
257 JobsStartNextFailed,
258 /* Topics below use a job ID. */
259 JobsDescribeSuccess,
260 JobsDescribeFailed,
261 JobsUpdateSuccess,
262 JobsUpdateFailed,
263 JobsMaxTopic
265
266/*-----------------------------------------------------------*/
267
326/* @[declare_jobs_gettopic] */
327JobsStatus_t Jobs_GetTopic( char * buffer,
328 size_t length,
329 const char * thingName,
330 uint16_t thingNameLength,
331 JobsTopic_t api,
332 size_t * outLength );
333/* @[declare_jobs_gettopic] */
334
444/* @[declare_jobs_matchtopic] */
445JobsStatus_t Jobs_MatchTopic( char * topic,
446 size_t length,
447 const char * thingName,
448 uint16_t thingNameLength,
449 JobsTopic_t * outApi,
450 char ** outJobId,
451 uint16_t * outJobIdLength );
452/* @[declare_jobs_matchtopic] */
453
512/* @[declare_jobs_getpending] */
513JobsStatus_t Jobs_GetPending( char * buffer,
514 size_t length,
515 const char * thingName,
516 uint16_t thingNameLength,
517 size_t * outLength );
518/* @[declare_jobs_getpending] */
519
578/* @[declare_jobs_startnext] */
579JobsStatus_t Jobs_StartNext( char * buffer,
580 size_t length,
581 const char * thingName,
582 uint16_t thingNameLength,
583 size_t * outLength );
584/* @[declare_jobs_startnext] */
585
656/* @[declare_jobs_describe] */
657JobsStatus_t Jobs_Describe( char * buffer,
658 size_t length,
659 const char * thingName,
660 uint16_t thingNameLength,
661 const char * jobId,
662 uint16_t jobIdLength,
663 size_t * outLength );
664/* @[declare_jobs_describe] */
665
733/* @[declare_jobs_update] */
734JobsStatus_t Jobs_Update( char * buffer,
735 size_t length,
736 const char * thingName,
737 uint16_t thingNameLength,
738 const char * jobId,
739 uint16_t jobIdLength,
740 size_t * outLength );
741/* @[declare_jobs_update] */
742
743/* *INDENT-OFF* */
744#ifdef __cplusplus
745 }
746#endif
747/* *INDENT-ON* */
748
749#endif /* ifndef JOBS_H_ */
JobsTopic_t
Topic values for subscription requests.
Definition: jobs.h:250
JobsStatus_t
Return codes from jobs functions.
Definition: jobs.h:225
@ JobsNoMatch
The buffer does not contain a jobs topic.
Definition: jobs.h:228
@ JobsBufferTooSmall
The buffer write was truncated.
Definition: jobs.h:230
@ JobsSuccess
The buffer was properly written or a match was found.
Definition: jobs.h:227
@ JobsBadParameter
A function parameter was NULL or has an illegal value.
Definition: jobs.h:229
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:677
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:569
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:602
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:636
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:509
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:264