Skip to content

Commit

Permalink
Merge pull request aws#16 from aws/update/pull-from-public-repo
Browse files Browse the repository at this point in the history
Pull changes from public repository and tweak the Foundry SDK to accommodate those changes
  • Loading branch information
aggarw13 authored Nov 19, 2019
2 parents 475a7d3 + b21da12 commit 7b685b8
Show file tree
Hide file tree
Showing 77 changed files with 5,547 additions and 2,670 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ if( NOT EXISTS ${PROJECT_SOURCE_DIR}/ports/${IOT_PLATFORM_NAME} )
endif()

# Set output directories.
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/bin )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/lib )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/lib )

# Set the path to the config header.
if( ${IOT_BUILD_TESTS} )
Expand Down Expand Up @@ -106,8 +107,8 @@ add_subdirectory( libraries/aws/provisioning )
# TinyCBOR library (third-party).
add_subdirectory( third_party/tinycbor )

# mbed TLS library (third-party).
if( NOT IOT_NETWORK_USE_OPENSSL )
# mbed TLS library (third-party). This is only needed on ports using mbed TLS.
if( ${MBEDTLS_REQUIRED} )
add_subdirectory( third_party/mbedtls )
endif()

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This SDK builds with [CMake](https://cmake.org/), a cross-platform build tool. T
```sh
cmake ..
```
CMake will generate a project based on the detected operating system. On Linux, the default project is a Makefile. To build the SDK with this Makefile, run `make`.
CMake will generate a project based on the detected operating system. On Linux, the default project is a Makefile. To build the SDK with this Makefile, run `make`. The resulting binaries (the demo executables) and libraries will be placed in the `build/output` directory.

You may also use CMake GUI. Specify the SDK's root directory as the source directory and the build directory created in step 4 as the build directory in CMake GUI.
Expand Down
6 changes: 3 additions & 3 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ set( DEMO_SOURCES
src/aws_iot_demo_provisioning.c )
set( DEMO_LIBRARY_DEPENDENCY
iotmqtt
"awsiotshadow\\\;iotserializer"
"awsiotshadow\\\;awsiotcommon"
awsiotdefender
"awsiotjobs\\\;iotserializer"
"awsiotprovisioning\\\;iotserializer" )
"awsiotjobs\\\;awsiotcommon"
"awsiotprovisioning\\\;awsiotcommon" )

# Get the list length to iterate over it. Since CMake indexes from 0, subtract
# 1 for the iteration range.
Expand Down
4 changes: 2 additions & 2 deletions demos/app/iot_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ int main( int argc,
IotDemoArguments_t demoArguments = IOT_DEMO_ARGUMENTS_INITIALIZER;

/* Network server info and credentials. */
IotNetworkServerInfo_t serverInfo = IOT_DEMO_SERVER_INFO_INITIALIZER;
IotNetworkCredentials_t credentials = IOT_DEMO_CREDENTIALS_INITIALIZER,
struct IotNetworkServerInfo serverInfo = IOT_DEMO_SERVER_INFO_INITIALIZER;
struct IotNetworkCredentials credentials = IOT_DEMO_CREDENTIALS_INITIALIZER,
* pCredentials = NULL;

/* Parse and validate any command line arguments. */
Expand Down
76 changes: 45 additions & 31 deletions demos/src/aws_iot_demo_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "aws_iot_jobs.h"

/* JSON utilities include. */
#include "iot_json_utils.h"
#include "aws_iot_doc_parser.h"

/* Atomics include. */
#include "iot_atomic.h"
Expand All @@ -56,14 +56,14 @@
/**
* @brief The timeout for Jobs and MQTT operations in this demo.
*/
#define TIMEOUT_MS ( ( uint32_t ) 5000u )
#define TIMEOUT_MS ( ( uint32_t ) 5000u )

/**
* @brief The keep-alive interval used for this demo.
*
* An MQTT ping request will be sent periodically at this interval.
*/
#define KEEP_ALIVE_SECONDS ( ( uint16_t ) 60u )
#define KEEP_ALIVE_SECONDS ( ( uint16_t ) 60u )

/**
* @brief The JSON key of the Job ID.
Expand All @@ -72,12 +72,12 @@
* All Job documents will contain this key, whose value represents the unique
* identifier of a Job.
*/
#define JOB_ID_KEY "jobId"
#define JOB_ID_KEY "jobId"

/**
* @brief The length of #JOB_ID_KEY.
*/
#define JOB_ID_KEY_LENGTH ( sizeof( JOB_ID_KEY ) - 1 )
#define JOB_ID_KEY_LENGTH ( sizeof( JOB_ID_KEY ) - 1 )

/**
* @brief The JSON key of the Job document.
Expand All @@ -86,25 +86,25 @@
* All Job documents will contain this key, whose value is an application-specific
* JSON document.
*/
#define JOB_DOC_KEY "jobDocument"
#define JOB_DOC_KEY "jobDocument"

/**
* @brief The length of #JOB_DOC_KEY.
*/
#define JOB_DOC_KEY_LENGTH ( sizeof( JOB_DOC_KEY ) - 1 )
#define JOB_DOC_KEY_LENGTH ( sizeof( JOB_DOC_KEY ) - 1 )

/**
* @brief The JSON key whose value represents the action this demo should take.
*
* This demo program expects this key to be in the Job document. It is a key
* specific to this demo.
*/
#define JOB_ACTION_KEY "action"
#define JOB_ACTION_KEY "action"

/**
* @brief The length of #JOB_ACTION_KEY.
*/
#define JOB_ACTION_KEY_LENGTH ( sizeof( JOB_ACTION_KEY ) - 1 )
#define JOB_ACTION_KEY_LENGTH ( sizeof( JOB_ACTION_KEY ) - 1 )

/**
* @brief A message associated with the Job action.
Expand All @@ -113,12 +113,12 @@
* is either "publish" or "print". It represents the message that should be
* published or printed, respectively.
*/
#define JOB_MESSAGE_KEY "message"
#define JOB_MESSAGE_KEY "message"

/**
* @brief The length of #JOB_MESSAGE_KEY.
*/
#define JOB_MESSAGE_KEY_LENGTH ( sizeof( JOB_MESSAGE_KEY ) - 1 )
#define JOB_MESSAGE_KEY_LENGTH ( sizeof( JOB_MESSAGE_KEY ) - 1 )

/**
* @brief An MQTT topic associated with the Job "publish" action.
Expand All @@ -127,20 +127,20 @@
* is "publish". It represents the MQTT topic on which the message should be
* published.
*/
#define JOB_TOPIC_KEY "topic"
#define JOB_TOPIC_KEY "topic"

/**
* @brief The length of #JOB_TOPIC_KEY.
*/
#define JOB_TOPIC_KEY_LENGTH ( sizeof( JOB_TOPIC_KEY ) - 1 )
#define JOB_TOPIC_KEY_LENGTH ( sizeof( JOB_TOPIC_KEY ) - 1 )

/**
* @brief The minimum length of a string in a JSON Job document.
*
* At the very least the Job ID must have the quotes that identify it as a JSON
* string and 1 character for the string itself (the string must not be empty).
*/
#define JSON_STRING_MIN_LENGTH ( ( size_t ) 3 )
#define JSON_STRING_MIN_LENGTH ( ( size_t ) 3 )

/**
* @brief The maximum length of a Job ID.
Expand All @@ -150,28 +150,28 @@
*
* https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#job-limits
*/
#define JOB_ID_MAX_LENGTH ( ( size_t ) 64 )
#define JOB_ID_MAX_LENGTH ( ( size_t ) 64 )

/**
* @brief A value passed as context to #_operationCompleteCallback to specify that
* it should set the #JOBS_DEMO_FINISHED flag.
*/
#define JOBS_DEMO_SHOULD_EXIT ( ( void * ) ( ( intptr_t ) 1 ) )
#define JOBS_DEMO_SHOULD_EXIT ( ( void * ) ( ( intptr_t ) 1 ) )

/**
* @brief Flag value for signaling that the demo is still running.
*
* The initial value of #_exitFlag.
*/
#define JOBS_DEMO_RUNNING ( ( uint32_t ) 0 )
#define JOBS_DEMO_RUNNING ( ( uint32_t ) 0 )

/**
* @brief Flag value for signaling that the demo is finished.
*
* #_exitFlag will be set to this when a Job document with { "action": "exit" }
* is received.
*/
#define JOBS_DEMO_FINISHED ( ( uint32_t ) 1 )
#define JOBS_DEMO_FINISHED ( ( uint32_t ) 1 )

/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -364,12 +364,19 @@ static bool _getJsonString( const char * pJsonDoc,
const char ** pValue,
size_t * valueLength )
{
bool keyFound = IotJsonUtils_FindJsonValue( pJsonDoc,
jsonDocLength,
pKey,
keyLength,
pValue,
valueLength );
/*
* Note: This parser used is specific for parsing AWS IoT document received
* through a mutually authenticated connection. This parser will not check
* for the correctness of the document as it is designed for low memory
* footprint rather than checking for correctness of the document. This
* parser is not meant to be used as a general purpose JSON parser.
*/
bool keyFound = AwsIotDocParser_FindValue( pJsonDoc,
jsonDocLength,
pKey,
keyLength,
pValue,
valueLength );

if( keyFound == true )
{
Expand Down Expand Up @@ -659,13 +666,20 @@ static void _jobsCallback( void * pCallbackContext,
}
}

/* Get the Job document. */
docKeyFound = IotJsonUtils_FindJsonValue( pCallbackInfo->u.callback.pDocument,
pCallbackInfo->u.callback.documentLength,
JOB_DOC_KEY,
JOB_DOC_KEY_LENGTH,
&pJobDoc,
&jobDocLength );
/* Get the Job document.
*
* Note: This parser used is specific for parsing AWS IoT document received
* through a mutually authenticated connection. This parser will not check
* for the correctness of the document as it is designed for low memory
* footprint rather than checking for correctness of the document. This
* parser is not meant to be used as a general purpose JSON parser.
*/
docKeyFound = AwsIotDocParser_FindValue( pCallbackInfo->u.callback.pDocument,
pCallbackInfo->u.callback.documentLength,
JOB_DOC_KEY,
JOB_DOC_KEY_LENGTH,
&pJobDoc,
&jobDocLength );

/* When both the Job ID and Job document are available, process the Job. */
if( ( idKeyFound == true ) && ( docKeyFound == true ) )
Expand Down
3 changes: 0 additions & 3 deletions demos/src/aws_iot_demo_provisioning.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
/* Provisioning include. */
#include "aws_iot_provisioning.h"

/* JSON utilities include. */
#include "iot_json_utils.h"

/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore this section.
Expand Down
86 changes: 57 additions & 29 deletions demos/src/aws_iot_demo_shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "aws_iot_shadow.h"

/* JSON utilities include. */
#include "iot_json_utils.h"
#include "aws_iot_doc_parser.h"

/**
* @cond DOXYGEN_IGNORE
Expand Down Expand Up @@ -169,23 +169,37 @@ static bool _getDelta( const char * pDeltaDocument,
const char * pState = NULL;
size_t stateLength = 0;

/* Find the "state" key in the delta document. */
stateFound = IotJsonUtils_FindJsonValue( pDeltaDocument,
deltaDocumentLength,
"state",
5,
&pState,
&stateLength );
/* Find the "state" key in the delta document.
*
* Note: This parser used is specific for parsing AWS IoT document received
* through a mutually authenticated connection. This parser will not check
* for the correctness of the document as it is designed for low memory
* footprint rather than checking for correctness of the document. This
* parser is not meant to be used as a general purpose JSON parser.
*/
stateFound = AwsIotDocParser_FindValue( pDeltaDocument,
deltaDocumentLength,
"state",
5,
&pState,
&stateLength );

if( stateFound == true )
{
/* Find the delta key within the "state" section. */
deltaFound = IotJsonUtils_FindJsonValue( pState,
stateLength,
pDeltaKey,
deltaKeyLength,
pDelta,
pDeltaLength );
/* Find the delta key within the "state" section.
*
* Note: This parser used is specific for parsing AWS IoT document received
* through a mutually authenticated connection. This parser will not check
* for the correctness of the document as it is designed for low memory
* footprint rather than checking for correctness of the document. This
* parser is not meant to be used as a general purpose JSON parser.
*/
deltaFound = AwsIotDocParser_FindValue( pState,
stateLength,
pDeltaKey,
deltaKeyLength,
pDelta,
pDeltaLength );
}
else
{
Expand Down Expand Up @@ -220,23 +234,37 @@ static bool _getUpdatedState( const char * pUpdatedDocument,
const char * pSection = NULL;
size_t sectionLength = 0;

/* Find the given section in the updated document. */
sectionFound = IotJsonUtils_FindJsonValue( pUpdatedDocument,
updatedDocumentLength,
pSectionKey,
sectionKeyLength,
&pSection,
&sectionLength );
/* Find the given section in the updated document.
*
* Note: This parser used is specific for parsing AWS IoT document received
* through a mutually authenticated connection. This parser will not check
* for the correctness of the document as it is designed for low memory
* footprint rather than checking for correctness of the document. This
* parser is not meant to be used as a general purpose JSON parser.
*/
sectionFound = AwsIotDocParser_FindValue( pUpdatedDocument,
updatedDocumentLength,
pSectionKey,
sectionKeyLength,
&pSection,
&sectionLength );

if( sectionFound == true )
{
/* Find the "state" key within the "previous" or "current" section. */
stateFound = IotJsonUtils_FindJsonValue( pSection,
sectionLength,
"state",
5,
pState,
pStateLength );
/* Find the "state" key within the "previous" or "current" section.
*
* Note: This parser used is specific for parsing AWS IoT document received
* through a mutually authenticated connection. This parser will not check
* for the correctness of the document as it is designed for low memory
* footprint rather than checking for correctness of the document. This
* parser is not meant to be used as a general purpose JSON parser.
*/
stateFound = AwsIotDocParser_FindValue( pSection,
sectionLength,
"state",
5,
pState,
pStateLength );
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions doc/guide/building.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cmake ..
make
@endcode

Demo application executables will be placed in a `bin` directory of the CMake build directory, i.e. `build/bin` in the example above. The executables will be named `aws_iot_demo_library` or `iot_demo_library`, depending on whether the demo is specific to AWS IoT. For example, the MQTT demo application, which may be used with any MQTT server, will be named `iot_demo_mqtt`. The Thing Shadow demo, which is specific to AWS IoT, will be named `aws_iot_demo_shadow`.
Demo application executables will be placed in a `output/bin` directory of the CMake build directory, i.e. `build/output/bin` in the example above. The executables will be named `aws_iot_demo_library` or `iot_demo_library`, depending on whether the demo is specific to AWS IoT. For example, the MQTT demo application, which may be used with any MQTT server, will be named `iot_demo_mqtt`. The Thing Shadow demo, which is specific to AWS IoT, will be named `aws_iot_demo_shadow`.

Configuration settings may also be set using CMake by setting `CMAKE_C_FLAGS`. However, placing configuration settings in `demos/iot_demo_config.h` is recommended over setting them using CMake.
@code{sh}
Expand Down Expand Up @@ -147,7 +147,7 @@ make

The `IOT_BUILD_TESTS` option can also be set by a checkbox in CMake GUI.

Test executables will be placed in a `bin` directory of the CMake build directory (i.e. `build/bin`) alongside the demo applications. They will be named `aws_iot_tests_library` or `iot_tests_library`, depending on whether the tests are specific to AWS IoT. For example, the MQTT tests application, which may be used with any MQTT server, will be named `iot_tests_mqtt`. The Thing Shadow tests, which are specific to AWS IoT, will be named `aws_iot_tests_shadow`.
Test executables will be placed in a `output/bin` directory of the CMake build directory (i.e. `build/output/bin`) alongside the demo applications. They will be named `aws_iot_tests_library` or `iot_tests_library`, depending on whether the tests are specific to AWS IoT. For example, the MQTT tests application, which may be used with any MQTT server, will be named `iot_tests_mqtt`. The Thing Shadow tests, which are specific to AWS IoT, will be named `aws_iot_tests_shadow`.

By default, running a test executable with no command line arguments will only run the basic unit tests and system tests. This run is expected to take up to a few minutes per library test. The command line option `-l` may be passed to a test executable to enable long-running tests (such as stress tests) which may run for several hours. The command line option `-n` may be passed to the test executable to disable tests that require network connectivity.
*/
Loading

0 comments on commit 7b685b8

Please sign in to comment.