/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include #include #include #include #include #include namespace HttpRequestor { class Manager { public: Manager(); virtual ~Manager(); // Add these parameters to a queue of request parameters to send off as an HTTP request as soon as they reach the head of the queue void AddRequest(Parameters && httpRequestParameters); // Add these parameters to a queue of request parameters to send off as an HTTP TEXT request as soon as they reach the head of the queue void AddTextRequest(TextParameters && httpTextRequestParameters); private: // RequestManager thread loop. void ThreadFunction(); // Called by ThreadFunction. Waits for timeout or until notified and processes any requests queued up. void HandleRequestBatch(); // Perform an HTTP request, block until a response is received, then give the returned JSON to the callback to parse. Returns the HTTPResponseCode to the callback to handle any errors. void HandleRequest(const Parameters & httpRequestParameters); // Perform an HTTP request, block until a response is received, then give the returned TEXT to the callback to parse. Returns the HTTPResponseCode to the callback to handle any errors. void HandleTextRequest(const TextParameters & httpTextRequestParameters); private: AZStd::queue m_requestsToHandle; // Queue of requests that will be made in order of time received AZStd::queue m_textRequestsToHandle; // Queue of requests for TEXT blobs that will be made in order of time received AZStd::mutex m_requestMutex; // Member variables for synchronization AZStd::condition_variable m_requestConditionVar; AZStd::atomic m_runThread; // Run flag used to signal the worker thread AZStd::thread m_thread; // This is the thread that will be used for all async operations static const char* s_loggingName; // Name to use for log messages etc... }; using ManagerPtr = AZStd::shared_ptr; }