├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ ├── documentation.yml │ └── feature-request.yml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── closed-issue-message.yml │ ├── handle-stale-discussions.yml │ ├── issue-regression-labeler.yml │ └── stale_issue.yml ├── .gitignore ├── CMakeLists-rapidjson.txt.in ├── CMakeLists-sanitizers.txt.in ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Changelog.md ├── ClangToolchainFile.cmake ├── DevGuide.md ├── GreengrassDiscovery.md ├── KnownIssues.md ├── LICENSE ├── NOTICE ├── Platform.md ├── README.md ├── ToolchainFile.cmake ├── certs └── README.txt ├── cli ├── CMakeLists.txt ├── cli.cpp └── cli.hpp ├── cmake └── FindMbedTLS.cmake ├── common ├── ConfigCommon.cpp ├── ConfigCommon.hpp ├── RobotArmConfig.json ├── SampleConfig.json └── SwitchConfig.json ├── doxygen ├── doxygen.conf └── doxygen.conf.in ├── include ├── Action.hpp ├── ClientCore.hpp ├── ClientCoreState.hpp ├── NetworkConnection.hpp ├── ResponseCode.hpp ├── discovery │ ├── Discovery.hpp │ └── DiscoveryResponse.hpp ├── jobs │ └── Jobs.hpp ├── mqtt │ ├── Client.hpp │ ├── ClientState.hpp │ ├── Common.hpp │ ├── Connect.hpp │ ├── GreengrassMqttClient.hpp │ ├── NetworkRead.hpp │ ├── Packet.hpp │ ├── Publish.hpp │ └── Subscribe.hpp ├── shadow │ └── Shadow.hpp └── util │ ├── Core_EXPORTS.hpp │ ├── JsonParser.hpp │ ├── Utf8String.hpp │ ├── logging │ ├── ConsoleLogSystem.hpp │ ├── FormattedLogSystem.hpp │ ├── LogLevel.hpp │ ├── LogMacros.hpp │ ├── LogSystemInterface.hpp │ └── Logging.hpp │ ├── memory │ └── stl │ │ ├── Map.hpp │ │ ├── Queue.hpp │ │ ├── String.hpp │ │ ├── StringStream.hpp │ │ └── Vector.hpp │ └── threading │ └── ThreadTask.hpp ├── network ├── CMakeLists-mbedtls.txt.in ├── CMakeLists.txt.in ├── MbedTLS │ ├── MbedTLSConnection.cpp │ └── MbedTLSConnection.hpp ├── OpenSSL │ ├── OpenSSLConnection.cpp │ └── OpenSSLConnection.hpp ├── README.md └── WebSocket │ ├── WebSocketConnection.cpp │ ├── WebSocketConnection.hpp │ └── wslay │ ├── wslay.hpp │ ├── wslay_frame.cpp │ ├── wslay_frame.hpp │ ├── wslay_net.cpp │ └── wslay_net.hpp ├── samples ├── Discovery │ ├── CMakeLists.txt │ ├── Discovery.cpp │ └── Discovery.hpp ├── Jobs │ ├── CMakeLists.txt │ ├── JobsSample.cpp │ └── JobsSample.hpp ├── JobsAgent │ ├── CMakeLists.txt │ ├── JobsAgent.cpp │ ├── JobsAgent.hpp │ └── JobsAgentOperations.cpp ├── PubSub │ ├── CMakeLists.txt │ ├── PubSub.cpp │ └── PubSub.hpp ├── README.md ├── ShadowDelta │ ├── CMakeLists.txt │ ├── ShadowDelta.cpp │ └── ShadowDelta.hpp ├── StoryRobotArm │ ├── CMakeLists.txt │ ├── robotArm.cpp │ └── robotArm.hpp └── StorySwitch │ ├── CMakeLists.txt │ ├── switch.cpp │ └── switch.hpp ├── src ├── Action.cpp ├── ClientCore.cpp ├── ClientCoreState.cpp ├── NetworkConnection.cpp ├── ResponseCode.cpp ├── discovery │ ├── Discovery.cpp │ └── DiscoveryResponse.cpp ├── jobs │ └── Jobs.cpp ├── mqtt │ ├── Client.cpp │ ├── ClientState.cpp │ ├── Common.cpp │ ├── Connect.cpp │ ├── GreengrassMqttClient.cpp │ ├── NetworkRead.cpp │ ├── Packet.cpp │ ├── Publish.cpp │ └── Subscribe.cpp ├── shadow │ └── Shadow.cpp └── util │ ├── JsonParser.cpp │ ├── Utf8String.cpp │ ├── logging │ ├── ConsoleLogSystem.cpp │ ├── FormattedLogSystem.cpp │ ├── LogLevel.cpp │ └── Logging.cpp │ └── threading │ └── ThreadTask.cpp └── tests ├── README.md ├── integration ├── CMakeLists.txt ├── include │ ├── AutoReconnect.hpp │ ├── IntegTestRunner.hpp │ ├── JobsTest.hpp │ ├── MultipleClients.hpp │ ├── MultipleSubAutoReconnect.hpp │ ├── PubSub.hpp │ └── SdkTestConfig.hpp └── src │ ├── AutoReconnect.cpp │ ├── IntegTestRunner.cpp │ ├── JobsTest.cpp │ ├── MultipleClients.cpp │ ├── MultipleSubAutoReconnect.cpp │ ├── PubSub.cpp │ └── SdkTestConfig.cpp └── unit ├── CMakeLists-gtest.txt.in ├── CMakeLists.txt ├── include ├── JobsMock.hpp ├── MockNetworkConnection.hpp └── TestHelper.hpp └── src ├── ClientCoreTests.cpp ├── ConfigCommonTests.cpp ├── MockNetworkConnection.cpp ├── ResponseCodeTests.cpp ├── TestHelper.cpp ├── TestRunner.cpp ├── discovery └── DiscoveryTests.cpp ├── jobs ├── JobsAgentTests.cpp └── JobsTests.cpp ├── mqtt ├── ClientTests.cpp ├── ConnectTests.cpp ├── PublishTests.cpp └── SubscribeTests.cpp ├── shadow └── ShadowTests.cpp └── util ├── JsonParserTests.cpp └── TestParser.json /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "🐛 Bug Report" 3 | description: Report a bug 4 | title: "(short issue description)" 5 | labels: [bug, needs-triage] 6 | assignees: [] 7 | body: 8 | - type: textarea 9 | id: description 10 | attributes: 11 | label: Describe the bug 12 | description: What is the problem? A clear and concise description of the bug. 13 | validations: 14 | required: true 15 | - type: checkboxes 16 | id: regression 17 | attributes: 18 | label: Regression Issue 19 | description: What is a regression? If it worked in a previous version but doesn't in the latest version, it's considered a regression. In this case, please provide specific version number in the report. 20 | options: 21 | - label: Select this option if this issue appears to be a regression. 22 | required: false 23 | - type: textarea 24 | id: expected 25 | attributes: 26 | label: Expected Behavior 27 | description: | 28 | What did you expect to happen? 29 | validations: 30 | required: true 31 | - type: textarea 32 | id: current 33 | attributes: 34 | label: Current Behavior 35 | description: | 36 | What actually happened? 37 | 38 | Please include full errors, uncaught exceptions, stack traces, and relevant logs. 39 | If service responses are relevant, please include wire logs. 40 | validations: 41 | required: true 42 | - type: textarea 43 | id: reproduction 44 | attributes: 45 | label: Reproduction Steps 46 | description: | 47 | Provide a self-contained, concise snippet of code that can be used to reproduce the issue. 48 | For more complex issues provide a repo with the smallest sample that reproduces the bug. 49 | 50 | Avoid including business logic or unrelated code, it makes diagnosis more difficult. 51 | The code sample should be an SSCCE. See http://sscce.org/ for details. In short, please provide a code sample that we can copy/paste, run and reproduce. 52 | validations: 53 | required: true 54 | - type: textarea 55 | id: solution 56 | attributes: 57 | label: Possible Solution 58 | description: | 59 | Suggest a fix/reason for the bug 60 | validations: 61 | required: false 62 | - type: textarea 63 | id: context 64 | attributes: 65 | label: Additional Information/Context 66 | description: | 67 | Anything else that might be relevant for troubleshooting this bug. Providing context helps us come up with a solution that is most useful in the real world. 68 | validations: 69 | required: false 70 | - type: input 71 | id: sdk-version 72 | attributes: 73 | label: SDK version used 74 | validations: 75 | required: true 76 | - type: input 77 | id: environment 78 | attributes: 79 | label: Environment details (OS name and version, etc.) 80 | validations: 81 | required: true 82 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | blank_issues_enabled: false 3 | contact_links: 4 | - name: 💬 General Question 5 | url: https://github.com/aws/aws-iot-device-sdk-cpp/discussions/categories/q-a 6 | about: Please ask and answer questions as a discussion thread -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "📕 Documentation Issue" 3 | description: Report an issue in the API Reference documentation or Developer Guide 4 | title: "(short issue description)" 5 | labels: [documentation, needs-triage] 6 | assignees: [] 7 | body: 8 | - type: textarea 9 | id: description 10 | attributes: 11 | label: Describe the issue 12 | description: A clear and concise description of the issue. 13 | validations: 14 | required: true 15 | 16 | - type: textarea 17 | id: links 18 | attributes: 19 | label: Links 20 | description: | 21 | Include links to affected documentation page(s). 22 | validations: 23 | required: true 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🚀 Feature Request 3 | description: Suggest an idea for this project 4 | title: "(short issue description)" 5 | labels: [feature-request, needs-triage] 6 | assignees: [] 7 | body: 8 | - type: textarea 9 | id: description 10 | attributes: 11 | label: Describe the feature 12 | description: A clear and concise description of the feature you are proposing. 13 | validations: 14 | required: true 15 | - type: textarea 16 | id: use-case 17 | attributes: 18 | label: Use Case 19 | description: | 20 | Why do you need this feature? For example: "I'm always frustrated when..." 21 | validations: 22 | required: true 23 | - type: textarea 24 | id: solution 25 | attributes: 26 | label: Proposed Solution 27 | description: | 28 | Suggest how to implement the addition or change. Please include prototype/workaround/sketch/reference implementation. 29 | validations: 30 | required: false 31 | - type: textarea 32 | id: other 33 | attributes: 34 | label: Other Information 35 | description: | 36 | Any alternative solutions or features you considered, a more detailed explanation, stack traces, related issues, links for context, etc. 37 | validations: 38 | required: false 39 | - type: checkboxes 40 | id: ack 41 | attributes: 42 | label: Acknowledgements 43 | options: 44 | - label: I may be able to implement this feature request 45 | required: false 46 | - label: This feature might incur a breaking change 47 | required: false 48 | - type: input 49 | id: sdk-version 50 | attributes: 51 | label: SDK version used 52 | validations: 53 | required: true 54 | - type: input 55 | id: environment 56 | attributes: 57 | label: Environment details (OS name and version, etc.) 58 | validations: 59 | required: true 60 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 7 | -------------------------------------------------------------------------------- /.github/workflows/closed-issue-message.yml: -------------------------------------------------------------------------------- 1 | name: Closed Issue Message 2 | on: 3 | issues: 4 | types: [closed] 5 | jobs: 6 | auto_comment: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | issues: write 10 | steps: 11 | - uses: aws-actions/closed-issue-message@v1 12 | with: 13 | # These inputs are both required 14 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 15 | message: | 16 | This issue is now closed. Comments on closed issues are hard for our team to see. 17 | If you need more assistance, please open a new issue that references this one. 18 | -------------------------------------------------------------------------------- /.github/workflows/handle-stale-discussions.yml: -------------------------------------------------------------------------------- 1 | name: HandleStaleDiscussions 2 | on: 3 | schedule: 4 | - cron: '0 */4 * * *' 5 | discussion_comment: 6 | types: [created] 7 | 8 | jobs: 9 | handle-stale-discussions: 10 | name: Handle stale discussions 11 | runs-on: ubuntu-latest 12 | permissions: 13 | discussions: write 14 | steps: 15 | - name: Stale discussions action 16 | uses: aws-github-ops/handle-stale-discussions@v1 17 | env: 18 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} -------------------------------------------------------------------------------- /.github/workflows/issue-regression-labeler.yml: -------------------------------------------------------------------------------- 1 | # Apply potential regression label on issues 2 | name: issue-regression-label 3 | on: 4 | issues: 5 | types: [opened, edited] 6 | jobs: 7 | add-regression-label: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | issues: write 11 | steps: 12 | - name: Fetch template body 13 | id: check_regression 14 | uses: actions/github-script@v7 15 | env: 16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 17 | TEMPLATE_BODY: ${{ github.event.issue.body }} 18 | with: 19 | script: | 20 | const regressionPattern = /\[x\] Select this option if this issue appears to be a regression\./i; 21 | const template = `${process.env.TEMPLATE_BODY}` 22 | const match = regressionPattern.test(template); 23 | core.setOutput('is_regression', match); 24 | - name: Manage regression label 25 | env: 26 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | run: | 28 | if [ "${{ steps.check_regression.outputs.is_regression }}" == "true" ]; then 29 | gh issue edit ${{ github.event.issue.number }} --add-label "potential-regression" -R ${{ github.repository }} 30 | else 31 | gh issue edit ${{ github.event.issue.number }} --remove-label "potential-regression" -R ${{ github.repository }} 32 | fi 33 | -------------------------------------------------------------------------------- /.github/workflows/stale_issue.yml: -------------------------------------------------------------------------------- 1 | name: "Close stale issues" 2 | 3 | # Controls when the action will run. 4 | on: 5 | schedule: 6 | - cron: "0 0 * * *" 7 | 8 | jobs: 9 | cleanup: 10 | runs-on: ubuntu-latest 11 | name: Stale issue job 12 | permissions: 13 | issues: write 14 | pull-requests: write 15 | steps: 16 | - uses: aws-actions/stale-issue-cleanup@v3 17 | with: 18 | # Setting messages to an empty string will cause the automation to skip 19 | # that category 20 | ancient-issue-message: Greetings! Sorry to say but this is a very old issue that is probably not getting as much attention as it deserves. We encourage you to try V2 and if you find that this is still a problem, please feel free to open a new issue there. 21 | stale-issue-message: Greetings! It looks like this issue hasn’t been active in longer than a week. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one, also please try V2 as this might be solved there too. 22 | stale-pr-message: Greetings! It looks like this PR hasn’t been active in longer than a week, add a comment or an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one. 23 | 24 | # These labels are required 25 | stale-issue-label: closing-soon 26 | exempt-issue-label: automation-exempt 27 | stale-pr-label: closing-soon 28 | exempt-pr-label: pr/needs-review 29 | response-requested-label: response-requested 30 | 31 | # Don't set closed-for-staleness label to skip closing very old issues 32 | # regardless of label 33 | closed-for-staleness-label: closed-for-staleness 34 | 35 | # Issue timing 36 | days-before-stale: 10 37 | days-before-close: 4 38 | days-before-ancient: 36500 39 | 40 | # If you don't want to mark a issue as being ancient based on a 41 | # threshold of "upvotes", you can set this here. An "upvote" is 42 | # the total number of +1, heart, hooray, and rocket reactions 43 | # on an issue. 44 | minimum-upvotes-to-exempt: 1 45 | 46 | repo-token: ${{ secrets.GITHUB_TOKEN }} 47 | loglevel: DEBUG 48 | # Set dry-run to true to not perform label or close actions. 49 | dry-run: false 50 | -------------------------------------------------------------------------------- /CMakeLists-rapidjson.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | project(rapidjson-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(rapidjson 7 | DOWNLOAD_COMMAND git clone --depth 1 https://github.com/Tencent/rapidjson.git . 8 | DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src" 9 | CONFIGURE_COMMAND "" 10 | BUILD_COMMAND "" 11 | INSTALL_COMMAND "" 12 | TEST_COMMAND "" 13 | GIT_SUBMODULES "" 14 | ) 15 | -------------------------------------------------------------------------------- /CMakeLists-sanitizers.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | project(sanitizers-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(sanitizers 7 | DOWNLOAD_COMMAND git clone --depth 1 https://github.com/arsenm/sanitizers-cmake.git . 8 | DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/sanitizers/src" 9 | CONFIGURE_COMMAND "" 10 | BUILD_COMMAND "" 11 | INSTALL_COMMAND "" 12 | TEST_COMMAND "" 13 | GIT_SUBMODULES "" 14 | ) 15 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/aws/aws-iot-device-sdk-cpp/issues), or [recently closed](https://github.com/aws/aws-iot-device-sdk-cpp/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/aws-iot-device-sdk-cpp/labels/help%20wanted) issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /ClangToolchainFile.cmake: -------------------------------------------------------------------------------- 1 | # The OpenSSL paths in the network/CMakeLists.txt needs to be replaced with the path to the cross-compiled OpenSSL library for 2 | # the required paltform 3 | 4 | # General CMAKE cross compile settings 5 | SET(CMAKE_SYSTEM_NAME Generic) 6 | SET(CMAKE_SYSTEM_VERSION 1) 7 | 8 | # Set compiler 9 | SET(CMAKE_CXX_COMPILER clang++) 10 | 11 | # Set linker 12 | SET(CMAKE_LINKER ld) 13 | 14 | # Set compiler flags 15 | SET(CMAKE_CXX_FLAGS ${COMMON_FLAGS} -std=c++11) 16 | 17 | # Set archiving tool 18 | SET(CMAKE_AR ar CACHE FILEPATH "Archiver") 19 | 20 | # Set randomizing tool for static libraries 21 | SET(CMAKE_RANLIB ranlib) 22 | 23 | # Set strip tool 24 | SET(CMAKE_STRIP strip) 25 | 26 | # Set objdump tool 27 | SET(CMAKE_OBJDUMP objdump) 28 | 29 | # Set objcopy tool 30 | SET(CMAKE_OBJCOPY objcopy) 31 | 32 | # Set nm tool 33 | SET(CMAKE_NM nm) 34 | -------------------------------------------------------------------------------- /KnownIssues.md: -------------------------------------------------------------------------------- 1 | # Known Issues/Limitations 2 | ## [1.4.0](https://github.com/aws/aws-iot-device-sdk-cpp/releases/tag/v1.4.0) (May 10, 2018) 3 | 4 | ### Common 5 | 6 | - Client Core - Reduce shared pointer usage, figure out ways to use fewer copy operations 7 | - MQTT - if subcriptions are disallowed by the policy, enabling auto resubcribe can lead to a connect-disconnect loop, issue [#94](https://github.com/aws/aws-iot-device-sdk-cpp/issues/94) 8 | - Network Read - Add recovery options for out of sync buffers 9 | - Network Layer, Common - Currently, vector resize is called before the vector is passed for reading in data. Determine if a more flexible solution is possible with fewer allocations 10 | - Network Layer, OpenSSL - error handling for library API call 11 | - Network Layer, OpenSSL - setting for disconnect timeouts 12 | - Network Layer, WebSocket - Refactor WSLay and merge it with the WebSocket wrapper, improve testing 13 | - Network Layer, WebSocket - TLS Read and Write are highly inefficient in current implementation, improvements required 14 | - Network Layer, Common - Add support for IPv6, remove deprecated system API calls 15 | - Shadow - Refactor delta requests into separate function 16 | - Shadow - Add action for automatically performing Shadow updates 17 | - Samples, Shadow - Add Console Echo Sample 18 | - Threading - lock-order-inversion (potential deadlock), issue [#14](https://github.com/aws/aws-iot-device-sdk-cpp/issues/14) 19 | - CLI, Configuration - Add support for command line cert paths 20 | - CMake, path warnings - Cleaner way to download repositories from github and build them 21 | - CMake, build settings - Provide options for setting up certain values that are hardcoded using macros at the moment 22 | - Testing - More edge case testing required for Reconnect logic 23 | - Testing - Improvements needed on Integration testing for network reference layers specifically for different compilers and platforms 24 | - UTF-8 string - improve validation checks 25 | 26 | ### Windows 27 | 28 | - Build issues with VS 2013 29 | - Project structure in Solution Explorer needs to be updated 30 | - CMake warnings on solution generation 31 | - Working directory needs to be updated every time CMake solution is rebuilt to ${OutDir} for configuration to be picked up as expected 32 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | AWS C++ SDK for Internet of Things Service 2 | Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | This product includes software developed by 5 | Amazon Inc (http://www.amazon.com/). 6 | 7 | ********************** 8 | THIRD PARTY COMPONENTS 9 | ********************** 10 | This software includes third party software subject to the following licensing: 11 | - OpenSSL library (wrapper code) - OpenSSL license 12 | - mbedTLS (external library, downloaded separately) - Apache 2.0 13 | - RapidJson (JSON Parsing) - MIT 14 | - Wslay (Websocket support) - MIT 15 | - Utf8cpp - Custom 16 | - GoogleTest/GoogleMock - Google's License 17 | - sanitizers-cmake (external library, downloaded separately)- MIT 18 | 19 | The licenses for these third party components are included in LICENSE 20 | -------------------------------------------------------------------------------- /ToolchainFile.cmake: -------------------------------------------------------------------------------- 1 | # The OpenSSL paths in the network/CMakeLists.txt needs to be replaced with the path to the cross-compiled OpenSSL library for 2 | # the required paltform 3 | 4 | # General CMAKE cross compile settings 5 | SET(CMAKE_SYSTEM_NAME Generic) 6 | SET(CMAKE_SYSTEM_VERSION 1) 7 | 8 | # Specify toolchain directory 9 | SET(TOOLCHAIN_DIR /home/toolchain/dir/here/bin) 10 | 11 | # Specify cross compilation target 12 | SET(TARGET_CROSS target-here) 13 | 14 | # Set compilers 15 | SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/${TARGET_CROSS}g++) 16 | 17 | # Set linker 18 | SET(CMAKE_LINKER ${TOOLCHAIN_DIR}/${TARGET_CROSS}ld) 19 | 20 | # Set compiler flags 21 | SET(CMAKE_CXX_FLAGS ${COMMON_FLAGS} -std=c++11) 22 | 23 | # Set archiving tool 24 | SET(CMAKE_AR ${TOOLCHAIN_DIR}/${TARGET_CROSS}ar CACHE FILEPATH "Archiver") 25 | 26 | # Set randomizing tool for static libraries 27 | SET(CMAKE_RANLIB ${TOOLCHAIN_DIR}/${TARGET_CROSS}ranlib) 28 | 29 | # Set strip tool 30 | SET(CMAKE_STRIP ${TOOLCHAIN_DIR}/${TARGET_CROSS}strip) 31 | 32 | # Set objdump tool 33 | SET(CMAKE_OBJDUMP ${TOOLCHAIN_DIR}/${TARGET_CROSS}objdump) 34 | 35 | # Set objcopy tool 36 | SET(CMAKE_OBJCOPY ${TOOLCHAIN_DIR}/${TARGET_CROSS}objcopy) 37 | 38 | # Set nm tool 39 | SET(CMAKE_NM ${TOOLCHAIN_DIR}/${TARGET_CROSS}nm) 40 | 41 | # Set THREADS_PTHREAD_ARG for testing threading 42 | SET(THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by ToolchainFile.cmake." FORCE) 43 | -------------------------------------------------------------------------------- /certs/README.txt: -------------------------------------------------------------------------------- 1 | # Copy certificates for running the samples and tests provided with the SDK into this directory 2 | # Certificates can be created and downloaded from the AWS IoT Console 3 | # The IoT Client takes the full path of the certificates as an input parameter while initializing 4 | # This is the default folder for the certificates only for samples and tests. A different path can be specified if required. -------------------------------------------------------------------------------- /cli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cli CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | ######################################## 13 | # Section : Common Build setttings # 14 | ######################################## 15 | # Set required compiler standard to standard c++11. Disable extensions. 16 | set(CMAKE_CXX_STANDARD 11) # C++11... 17 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 18 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 19 | 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 23 | 24 | # Configure Compiler flags 25 | if (UNIX AND NOT APPLE) 26 | # Prefer pthread if found 27 | set(THREADS_PREFER_PTHREAD_FLAG ON) 28 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 29 | elseif (APPLE) 30 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 31 | elseif (WIN32) 32 | set(CUSTOM_COMPILER_FLAGS "/W4") 33 | endif () 34 | 35 | ###################### 36 | # Target : Build CLI # 37 | ###################### 38 | 39 | set(CLI_TARGET_NAME aws-iot) 40 | # Add Target 41 | add_executable(${CLI_TARGET_NAME} "${PROJECT_SOURCE_DIR}/cli.cpp;${PROJECT_SOURCE_DIR}/../common/ConfigCommon.cpp") 42 | 43 | # Add Target specific includes 44 | target_include_directories(${CLI_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../common) 45 | target_include_directories(${CLI_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../cli) 46 | 47 | # Configure Threading library 48 | find_package(Threads REQUIRED) 49 | 50 | # Add SDK includes 51 | target_include_directories(${CLI_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/third_party/rapidjson/src/include) 52 | target_include_directories(${CLI_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../include) 53 | 54 | target_link_libraries(${CLI_TARGET_NAME} PUBLIC "Threads::Threads") 55 | target_link_libraries(${CLI_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 56 | 57 | # Copy Json config file 58 | add_custom_command(TARGET ${CLI_TARGET_NAME} PRE_BUILD 59 | COMMAND ${CMAKE_COMMAND} -E 60 | copy ${PROJECT_SOURCE_DIR}/../common/SampleConfig.json $/CliConfig.json) 61 | 62 | target_link_libraries(${CLI_TARGET_NAME} PUBLIC ${THREAD_LIBRARY_LINK_STRING}) 63 | target_link_libraries(${CLI_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 64 | set_property(TARGET ${CLI_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 65 | 66 | # Gather list of all .cert files in "/cert" 67 | add_custom_command(TARGET ${CLI_TARGET_NAME} PRE_BUILD 68 | COMMAND ${CMAKE_COMMAND} -E 69 | copy_directory ${PROJECT_SOURCE_DIR}/../certs $/certs) 70 | 71 | if (MSVC) 72 | set(CLI_HEADERS "${PROJECT_SOURCE_DIR}/cli.hpp") 73 | target_sources(${CLI_TARGET_NAME} PUBLIC ${CLI_HEADERS}) 74 | source_group("Header Files\\CLI" FILES ${CLI_HEADERS}) 75 | source_group("Source Files\\CLI" FILES ${CLI_SOURCES}) 76 | endif () 77 | 78 | ######################### 79 | # Add Network libraries # 80 | ######################### 81 | 82 | set(NETWORK_WRAPPER_DEST_TARGET ${CLI_TARGET_NAME}) 83 | include(${PROJECT_SOURCE_DIR}/../network/CMakeLists.txt.in) 84 | -------------------------------------------------------------------------------- /cli/cli.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file cli.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef WIN32 25 | #define MAX_PATH_LENGTH_ 260 26 | #include 27 | #define getcwd _getcwd // avoid MSFT "deprecation" warning 28 | #else 29 | #include 30 | #define MAX_PATH_LENGTH_ PATH_MAX 31 | #endif 32 | 33 | #include "NetworkConnection.hpp" 34 | 35 | #include "ResponseCode.hpp" 36 | #include "ClientCore.hpp" 37 | #include "mqtt/Client.hpp" 38 | #include "util/memory/stl/Vector.hpp" 39 | #include "util/Utf8String.hpp" 40 | 41 | using namespace awsiotsdk; 42 | 43 | namespace cppsdkcli { 44 | class CLI { 45 | protected: 46 | int port_; 47 | int qos_; 48 | bool is_publish_; 49 | bool is_subscribe_; 50 | char topic_[MAX_PATH_LENGTH_]; 51 | util::String endpoint_; 52 | std::shared_ptr p_iot_client_; 53 | std::shared_ptr p_network_connection_; 54 | 55 | ResponseCode InitializeTLS(); 56 | 57 | ResponseCode InitializeCliConfig(); 58 | 59 | ResponseCode Connect(); 60 | 61 | ResponseCode RunPublish(); 62 | 63 | ResponseCode RunPublish(int msg_count); 64 | 65 | ResponseCode Subscribe(std::unique_ptr p_topic_name, awsiotsdk::mqtt::QoS qos); 66 | 67 | ResponseCode RunSubscribe(); 68 | 69 | util::JsonDocument cli_config_; 70 | 71 | static ResponseCode SubscribeCallback(util::String topic_name, 72 | util::String payload, 73 | std::shared_ptr p_app_handler_data); 74 | 75 | public: 76 | CLI() { 77 | port_ = 8883; 78 | qos_ = 0; 79 | is_publish_ = false; 80 | is_subscribe_ = false; 81 | topic_[0] = '\0'; 82 | endpoint_[0] = '\0'; 83 | p_iot_client_ = nullptr; 84 | p_network_connection_ = nullptr; 85 | } 86 | awsiotsdk::ResponseCode InitializeCLI(int argc, char **argv); 87 | 88 | awsiotsdk::ResponseCode RunCLI(); 89 | }; 90 | } 91 | -------------------------------------------------------------------------------- /cmake/FindMbedTLS.cmake: -------------------------------------------------------------------------------- 1 | 2 | find_path(MBEDTLS_INCLUDE_DIR mbedtls/ssl.h) 3 | 4 | find_library(MBEDTLS_TLS_LIB mbedtls) 5 | find_library(MBEDTLS_X509_LIB mbedx509) 6 | find_library(MBEDTLS_CRYPTO_LIB mbedcrypto) 7 | 8 | set(MBEDTLS_LIBS "${MBEDTLS_TLS_LIB}" "${MBEDTLS_X509_LIB}" "${MBEDTLS_CRYPTO_LIB}") 9 | 10 | include(FindPackageHandleStandardArgs) 11 | find_package_handle_standard_args(MBEDTLS DEFAULT_MSG MBEDTLS_TLS_LIB MBEDTLS_X509_LIB MBEDTLS_CRYPTO_LIB MBEDTLS_INCLUDE_DIR) 12 | 13 | mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDTLS_TLS_LIB MBEDTLS_X509_LIB MBEDTLS_CRYPTO_LIB) 14 | -------------------------------------------------------------------------------- /common/ConfigCommon.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file SampleCommon.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | #include "util/memory/stl/String.hpp" 28 | #include "util/JsonParser.hpp" 29 | 30 | namespace awsiotsdk { 31 | class ConfigCommon { 32 | protected: 33 | static util::JsonDocument sdk_config_json_; 34 | 35 | static void LogParseError(const ResponseCode& response_code, const util::JsonDocument& config, util::String key); 36 | public: 37 | static uint16_t endpoint_mqtt_port_; 38 | static uint16_t endpoint_https_port_; 39 | static uint16_t endpoint_greengrass_discovery_port_; 40 | 41 | static util::String endpoint_; 42 | static util::String root_ca_path_; 43 | static util::String client_cert_path_; 44 | static util::String client_key_path_; 45 | static util::String base_client_id_; 46 | static util::String thing_name_; 47 | static util::String aws_region_; 48 | static util::String aws_access_key_id_; 49 | static util::String aws_secret_access_key_; 50 | static util::String aws_session_token_; 51 | 52 | static std::chrono::milliseconds mqtt_command_timeout_; 53 | static std::chrono::milliseconds tls_handshake_timeout_; 54 | static std::chrono::milliseconds tls_read_timeout_; 55 | static std::chrono::milliseconds tls_write_timeout_; 56 | static std::chrono::milliseconds discover_action_timeout_; 57 | static std::chrono::seconds keep_alive_timeout_secs_; 58 | 59 | static bool is_clean_session_; 60 | static std::chrono::seconds minimum_reconnect_interval_; 61 | static std::chrono::seconds maximum_reconnect_interval_; 62 | static size_t max_pending_acks_; 63 | static size_t maximum_outgoing_action_queue_length_; 64 | static uint32_t action_processing_rate_hz_; 65 | 66 | static ResponseCode InitializeCommon(const util::String &config_file_path); 67 | static util::String GetCurrentPath(); 68 | }; 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /common/RobotArmConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "endpoint": "", 3 | "mqtt_port": 8883, 4 | "https_port": 443, 5 | "greengrass_discovery_port": 8443, 6 | "root_ca_relative_path": "", 7 | "device_certificate_relative_path": "", 8 | "device_private_key_relative_path": "", 9 | "tls_handshake_timeout_msecs": 60000, 10 | "tls_read_timeout_msecs": 2000, 11 | "tls_write_timeout_msecs": 2000, 12 | "aws_region": "", 13 | "aws_access_key_id": "", 14 | "aws_secret_access_key": "", 15 | "aws_session_token": "", 16 | "client_id": "RobotArm_Thing", 17 | "thing_name": "RobotArm_Thing", 18 | "is_clean_session": true, 19 | "mqtt_command_timeout_msecs": 20000, 20 | "keepalive_interval_secs": 600, 21 | "minimum_reconnect_interval_secs": 1, 22 | "maximum_reconnect_interval_secs": 128, 23 | "maximum_acks_to_wait_for": 32, 24 | "action_processing_rate_hz": 5, 25 | "maximum_outgoing_action_queue_length": 32, 26 | "discover_action_timeout_msecs": 300000 27 | } 28 | -------------------------------------------------------------------------------- /common/SampleConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "endpoint": "", 3 | "mqtt_port": 8883, 4 | "https_port": 443, 5 | "greengrass_discovery_port": 8443, 6 | "root_ca_relative_path": "certs/rootCA.crt", 7 | "device_certificate_relative_path": "certs/cert.pem", 8 | "device_private_key_relative_path": "certs/privkey.pem", 9 | "tls_handshake_timeout_msecs": 60000, 10 | "tls_read_timeout_msecs": 2000, 11 | "tls_write_timeout_msecs": 2000, 12 | "aws_region": "", 13 | "aws_access_key_id": "", 14 | "aws_secret_access_key": "", 15 | "aws_session_token": "", 16 | "client_id": "CppSDKTesting", 17 | "thing_name": "CppSDKTesting", 18 | "is_clean_session": true, 19 | "mqtt_command_timeout_msecs": 20000, 20 | "keepalive_interval_secs": 600, 21 | "minimum_reconnect_interval_secs": 1, 22 | "maximum_reconnect_interval_secs": 128, 23 | "maximum_acks_to_wait_for": 32, 24 | "action_processing_rate_hz": 5, 25 | "maximum_outgoing_action_queue_length": 32, 26 | "discover_action_timeout_msecs": 300000 27 | } 28 | -------------------------------------------------------------------------------- /common/SwitchConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "endpoint": "", 3 | "mqtt_port": 8883, 4 | "https_port": 443, 5 | "greengrass_discovery_port": 8443, 6 | "root_ca_relative_path": "", 7 | "device_certificate_relative_path": "", 8 | "device_private_key_relative_path": "", 9 | "tls_handshake_timeout_msecs": 60000, 10 | "tls_read_timeout_msecs": 2000, 11 | "tls_write_timeout_msecs": 2000, 12 | "aws_region": "", 13 | "aws_access_key_id": "", 14 | "aws_secret_access_key": "", 15 | "aws_session_token": "", 16 | "client_id": "Switch_Thing", 17 | "thing_name": "Switch_Thing", 18 | "is_clean_session": true, 19 | "mqtt_command_timeout_msecs": 20000, 20 | "keepalive_interval_secs": 600, 21 | "minimum_reconnect_interval_secs": 1, 22 | "maximum_reconnect_interval_secs": 128, 23 | "maximum_acks_to_wait_for": 32, 24 | "action_processing_rate_hz": 5, 25 | "maximum_outgoing_action_queue_length": 32, 26 | "discover_action_timeout_msecs": 300000, 27 | "switch_target_thing": "RobotArm_Thing" 28 | } 29 | -------------------------------------------------------------------------------- /doxygen/doxygen.conf: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "AWS IoT C++ SDK" 2 | 3 | # Generate only HTML documentation 4 | GENERATE_HTML = YES 5 | GENERATE_LATEX = NO 6 | 7 | IMAGE_PATH = doxygen/image/ 8 | 9 | # Output in the build directory 10 | OUTPUT_DIRECTORY = 11 | INPUT = /var/lib/jenkins/workspace/ReleaseToProd/release/../. 12 | 13 | # Scan only the source files that we wish to make part of the public API 14 | EXCLUDE_PATTERNS += */.git/* 15 | EXCLUDE_PATTERNS += */.idea/* 16 | EXCLUDE_PATTERNS += */build/* 17 | EXCLUDE_PATTERNS += */certs/* 18 | EXCLUDE_PATTERNS += */cli/* 19 | EXCLUDE_PATTERNS += */doxygen/* 20 | EXCLUDE_PATTERNS += */network/* 21 | EXCLUDE_PATTERNS += */samples/* 22 | EXCLUDE_PATTERNS += */tests/* 23 | EXCLUDE_SYMLINKS = YES # Skip build directory 24 | RECURSIVE = YES # Suck up everything 25 | FILE_PATTERNS = *.hpp *.cpp *.md 26 | 27 | # General settings for formatting 28 | BUILTIN_STL_SUPPORT = YES # Simplify STL documentation 29 | REPEAT_BRIEF = NO 30 | SORT_NAMES = YES 31 | GENERATE_DEPRECATEDLIST = YES 32 | GENERATE_TODOLIST = YES 33 | WARN_IF_UNDOCUMENTED = YES # Encourage good documentation 34 | WARN_NO_PARAMDOC = YES # Encourage good documentation 35 | 36 | 37 | # Settings for Package Directory friendliness 38 | SOURCE_BROWSER = NO # Will not work in Package Directory ATM 39 | REFERENCES_LINK_SOURCE = NO # Will not work in Package Directory ATM 40 | SHOW_USED_FILES = NO # Will not work in Package Directory ATM 41 | FULL_PATH_NAMES = NO # Use relative paths 42 | 43 | HAVE_DOT = NO 44 | INCLUDE_GRAPH = NO 45 | OPTIMIZE_OUTPUT_FOR_C = YES 46 | USE_MDFILE_AS_MAINPAGE = README.md 47 | MARKDOWN_SUPPORT = YES 48 | -------------------------------------------------------------------------------- /doxygen/doxygen.conf.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "AWS IoT C++ SDK" 2 | 3 | # Generate only HTML documentation 4 | GENERATE_HTML = YES 5 | GENERATE_LATEX = NO 6 | 7 | IMAGE_PATH = doxygen/image/ 8 | 9 | # Output in the build directory 10 | OUTPUT_DIRECTORY = @DOC_OUTPUT_DIR@ 11 | INPUT = @DOC_SOURCE_DIR@ 12 | 13 | # Scan only the source files that we wish to make part of the public API 14 | EXCLUDE_PATTERNS += */.git/* 15 | EXCLUDE_PATTERNS += */.idea/* 16 | EXCLUDE_PATTERNS += */build/* 17 | EXCLUDE_PATTERNS += */certs/* 18 | EXCLUDE_PATTERNS += */cli/* 19 | EXCLUDE_PATTERNS += */doxygen/* 20 | EXCLUDE_PATTERNS += */network/* 21 | EXCLUDE_PATTERNS += */samples/* 22 | EXCLUDE_PATTERNS += */tests/* 23 | EXCLUDE_SYMLINKS = YES # Skip build directory 24 | RECURSIVE = YES # Suck up everything 25 | FILE_PATTERNS = *.hpp *.cpp *.md 26 | 27 | # General settings for formatting 28 | BUILTIN_STL_SUPPORT = YES # Simplify STL documentation 29 | REPEAT_BRIEF = NO 30 | SORT_NAMES = YES 31 | GENERATE_DEPRECATEDLIST = YES 32 | GENERATE_TODOLIST = YES 33 | WARN_IF_UNDOCUMENTED = YES # Encourage good documentation 34 | WARN_NO_PARAMDOC = YES # Encourage good documentation 35 | 36 | 37 | # Settings for Package Directory friendliness 38 | SOURCE_BROWSER = NO # Will not work in Package Directory ATM 39 | REFERENCES_LINK_SOURCE = NO # Will not work in Package Directory ATM 40 | SHOW_USED_FILES = NO # Will not work in Package Directory ATM 41 | FULL_PATH_NAMES = NO # Use relative paths 42 | 43 | HAVE_DOT = NO 44 | INCLUDE_GRAPH = NO 45 | OPTIMIZE_OUTPUT_FOR_C = YES 46 | USE_MDFILE_AS_MAINPAGE = README.md 47 | MARKDOWN_SUPPORT = YES -------------------------------------------------------------------------------- /include/mqtt/ClientState.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file ClientState.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "util/Utf8String.hpp" 27 | #include "util/memory/stl/Map.hpp" 28 | 29 | #include "Action.hpp" 30 | #include "ClientCore.hpp" 31 | 32 | #include "mqtt/Common.hpp" 33 | 34 | namespace awsiotsdk { 35 | namespace mqtt { 36 | class ClientState : public ClientCoreState { 37 | protected: 38 | 39 | bool is_session_present_; 40 | std::atomic_bool is_connected_; 41 | std::atomic_bool is_auto_reconnect_enabled_; 42 | std::atomic_bool is_auto_reconnect_required_; 43 | std::atomic_bool is_pingreq_pending_; 44 | 45 | uint16_t last_sent_packet_id_; 46 | 47 | std::chrono::seconds keep_alive_timeout_; 48 | std::chrono::seconds min_reconnect_backoff_timeout_; 49 | std::chrono::seconds max_reconnect_backoff_timeout_; 50 | std::chrono::milliseconds mqtt_command_timeout_; 51 | 52 | std::shared_ptr p_connect_data_; 53 | 54 | std::atomic_bool trigger_disconnect_callback_; 55 | public: 56 | util::Map> subscription_map_; 57 | 58 | // Rule of 5 stuff 59 | // Disable copying and moving because class contains std::atomic<> types used for thread synchronization 60 | ClientState() = delete; // Default constructor 61 | ClientState(const ClientState &) = delete; // Delete Copy constructor 62 | ClientState(ClientState &&) = delete; // Move constructor 63 | ClientState &operator=(const ClientState &) & = delete; // Delete Copy assignment operator 64 | ClientState &operator=(ClientState &&) & = delete; // Move assignment operator 65 | ~ClientState() = default; // Default destructor 66 | 67 | ClientState(std::chrono::milliseconds mqtt_command_timeout); 68 | static std::shared_ptr Create(std::chrono::milliseconds mqtt_command_timeout); 69 | 70 | bool IsSessionPresent() { return is_session_present_; } 71 | void SetSessionPresent(bool value) { is_session_present_ = value; } 72 | 73 | bool IsConnected() { return is_connected_; } 74 | void SetConnected(bool value) { 75 | is_connected_ = value; 76 | if (value) { 77 | is_auto_reconnect_required_ = false; 78 | } 79 | SetProcessQueuedActions(value); 80 | } 81 | 82 | bool IsAutoReconnectEnabled() { return is_auto_reconnect_enabled_; } 83 | void SetAutoReconnectEnabled(bool value) { is_auto_reconnect_enabled_ = value; } 84 | 85 | bool IsAutoReconnectRequired() { return is_auto_reconnect_required_; } 86 | void SetAutoReconnectRequired(bool value) { is_auto_reconnect_required_ = value; } 87 | 88 | bool IsPingreqPending() { return is_pingreq_pending_; } 89 | void SetPingreqPending(bool value) { is_pingreq_pending_ = value; } 90 | 91 | bool isDisconnectCallbackPending() { return trigger_disconnect_callback_; } 92 | void setDisconnectCallbackPending(bool value) { trigger_disconnect_callback_ = value; } 93 | 94 | virtual uint16_t GetNextPacketId(); 95 | virtual uint16_t GetNextActionId() { return GetNextPacketId(); } 96 | 97 | /** 98 | * @brief Get duration of Keep alive interval in seconds 99 | * @return std::chrono::seconds Keep alive interval duration 100 | */ 101 | std::chrono::seconds GetKeepAliveTimeout() { return keep_alive_timeout_; } 102 | void SetKeepAliveTimeout(std::chrono::seconds keep_alive_timeout) { 103 | keep_alive_timeout_ = keep_alive_timeout; 104 | } 105 | 106 | std::chrono::milliseconds GetMqttCommandTimeout() { return mqtt_command_timeout_; } 107 | void SetMqttCommandTimeout(std::chrono::milliseconds mqtt_command_timeout) { 108 | mqtt_command_timeout_ = mqtt_command_timeout; 109 | } 110 | 111 | std::chrono::seconds GetMinReconnectBackoffTimeout() { return min_reconnect_backoff_timeout_; } 112 | void SetMinReconnectBackoffTimeout(std::chrono::seconds min_reconnect_backoff_timeout) { 113 | min_reconnect_backoff_timeout_ = min_reconnect_backoff_timeout; 114 | } 115 | 116 | std::chrono::seconds GetMaxReconnectBackoffTimeout() { return max_reconnect_backoff_timeout_; } 117 | void SetMaxReconnectBackoffTimeout(std::chrono::seconds max_reconnect_backoff_timeout) { 118 | max_reconnect_backoff_timeout_ = max_reconnect_backoff_timeout; 119 | } 120 | 121 | std::shared_ptr GetAutoReconnectData() { return p_connect_data_; } 122 | void SetAutoReconnectData(std::shared_ptr p_connect_data) { p_connect_data_ = p_connect_data; } 123 | 124 | std::shared_ptr GetSubscription(util::String p_topic_name); 125 | 126 | std::shared_ptr SetSubscriptionPacketInfo(util::String p_topic_name, 127 | uint16_t packet_id, 128 | uint8_t index_in_packet); 129 | 130 | ResponseCode SetSubscriptionActive(uint16_t packet_id, uint8_t index_in_sub_packet, mqtt::QoS max_qos); 131 | 132 | ResponseCode RemoveSubscription(uint16_t packet_id, uint8_t index_in_sub_packet); 133 | 134 | ResponseCode RemoveAllSubscriptionsForPacketId(uint16_t packet_id); 135 | 136 | ResponseCode RemoveSubscription(util::String p_topic_name); 137 | }; 138 | } 139 | } 140 | 141 | -------------------------------------------------------------------------------- /include/mqtt/Packet.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Packet.hpp 18 | * @brief 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "util/Utf8String.hpp" 28 | 29 | #include "Action.hpp" 30 | #include "ResponseCode.hpp" 31 | #include "NetworkConnection.hpp" 32 | 33 | #include "mqtt/Common.hpp" 34 | 35 | namespace awsiotsdk { 36 | namespace mqtt { 37 | /** 38 | * @brief Define a class for the MQTT Fixed header 39 | */ 40 | class PacketFixedHeader { 41 | private: 42 | MessageTypes message_type_; ///< Message type for this Fixed Header instance 43 | unsigned char fixed_header_byte_; ///< Unsigned char byte to store in required formate 44 | size_t remaining_length_; ///< Remaining Length 45 | bool is_valid_; ///< Is this header valid/has been initialized? 46 | 47 | public: 48 | /** 49 | * @brief Constructor 50 | * @return Initializes the fixed header with default values, sets is_valid_ to false 51 | */ 52 | PacketFixedHeader(); 53 | 54 | /** 55 | * @brief Initialize the fixed header with provided values. Checks for validity 56 | * 57 | * @param message_type MQTT message type 58 | * @param is_duplicate Is this a duplicate message (For publish messages) 59 | * @param qos QoS to use for this message (For publish messages) 60 | * @param is_retained MQTT is retained flag (For publish messages) 61 | * @param rem_len Remaining length 62 | * 63 | * @return ResponseCode indicating status of request 64 | */ 65 | ResponseCode Initialize(MessageTypes message_type, bool is_duplicate, QoS qos, bool is_retained, 66 | size_t rem_len); 67 | 68 | /** 69 | * @brief Is this a valid fixed header? 70 | * 71 | * @return boolean indicating validity 72 | */ 73 | bool isHeaderValid(); 74 | 75 | /** 76 | * @brief Get message type 77 | * 78 | * @return Message type 79 | */ 80 | MessageTypes GetMessageType(); 81 | 82 | /** 83 | * @brief Get remaining length 84 | * @return Remaining length 85 | */ 86 | size_t GetRemainingLength() { return remaining_length_; } 87 | 88 | /** 89 | * @brief Get number of bytes required to store remaining length 90 | * @return Number of butes required to store remaining length 91 | */ 92 | size_t GetRemainingLengthByteCount(); 93 | 94 | /** 95 | * @brief Get length of the fixed header 96 | * @return Length 97 | */ 98 | size_t Length() { 99 | return GetRemainingLengthByteCount() + 1; 100 | } 101 | 102 | /** 103 | * @brief Append this header to a string 104 | * 105 | * @param p_buf Reference to target string 106 | */ 107 | void AppendToBuffer(util::String &p_buf); 108 | }; 109 | 110 | /** 111 | * @brief Define a base class for all MQTT Packet types 112 | */ 113 | class Packet : public ActionData { 114 | protected: 115 | PacketFixedHeader fixed_header_; ///< Fixed header for this packet instance 116 | size_t packet_size_; ///< Size of the packet 117 | size_t serialized_packet_length_; ///< Serialized length of the entire packet including fixed header 118 | std::atomic_uint_fast16_t packet_id_; ///< Message sequence identifier. Handled automatically by the MQTT client 119 | 120 | public: 121 | // Rule of 5 stuff 122 | // Disable copying and moving because class contains std::atomic<> types used for thread synchronization 123 | Packet() = default; // Default constructor 124 | Packet(const Packet &) = delete; // Copy constructor 125 | Packet(Packet &&) = delete; // Move constructor 126 | Packet &operator=(const Packet &) & = delete; // Copy assignment operator 127 | Packet &operator=(Packet &&) & = delete; // Move assignment operator 128 | virtual ~Packet() = default; // Default destructor 129 | 130 | uint16_t GetActionId() { return (uint16_t) packet_id_.load(std::memory_order_relaxed); } 131 | void SetActionId(uint16_t action_id) { packet_id_.store(action_id, std::memory_order_relaxed); } 132 | bool isPacketDataValid(); 133 | 134 | uint16_t GetPacketId() { return (uint16_t) packet_id_.load(std::memory_order_relaxed); } 135 | void SetPacketId(uint16_t packet_id) { packet_id_.store(packet_id, std::memory_order_relaxed); } 136 | 137 | size_t Size() { return serialized_packet_length_; } 138 | 139 | static void AppendUInt16ToBuffer(util::String &buf, uint16_t value); 140 | static void AppendUtf8StringToBuffer(util::String &buf, std::unique_ptr &utf8_str); 141 | static void AppendUtf8StringToBuffer(util::String &buf, std::shared_ptr &utf8_str); 142 | 143 | static uint16_t ReadUInt16FromBuffer(const util::Vector &buf, size_t &extract_index); 144 | static std::unique_ptr ReadUtf8StringFromBuffer(const util::Vector &buf, 145 | size_t &extract_index); 146 | 147 | virtual util::String ToString() = 0; 148 | }; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /include/util/Core_EXPORTS.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #pragma once 17 | 18 | #if defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) 19 | #ifdef _MSC_VER 20 | #pragma warning(disable : 4251) 21 | #endif // _MSC_VER 22 | 23 | #ifdef USE_EXPORT 24 | #define AWS_API_EXPORT __declspec(dllexport) 25 | #else // USE_EXPORT 26 | #define AWS_API_EXPORT 27 | #endif // USE_EXPORT 28 | #else // defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) 29 | #define AWS_API_EXPORT 30 | #endif // defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) 31 | 32 | -------------------------------------------------------------------------------- /include/util/JsonParser.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file JsonParser.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "util/memory/stl/String.hpp" 28 | #include "ResponseCode.hpp" 29 | 30 | #define MAX_CONFIG_FILE_SIZE_BYTES 4096 //Increase if adding more configuration options 31 | 32 | namespace awsiotsdk { 33 | namespace util { 34 | using JsonDocument = rapidjson::Document; 35 | using JsonValue = rapidjson::Value; 36 | 37 | class JsonParser { 38 | public: 39 | static ResponseCode InitializeFromJsonFile(JsonDocument &json_document, 40 | const util::String &input_file_path); 41 | 42 | static ResponseCode InitializeFromJsonString(JsonDocument &json_document, 43 | const util::String &input_json_string); 44 | 45 | static ResponseCode GetBoolValue(const JsonDocument &json_document, const char *key, bool &value); 46 | 47 | static ResponseCode GetIntValue(const JsonDocument &json_document, const char *key, int &value); 48 | 49 | static ResponseCode GetUint16Value(const JsonDocument &json_document, const char *key, 50 | uint16_t &value); 51 | 52 | static ResponseCode GetUint32Value(const JsonDocument &json_document, const char *key, 53 | uint32_t &value); 54 | 55 | static ResponseCode GetSizeTValue(const JsonDocument &json_document, const char *key, size_t &value); 56 | 57 | static ResponseCode GetCStringValue(const JsonDocument &json_document, const char *key, char *value, 58 | uint16_t max_string_len); 59 | 60 | static ResponseCode GetStringValue(const JsonDocument &json_document, const char *key, 61 | util::String &value); 62 | 63 | static rapidjson::ParseErrorCode GetParseErrorCode(const JsonDocument &json_document); 64 | 65 | static size_t GetParseErrorOffset(const JsonDocument &json_document); 66 | 67 | static ResponseCode MergeValues(JsonValue &target, JsonValue &source, JsonValue::AllocatorType &allocator); 68 | 69 | static ResponseCode DiffValues(JsonValue &target_doc, 70 | JsonValue &old_doc, 71 | JsonValue &new_doc, 72 | JsonValue::AllocatorType &allocator); 73 | 74 | static util::String ToString(JsonDocument &json_document); 75 | 76 | static util::String ToString(JsonValue &json_value); 77 | 78 | static ResponseCode WriteToFile(JsonDocument &json_document, const util::String &output_file_path); 79 | }; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /include/util/Utf8String.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Utf8String.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include "util/memory/stl/String.hpp" 26 | 27 | namespace awsiotsdk { 28 | class Utf8String { 29 | protected: 30 | util::String data; 31 | std::size_t length; 32 | 33 | Utf8String(util::String str); 34 | 35 | Utf8String(const char *str, std::size_t length); 36 | 37 | static bool IsValidInput(util::String str); 38 | 39 | static bool IsValidInput(const char *str, std::size_t length); 40 | 41 | public: 42 | // Rule of 5 stuff 43 | // Disabling default constructor while keeping defaults for the rest 44 | Utf8String() = delete; // Delete Default constructor 45 | Utf8String(const Utf8String &) = default; // Copy constructor 46 | Utf8String(Utf8String &&) = default; // Move constructor 47 | Utf8String &operator=(const Utf8String &) & = default; // Copy assignment operator 48 | Utf8String &operator=(Utf8String &&) & = default; // Move assignment operator 49 | ~Utf8String() = default; // Default destructor 50 | 51 | static std::unique_ptr Create(util::String str); 52 | 53 | static std::unique_ptr Create(const char *str, std::size_t length); 54 | 55 | std::size_t Length(); 56 | 57 | util::String ToStdString(); 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /include/util/logging/ConsoleLogSystem.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file ConsoleLogSystem.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "util/logging/FormattedLogSystem.hpp" 25 | #include "util/Core_EXPORTS.hpp" 26 | 27 | namespace awsiotsdk { 28 | namespace util { 29 | namespace Logging { 30 | /** 31 | * Log system interface that logs to std::cout 32 | */ 33 | class AWS_API_EXPORT ConsoleLogSystem : public FormattedLogSystem { 34 | public: 35 | 36 | using Base = FormattedLogSystem; 37 | 38 | ConsoleLogSystem(LogLevel logLevel) : 39 | Base(logLevel) {} 40 | 41 | virtual ~ConsoleLogSystem() {} 42 | 43 | protected: 44 | 45 | virtual void ProcessFormattedStatement(util::String &&statement) override; 46 | }; 47 | 48 | } // namespace Logging 49 | } // namespace util 50 | } // namespace awsiotsdk 51 | -------------------------------------------------------------------------------- /include/util/logging/FormattedLogSystem.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file FormattedLogSystem.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "util/Core_EXPORTS.hpp" 25 | #include "util/logging/LogSystemInterface.hpp" 26 | #include "util/logging/LogLevel.hpp" 27 | 28 | #include 29 | 30 | namespace awsiotsdk { 31 | namespace util { 32 | namespace Logging { 33 | /** 34 | * Logger that formats log messages into [LEVEL] timestamp [threadid] message 35 | */ 36 | class AWS_API_EXPORT FormattedLogSystem : public LogSystemInterface { 37 | public: 38 | using Base = LogSystemInterface; 39 | 40 | /** 41 | * Initializes log system with logLevel 42 | */ 43 | FormattedLogSystem(LogLevel logLevel); 44 | 45 | virtual ~FormattedLogSystem() = default; 46 | 47 | /** 48 | * Gets the currently configured log level. 49 | */ 50 | virtual LogLevel GetLogLevel(void) const override { return m_logLevel; } 51 | 52 | /** 53 | * Set a new log level. This has the immediate effect of changing the log output to the new level. 54 | */ 55 | void SetLogLevel(LogLevel logLevel) { m_logLevel.store(logLevel); } 56 | 57 | /** 58 | * Does a printf style output to ProcessFormattedStatement. Don't use this, it's unsafe. See LogStream 59 | */ 60 | virtual void Log(LogLevel logLevel, const char *tag, const char *function, unsigned int line, 61 | const char *formatStr, ...) override; 62 | 63 | /** 64 | * Writes the stream to ProcessFormattedStatement. 65 | */ 66 | virtual void LogStream(LogLevel logLevel, 67 | const char *tag, 68 | const util::OStringStream &messageStream) override; 69 | 70 | protected: 71 | /** 72 | * This is the method that most logger implementations will want to override. 73 | * At this point the message is formatted and is ready to go to the output stream 74 | */ 75 | virtual void ProcessFormattedStatement(util::String &&statement) = 0; 76 | 77 | private: 78 | std::atomic m_logLevel; 79 | }; 80 | 81 | } // namespace Logging 82 | } // namespace util 83 | } // namespace awsiotsdk 84 | -------------------------------------------------------------------------------- /include/util/logging/LogLevel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file LogLevel.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "util/Core_EXPORTS.hpp" 25 | #include "util/memory/stl/String.hpp" 26 | 27 | namespace awsiotsdk { 28 | namespace util { 29 | namespace Logging { 30 | /** 31 | * LogLevel used to control verbosity of logging system. 32 | */ 33 | enum class LogLevel : int { 34 | Off = 0, 35 | Fatal = 1, 36 | Error = 2, 37 | Warn = 3, 38 | Info = 4, 39 | Debug = 5, 40 | Trace = 6 41 | }; 42 | 43 | AWS_API_EXPORT util::String GetLogLevelName(LogLevel logLevel); 44 | } // namespace Logging 45 | } // namespace util 46 | } // namespace awsiotsdk 47 | -------------------------------------------------------------------------------- /include/util/logging/LogSystemInterface.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file LogSystemInterface.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "util/Core_EXPORTS.hpp" 25 | #include "util/memory/stl/String.hpp" 26 | #include "util/memory/stl/StringStream.hpp" 27 | 28 | namespace awsiotsdk { 29 | namespace util { 30 | namespace Logging { 31 | enum class LogLevel : int; 32 | 33 | /** 34 | * Interface for logging implementations. If you want to write your own logger, you can start here, though you may have more 35 | * luck going down one more level to FormattedLogSystem. It does a bit more of the work for you and still gives you the ability 36 | * to override the IO portion. 37 | */ 38 | class AWS_API_EXPORT LogSystemInterface { 39 | public: 40 | virtual ~LogSystemInterface() = default; 41 | 42 | /** 43 | * Gets the currently configured log level for this logger. 44 | */ 45 | virtual LogLevel GetLogLevel(void) const = 0; 46 | 47 | /** 48 | * Does a printf style output to the output stream. Don't use this, it's unsafe. See LogStream 49 | */ 50 | virtual void Log(LogLevel logLevel, const char *tag, const char *function, unsigned int line, const char *formatStr, ...) = 0; 51 | 52 | /** 53 | * Writes the stream to the output stream. 54 | */ 55 | virtual void LogStream(LogLevel logLevel, 56 | const char *tag, 57 | const util::OStringStream &messageStream) = 0; 58 | }; 59 | 60 | } // namespace Logging 61 | } // namespace util 62 | } // namespace awsiotsdk 63 | -------------------------------------------------------------------------------- /include/util/logging/Logging.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Logging.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include "util/Core_EXPORTS.hpp" 26 | 27 | namespace awsiotsdk { 28 | namespace util { 29 | namespace Logging { 30 | class LogSystemInterface; 31 | 32 | // Standard interface 33 | 34 | /** 35 | * Call this at the beginning of your program, prior to any AWS calls. 36 | */ 37 | AWS_API_EXPORT void InitializeAWSLogging(const std::shared_ptr &logSystem); 38 | 39 | /** 40 | * Call this at the exit point of your program, after all calls have finished. 41 | */ 42 | AWS_API_EXPORT void ShutdownAWSLogging(void); 43 | 44 | /** 45 | * Get currently configured log system instance. 46 | */ 47 | AWS_API_EXPORT LogSystemInterface *GetLogSystem(); 48 | 49 | // Testing interface 50 | 51 | /** 52 | * Replaces the current logger with a new one, while pushing the old one onto a 1-deep stack; primarily for testing 53 | */ 54 | AWS_API_EXPORT void PushLogger(const std::shared_ptr &logSystem); 55 | 56 | /** 57 | * Pops the logger off the logger stack and replaces the current logger with it. Disables logging if the top logger is actually a nullptr 58 | */ 59 | AWS_API_EXPORT void PopLogger(); 60 | 61 | } // namespace Logging 62 | } // namespace util 63 | } // namespace awsiotsdk 64 | -------------------------------------------------------------------------------- /include/util/memory/stl/Map.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Map.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace awsiotsdk { 27 | namespace util { 28 | template using Map = std::map; 29 | } // namespace util 30 | } // namespace awsiotsdk 31 | -------------------------------------------------------------------------------- /include/util/memory/stl/Queue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Queue.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "util/Core_EXPORTS.hpp" 26 | 27 | #include 28 | #include 29 | 30 | namespace awsiotsdk { 31 | namespace util { 32 | template using Queue = std::queue; 33 | } // namespace util 34 | } // namespace awsiotsdk 35 | -------------------------------------------------------------------------------- /include/util/memory/stl/String.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file String.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "util/Core_EXPORTS.hpp" 25 | #include 26 | #include 27 | 28 | namespace awsiotsdk { 29 | namespace util { 30 | using String = std::basic_string>; 31 | 32 | #ifdef _WIN32 33 | using WString = std::basic_string>; 34 | #endif 35 | } // namespace util 36 | } // namespace awsiotsdk 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /include/util/memory/stl/StringStream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file StringStream.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "util/Core_EXPORTS.hpp" 25 | 26 | #include 27 | 28 | namespace awsiotsdk { 29 | namespace util { 30 | typedef std::basic_stringstream > StringStream; 31 | typedef std::basic_istringstream > IStringStream; 32 | typedef std::basic_ostringstream > OStringStream; 33 | typedef std::basic_stringbuf > StringBuf; 34 | } // namespace util 35 | } // namespace awsiotsdk 36 | -------------------------------------------------------------------------------- /include/util/memory/stl/Vector.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Vector.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "util/Core_EXPORTS.hpp" 25 | #include 26 | 27 | namespace awsiotsdk { 28 | namespace util { 29 | template using Vector = std::vector; 30 | } // namespace util 31 | } // namespace awsiotsdk 32 | -------------------------------------------------------------------------------- /include/util/threading/ThreadTask.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file ActionThread.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "util/Core_EXPORTS.hpp" 29 | 30 | #include "NetworkConnection.hpp" 31 | #include "Action.hpp" 32 | 33 | namespace awsiotsdk { 34 | namespace util { 35 | namespace Threading { 36 | enum class DestructorAction { 37 | JOIN, 38 | DETACH 39 | }; 40 | 41 | class AWS_API_EXPORT ThreadTask { 42 | public: 43 | ThreadTask(DestructorAction destructor_action, std::shared_ptr sync_point, 44 | util::String thread_descriptor); 45 | ~ThreadTask(); 46 | 47 | // Rule of 5 stuff. 48 | // Don't copy or move 49 | ThreadTask(const ThreadTask &) = delete; 50 | ThreadTask &operator=(const ThreadTask &) = delete; 51 | ThreadTask(ThreadTask &&) = delete; 52 | ThreadTask &operator=(ThreadTask &&) = delete; 53 | 54 | template 55 | void Run(Fn &&fn, Args &&... args) { 56 | m_thread_ = std::thread(std::bind(std::forward(fn), std::forward(args)...)); 57 | } 58 | 59 | void Stop(); 60 | private: 61 | DestructorAction destructor_action_; 62 | std::shared_ptr m_continue_; 63 | std::thread m_thread_; 64 | util::String thread_descriptor_; 65 | }; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /network/CMakeLists-mbedtls.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | project(mbedtls-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(mbedtls 7 | GIT_REPOSITORY https://github.com/ARMmbed/mbedtls.git 8 | GIT_TAG mbedtls-2.6.0 9 | SOURCE_DIR "${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/mbedtls/src" 10 | BINARY_DIR "${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/mbedtls/build" 11 | CONFIGURE_COMMAND "" 12 | BUILD_COMMAND "" 13 | INSTALL_COMMAND "" 14 | TEST_COMMAND "" 15 | ) 16 | -------------------------------------------------------------------------------- /network/README.md: -------------------------------------------------------------------------------- 1 | ## Network Layer Implementation Guide 2 | 3 | ### Design 4 | The Network interface for the SDK has been designed to give control of how the Network is initialized to the application. The SDK provides a base class for [Network Connection](https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/include/NetworkConnection.hpp). The SDK itself interacts with shared_ptr instances of Concrete implementations of this base class. 5 | 6 | The SDK will only ever call the functions that are defined in the NetworkConnection base class as public members. The only exception to this is the Destroy function. Further description of each function's purpose is below. Each Network function should return a certain set of Response Codes that the SDK will understand and process. All other codes are treated as unknown and a disconnect occurs. 7 | 8 | ### APIs 9 | The Network Base class defines the following functions that are a Concrete implementation is required to provide: 10 | 11 | * virtual bool IsConnected() - Pure virtual function, public, directly called by SDK, implementation should return the state of the underlying Network Connection 12 | * virtual bool IsPhysicalLayerConnected() - Pure virtual function, public, directly called by SDK, implementation should return the state of the Network itself. Used to determine if a connection attempt is even possible at this time. This is an optional call and provided for convenience. The reference implementations simply returns true 13 | * virtual ResponseCode ConnectInternal() - Pure virtual function, Protected, Not called by SDK directly. This function should contain the Connect implementation. It will also be used for auto-reconnect 14 | * virtual ResponseCode WriteInternal(const util::String &buf, size_t &size_written_bytes_out) - Pure virtual function, Protected, Not called by SDK directly. This function function is used for Write operations. 15 | * virtual ResponseCode ReadInternal(util::Vector &buf, size_t buf_read_offset, size_t size_bytes_to_read, size_t &size_read_bytes_out) - Pure virtual function, Protected, Not called by SDK directly. This function is used for Read operations. The buffer is resized to size_bytes_to_read before it is passed to the function. The size of the buffer should not be updated before returning. 16 | * virtual ResponseCode DisconnectInternal() - Pure virtual function, Protected, Not called by SDK directly. This function should Disconnect the TLS layer but should not destroy the instance. The SDK expects to be able to call Connect afterwards to perform a Reconnect if required. For complete cleanup, please use destructor 17 | 18 | It also defines the following functions that are called by the SDK: 19 | * virtual ResponseCode Connect() final - Final function. Implementation in base class blocks on obtaining read and write locks. Calls ConnectInternal when successful. 20 | * virtual ResponseCode Write(const util::String &buf, size_t &size_written_bytes_out) final - Final function. Implementation in base class blocks on obtaining write lock. It then verifies if the Network is Connected and if it is, calls WriteInternal. 21 | * virtual ResponseCode Read(util::Vector &buf, size_t buf_read_offset, size_t size_bytes_to_read, size_t &size_read_bytes_out) final - Final function. Implementation in base class blocks on obtaining read lock. It then verifies if the Network is Connected and if it is, calls ReadInternal. 22 | * virtual ResponseCode Disconnect() final - Final function. Checks if Network is connected. Returns error if it isn't. Calls DisconnectInternal if connected. 23 | 24 | ### Response Codes 25 | The [ResponseCode](https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/include/ResponseCode.hpp) enum class contains strongly typed Response Codes used by the SDK. They are divided into sections. The NetworkConnection implementations are expected to return response codes defined in the below sections 26 | 27 | * Network Success Codes (Values in the +200 range) 28 | * Generic Response Codes (Values in the 0 - 99 range). Please be aware that anything except SUCCESS here would be treated as a reason to Reconnect or Failed request as appropriate 29 | * Network TCP Error Codes (Values in the 300-399 range) 30 | * Network SSL Error Codes (Values in the 400-499 range) 31 | * Network Generic Error Codes (Values in the 500-599 range) 32 | 33 | Any unexpected behavior is always treated as an issue with the Network Connection at the moment and a Reconnect occurs. 34 | 35 | ### Thread Safety 36 | Since the SDK itself cannot guarantee thread safety within the Network libraries that are being used, we apply mutex guards at the Base class level. Only one read and one write request can be in progress at a time. 37 | 38 | ### ALPN 39 | AWS IoT supports connections using MQTT over TLS on port 443. This requires that ALPN support be enabled in the TLS layer. The provided reference network layers for MbedTLS and OpenSSL provide an additional constructor that allows enabling ALPN when port 443 is being used. The MBEDTLS_SSL_ALPN macro should be uncommented (which it is by default) in MbedTLS [config.h](https://github.com/ARMmbed/mbedtls/blob/development/include/mbedtls/config.h) to enable ALPN. 40 | -------------------------------------------------------------------------------- /network/WebSocket/wslay/wslay_frame.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAY_FRAME_H 26 | #define WSLAY_FRAME_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include "wslay.hpp" 33 | 34 | enum wslay_frame_state { 35 | PREP_HEADER, 36 | SEND_HEADER, 37 | SEND_PAYLOAD, 38 | RECV_HEADER1, 39 | RECV_PAYLOADLEN, 40 | RECV_EXT_PAYLOADLEN, 41 | RECV_MASKKEY, 42 | RECV_PAYLOAD 43 | }; 44 | 45 | struct wslay_frame_opcode_memo { 46 | uint8_t fin; 47 | uint8_t opcode; 48 | uint8_t rsv; 49 | }; 50 | 51 | struct wslay_frame_context { 52 | uint8_t ibuf[4096]; 53 | uint8_t *ibufmark; 54 | uint8_t *ibuflimit; 55 | struct wslay_frame_opcode_memo iom; 56 | uint64_t ipayloadlen; 57 | uint64_t ipayloadoff; 58 | uint8_t imask; 59 | uint8_t imaskkey[4]; 60 | enum wslay_frame_state istate; 61 | size_t ireqread; 62 | 63 | uint8_t oheader[14]; 64 | uint8_t *oheadermark; 65 | uint8_t *oheaderlimit; 66 | uint64_t opayloadlen; 67 | uint64_t opayloadoff; 68 | uint8_t omask; 69 | uint8_t omaskkey[4]; 70 | enum wslay_frame_state ostate; 71 | 72 | struct wslay_frame_callbacks callbacks; 73 | void *user_data; 74 | }; 75 | 76 | #endif /* WSLAY_FRAME_H */ 77 | -------------------------------------------------------------------------------- /network/WebSocket/wslay/wslay_net.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "wslay_net.hpp" 26 | 27 | #ifndef WORDS_BIGENDIAN 28 | 29 | uint64_t wslay_byteswap64(uint64_t x) { 30 | uint64_t u = ntohl(x & 0xffffffffllu); 31 | uint64_t l = ntohl(x >> 32); 32 | return (u << 32) | l; 33 | } 34 | 35 | #endif /* !WORDS_BIGENDIAN */ 36 | -------------------------------------------------------------------------------- /network/WebSocket/wslay/wslay_net.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Wslay - The WebSocket Library 3 | * 4 | * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef WSLAY_NET_H 26 | #define WSLAY_NET_H 27 | 28 | #include "wslay.hpp" 29 | #include "OpenSSLConnection.hpp" 30 | 31 | #ifdef WORDS_BIGENDIAN 32 | # define ntoh64(x) (x) 33 | # define hton64(x) (x) 34 | #else /* !WORDS_BIGENDIAN */ 35 | uint64_t wslay_byteswap64(uint64_t x); 36 | # define ntoh64(x) wslay_byteswap64(x) 37 | # define hton64(x) wslay_byteswap64(x) 38 | #endif /* !WORDS_BIGENDIAN */ 39 | 40 | #endif /* WSLAY_NET_H */ 41 | -------------------------------------------------------------------------------- /samples/Discovery/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-samples CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | if (NOT ${NETWORK_LIBRARY} STREQUAL "OpenSSL") 13 | message(WARNING "Discovery Sample compiles only with OpenSSL, skipping build") 14 | return() 15 | endif () 16 | 17 | ######################################## 18 | # Section : Common Build setttings # 19 | ######################################## 20 | # Set required compiler standard to standard c++11. Disable extensions. 21 | set(CMAKE_CXX_STANDARD 11) # C++11... 22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 23 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 24 | 25 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 26 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 27 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 28 | 29 | # Configure Compiler flags 30 | if (UNIX AND NOT APPLE) 31 | # Prefer pthread if found 32 | set(THREADS_PREFER_PTHREAD_FLAG ON) 33 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 34 | elseif (APPLE) 35 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 36 | elseif (WIN32) 37 | set(CUSTOM_COMPILER_FLAGS "/W4") 38 | endif () 39 | 40 | ################################ 41 | # Target : Build Discovery sample # 42 | ################################ 43 | set(DISCOVERY_SAMPLE_TARGET_NAME discovery-sample) 44 | # Add Target 45 | add_executable(${DISCOVERY_SAMPLE_TARGET_NAME} "${PROJECT_SOURCE_DIR}/Discovery.cpp;${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 46 | 47 | # Add Target specific includes 48 | target_include_directories(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common) 49 | target_include_directories(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) 50 | 51 | # Configure Threading library 52 | find_package(Threads REQUIRED) 53 | 54 | # Add SDK includes 55 | target_include_directories(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src/include) 56 | target_include_directories(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 57 | 58 | target_link_libraries(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC "Threads::Threads") 59 | target_link_libraries(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 60 | 61 | # Copy Json config file 62 | add_custom_command(TARGET ${DISCOVERY_SAMPLE_TARGET_NAME} POST_BUILD 63 | COMMAND ${CMAKE_COMMAND} -E 64 | copy ${PROJECT_SOURCE_DIR}/../../common/SampleConfig.json $/config/SampleConfig.json) 65 | set_property(TARGET ${DISCOVERY_SAMPLE_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 66 | 67 | # Gather list of all .cert files in "/cert" 68 | add_custom_command(TARGET ${DISCOVERY_SAMPLE_TARGET_NAME} PRE_BUILD 69 | COMMAND ${CMAKE_COMMAND} -E 70 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs $/certs) 71 | 72 | if (MSVC) 73 | target_sources(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 74 | source_group("Header Files\\Samples\\Discovery" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 75 | source_group("Source Files\\Samples\\Discovery" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 76 | 77 | target_sources(${DISCOVERY_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/Discovery.hpp) 78 | source_group("Header Files\\Samples\\Discovery" FILES ${PROJECT_SOURCE_DIR}/Discovery.hpp) 79 | source_group("Source Files\\Samples\\Discovery" FILES ${PROJECT_SOURCE_DIR}/Discovery.cpp) 80 | endif () 81 | 82 | ######################### 83 | # Add Network libraries # 84 | ######################### 85 | 86 | set(NETWORK_WRAPPER_DEST_TARGET ${DISCOVERY_SAMPLE_TARGET_NAME}) 87 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) 88 | -------------------------------------------------------------------------------- /samples/Discovery/Discovery.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Discovery.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/GreengrassMqttClient.hpp" 26 | #include "NetworkConnection.hpp" 27 | #include "discovery/DiscoveryResponse.hpp" 28 | 29 | namespace awsiotsdk { 30 | namespace samples { 31 | class Discovery { 32 | protected: 33 | std::shared_ptr p_network_connection_; 34 | std::atomic_int cur_pending_messages_; 35 | std::atomic_int total_published_messages_; 36 | std::shared_ptr p_iot_client_; 37 | 38 | ResponseCode RunPublish(int msg_count); 39 | ResponseCode SubscribeCallback(util::String topic_name, 40 | util::String payload, 41 | std::shared_ptr p_app_handler_data); 42 | ResponseCode Subscribe(); 43 | ResponseCode Unsubscribe(); 44 | static bool ConnectivitySortFunction(ConnectivityInfo info1, ConnectivityInfo info2); 45 | 46 | public: 47 | ResponseCode RunSample(); 48 | }; 49 | } 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /samples/Jobs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-samples CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | ######################################## 13 | # Section : Common Build setttings # 14 | ######################################## 15 | # Set required compiler standard to standard c++11. Disable extensions. 16 | set(CMAKE_CXX_STANDARD 11) # C++11... 17 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 18 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 19 | 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 23 | 24 | # Configure Compiler flags 25 | if (UNIX AND NOT APPLE) 26 | # Prefer pthread if found 27 | set(THREADS_PREFER_PTHREAD_FLAG ON) 28 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 29 | elseif (APPLE) 30 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 31 | elseif (WIN32) 32 | set(CUSTOM_COMPILER_FLAGS "/W4") 33 | endif () 34 | 35 | ################################ 36 | # Target : Build Jobs sample # 37 | ################################ 38 | set(JOBS_SAMPLE_TARGET_NAME jobs-sample) 39 | # Add Target 40 | add_executable(${JOBS_SAMPLE_TARGET_NAME} "${PROJECT_SOURCE_DIR}/JobsSample.cpp;${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 41 | 42 | # Add Target specific includes 43 | target_include_directories(${JOBS_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common) 44 | target_include_directories(${JOBS_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) 45 | 46 | # Configure Threading library 47 | find_package(Threads REQUIRED) 48 | 49 | # Add SDK includes 50 | target_include_directories(${JOBS_SAMPLE_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src/include) 51 | target_include_directories(${JOBS_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 52 | 53 | target_link_libraries(${JOBS_SAMPLE_TARGET_NAME} PUBLIC "Threads::Threads") 54 | target_link_libraries(${JOBS_SAMPLE_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 55 | 56 | # Copy Json config file 57 | add_custom_command(TARGET ${JOBS_SAMPLE_TARGET_NAME} POST_BUILD 58 | COMMAND ${CMAKE_COMMAND} -E 59 | copy ${PROJECT_SOURCE_DIR}/../../common/SampleConfig.json $/config/SampleConfig.json) 60 | set_property(TARGET ${JOBS_SAMPLE_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 61 | 62 | # Gather list of all .cert files in "/cert" 63 | add_custom_command(TARGET ${JOBS_SAMPLE_TARGET_NAME} PRE_BUILD 64 | COMMAND ${CMAKE_COMMAND} -E 65 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs $/certs) 66 | 67 | if (MSVC) 68 | target_sources(${JOBS_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 69 | source_group("Header Files\\Samples\\Jobs" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 70 | source_group("Source Files\\Samples\\Jobs" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 71 | 72 | target_sources(${JOBS_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/JobsSample.hpp) 73 | source_group("Header Files\\Samples\\Jobs" FILES ${PROJECT_SOURCE_DIR}/JobsSample.hpp) 74 | source_group("Source Files\\Samples\\Jobs" FILES ${PROJECT_SOURCE_DIR}/JobsSample.cpp) 75 | endif () 76 | 77 | ######################### 78 | # Add Network libraries # 79 | ######################### 80 | 81 | set(NETWORK_WRAPPER_DEST_TARGET ${JOBS_SAMPLE_TARGET_NAME}) 82 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) 83 | -------------------------------------------------------------------------------- /samples/Jobs/JobsSample.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file JobsSample.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/Client.hpp" 26 | #include "NetworkConnection.hpp" 27 | 28 | namespace awsiotsdk { 29 | namespace samples { 30 | class JobsSample { 31 | protected: 32 | std::shared_ptr p_network_connection_; 33 | std::shared_ptr p_iot_client_; 34 | std::shared_ptr p_jobs_; 35 | std::atomic done_; 36 | 37 | ResponseCode DisconnectCallback(util::String topic_name, 38 | std::shared_ptr p_app_handler_data); 39 | ResponseCode ReconnectCallback(util::String client_id, 40 | std::shared_ptr p_app_handler_data, 41 | ResponseCode reconnect_result); 42 | ResponseCode ResubscribeCallback(util::String client_id, 43 | std::shared_ptr p_app_handler_data, 44 | ResponseCode resubscribe_result); 45 | 46 | ResponseCode GetPendingCallback(util::String topic_name, 47 | util::String payload, 48 | std::shared_ptr p_app_handler_data); 49 | ResponseCode NextJobCallback(util::String topic_name, 50 | util::String payload, 51 | std::shared_ptr p_app_handler_data); 52 | ResponseCode UpdateAcceptedCallback(util::String topic_name, 53 | util::String payload, 54 | std::shared_ptr p_app_handler_data); 55 | ResponseCode UpdateRejectedCallback(util::String topic_name, 56 | util::String payload, 57 | std::shared_ptr p_app_handler_data); 58 | 59 | ResponseCode Subscribe(); 60 | ResponseCode InitializeTLS(); 61 | 62 | public: 63 | ResponseCode RunSample(); 64 | }; 65 | } 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /samples/JobsAgent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-samples CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | ######################################## 13 | # Section : Common Build setttings # 14 | ######################################## 15 | # Set required compiler standard to standard c++11. Disable extensions. 16 | set(CMAKE_CXX_STANDARD 11) # C++11... 17 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 18 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 19 | 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 23 | 24 | # Configure Compiler flags 25 | if (UNIX AND NOT APPLE) 26 | # Prefer pthread if found 27 | set(THREADS_PREFER_PTHREAD_FLAG ON) 28 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 29 | elseif (APPLE) 30 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 31 | elseif (WIN32) 32 | set(CUSTOM_COMPILER_FLAGS "/W4") 33 | endif () 34 | 35 | ################################ 36 | # Target : Build JobsAgent sample # 37 | ################################ 38 | set(JOBS_AGENT_TARGET_NAME jobs-agent) 39 | # Add Target 40 | add_executable(${JOBS_AGENT_TARGET_NAME} "${PROJECT_SOURCE_DIR}/JobsAgent.cpp;${PROJECT_SOURCE_DIR}/JobsAgentOperations.cpp;${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 41 | 42 | # Add Target specific includes 43 | target_include_directories(${JOBS_AGENT_TARGET_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/../../common) 44 | target_include_directories(${JOBS_AGENT_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) 45 | 46 | # Configure Threading library 47 | find_package(Threads REQUIRED) 48 | 49 | # Configure CURL library 50 | find_package(CURL REQUIRED) 51 | 52 | # Add SDK includes 53 | target_include_directories(${JOBS_AGENT_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src/include) 54 | target_include_directories(${JOBS_AGENT_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 55 | 56 | target_link_libraries(${JOBS_AGENT_TARGET_NAME} PUBLIC "Threads::Threads") 57 | target_link_libraries(${JOBS_AGENT_TARGET_NAME} PUBLIC ${CURL_LIBRARIES}) 58 | target_link_libraries(${JOBS_AGENT_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 59 | 60 | # Copy Json config file 61 | add_custom_command(TARGET ${JOBS_AGENT_TARGET_NAME} POST_BUILD 62 | COMMAND ${CMAKE_COMMAND} -E 63 | copy ${PROJECT_SOURCE_DIR}/../../common/SampleConfig.json $/config/SampleConfig.json) 64 | set_property(TARGET ${JOBS_AGENT_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 65 | 66 | # Gather list of all .cert files in "/cert" 67 | add_custom_command(TARGET ${JOBS_AGENT_TARGET_NAME} PRE_BUILD 68 | COMMAND ${CMAKE_COMMAND} -E 69 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs $/certs) 70 | 71 | if (MSVC) 72 | target_sources(${JOBS_AGENT_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 73 | source_group("Header Files\\Samples\\JobsAgent" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 74 | source_group("Source Files\\Samples\\JobsAgent" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 75 | 76 | target_sources(${JOBS_AGENT_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/JobsAgent.hpp) 77 | source_group("Header Files\\Samples\\JobsAgent" FILES ${PROJECT_SOURCE_DIR}/JobsAgent.hpp) 78 | source_group("Source Files\\Samples\\JobsAgent" FILES ${PROJECT_SOURCE_DIR}/JobsAgent.cpp) 79 | source_group("Source Files\\Samples\\JobsAgent" FILES ${PROJECT_SOURCE_DIR}/JobsAgentOperations.cpp) 80 | endif () 81 | 82 | ######################### 83 | # Add Network libraries # 84 | ######################### 85 | 86 | set(NETWORK_WRAPPER_DEST_TARGET ${JOBS_AGENT_TARGET_NAME}) 87 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) 88 | -------------------------------------------------------------------------------- /samples/JobsAgent/JobsAgent.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file JobsAgent.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/Client.hpp" 26 | #include "NetworkConnection.hpp" 27 | #include "jobs/Jobs.hpp" 28 | #include 29 | #ifdef UNIT_TESTS 30 | #include "JobsMock.hpp" 31 | #endif 32 | 33 | #define LOG_TAG_JOBS_AGENT "[Sample - JobsAgent]" 34 | 35 | #define DEFAULT_INSTALLED_PACKAGES_FILENAME "installedPackages.json" 36 | 37 | namespace awsiotsdk { 38 | namespace samples { 39 | class JobsAgent { 40 | protected: 41 | std::mutex m_; 42 | std::condition_variable cv_done_; 43 | 44 | std::shared_ptr p_network_connection_; 45 | std::shared_ptr p_iot_client_; 46 | #ifdef UNIT_TESTS 47 | std::shared_ptr p_jobs_; 48 | #else 49 | std::shared_ptr p_jobs_; 50 | #endif 51 | 52 | util::String process_title_; 53 | util::String installed_packages_filename_; 54 | util::JsonDocument installed_packages_json_; 55 | util::Map package_runtimes_map_; 56 | 57 | static void ShowJobsError(util::String operation, ResponseCode rc); 58 | static util::String GetShutdownSystemCommand(bool dryRun, bool reboot); 59 | static util::String GetFullPath(util::String workingDirectory, util::String fileName); 60 | 61 | ResponseCode DisconnectCallback(util::String topic_name, 62 | std::shared_ptr p_app_handler_data); 63 | 64 | ResponseCode ReconnectCallback(util::String client_id, 65 | std::shared_ptr p_app_handler_data, 66 | ResponseCode reconnect_result); 67 | 68 | ResponseCode ResubscribeCallback(util::String client_id, 69 | std::shared_ptr p_app_handler_data, 70 | ResponseCode resubscribe_result); 71 | 72 | ResponseCode BackupFiles(util::Map & statusDetailsMap, 73 | util::String workingDirectory, 74 | util::JsonValue & files); 75 | ResponseCode RollbackFiles(util::Map & statusDetailsMap, 76 | util::String workingDirectory, 77 | util::JsonValue & files); 78 | ResponseCode DownloadFiles(util::Map & statusDetailsMap, 79 | util::String workingDirectory, 80 | util::JsonValue & file); 81 | 82 | ResponseCode UpdateInstalledPackage(util::JsonValue & packageJobDocument); 83 | bool PackageIsExecutable(util::String packageName); 84 | bool PackageIsRunning(util::String packageName); 85 | bool PackageIsAutoStart(util::String packageName); 86 | void StartInstalledPackages(); 87 | 88 | ResponseCode StartPackage(util::Map & statusDetailsMap, 89 | util::String packageName); 90 | ResponseCode StopPackage(util::Map & statusDetailsMap, 91 | util::String packageName); 92 | 93 | ResponseCode StartPackageHandler(util::String jobId, 94 | util::String packageName); 95 | ResponseCode StopPackageHandler(util::String jobId, 96 | util::String packageName); 97 | ResponseCode RestartPackageHandler(util::String jobId, 98 | util::String packageName); 99 | ResponseCode InstallPackageHandler(util::String jobId, 100 | util::JsonValue &jobDocument); 101 | ResponseCode UninstallPackageHandler(util::String jobId, 102 | util::String packageName); 103 | ResponseCode ShutdownHandler(util::String jobId, 104 | util::String step, 105 | bool reboot); 106 | ResponseCode SystemStatusHandler(util::String jobId); 107 | 108 | ResponseCode NextJobCallback(util::String topic_name, 109 | util::String payload, 110 | std::shared_ptr p_app_handler_data); 111 | 112 | ResponseCode UpdateAcceptedCallback(util::String topic_name, 113 | util::String payload, 114 | std::shared_ptr p_app_handler_data); 115 | 116 | ResponseCode UpdateRejectedCallback(util::String topic_name, 117 | util::String payload, 118 | std::shared_ptr p_app_handler_data); 119 | 120 | ResponseCode Subscribe(); 121 | ResponseCode InitializeTLS(); 122 | 123 | public: 124 | ResponseCode RunAgent(const util::String &processTitle = util::String()); 125 | }; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /samples/PubSub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-samples CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | ######################################## 13 | # Section : Common Build setttings # 14 | ######################################## 15 | # Set required compiler standard to standard c++11. Disable extensions. 16 | set(CMAKE_CXX_STANDARD 11) # C++11... 17 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 18 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 19 | 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 23 | 24 | # Configure Compiler flags 25 | if (UNIX AND NOT APPLE) 26 | # Prefer pthread if found 27 | set(THREADS_PREFER_PTHREAD_FLAG ON) 28 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 29 | elseif (APPLE) 30 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 31 | elseif (WIN32) 32 | set(CUSTOM_COMPILER_FLAGS "/W4") 33 | endif () 34 | 35 | ################################ 36 | # Target : Build PubSub sample # 37 | ################################ 38 | set(PUB_SUB_SAMPLE_TARGET_NAME pub-sub-sample) 39 | # Add Target 40 | add_executable(${PUB_SUB_SAMPLE_TARGET_NAME} "${PROJECT_SOURCE_DIR}/PubSub.cpp;${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 41 | 42 | # Add Target specific includes 43 | target_include_directories(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common) 44 | target_include_directories(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) 45 | 46 | # Configure Threading library 47 | find_package(Threads REQUIRED) 48 | 49 | # Add SDK includes 50 | target_include_directories(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src/include) 51 | target_include_directories(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 52 | 53 | target_link_libraries(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC "Threads::Threads") 54 | target_link_libraries(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 55 | 56 | # Copy Json config file 57 | add_custom_command(TARGET ${PUB_SUB_SAMPLE_TARGET_NAME} POST_BUILD 58 | COMMAND ${CMAKE_COMMAND} -E 59 | copy ${PROJECT_SOURCE_DIR}/../../common/SampleConfig.json $/config/SampleConfig.json) 60 | set_property(TARGET ${PUB_SUB_SAMPLE_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 61 | 62 | # Gather list of all .cert files in "/cert" 63 | add_custom_command(TARGET ${PUB_SUB_SAMPLE_TARGET_NAME} PRE_BUILD 64 | COMMAND ${CMAKE_COMMAND} -E 65 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs $/certs) 66 | 67 | if (MSVC) 68 | target_sources(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 69 | source_group("Header Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 70 | source_group("Source Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 71 | 72 | target_sources(${PUB_SUB_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/PubSub.hpp) 73 | source_group("Header Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/PubSub.hpp) 74 | source_group("Source Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/PubSub.cpp) 75 | endif () 76 | 77 | ######################### 78 | # Add Network libraries # 79 | ######################### 80 | 81 | set(NETWORK_WRAPPER_DEST_TARGET ${PUB_SUB_SAMPLE_TARGET_NAME}) 82 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) 83 | -------------------------------------------------------------------------------- /samples/PubSub/PubSub.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file PubSub.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/Client.hpp" 26 | #include "NetworkConnection.hpp" 27 | 28 | namespace awsiotsdk { 29 | namespace samples { 30 | class PubSub { 31 | protected: 32 | std::shared_ptr p_network_connection_; 33 | std::shared_ptr p_connect_packet_; 34 | std::atomic_int cur_pending_messages_; 35 | std::atomic_int total_published_messages_; 36 | std::shared_ptr p_iot_client_; 37 | 38 | ResponseCode RunPublish(int msg_count); 39 | ResponseCode SubscribeCallback(util::String topic_name, 40 | util::String payload, 41 | std::shared_ptr p_app_handler_data); 42 | ResponseCode DisconnectCallback(util::String topic_name, 43 | std::shared_ptr p_app_handler_data); 44 | ResponseCode ReconnectCallback(util::String client_id, 45 | std::shared_ptr p_app_handler_data, 46 | ResponseCode reconnect_result); 47 | ResponseCode ResubscribeCallback(util::String client_id, 48 | std::shared_ptr p_app_handler_data, 49 | ResponseCode resubscribe_result); 50 | ResponseCode Subscribe(); 51 | ResponseCode Unsubscribe(); 52 | ResponseCode InitializeTLS(); 53 | 54 | public: 55 | ResponseCode RunSample(); 56 | }; 57 | } 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /samples/ShadowDelta/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-samples CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | ######################################## 13 | # Section : Common Build setttings # 14 | ######################################## 15 | # Set required compiler standard to standard c++11. Disable extensions. 16 | set(CMAKE_CXX_STANDARD 11) # C++11... 17 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 18 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 19 | 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 23 | 24 | # Configure Compiler flags 25 | if (UNIX AND NOT APPLE) 26 | # Prefer pthread if found 27 | set(THREADS_PREFER_PTHREAD_FLAG ON) 28 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 29 | elseif (APPLE) 30 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 31 | elseif (WIN32) 32 | set(CUSTOM_COMPILER_FLAGS "/W4") 33 | endif () 34 | 35 | ################################ 36 | # Target : Build ShadowDelta sample # 37 | ################################ 38 | set(SHADOW_DELTA_SAMPLE_TARGET_NAME shadow-delta-sample) 39 | # Add Target 40 | add_executable(${SHADOW_DELTA_SAMPLE_TARGET_NAME} "${PROJECT_SOURCE_DIR}/ShadowDelta.cpp;${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 41 | 42 | # Add Target specific includes 43 | target_include_directories(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common) 44 | target_include_directories(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) 45 | 46 | # Configure Threading library 47 | find_package(Threads REQUIRED) 48 | 49 | # Add SDK includes 50 | target_include_directories(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src/include) 51 | target_include_directories(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 52 | 53 | target_link_libraries(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC "Threads::Threads") 54 | target_link_libraries(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 55 | 56 | # Copy Json config file 57 | add_custom_command(TARGET ${SHADOW_DELTA_SAMPLE_TARGET_NAME} POST_BUILD 58 | COMMAND ${CMAKE_COMMAND} -E 59 | copy ${PROJECT_SOURCE_DIR}/../../common/SampleConfig.json $/config/SampleConfig.json) 60 | set_property(TARGET ${SHADOW_DELTA_SAMPLE_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 61 | 62 | # Gather list of all .cert files in "/cert" 63 | add_custom_command(TARGET ${SHADOW_DELTA_SAMPLE_TARGET_NAME} PRE_BUILD 64 | COMMAND ${CMAKE_COMMAND} -E 65 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs $/certs) 66 | 67 | if (MSVC) 68 | target_sources(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 69 | source_group("Header Files\\Samples\\ShadowDelta" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 70 | source_group("Source Files\\Samples\\ShadowDelta" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 71 | 72 | target_sources(${SHADOW_DELTA_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/ShadowDelta.hpp) 73 | source_group("Header Files\\Samples\\ShadowDelta" FILES ${PROJECT_SOURCE_DIR}/ShadowDelta.hpp) 74 | source_group("Source Files\\Samples\\ShadowDelta" FILES ${PROJECT_SOURCE_DIR}/ShadowDelta.cpp) 75 | endif () 76 | 77 | ######################### 78 | # Add Network libraries # 79 | ######################### 80 | 81 | set(NETWORK_WRAPPER_DEST_TARGET ${SHADOW_DELTA_SAMPLE_TARGET_NAME}) 82 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) 83 | -------------------------------------------------------------------------------- /samples/ShadowDelta/ShadowDelta.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file ShadowDelta.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/Client.hpp" 26 | #include "NetworkConnection.hpp" 27 | #include "shadow/Shadow.hpp" 28 | 29 | namespace awsiotsdk { 30 | namespace samples { 31 | class ShadowDelta { 32 | protected: 33 | std::shared_ptr p_network_connection_; 34 | std::shared_ptr p_connect_packet_; 35 | std::atomic_int cur_pending_messages_; 36 | std::atomic_int total_published_messages_; 37 | std::shared_ptr p_iot_client_; 38 | std::atomic_bool publish_mqtt_messages_; 39 | 40 | ResponseCode InitializeTLS(); 41 | ResponseCode ActionResponseHandler(util::String thing_name, ShadowRequestType request_type, 42 | ShadowResponseType response_type, util::JsonDocument &payload); 43 | 44 | std::mutex sync_action_response_lock_; ///< Mutex for Sync Action Response flow 45 | std::condition_variable sync_action_response_wait_; ///< Condition variable used to wake up calling thread on Sync Action response 46 | ResponseCode sync_action_response_; ///< Variable to store received Sync Action response 47 | public: 48 | ResponseCode RunSample(); 49 | }; 50 | } 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /samples/StoryRobotArm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-samples CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | if (NOT ${NETWORK_LIBRARY} STREQUAL "OpenSSL") 13 | message(WARNING "Robot Arm Sample compiles only with OpenSSL, skipping build") 14 | return() 15 | endif () 16 | 17 | ######################################## 18 | # Section : Common Build setttings # 19 | ######################################## 20 | # Set required compiler standard to standard c++11. Disable extensions. 21 | set(CMAKE_CXX_STANDARD 11) # C++11... 22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 23 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 24 | 25 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 26 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 27 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 28 | 29 | # Configure Compiler flags 30 | if (UNIX AND NOT APPLE) 31 | # Prefer pthread if found 32 | set(THREADS_PREFER_PTHREAD_FLAG ON) 33 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 34 | elseif (APPLE) 35 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 36 | elseif (WIN32) 37 | set(CUSTOM_COMPILER_FLAGS "/W4") 38 | endif () 39 | 40 | ################################ 41 | # Target : Build Robot Arm sample # 42 | ################################ 43 | set(ROBOT_ARM_SAMPLE_TARGET_NAME robot-arm-sample) 44 | # Add Target 45 | add_executable(${ROBOT_ARM_SAMPLE_TARGET_NAME} "${PROJECT_SOURCE_DIR}/robotArm.cpp;${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 46 | 47 | # Add Target specific includes 48 | target_include_directories(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common) 49 | target_include_directories(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) 50 | 51 | # Configure Threading library 52 | find_package(Threads REQUIRED) 53 | 54 | # Add SDK includes 55 | target_include_directories(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src/include) 56 | target_include_directories(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 57 | 58 | target_link_libraries(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC "Threads::Threads") 59 | target_link_libraries(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 60 | 61 | # Copy Json config file 62 | add_custom_command(TARGET ${ROBOT_ARM_SAMPLE_TARGET_NAME} POST_BUILD 63 | COMMAND ${CMAKE_COMMAND} -E 64 | copy ${PROJECT_SOURCE_DIR}/../../common/RobotArmConfig.json $/config/RobotArmConfig.json) 65 | set_property(TARGET ${ROBOT_ARM_SAMPLE_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 66 | 67 | # Gather list of all .cert files in "/cert" 68 | add_custom_command(TARGET ${ROBOT_ARM_SAMPLE_TARGET_NAME} PRE_BUILD 69 | COMMAND ${CMAKE_COMMAND} -E 70 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs/robotArm/ $/certs/robotArm) 71 | 72 | if (MSVC) 73 | target_sources(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 74 | source_group("Header Files\\Samples\\StoryRobotArm" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 75 | source_group("Source Files\\Samples\\StoryRobotArm" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 76 | 77 | target_sources(${ROBOT_ARM_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/robotArm.hpp) 78 | source_group("Header Files\\Samples\\StoryRobotArm" FILES ${PROJECT_SOURCE_DIR}/robotArm.hpp) 79 | source_group("Source Files\\Samples\\StoryRobotArm" FILES ${PROJECT_SOURCE_DIR}/robotArm.cpp) 80 | endif () 81 | 82 | ######################### 83 | # Add Network libraries # 84 | ######################### 85 | 86 | set(NETWORK_WRAPPER_DEST_TARGET ${ROBOT_ARM_SAMPLE_TARGET_NAME}) 87 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) -------------------------------------------------------------------------------- /samples/StoryRobotArm/robotArm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file robotArm.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/GreengrassMqttClient.hpp" 26 | #include "NetworkConnection.hpp" 27 | #include "discovery/DiscoveryResponse.hpp" 28 | #include "shadow/Shadow.hpp" 29 | 30 | namespace awsiotsdk { 31 | namespace samples { 32 | class RobotArmThing { 33 | protected: 34 | std::shared_ptr p_network_connection_; 35 | std::shared_ptr p_iot_client_; 36 | 37 | ResponseCode RunPublish(); 38 | static bool ConnectivitySortFunction(ConnectivityInfo info1, ConnectivityInfo info2); 39 | ResponseCode ActionResponseHandler(util::String thing_name, ShadowRequestType request_type, 40 | ShadowResponseType response_type, util::JsonDocument &payload); 41 | 42 | std::mutex sync_action_response_lock_; ///< Mutex for Sync Action Response flow 43 | std::condition_variable sync_action_response_wait_; ///< Condition variable used to wake up calling thread on Sync Action response 44 | ResponseCode sync_action_response_; ///< Variable to store received Sync Action response 45 | 46 | public: 47 | ResponseCode RunSample(); 48 | }; 49 | } 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /samples/StorySwitch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-samples CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | if (NOT ${NETWORK_LIBRARY} STREQUAL "OpenSSL") 13 | message(WARNING "Switch Sample compiles only with OpenSSL, skipping build") 14 | return() 15 | endif () 16 | 17 | ######################################## 18 | # Section : Common Build setttings # 19 | ######################################## 20 | # Set required compiler standard to standard c++11. Disable extensions. 21 | set(CMAKE_CXX_STANDARD 11) # C++11... 22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 23 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 24 | 25 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 26 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 27 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 28 | 29 | # Configure Compiler flags 30 | if (UNIX AND NOT APPLE) 31 | # Prefer pthread if found 32 | set(THREADS_PREFER_PTHREAD_FLAG ON) 33 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 34 | elseif (APPLE) 35 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 36 | elseif (WIN32) 37 | set(CUSTOM_COMPILER_FLAGS "/W4") 38 | endif () 39 | 40 | ################################ 41 | # Target : Build Switch sample # 42 | ################################ 43 | set(SWITCH_SAMPLE_TARGET_NAME switch-sample) 44 | # Add Target 45 | add_executable(${SWITCH_SAMPLE_TARGET_NAME} "${PROJECT_SOURCE_DIR}/switch.cpp;${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 46 | 47 | # Add Target specific includes 48 | target_include_directories(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common) 49 | target_include_directories(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) 50 | 51 | # Configure Threading library 52 | find_package(Threads REQUIRED) 53 | 54 | # Add SDK includes 55 | target_include_directories(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/rapidjson/src/include) 56 | target_include_directories(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 57 | 58 | target_link_libraries(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC "Threads::Threads") 59 | target_link_libraries(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 60 | 61 | # Copy Json config file 62 | add_custom_command(TARGET ${SWITCH_SAMPLE_TARGET_NAME} POST_BUILD 63 | COMMAND ${CMAKE_COMMAND} -E 64 | copy ${PROJECT_SOURCE_DIR}/../../common/SwitchConfig.json $/config/SwitchConfig.json) 65 | set_property(TARGET ${SWITCH_SAMPLE_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 66 | 67 | # Gather list of all .cert files in "/cert" 68 | add_custom_command(TARGET ${SWITCH_SAMPLE_TARGET_NAME} PRE_BUILD 69 | COMMAND ${CMAKE_COMMAND} -E 70 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs/switch $/certs/switch) 71 | 72 | if (MSVC) 73 | target_sources(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 74 | source_group("Header Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 75 | source_group("Source Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 76 | 77 | target_sources(${SWITCH_SAMPLE_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/switch.hpp) 78 | source_group("Header Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/switch.hpp) 79 | source_group("Source Files\\Samples\\PubSub" FILES ${PROJECT_SOURCE_DIR}/switch.cpp) 80 | endif () 81 | 82 | ######################### 83 | # Add Network libraries # 84 | ######################### 85 | 86 | set(NETWORK_WRAPPER_DEST_TARGET ${SWITCH_SAMPLE_TARGET_NAME}) 87 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) -------------------------------------------------------------------------------- /samples/StorySwitch/switch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file switch.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/GreengrassMqttClient.hpp" 26 | #include "NetworkConnection.hpp" 27 | #include "discovery/DiscoveryResponse.hpp" 28 | 29 | namespace awsiotsdk { 30 | namespace samples { 31 | class SwitchThing { 32 | protected: 33 | std::shared_ptr p_network_connection_; 34 | std::shared_ptr p_iot_client_; 35 | 36 | ResponseCode RunPublish(); 37 | static bool ConnectivitySortFunction(ConnectivityInfo info1, ConnectivityInfo info2); 38 | 39 | public: 40 | ResponseCode RunSample(); 41 | }; 42 | } 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/Action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Action.cpp 18 | * @brief Action Base class and related definitions for IoT Client 19 | * 20 | * Defines a base class to be used by all Actions that can be run by the 21 | * IoT Client. Also contains definitions for related Action types like 22 | * ActionType, ActionState and ActionData 23 | * 24 | */ 25 | 26 | #include "Action.hpp" 27 | 28 | namespace awsiotsdk { 29 | Action::Action(ActionType action_type, util::String action_info_string) { 30 | p_thread_continue_ = std::make_shared(false); // Only one execution by default 31 | action_type_ = action_type; 32 | action_info_string_ = action_info_string; 33 | } 34 | 35 | ResponseCode Action::ReadFromNetworkBuffer(std::shared_ptr p_network_connection, 36 | util::Vector &read_buf, 37 | size_t bytes_to_read) { 38 | // TODO : Check if there are corner cases for this function not terminating until it has read the required number of bytes 39 | // TODO : Is there a more efficient way to do this? 40 | 41 | if (nullptr == p_network_connection) { 42 | return ResponseCode::NULL_VALUE_ERROR; 43 | } 44 | 45 | size_t total_read_bytes = 0; 46 | size_t cur_read_bytes = 0; 47 | ResponseCode rc = ResponseCode::FAILURE; 48 | 49 | std::atomic_bool &_p_thread_continue_ = *p_thread_continue_; 50 | read_buf.resize(bytes_to_read); 51 | do { 52 | rc = p_network_connection->Read(read_buf, 53 | total_read_bytes, 54 | bytes_to_read - total_read_bytes, 55 | cur_read_bytes); 56 | total_read_bytes += cur_read_bytes; 57 | if (total_read_bytes != bytes_to_read) { 58 | std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_NETWORK_ACTION_THREAD_SLEEP_DURATION_MS)); 59 | } 60 | } while (_p_thread_continue_ && total_read_bytes != bytes_to_read && ResponseCode::SUCCESS == rc); 61 | 62 | if (ResponseCode::SUCCESS == rc && total_read_bytes != bytes_to_read) { 63 | if (!_p_thread_continue_) { 64 | rc = ResponseCode::THREAD_EXITING; 65 | } else { 66 | rc = ResponseCode::FAILURE; 67 | } 68 | } 69 | 70 | return rc; 71 | } 72 | 73 | ResponseCode Action::WriteToNetworkBuffer(std::shared_ptr p_network_connection, 74 | const util::String &write_buf) { 75 | // TODO : Check if there are corner cases for this function not terminating until it has written the required number of bytes 76 | // TODO : Is there a more efficient way to do this? 77 | 78 | if (nullptr == p_network_connection) { 79 | return ResponseCode::NULL_VALUE_ERROR; 80 | } 81 | 82 | if (0 == write_buf.length()) { 83 | return ResponseCode::NETWORK_NOTHING_TO_WRITE_ERROR; 84 | } 85 | 86 | size_t total_written_bytes = 0; 87 | size_t cur_written_bytes = 0; 88 | size_t bytes_to_write = write_buf.length(); 89 | ResponseCode rc = ResponseCode::FAILURE; 90 | 91 | std::atomic_bool &_p_thread_continue_ = *p_thread_continue_; 92 | util::String temp_buf = write_buf; 93 | do { 94 | rc = p_network_connection->Write(temp_buf, cur_written_bytes); 95 | total_written_bytes += cur_written_bytes; 96 | if (total_written_bytes != bytes_to_write) { 97 | temp_buf = write_buf.substr(total_written_bytes); 98 | std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_NETWORK_ACTION_THREAD_SLEEP_DURATION_MS)); 99 | } 100 | } while (_p_thread_continue_ && total_written_bytes != cur_written_bytes && ResponseCode::SUCCESS == rc); 101 | 102 | if (ResponseCode::SUCCESS == rc && total_written_bytes != bytes_to_write) { 103 | if (!_p_thread_continue_) { 104 | rc = ResponseCode::THREAD_EXITING; 105 | } else { 106 | rc = ResponseCode::FAILURE; 107 | } 108 | } 109 | 110 | return rc; 111 | } 112 | } -------------------------------------------------------------------------------- /src/ClientCore.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file ClientCore.cpp 18 | * @brief 19 | */ 20 | 21 | #include 22 | 23 | #include "util/logging/LogMacros.hpp" 24 | #include "ClientCore.hpp" 25 | 26 | #define LOG_TAG_CLIENT_CORE "[Client Core]" 27 | 28 | namespace awsiotsdk { 29 | std::unique_ptr ClientCore::Create(std::shared_ptr p_network_connection, 30 | std::shared_ptr p_state) { 31 | if (nullptr == p_network_connection || nullptr == p_state) { 32 | return nullptr; 33 | } 34 | 35 | return std::unique_ptr(new ClientCore(p_network_connection, p_state)); 36 | } 37 | 38 | ClientCore::ClientCore(std::shared_ptr p_network_connection, 39 | std::shared_ptr p_state) { 40 | p_client_core_state_ = p_state; 41 | p_client_core_state_->p_network_connection_ = p_network_connection; 42 | p_client_core_state_->SetProcessQueuedActions(false); 43 | 44 | std::shared_ptr thread_task_out_sync = std::make_shared(true); 45 | std::shared_ptr thread_task_out = std::shared_ptr( 46 | new util::Threading::ThreadTask(util::Threading::DestructorAction::JOIN, 47 | thread_task_out_sync, 48 | "Outbound Action Processing")); 49 | thread_map_.insert(std::make_pair(ActionType::CORE_PROCESS_OUTBOUND, thread_task_out)); 50 | thread_task_out->Run(&ClientCoreState::ProcessOutboundActionQueue, p_client_core_state_, thread_task_out_sync); 51 | } 52 | 53 | ResponseCode ClientCore::RegisterAction(ActionType action_type, Action::CreateHandlerPtr p_action_create_handler) { 54 | return p_client_core_state_->RegisterAction(action_type, p_action_create_handler, p_client_core_state_); 55 | } 56 | 57 | ResponseCode ClientCore::PerformAction(ActionType action_type, std::shared_ptr p_action_data, 58 | std::chrono::milliseconds action_reponse_timeout) { 59 | return p_client_core_state_->PerformAction(action_type, p_action_data, action_reponse_timeout); 60 | } 61 | 62 | ResponseCode ClientCore::PerformActionAsync(ActionType action_type, std::shared_ptr p_action_data, 63 | uint16_t &action_id_out) { 64 | return p_client_core_state_->EnqueueOutboundAction(action_type, p_action_data, action_id_out); 65 | } 66 | 67 | ResponseCode ClientCore::CreateActionRunner(ActionType action_type, std::shared_ptr p_action_data) { 68 | Action::CreateHandlerPtr p_action_create_handler = nullptr; 69 | std::unique_ptr p_action = nullptr; 70 | 71 | ResponseCode rc = p_client_core_state_->GetActionCreateHandler(action_type, &p_action_create_handler); 72 | if (ResponseCode::SUCCESS != rc) { 73 | return rc; 74 | } 75 | 76 | p_action = p_action_create_handler(p_client_core_state_); 77 | if (nullptr == p_action) { 78 | rc = ResponseCode::NULL_VALUE_ERROR; 79 | } else { 80 | std::shared_ptr thread_task_sync = std::make_shared(true); 81 | p_action->SetParentThreadSync(thread_task_sync); 82 | std::shared_ptr thread_task = std::shared_ptr( 83 | new util::Threading::ThreadTask(util::Threading::DestructorAction::JOIN, 84 | thread_task_sync, 85 | p_action->GetActionInfo())); 86 | thread_map_.insert(std::make_pair(action_type, thread_task)); 87 | thread_task->Run(&Action::PerformAction, std::move(p_action), p_client_core_state_->p_network_connection_, 88 | p_action_data); 89 | } 90 | 91 | return rc; 92 | } 93 | 94 | void ClientCore::GracefulShutdownAllThreadTasks() { 95 | thread_map_.clear(); 96 | } 97 | 98 | ClientCore::~ClientCore() { 99 | thread_map_.clear(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/NetworkConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file NetworkConnection.cpp 18 | * @brief Network interface base class for IoT Client 19 | * 20 | * Defines an interface to the Network layer to be used by the MQTT client. 21 | * These functions should not be implemented/modified by the derived classes 22 | * 23 | */ 24 | 25 | #include "util/memory/stl/String.hpp" 26 | #include "NetworkConnection.hpp" 27 | 28 | namespace awsiotsdk { 29 | ResponseCode NetworkConnection::Connect() { 30 | std::lock(read_mutex, write_mutex); 31 | std::lock_guard read_guard(read_mutex, std::adopt_lock); 32 | std::lock_guard write_guard(write_mutex, std::adopt_lock); 33 | return ConnectInternal(); 34 | } 35 | 36 | ResponseCode NetworkConnection::Write(const util::String &buf, size_t &size_written_bytes_out) { 37 | ResponseCode rc; 38 | std::lock_guard write_guard(write_mutex); 39 | { 40 | // Check connection state before calling internal write 41 | if (IsConnected()) { 42 | rc = WriteInternal(buf, size_written_bytes_out); 43 | } else { 44 | rc = ResponseCode::NETWORK_DISCONNECTED_ERROR; 45 | } 46 | } 47 | return rc; 48 | } 49 | 50 | ResponseCode NetworkConnection::Read(util::Vector &buf, size_t buf_read_offset, 51 | size_t size_bytes_to_read, size_t &size_read_bytes_out) { 52 | ResponseCode rc; 53 | std::lock_guard read_guard(read_mutex); 54 | { 55 | // Check connection state before calling internal read 56 | if (IsConnected()) { 57 | rc = ReadInternal(buf, buf_read_offset, size_bytes_to_read, size_read_bytes_out); 58 | } else { 59 | rc = ResponseCode::NETWORK_DISCONNECTED_ERROR; 60 | } 61 | } 62 | return rc; 63 | } 64 | 65 | ResponseCode NetworkConnection::Disconnect() { 66 | // Disconnect irrespective of state of other requests 67 | std::lock(read_mutex, write_mutex); 68 | std::lock_guard read_guard(read_mutex, std::adopt_lock); 69 | std::lock_guard write_guard(write_mutex, std::adopt_lock); 70 | return DisconnectInternal(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/discovery/DiscoveryResponse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file DiscoveryResponse.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "util/logging/Logging.hpp" 23 | #include "util/logging/LogMacros.hpp" 24 | #include "util/logging/ConsoleLogSystem.hpp" 25 | 26 | #include "discovery/DiscoveryResponse.hpp" 27 | 28 | #define LOG_TAG_DISCOVERY_RESPONSE "[Discovery Response]" 29 | 30 | namespace awsiotsdk { 31 | const util::String awsiotsdk::DiscoveryResponse::GROUP_ARRAY_KEY = "GGGroups"; 32 | const util::String awsiotsdk::DiscoveryResponse::GROUP_ID_KEY = "GGGroupId"; 33 | const util::String awsiotsdk::DiscoveryResponse::GGC_ARRAY_KEY = "Cores"; 34 | const util::String awsiotsdk::DiscoveryResponse::GGC_THING_ARN_KEY = "thingArn"; 35 | const util::String awsiotsdk::DiscoveryResponse::ROOT_CA_KEY = "CAs"; 36 | const util::String awsiotsdk::DiscoveryResponse::CONNECTIVITY_INFO_ARRAY_KEY = "Connectivity"; 37 | const util::String awsiotsdk::DiscoveryResponse::ID_KEY = "Id"; 38 | const util::String awsiotsdk::DiscoveryResponse::HOST_ADDRESS_KEY = "HostAddress"; 39 | const util::String awsiotsdk::DiscoveryResponse::PORT_KEY = "PortNumber"; 40 | const util::String awsiotsdk::DiscoveryResponse::METADATA_KEY = "Metadata"; 41 | const util::String awsiotsdk::DiscoveryResponse::DEFAULT_DISCOVERY_RESPONSE_FILE_NAME = "discovery_response.json"; 42 | 43 | util::JsonDocument DiscoveryResponse::GetResponseDocument() { 44 | util::JsonDocument response; 45 | response.CopyFrom(response_document_, response.GetAllocator()); 46 | return std::move(response); 47 | } 48 | 49 | void DiscoveryResponse::SetResponseDocument(util::JsonDocument response_document) { 50 | response_document_ = std::move(response_document); 51 | } 52 | 53 | DiscoveryResponse::DiscoveryResponse(util::JsonDocument response_document) { 54 | response_document_ = std::move(response_document); 55 | } 56 | 57 | DiscoveryResponse::~DiscoveryResponse() { 58 | } 59 | 60 | ResponseCode DiscoveryResponse::WriteToPath(util::String output_file_absolute_path) { 61 | return util::JsonParser::WriteToFile(response_document_, output_file_absolute_path); 62 | } 63 | 64 | // The runtime for this is O(n) where n is the total number of individual Connectivity Information sets in the 65 | // response json over ALL groups and GGCs 66 | ResponseCode DiscoveryResponse::GetParsedResponse(util::Vector &connectivity_info_list, 67 | util::Map> &root_ca_map) { 69 | util::String group_name; 70 | util::String core_name; 71 | util::String ca_string; 72 | util::String id; 73 | util::String host_name; 74 | util::String metadata; 75 | uint16_t port; 76 | ResponseCode parsing_response = ResponseCode::SUCCESS; 77 | 78 | const char *group_array_key = GROUP_ARRAY_KEY.c_str(); 79 | const char *group_id_key = GROUP_ID_KEY.c_str(); 80 | const char *ggc_array_key = GGC_ARRAY_KEY.c_str(); 81 | const char *root_ca_key = ROOT_CA_KEY.c_str(); 82 | const char *connectivity_info_array_key = CONNECTIVITY_INFO_ARRAY_KEY.c_str(); 83 | const char *id_key = ID_KEY.c_str(); 84 | const char *host_address_key = HOST_ADDRESS_KEY.c_str(); 85 | const char *port_key = PORT_KEY.c_str(); 86 | const char *metadata_key = METADATA_KEY.c_str(); 87 | const char *ggc_thing_arn_key = GGC_THING_ARN_KEY.c_str(); 88 | 89 | for (auto &group_itr : response_document_[group_array_key].GetArray()) { 90 | if (!group_itr.HasMember(group_id_key) 91 | || !group_itr.HasMember(ggc_array_key) 92 | || !group_itr.HasMember(root_ca_key)) { 93 | parsing_response = ResponseCode::DISCOVER_RESPONSE_UNEXPECTED_JSON_STRUCTURE_ERROR; 94 | break; 95 | } 96 | 97 | group_name = util::String(group_itr[group_id_key].GetString()); 98 | 99 | for (auto &core_itr : group_itr[ggc_array_key].GetArray()) { 100 | if (!core_itr.HasMember(ggc_thing_arn_key) 101 | || !core_itr.HasMember(connectivity_info_array_key)) { 102 | parsing_response = ResponseCode::DISCOVER_RESPONSE_UNEXPECTED_JSON_STRUCTURE_ERROR; 103 | break; 104 | } 105 | core_name = util::String(core_itr[ggc_thing_arn_key].GetString()); 106 | for (auto &connectivity_info_itr : core_itr[connectivity_info_array_key].GetArray()) { 107 | if (!connectivity_info_itr.HasMember(id_key) 108 | || !connectivity_info_itr.HasMember(host_address_key) 109 | || !connectivity_info_itr.HasMember(port_key)) { 110 | parsing_response = ResponseCode::DISCOVER_RESPONSE_UNEXPECTED_JSON_STRUCTURE_ERROR; 111 | break; 112 | } 113 | 114 | id = util::String(connectivity_info_itr[id_key].GetString()); 115 | 116 | host_name = util::String(connectivity_info_itr[host_address_key].GetString()); 117 | 118 | if (connectivity_info_itr.HasMember(metadata_key)) { 119 | metadata = util::String(connectivity_info_itr[metadata_key].GetString()); 120 | } else { 121 | metadata = util::String(""); 122 | } 123 | 124 | port = static_cast(connectivity_info_itr[port_key].GetInt()); 125 | 126 | ConnectivityInfo connectivity_info(group_name, core_name, id, host_name, port, metadata); 127 | 128 | connectivity_info_list.push_back(connectivity_info); 129 | util::Vector ca_list; 130 | for (auto &ca_itr : group_itr[root_ca_key].GetArray()) { 131 | ca_string = util::String(ca_itr.GetString()); 132 | ca_list.push_back(ca_string); 133 | } 134 | root_ca_map.insert(std::pair>(group_name, ca_list)); 135 | } 136 | } 137 | if (ResponseCode::SUCCESS != parsing_response) { 138 | break; 139 | } 140 | } 141 | return parsing_response; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/util/logging/ConsoleLogSystem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file ConsoleLogSystem.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "util/logging/ConsoleLogSystem.hpp" 23 | 24 | #include 25 | 26 | using namespace awsiotsdk; 27 | using namespace awsiotsdk::util::Logging; 28 | 29 | void ConsoleLogSystem::ProcessFormattedStatement(util::String &&statement) { 30 | std::cout << statement; 31 | } 32 | -------------------------------------------------------------------------------- /src/util/logging/FormattedLogSystem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file FormattedLogSystem.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "util/logging/FormattedLogSystem.hpp" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | using namespace awsiotsdk; 32 | using namespace awsiotsdk::util::Logging; 33 | 34 | static util::String CreateLogPrefixLine(LogLevel logLevel, const char *tag, const char *function, unsigned int line) { 35 | util::StringStream ss; 36 | 37 | ss << "[" << GetLogLevelName(logLevel) << "] "; 38 | 39 | std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); 40 | std::chrono::milliseconds now_ms = std::chrono::duration_cast(now.time_since_epoch()); 41 | std::time_t time_now = std::chrono::duration_cast(now_ms).count(); 42 | 43 | char *time = std::ctime(&time_now); 44 | if (nullptr != time) { 45 | ss << time << ":" << now_ms.count() % 1000 << " "; 46 | } 47 | ss << tag << " [" << std::this_thread::get_id() << "] "; 48 | if (line && function) { 49 | ss << "[" << function << ":L"<< line << "] : "; 50 | } 51 | return ss.str(); 52 | } 53 | 54 | FormattedLogSystem::FormattedLogSystem(LogLevel logLevel) : 55 | m_logLevel(logLevel) { 56 | } 57 | 58 | void FormattedLogSystem::Log(LogLevel logLevel, const char *tag, const char *function, unsigned int line, const char *formatStr, ...) { 59 | util::StringStream ss; 60 | ss << CreateLogPrefixLine(logLevel, tag, function, line); 61 | 62 | std::va_list args; 63 | va_start(args, formatStr); 64 | 65 | va_list tmp_args; //unfortunately you cannot consume a va_list twice 66 | va_copy(tmp_args, args); //so we have to copy it 67 | #ifdef WIN32 68 | const int requiredLength = _vscprintf(formatStr, tmp_args) + 1; 69 | #else 70 | const int requiredLength = vsnprintf(nullptr, 0, formatStr, tmp_args) + 1; 71 | #endif 72 | va_end(tmp_args); 73 | 74 | std::unique_ptr outputBuff_uptr = std::unique_ptr(new char[requiredLength]); 75 | char *outputBuff = outputBuff_uptr.get(); 76 | #ifdef WIN32 77 | vsnprintf_s(outputBuff, requiredLength, _TRUNCATE, formatStr, args); 78 | #else 79 | vsnprintf(outputBuff, static_cast(requiredLength), formatStr, args); 80 | #endif // WIN32 81 | 82 | ss << outputBuff << std::endl; 83 | 84 | ProcessFormattedStatement(ss.str()); 85 | 86 | va_end(args); 87 | } 88 | 89 | void FormattedLogSystem::LogStream(LogLevel logLevel, const char *tag, const util::OStringStream &message_stream) { 90 | util::StringStream ss; 91 | ss << CreateLogPrefixLine(logLevel, tag, NULL, 0) << message_stream.rdbuf()->str() << std::endl; 92 | 93 | ProcessFormattedStatement(ss.str()); 94 | } 95 | -------------------------------------------------------------------------------- /src/util/logging/LogLevel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file LogLevel.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "util/logging/LogLevel.hpp" 23 | 24 | #include "util/memory/stl/String.hpp" 25 | #include 26 | 27 | using namespace awsiotsdk::util::Logging; 28 | 29 | namespace awsiotsdk { 30 | namespace util { 31 | namespace Logging { 32 | util::String GetLogLevelName(LogLevel logLevel) { 33 | switch (logLevel) { 34 | case LogLevel::Off: 35 | return "OFF"; 36 | case LogLevel::Fatal: 37 | return "FATAL"; 38 | case LogLevel::Error: 39 | return "ERROR"; 40 | case LogLevel::Warn: 41 | return "WARN"; 42 | case LogLevel::Info: 43 | return "INFO"; 44 | case LogLevel::Debug: 45 | return "DEBUG"; 46 | case LogLevel::Trace: 47 | return "TRACE"; 48 | } 49 | // Can never happen but required for compilation 50 | return "UNKNOWN LOG LEVEL"; 51 | } 52 | } // namespace Logging 53 | } // namespace util 54 | } // namespace awsiotsdk 55 | -------------------------------------------------------------------------------- /src/util/logging/Logging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Logging.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "util/logging/Logging.hpp" 23 | #include "util/logging/LogSystemInterface.hpp" 24 | 25 | #include 26 | 27 | using namespace awsiotsdk::util; 28 | using namespace awsiotsdk::util::Logging; 29 | 30 | static std::shared_ptr AWSLogSystem(nullptr); 31 | static std::shared_ptr OldLogger(nullptr); 32 | 33 | namespace awsiotsdk { 34 | namespace util { 35 | namespace Logging { 36 | 37 | void InitializeAWSLogging(const std::shared_ptr &logSystem) { 38 | AWSLogSystem = logSystem; 39 | } 40 | 41 | void ShutdownAWSLogging(void) { 42 | InitializeAWSLogging(nullptr); 43 | } 44 | 45 | LogSystemInterface *GetLogSystem() { 46 | return AWSLogSystem.get(); 47 | } 48 | 49 | void PushLogger(const std::shared_ptr &logSystem) { 50 | OldLogger = AWSLogSystem; 51 | AWSLogSystem = logSystem; 52 | } 53 | 54 | void PopLogger() { 55 | AWSLogSystem = OldLogger; 56 | OldLogger = nullptr; 57 | } 58 | 59 | } // namespace Logging 60 | } // namespace util 61 | } // namespace awsiotsdk -------------------------------------------------------------------------------- /src/util/threading/ThreadTask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file ThreadTask.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "util/threading/ThreadTask.hpp" 23 | #include "util/logging/LogMacros.hpp" 24 | #define THREAD_TASK_LOG_TAG "[Thread Task]" 25 | 26 | namespace awsiotsdk { 27 | namespace util { 28 | namespace Threading { 29 | ThreadTask::ThreadTask(DestructorAction destructor_action, std::shared_ptr sync_point, 30 | util::String thread_descriptor) 31 | : destructor_action_(destructor_action), m_continue_(std::move(sync_point)), 32 | thread_descriptor_(std::move(thread_descriptor)) { 33 | AWS_LOGSTREAM_DEBUG(THREAD_TASK_LOG_TAG, "Creating Thread " << thread_descriptor_ << "!!"); 34 | } 35 | 36 | ThreadTask::~ThreadTask() { 37 | Stop(); 38 | AWS_LOGSTREAM_DEBUG(THREAD_TASK_LOG_TAG, "Exiting Thread " << thread_descriptor_ << "!!"); 39 | if (m_thread_.joinable()) { 40 | if (destructor_action_ == DestructorAction::JOIN) { 41 | m_thread_.join(); 42 | } else { 43 | m_thread_.detach(); 44 | } 45 | } 46 | AWS_LOGSTREAM_DEBUG(THREAD_TASK_LOG_TAG, "Successfully Exited Thread " << thread_descriptor_ << "!!"); 47 | } 48 | 49 | void ThreadTask::Stop() { 50 | std::atomic_bool &_m_continue_ = *m_continue_; 51 | _m_continue_ = false; 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | ## Tests 2 | 3 | The SDK provides several unit and integration tests to verify SDK features and functionality. These tests can be run on any of the supported Operating Systems. 4 | 5 | Please note that while the test descriptions apply across all supported platforms, the below execution instructions are for Linux. On Windows, the test targets show up as individual projects in Visual Studio after cmake generation and can be run by simply running the project. Please note that the network library needs to be selected while generating the solution at this time. 6 | 7 | ## Integration Tests 8 | 9 | Prerequisites: 10 | * Create an AWS IoT thing on the IoT console and download the certificates. Make sure the certificates are activated 11 | * Note down the endpoint that you will use to interact with the thing (will be of the form .iot..amazonaws.com). 12 | * Copy the certs into the /certs folder along with the Symantec root CA. 13 | 14 | The SDK comes with the below Integration tests for various SDK features. All tests can be run for the provided reference Network wrappers. To build the tests for each provided wrapper, use the below cmake calls from the build directory: 15 | * OpenSSL (Default if no argument is provided)- `cmake ` OR `cmake -DNETWORK_LIBRARY=OpenSSL` 16 | * MbedTLS - `cmake -DNETWORK_LIBRARY=MbedTLS` 17 | * WebSocket - `cmake -DNETWORK_LIBRARY=WebSocket` 18 | 19 | Followed by: 20 | 21 | `make aws-iot-integration-tests` 22 | 23 | To run the tests, 24 | * switch to the generated `bin` folder 25 | * modify the `config/IntegrationTestConfig.json` with the certificate names and the endpoint for your thing 26 | * run `./aws-iot-integration-tests` 27 | 28 | ### Basic MQTT Publish Subscribe 29 | 30 | This tests basic MQTT features. It creates one MQTT Client with all MQTT features and then proceeds to subscribe to a test topic. Once it has subscribe successfully it publishes messages on that topic and verifies that all messages were received successfully. 31 | There are two distinct publish phases: 32 | * Publish close to the max size payload supported by the AWS IoT service (128KB) and verify successful publish. 33 | * Publish enough messages to completely fill up the MQTT Client's action queue and wait for space to become available before filling it up again. Repeats this process upto the maximum number of messages and then verifies all messages were received. 34 | 35 | NOTE - This test can fail if auto-reconnect happens while the test is in progress. Its a reliable indicator that functionality is working as expected. It is not a reliable indicator of the stability of the connection. 36 | 37 | 38 | ### Auto-reconnect test 39 | 40 | This test verifies the Auto-reconnect functionality. It creates an MQTT Client similar to the above basic test and publishes a few messages to verify connectivity. Then it proceeds to simulate a disconnect and waits for reconnect to occur. The connection is verified by messages on the subscribe lifecycle event topic. Once the connection is successfully restored, the client publishes messages again on the test topic to verify resubscribe worked as expected. 41 | 42 | 43 | ### Multiple Clients test 44 | 45 | This test verifies that the SDK can be used in applications that create several MQTT Clients at the same time. It creates three MQTT Clients, once that only subscribes to a test topic and two others that only publish to the test topic. Then it proceeds to publish messages using both the Publishers and verifies all messages were successfully received. 46 | 47 | NOTE - This test can fail if auto-reconnect happens while the test is in progress. Its a reliable indicator that functionality is working as expected. It is not a reliable indicator of the stability of the connection. 48 | 49 | 50 | ### Multiple Subscription Auto Reconnect Test 51 | 52 | This test verifies that the SDK can be used in applications with varying number of subscriptions and that the auto-reconnect will not fail irrespective of number of subscriptions. It creates a client that connects and subscribes to multiple topics, ranging from 0 to 8. It publishes a few messages to verify connectivity. Then it proceeds to simulate a disconnect and waits for reconnect to occur. The connection is verified by messages on the subscribe lifecycle event topic. Once the connection is successfully restored, the client publishes messages again on the test topic to verify resubscribe worked as expected. 53 | 54 | ## Using LLVM Sanitizers with unit/integration tests 55 | * Install a recent Clang compiler suite. Some sanitizers work with recent versions of GCC, but generally Clang has better support. For Ubuntu, run `sudo apt-get install clang`. Most Linux systems have support for all sanitizers but OSX only suports address sanitizers. 56 | * From the main directory, run these commands to pick the Clang compiler and turn on a sanitizer. _Picking the compiler must be done before the very first run of Cmake in a fresh build dir_ 57 | 58 | ```$xslt 59 | mkdir build 60 | cd build 61 | cmake .. -DCMAKE_BUILD_TYPE=debug -DSANITIZE_THREAD=On -DCMAKE_CXX_COMPILER=/usr/bin/clang++ 62 | make 63 | ``` 64 | * Supported sanitizers 65 | * -DSANITIZE_THREAD=On - Turns on [ThreadSanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html) which detects data races 66 | * -DSANITIZE_ADDRESS=On - Turns on [AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html) which detects memory errors 67 | * -DSANITIZE_UNDEFINED=On - Turns on [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) 68 | * -DSANITIZE_MEMORY=On - Turns on [MemorySanitizer](https://clang.llvm.org/docs/MemorySanitizer.html) which detects uninitialized reads. 69 | _Note that msan generally gives many false reports unless all supporting code, including stdlib, is compiled with msan on. This often makes it impractical to use_ 70 | * Only turn on one sanitizer at a time 71 | * Some helpful environmental variables that change sanitizer behavior: 72 | 73 | ```$xslt 74 | export TSAN_OPTIONS=${TSAN_OPTIONS:-"second_deadlock_stack=1,halt_on_error=0"} 75 | export UBSAN_OPTIONS=${UBSAN_OPTIONS:-"halt_on_error=0"} 76 | export ASAN_OPTIONS=${ASAN_OPTIONS:-"halt_on_error=0"} 77 | ``` 78 | -------------------------------------------------------------------------------- /tests/integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2 FATAL_ERROR) 2 | project(aws-iot-cpp-integration-tests CXX) 3 | 4 | ###################################### 5 | # Section : Disable in-source builds # 6 | ###################################### 7 | 8 | if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) 9 | message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") 10 | endif () 11 | 12 | ######################################## 13 | # Section : Common Build setttings # 14 | ######################################## 15 | # Set required compiler standard to standard c++11. Disable extensions. 16 | set(CMAKE_CXX_STANDARD 11) # C++11... 17 | set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... 18 | set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 19 | 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 23 | 24 | # Configure Compiler flags 25 | if (UNIX AND NOT APPLE) 26 | # Prefer pthread if found 27 | set(THREADS_PREFER_PTHREAD_FLAG ON) 28 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 29 | elseif (APPLE) 30 | set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") 31 | elseif (WIN32) 32 | set(CUSTOM_COMPILER_FLAGS "/W4") 33 | endif () 34 | 35 | if(SANITIZE_THREAD OR SANITIZE_MEMORY OR SANITIZE_ADDRESS OR SANITIZE_MEMORY) 36 | set(CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/third_party/sanitizers/src/cmake" ${CMAKE_MODULE_PATH}) 37 | find_package(Sanitizers) 38 | endif() 39 | 40 | #################################### 41 | # Target : Build Integration Tests # 42 | #################################### 43 | set(INTEGRATION_TEST_TARGET_NAME aws-iot-integration-tests) 44 | # Add Target 45 | add_executable(${INTEGRATION_TEST_TARGET_NAME} "${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp") 46 | 47 | target_include_directories(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/third_party/rapidjson/src/include) 48 | target_include_directories(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../include) 49 | 50 | # Configure Threading library 51 | find_package(Threads REQUIRED) 52 | target_link_libraries(${INTEGRATION_TEST_TARGET_NAME} PUBLIC "Threads::Threads") 53 | 54 | # Integration Tests 55 | file(GLOB_RECURSE INTEGRATION_TEST_SOURCES FOLLOW_SYMLINKS ${PROJECT_SOURCE_DIR}/src/*.cpp) 56 | 57 | # Add Target specific includes 58 | target_include_directories(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common) 59 | target_include_directories(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) 60 | target_sources(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${INTEGRATION_TEST_SOURCES}) 61 | 62 | # Copy Json config file 63 | add_custom_command(TARGET ${INTEGRATION_TEST_TARGET_NAME} POST_BUILD 64 | COMMAND ${CMAKE_COMMAND} -E 65 | copy ${PROJECT_SOURCE_DIR}/../../common/SampleConfig.json $/config/IntegrationTestConfig.json) 66 | 67 | target_link_libraries(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${THREAD_LIBRARY_LINK_STRING}) 68 | target_link_libraries(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${SDK_TARGET_NAME}) 69 | set_property(TARGET ${INTEGRATION_TEST_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) 70 | 71 | # Gather list of all .cert files in "/cert" 72 | add_custom_command(TARGET ${INTEGRATION_TEST_TARGET_NAME} PRE_BUILD 73 | COMMAND ${CMAKE_COMMAND} -E 74 | copy_directory ${PROJECT_SOURCE_DIR}/../../certs $/certs) 75 | 76 | if(SANITIZE_THREAD OR SANITIZE_MEMORY OR SANITIZE_ADDRESS OR SANITIZE_MEMORY) 77 | add_sanitizers(${INTEGRATION_TEST_TARGET_NAME}) 78 | endif() 79 | 80 | if (MSVC) 81 | target_sources(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 82 | source_group("Header Files\\Tests\\Integration" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.hpp) 83 | source_group("Source Files\\Tests\\Integration" FILES ${PROJECT_SOURCE_DIR}/../../common/ConfigCommon.cpp) 84 | 85 | file(GLOB_RECURSE INTEGRATION_TEST_HEADERS FOLLOW_SYMLINKS ${PROJECT_SOURCE_DIR}/include/*.hpp) 86 | target_sources(${INTEGRATION_TEST_TARGET_NAME} PUBLIC ${INTEGRATION_TEST_HEADERS}) 87 | source_group("Header Files\\Tests\\Integration" FILES ${INTEGRATION_TEST_HEADERS}) 88 | source_group("Source Files\\Tests\\Integration" FILES ${INTEGRATION_TEST_SOURCES}) 89 | endif () 90 | 91 | ######################### 92 | # Add Network libraries # 93 | ######################### 94 | 95 | set(NETWORK_WRAPPER_DEST_TARGET ${INTEGRATION_TEST_TARGET_NAME}) 96 | include(${PROJECT_SOURCE_DIR}/../../network/CMakeLists.txt.in) 97 | -------------------------------------------------------------------------------- /tests/integration/include/AutoReconnect.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file AutoReconnect.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include 26 | #include "mqtt/Client.hpp" 27 | 28 | namespace awsiotsdk { 29 | namespace tests { 30 | namespace integration { 31 | class AutoReconnect { 32 | protected: 33 | util::String client_id_tagged_; 34 | std::shared_ptr p_network_connection_; 35 | std::shared_ptr p_connect_packet_; 36 | std::atomic_int cur_pending_messages_; 37 | std::atomic_int total_published_messages_; 38 | std::mutex waiting_for_sub_lock_; 39 | std::condition_variable sub_lifecycle_wait_; 40 | std::shared_ptr p_iot_client_; 41 | 42 | ResponseCode RunPublish(int msg_count); 43 | ResponseCode SubscribeCallback(util::String topic_name, 44 | util::String payload, 45 | std::shared_ptr p_app_handler_data); 46 | ResponseCode LifecycleSubscribeCallback(util::String topic_name, 47 | util::String payload, 48 | std::shared_ptr p_app_handler_data); 49 | ResponseCode Subscribe(); 50 | ResponseCode Unsubscribe(); 51 | ResponseCode InitializeTLS(); 52 | 53 | public: 54 | AutoReconnect() { 55 | cur_pending_messages_ = 0; 56 | total_published_messages_ = 0; 57 | } 58 | ResponseCode RunTest(); 59 | }; 60 | } 61 | } 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /tests/integration/include/IntegTestRunner.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file IntegTestRunner.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | #include "ResponseCode.hpp" 29 | 30 | namespace awsiotsdk { 31 | namespace tests { 32 | namespace integration { 33 | class IntegTestRunner { 34 | protected: 35 | ResponseCode InitializeSdkTestConfig(); 36 | public: 37 | ResponseCode Initialize(); 38 | 39 | ResponseCode RunAllTests(); 40 | }; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /tests/integration/include/JobsTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file Jobs.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/Client.hpp" 26 | #include "NetworkConnection.hpp" 27 | #include "jobs/Jobs.hpp" 28 | 29 | namespace awsiotsdk { 30 | namespace tests { 31 | namespace integration { 32 | class JobsTest { 33 | protected: 34 | static const std::chrono::seconds keep_alive_timeout_; 35 | 36 | std::shared_ptr p_network_connection_; 37 | std::shared_ptr p_iot_client_; 38 | std::shared_ptr p_jobs_; 39 | std::atomic done_; 40 | 41 | ResponseCode GetPendingCallback(util::String topic_name, 42 | util::String payload, 43 | std::shared_ptr p_app_handler_data); 44 | ResponseCode NextJobCallback(util::String topic_name, 45 | util::String payload, 46 | std::shared_ptr p_app_handler_data); 47 | 48 | ResponseCode Subscribe(); 49 | ResponseCode Unsubscribe(); 50 | ResponseCode InitializeTLS(); 51 | 52 | public: 53 | ResponseCode RunTest(); 54 | }; 55 | } 56 | } 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /tests/integration/include/MultipleClients.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file MultipleClients.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/Client.hpp" 26 | 27 | namespace awsiotsdk { 28 | namespace tests { 29 | namespace integration { 30 | class MultipleClients { 31 | protected: 32 | std::shared_ptr p_network_connection_1_; 33 | std::shared_ptr p_iot_client_1_; 34 | 35 | std::shared_ptr p_network_connection_2_; 36 | std::shared_ptr p_iot_client_2_; 37 | 38 | std::shared_ptr p_network_connection_3_; 39 | std::shared_ptr p_iot_client_3_; 40 | 41 | std::atomic_int cur_pending_messages_; 42 | std::atomic_int total_published_messages_; 43 | std::chrono::milliseconds mqtt_command_timeout_; 44 | 45 | ResponseCode RunPublish(int msg_count); 46 | ResponseCode SubscribeCallback(util::String topic_name, 47 | util::String payload, 48 | std::shared_ptr p_app_handler_data); 49 | ResponseCode Subscribe(); 50 | ResponseCode Unsubscribe(); 51 | ResponseCode InitializeTLS(std::shared_ptr &p_network_connection); 52 | 53 | public: 54 | ResponseCode RunTest(); 55 | }; 56 | } 57 | } 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /tests/integration/include/MultipleSubAutoReconnect.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file MultipleSubAutoReconnect.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include 26 | #include "mqtt/Client.hpp" 27 | 28 | namespace awsiotsdk { 29 | namespace tests { 30 | namespace integration { 31 | class MultipleSubAutoReconnect { 32 | protected: 33 | util::String client_id_tagged_; 34 | std::shared_ptr p_network_connection_; 35 | std::shared_ptr p_connect_packet_; 36 | std::atomic_int cur_pending_messages_; 37 | std::atomic_int total_published_messages_; 38 | std::mutex waiting_for_sub_lock_; 39 | std::condition_variable sub_lifecycle_wait_; 40 | std::shared_ptr p_iot_client_; 41 | int number_of_subscriptions_; 42 | 43 | ResponseCode RunPublish(int msg_count); 44 | ResponseCode SubscribeCallback(util::String topic_name, 45 | util::String payload, 46 | std::shared_ptr p_app_handler_data); 47 | ResponseCode LifecycleSubscribeCallback(util::String topic_name, 48 | util::String payload, 49 | std::shared_ptr p_app_handler_data); 50 | ResponseCode Subscribe(); 51 | ResponseCode Unsubscribe(); 52 | ResponseCode InitializeTLS(); 53 | 54 | public: 55 | MultipleSubAutoReconnect() { 56 | cur_pending_messages_ = 0; 57 | total_published_messages_ = 0; 58 | number_of_subscriptions_ = 0; 59 | } 60 | MultipleSubAutoReconnect(int number_of_clients) { 61 | cur_pending_messages_ = 0; 62 | total_published_messages_ = 0; 63 | number_of_subscriptions_ = number_of_clients; 64 | } 65 | ResponseCode RunTest(); 66 | }; 67 | } 68 | } 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/integration/include/PubSub.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file PubSub.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "mqtt/Client.hpp" 26 | #include "NetworkConnection.hpp" 27 | 28 | namespace awsiotsdk { 29 | namespace tests { 30 | namespace integration { 31 | class PubSub { 32 | protected: 33 | std::shared_ptr p_network_connection_; 34 | std::shared_ptr p_connect_packet_; 35 | std::atomic_int cur_pending_messages_; 36 | std::atomic_int total_published_messages_; 37 | std::shared_ptr p_iot_client_; 38 | 39 | ResponseCode RunPublish(int msg_count); 40 | ResponseCode RunPublishNoQueueDelay(int msg_count); 41 | ResponseCode SubscribeCallback(util::String topic_name, 42 | util::String payload, 43 | std::shared_ptr p_app_handler_data); 44 | ResponseCode Subscribe(); 45 | ResponseCode Unsubscribe(); 46 | ResponseCode InitializeTLS(); 47 | 48 | public: 49 | PubSub() { 50 | cur_pending_messages_ = 0; 51 | total_published_messages_ = 0; 52 | } 53 | ResponseCode RunTest(); 54 | }; 55 | } 56 | } 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /tests/integration/include/SdkTestConfig.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file SdkConfig.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "ResponseCode.hpp" 32 | 33 | // Network settings 34 | #define SDK_CONFIG_ENDPOINT_KEY "endpoint" 35 | #define SDK_CONFIG_ENDPOINT_PORT_KEY "port" 36 | 37 | // TLS Settings 38 | #define SDK_CONFIG_ROOT_CA_RELATIVE_KEY "root_ca_relative_path" 39 | #define SDK_CONFIG_DEVICE_CERT_RELATIVE_KEY "device_certificate_relative_path" 40 | #define SDK_CONFIG_DEVICE_PRIVATE_KEY_RELATIVE_KEY "device_private_key_relative_path" 41 | #define SDK_CONFIG_TLS_HANDSHAKE_TIMEOUT_SECS_KEY "tls_handshake_timeout_secs" 42 | #define SDK_CONFIG_TLS_READ_TIMEOUT_SECS_KEY "tls_read_timeout_msecs" 43 | #define SDK_CONFIG_TLS_WRITE_TIMEOUT_SECS_KEY "tls_write_timeout_msecs" 44 | 45 | // Websocket settings 46 | #define SDK_CONFIG_AWS_ACCESS_KEY_ID_KEY "aws_access_key_id" 47 | #define SDK_CONFIG_SECRET_ACCESS_KEY "aws_secret_access_key" 48 | #define SDK_CONFIG_AWS_SESSION_TOKEN_KEY "aws_session_token" 49 | 50 | // MQTT Settings 51 | #define SDK_CONFIG_CLIENT_ID_KEY "client_id" 52 | #define SDK_CONFIG_THING_NAME_KEY "thing_name" 53 | #define SDK_CONFIG_IS_CLEAN_SESSION_KEY "is_clean_session" 54 | #define SDK_CONFIG_MQTT_COMMAND_TIMEOUT_MSECS_KEY "mqtt_command_timeout_msecs" 55 | #define SDK_CONFIG_KEEPALIVE_INTERVAL_SECS_KEY "keepalive_interval_secs" 56 | #define SDK_CONFIG_MIN_RECONNECT_INTERVAL_SECS_KEY "minimum_reconnect_interval_secs" 57 | #define SDK_CONFIG_MAX_RECONNECT_INTERVAL_SECS_KEY "maximum_reconnect_interval_secs" 58 | #define SDK_CONFIG_MAX_ACKS_TO_WAIT_FOR_KEY "maximum_acks_to_wait_for" 59 | 60 | // Core settings 61 | #define SDK_CONFIG_MAX_TX_ACTION_QUEUE_LENGTH_KEY "maximum_outgoing_action_queue_length" 62 | #define SDK_CONFIG_DRAINING_INTERVAL_MSECS_KEY "draining_interval_msecs" 63 | 64 | namespace awsiotsdk { 65 | namespace util { 66 | class SdkTestConfig { 67 | protected: 68 | static rapidjson::Document sdkConfigJson; 69 | public: 70 | static ResponseCode InitializeFromJsonFile(const util::String &configFilePath); 71 | 72 | static ResponseCode InitializeFromJsonString(const util::String &configJsonString); 73 | 74 | static ResponseCode GetBoolValue(const char *key, bool &value); 75 | 76 | static ResponseCode GetIntValue(const char *key, int &value); 77 | 78 | static ResponseCode GetUint16Value(const char *key, uint16_t &value); 79 | 80 | static ResponseCode GetUint32Value(const char *key, uint32_t &value); 81 | 82 | static ResponseCode GetSizeTValue(const char *key, size_t &value); 83 | 84 | static ResponseCode GetCStringValue(const char *key, char *value, uint16_t max_string_len); 85 | 86 | static ResponseCode GetStringValue(const char *key, util::String &value); 87 | 88 | static rapidjson::ParseErrorCode GetParseErrorCode(); 89 | 90 | static size_t GetParseErrorOffset(); 91 | 92 | static void PrintSdkConfig() { 93 | rapidjson::StringBuffer buffer; 94 | rapidjson::Writer writer(buffer); 95 | sdkConfigJson.Accept(writer); 96 | 97 | const char *document = buffer.GetString(); 98 | std::cout << std::endl << "Json Document" << std::endl; 99 | std::cout << document << std::endl; 100 | } 101 | }; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tests/integration/src/IntegTestRunner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file IntegTestRunner.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "util/memory/stl/String.hpp" 23 | 24 | #include "util/logging/Logging.hpp" 25 | #include "util/logging/LogMacros.hpp" 26 | #include "util/logging/ConsoleLogSystem.hpp" 27 | 28 | #include "ConfigCommon.hpp" 29 | #include "IntegTestRunner.hpp" 30 | #include "SdkTestConfig.hpp" 31 | #include "JobsTest.hpp" 32 | #include "PubSub.hpp" 33 | #include "AutoReconnect.hpp" 34 | #include "MultipleClients.hpp" 35 | #include "MultipleSubAutoReconnect.hpp" 36 | 37 | #define INTEG_TEST_RUNNER_LOG_TAG "[Integration Test Runner]" 38 | 39 | #define MAX_ALLOWED_SUBSCRIPTIONS 50 40 | 41 | namespace awsiotsdk { 42 | namespace tests { 43 | namespace integration { 44 | ResponseCode IntegTestRunner::Initialize() { 45 | ResponseCode rc = awsiotsdk::ConfigCommon::InitializeCommon("config/IntegrationTestConfig.json"); 46 | if (ResponseCode::SUCCESS != rc) { 47 | AWS_LOG_INFO(INTEG_TEST_RUNNER_LOG_TAG, 48 | "Initialize Test Config Failed with rc : %d", 49 | static_cast(rc)); 50 | } 51 | return rc; 52 | } 53 | 54 | ResponseCode IntegTestRunner::RunAllTests() { 55 | ResponseCode rc = ResponseCode::SUCCESS; 56 | // Each test runs in its own scope to ensure complete cleanup 57 | /** 58 | * Run Jobs Tests 59 | */ 60 | { 61 | JobsTest jobs_test_runner; 62 | rc = jobs_test_runner.RunTest(); 63 | if (ResponseCode::SUCCESS != rc) { 64 | return rc; 65 | } 66 | } 67 | 68 | /** 69 | * Run Subscribe Publish Tests 70 | */ 71 | { 72 | PubSub pub_sub_runner; 73 | rc = pub_sub_runner.RunTest(); 74 | if (ResponseCode::SUCCESS != rc) { 75 | return rc; 76 | } 77 | } 78 | 79 | /** 80 | * Run Autoreconnect test 81 | */ 82 | { 83 | AutoReconnect auto_reconnect_runner; 84 | rc = auto_reconnect_runner.RunTest(); 85 | if (ResponseCode::SUCCESS != rc) { 86 | return rc; 87 | } 88 | } 89 | 90 | /** 91 | * Run Multiple Clients test 92 | */ 93 | { 94 | MultipleClients multiple_client_runner; 95 | rc = multiple_client_runner.RunTest(); 96 | if (ResponseCode::SUCCESS != rc) { 97 | return rc; 98 | } 99 | } 100 | 101 | /** 102 | * Run Multiple Subscription auto reconnect test with 0 topics 103 | */ 104 | { 105 | MultipleSubAutoReconnect multiple_sub_runner(0); 106 | rc = multiple_sub_runner.RunTest(); 107 | if (ResponseCode::SUCCESS != rc) { 108 | return rc; 109 | } 110 | } 111 | 112 | /** 113 | * Run Multiple Subscription auto reconnect test with 8 topics 114 | */ 115 | { 116 | MultipleSubAutoReconnect multiple_sub_runner(8); 117 | rc = multiple_sub_runner.RunTest(); 118 | if (ResponseCode::SUCCESS != rc) { 119 | return rc; 120 | } 121 | } 122 | 123 | /** 124 | * Run Multiple Subscription auto reconnect test with 50 topics 125 | */ 126 | { 127 | MultipleSubAutoReconnect multiple_sub_runner(MAX_ALLOWED_SUBSCRIPTIONS); 128 | rc = multiple_sub_runner.RunTest(); 129 | if (ResponseCode::SUCCESS != rc) { 130 | return rc; 131 | } 132 | } 133 | 134 | return rc; 135 | } 136 | } 137 | } 138 | } 139 | 140 | int main(int argc, char **argv) { 141 | std::shared_ptr p_log_system = 142 | std::make_shared(awsiotsdk::util::Logging::LogLevel::Info); 143 | awsiotsdk::util::Logging::InitializeAWSLogging(p_log_system); 144 | 145 | std::unique_ptr test_runner = 146 | std::unique_ptr(new awsiotsdk::tests::integration::IntegTestRunner()); 147 | 148 | awsiotsdk::ResponseCode rc = test_runner->Initialize(); 149 | if (awsiotsdk::ResponseCode::SUCCESS == rc) { 150 | rc = test_runner->RunAllTests(); 151 | } 152 | #ifdef WIN32 153 | getchar(); 154 | #endif 155 | 156 | awsiotsdk::util::Logging::ShutdownAWSLogging(); 157 | return static_cast(rc); 158 | } 159 | -------------------------------------------------------------------------------- /tests/integration/src/SdkTestConfig.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file SdkConfig.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include 23 | 24 | #include "util/JsonParser.hpp" 25 | #include "SdkTestConfig.hpp" 26 | 27 | namespace awsiotsdk { 28 | namespace util { 29 | rapidjson::Document SdkTestConfig::sdkConfigJson; 30 | 31 | ResponseCode SdkTestConfig::InitializeFromJsonFile(const util::String &configFilePath) { 32 | return JsonParser::InitializeFromJsonFile(sdkConfigJson, configFilePath); 33 | } 34 | 35 | ResponseCode SdkTestConfig::InitializeFromJsonString(const util::String &configJsonString) { 36 | return JsonParser::InitializeFromJsonString(sdkConfigJson, configJsonString); 37 | } 38 | 39 | ResponseCode SdkTestConfig::GetBoolValue(const char *key, bool &value) { 40 | return JsonParser::GetBoolValue(sdkConfigJson, key, value); 41 | } 42 | 43 | ResponseCode SdkTestConfig::GetIntValue(const char *key, int &value) { 44 | return JsonParser::GetIntValue(sdkConfigJson, key, value); 45 | } 46 | 47 | ResponseCode SdkTestConfig::GetUint16Value(const char *key, uint16_t &value) { 48 | return JsonParser::GetUint16Value(sdkConfigJson, key, value); 49 | } 50 | 51 | ResponseCode SdkTestConfig::GetUint32Value(const char *key, uint32_t &value) { 52 | return JsonParser::GetUint32Value(sdkConfigJson, key, value); 53 | } 54 | 55 | ResponseCode SdkTestConfig::GetSizeTValue(const char *key, size_t &value) { 56 | return JsonParser::GetSizeTValue(sdkConfigJson, key, value); 57 | } 58 | 59 | ResponseCode SdkTestConfig::GetCStringValue(const char *key, char *value, uint16_t max_string_len) { 60 | return JsonParser::GetCStringValue(sdkConfigJson, key, value, max_string_len); 61 | } 62 | 63 | ResponseCode SdkTestConfig::GetStringValue(const char *key, util::String &value) { 64 | return JsonParser::GetStringValue(sdkConfigJson, key, value); 65 | } 66 | 67 | rapidjson::ParseErrorCode SdkTestConfig::GetParseErrorCode() { 68 | return JsonParser::GetParseErrorCode(sdkConfigJson); 69 | } 70 | 71 | size_t SdkTestConfig::GetParseErrorOffset() { 72 | return JsonParser::GetParseErrorOffset(sdkConfigJson); 73 | } 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /tests/unit/CMakeLists-gtest.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | project(googletest-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(googletest 7 | GIT_REPOSITORY https://github.com/google/googletest.git 8 | GIT_TAG main 9 | SOURCE_DIR "${CMAKE_BINARY_DIR}/third_party/googletest/src" 10 | BINARY_DIR "${CMAKE_BINARY_DIR}/third_party/googletest/build" 11 | CONFIGURE_COMMAND "" 12 | BUILD_COMMAND "" 13 | INSTALL_COMMAND "" 14 | TEST_COMMAND "" 15 | ) 16 | -------------------------------------------------------------------------------- /tests/unit/include/JobsMock.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file JobsMock.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | namespace awsiotsdk { 26 | 27 | class JobsMock : public Jobs { 28 | protected: 29 | static util::String last_update_payload_; 30 | 31 | public: 32 | JobsMock() : Jobs(nullptr, mqtt::QoS::QOS1, "testThingName", "testClientToken") {} 33 | 34 | ResponseCode SendJobsUpdate(const util::String &jobId, 35 | Jobs::JobExecutionStatus status, 36 | const util::Map &statusDetailsMap = util::Map(), 37 | int64_t expectedVersion = 0, // set to 0 to ignore 38 | int64_t executionNumber = 0, // set to 0 to ignore 39 | bool includeJobExecutionState = false, 40 | bool includeJobDocument = false) { 41 | util::Map statusDetailsMapCleaned = statusDetailsMap; 42 | statusDetailsMapCleaned.erase("arch"); 43 | statusDetailsMapCleaned.erase("cwd"); 44 | statusDetailsMapCleaned.erase("platform"); 45 | last_update_payload_ = SerializeJobExecutionUpdatePayload(status, statusDetailsMapCleaned, expectedVersion, executionNumber, 46 | includeJobExecutionState, includeJobDocument); 47 | return ResponseCode::SUCCESS; 48 | } 49 | 50 | static util::String GetLastUpdatePayload() { 51 | return last_update_payload_; 52 | } 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /tests/unit/include/MockNetworkConnection.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file MockNetworkConnection.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include "TestHelper.hpp" 33 | #include "ResponseCode.hpp" 34 | #include "NetworkConnection.hpp" 35 | 36 | namespace awsiotsdk { 37 | namespace tests { 38 | namespace mocks { 39 | class MockNetworkConnection : public NetworkConnection { 40 | protected: 41 | util::Vector next_read_buf_; 42 | std::atomic_bool has_read_buf_; 43 | 44 | public: 45 | std::atomic_bool was_read_called_; 46 | std::atomic_bool was_write_called_; 47 | util::String last_write_buf_; 48 | 49 | void ClearNextReadBuf(); 50 | void SetNextReadBuf(util::String next_read_buf); 51 | util::String GetNextReadBuf(); 52 | bool HasReadBufSet(); 53 | 54 | virtual ResponseCode WriteInternal(const util::String &buf, size_t &size_written_bytes_out); 55 | 56 | virtual ResponseCode ReadInternal(util::Vector &buf, size_t buf_read_offset, 57 | size_t size_bytes_to_read, size_t &size_read_bytes_out); 58 | 59 | MOCK_METHOD0(ConnectInternal, ResponseCode()); 60 | MOCK_METHOD2(WriteInternalProxy, ResponseCode( 61 | const util::String &, size_t &)); 62 | MOCK_METHOD3(ReadInternalProxy, ResponseCode(util::Vector & , size_t, size_t & )); 63 | MOCK_METHOD0(DisconnectInternal, ResponseCode()); 64 | MOCK_METHOD0(IsConnected, bool()); 65 | MOCK_METHOD0(IsPhysicalLayerConnected, bool()); 66 | MOCK_METHOD0(Destroy, ResponseCode()); 67 | }; 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /tests/unit/include/TestHelper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file TestHelper.hpp 18 | * @brief 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "util/Utf8String.hpp" 26 | 27 | #include "mqtt/Client.hpp" 28 | 29 | #define MAX_NO_OF_REMAINING_LENGTH_BYTES 4 30 | 31 | #define MAX_MQTT_PACKET_REM_LEN_BYTES 268435455 32 | 33 | // Fixed header first bytes as per MQTT spec 34 | // CONNECT - 0001 0000 35 | #define CONNECT_PACKET_FIXED_HEADER_VAL 0x10 36 | // CONNACK - 0010 0000 37 | #define CONNACK_PACKET_FIXED_HEADER_VAL 0x20 38 | // PUBLISH - 0011 39 | // = x00y 40 | // = x10y 41 | // = dxxx 42 | // = xxxr 43 | #define PUBLISH_PACKET_FIXED_HEADER_VAL 0x30 44 | // PUBACK - 0100 0000 45 | #define PUBACK_PACKET_FIXED_HEADER_VAL 0x40 46 | // PUBREC - 0101 0000 47 | #define PUBREC_PACKET_FIXED_HEADER_VAL 0x50 48 | // PUBREL 0110 0010 49 | #define PUBREL_PACKET_FIXED_HEADER_VAL 0x62 50 | // PUBCOMP 0111 0000 51 | #define PUBCOMP_PACKET_FIXED_HEADER_VAL 0x70 52 | // SUBSCRIBE 1000 0010 53 | #define SUBSCRIBE_PACKET_FIXED_HEADER_VAL 0x82 54 | // SUBACK 1001 0000 55 | #define SUBACK_PACKET_FIXED_HEADER_VAL 0x90 56 | // UNSUBSCRIBE 1010 0010 57 | #define UNSUBSCRIBE_PACKET_FIXED_HEADER_VAL 0xA2 58 | // UNSUBACK 1011 0000 59 | #define UNSUBACK_PACKET_FIXED_HEADER_VAL 0xB0 60 | // PINGREQ 1100 0000 61 | #define PINGREQ_PACKET_FIXED_HEADER_VAL 0xC0 62 | // PINGRESP 1101 0000 63 | #define PINGRESP_PACKET_FIXED_HEADER_VAL 0xD0 64 | // DISCONNECT 1110 0000 65 | #define DISCONNECT_PACKET_FIXED_HEADER_VAL 0xE0 66 | 67 | #define CONNACK_PACKET_REM_LEN_VAL 2 68 | #define PUBACK_PACKET_REM_LEN_VAL 2 69 | 70 | namespace awsiotsdk { 71 | namespace tests { 72 | enum class ConnackTestReturnCode { 73 | CONNECTION_ACCEPTED = 0, 74 | UNACCEPTABLE_PROTOCOL_VERSION_ERROR = 1, 75 | IDENTIFIER_REJECTED_ERROR = 2, 76 | SERVER_UNAVAILABLE_ERROR = 3, 77 | BAD_USERDATA_ERROR = 4, 78 | NOT_AUTHORIZED_ERROR = 5, 79 | INVALID_VALUE_ERROR = 6 80 | }; 81 | 82 | class TestHelper { 83 | public: 84 | static void WriteCharToBuffer(unsigned char **p_buf, unsigned char value); 85 | static void WriteUint16ToBuffer(unsigned char **p_buf, uint16_t value); 86 | static unsigned char ReadCharFromBuffer(unsigned char **p_buf); 87 | static uint16_t ReadUint16FromBuffer(unsigned char **p_buf); 88 | static std::unique_ptr ReadUtf8StringFromBuffer(unsigned char **p_buf); 89 | static size_t ParseRemLenFromBuffer(unsigned char **p_buf); 90 | static util::String GetEncodedRemLen(size_t rem_len); 91 | static util::String GetSerializedPublishMessage(util::String topic_name, 92 | uint16_t packet_id, 93 | mqtt::QoS qos, 94 | bool is_duplicate, 95 | bool is_retained, 96 | util::String payload); 97 | static util::String GetSerializedSubAckMessage(uint16_t packet_id, std::vector suback_list_); 98 | static util::String GetSerializedUnsubAckMessage(uint16_t packet_id); 99 | static util::String GetSerializedPubAckMessage(uint16_t packet_id); 100 | static util::String GetSerializedConnAckMessage(bool is_session_present, ConnackTestReturnCode connack_rc); 101 | }; 102 | } 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /tests/unit/src/MockNetworkConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file MockNetworkConnection.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include "MockNetworkConnection.hpp" 23 | 24 | namespace awsiotsdk { 25 | namespace tests { 26 | namespace mocks { 27 | void MockNetworkConnection::ClearNextReadBuf() { 28 | has_read_buf_ = false; 29 | next_read_buf_.clear(); 30 | } 31 | 32 | void MockNetworkConnection::SetNextReadBuf(util::String next_read_buf) { 33 | has_read_buf_ = true; 34 | was_read_called_ = false; 35 | next_read_buf_.clear(); 36 | for (char c : next_read_buf) { 37 | next_read_buf_.push_back(static_cast(c)); 38 | } 39 | } 40 | 41 | util::String MockNetworkConnection::GetNextReadBuf() { 42 | return util::String(next_read_buf_.begin(), next_read_buf_.end()); 43 | } 44 | 45 | bool MockNetworkConnection::HasReadBufSet() { return has_read_buf_; } 46 | 47 | ResponseCode MockNetworkConnection::WriteInternal(const util::String &buf, size_t &size_written_bytes_out) { 48 | was_write_called_ = true; 49 | last_write_buf_.clear(); 50 | last_write_buf_.append(buf); 51 | return WriteInternalProxy(buf, size_written_bytes_out); 52 | } 53 | 54 | ResponseCode MockNetworkConnection::ReadInternal(util::Vector &buf, size_t buf_read_offset, 55 | size_t size_bytes_to_read, size_t &size_read_bytes_out) { 56 | was_read_called_ = true; 57 | size_read_bytes_out = 0; 58 | 59 | if (has_read_buf_) { 60 | size_t remaining_bytes_in_buf = next_read_buf_.size(); 61 | size_t cur_read_bytes = 0; 62 | size_read_bytes_out = ((size_bytes_to_read <= remaining_bytes_in_buf) ? size_bytes_to_read 63 | : remaining_bytes_in_buf); 64 | //size_t cur_read_bytes = 0; 65 | auto begin_itr = next_read_buf_.begin(); 66 | auto end_itr = next_read_buf_.begin() + size_read_bytes_out; 67 | auto insert_itr = buf.begin() + buf_read_offset; 68 | auto insert_end_itr = buf.begin() + buf_read_offset + size_read_bytes_out; 69 | buf.erase(insert_itr, insert_end_itr); 70 | for (unsigned char c : next_read_buf_) { 71 | buf.push_back(c); 72 | if (cur_read_bytes >= size_read_bytes_out) { 73 | break; 74 | } 75 | } 76 | 77 | next_read_buf_.erase(begin_itr, end_itr); 78 | 79 | if (0 == next_read_buf_.size()) { 80 | has_read_buf_ = false; 81 | } 82 | 83 | return ResponseCode::SUCCESS; 84 | } 85 | return ReadInternalProxy(buf, size_bytes_to_read, size_read_bytes_out); 86 | } 87 | } 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /tests/unit/src/TestRunner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file TestRunner.cpp 18 | * @brief 19 | * 20 | */ 21 | 22 | #include 23 | 24 | int main(int argc, char **argv) { 25 | testing::InitGoogleTest(&argc, argv); 26 | return RUN_ALL_TESTS(); 27 | } 28 | -------------------------------------------------------------------------------- /tests/unit/src/util/TestParser.json: -------------------------------------------------------------------------------- 1 | { 2 | "test_string": "json_parser_test_string", 3 | "test_cstr": "json_parser_test_cstring", 4 | "test_uint16_t": 16, 5 | "test_uin32_t": 32, 6 | "test_size_t": 64, 7 | "test_int": -128, 8 | "test_bool_true": true, 9 | "test_bool_false": false 10 | } 11 | --------------------------------------------------------------------------------