ServiceJob.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Framework/HttpRequestJob.h>
  10. #include <Framework/ServiceJobConfig.h>
  11. #include <Framework/RequestBuilder.h>
  12. #include <AzCore/std/smart_ptr/shared_ptr.h>
  13. namespace AWSCore
  14. {
  15. /// A ServiceJob encapsulates an HttpJob with all of the functionality necessary for an auto-generated AWS feature service.
  16. /// Inherits protected from HttpJob to hide all of the functionality not normally require.
  17. class ServiceJob
  18. : protected HttpRequestJob
  19. {
  20. public:
  21. using IConfig = IServiceJobConfig;
  22. using Config = ServiceJobConfig;
  23. static Config* GetDefaultConfig()
  24. {
  25. static AwsApiJobConfigHolder<Config> s_configHolder{};
  26. return s_configHolder.GetConfig(HttpRequestJob::GetDefaultConfig());
  27. }
  28. public:
  29. // To use a different allocator, extend this class and use this macro.
  30. AZ_CLASS_ALLOCATOR(ServiceJob, AZ::SystemAllocator);
  31. ServiceJob(bool isAutoDelete, IConfig* config)
  32. : HttpRequestJob(isAutoDelete, config)
  33. {
  34. }
  35. /// Access the underlying HttpRequestJob if lower-level access is needed
  36. HttpRequestJob& GetHttpRequestJob();
  37. const HttpRequestJob& GetHttpRequestJob() const;
  38. /// Start the asynchronous job
  39. void Start();
  40. private:
  41. /// Descendant classes must implement these in order to have their requests sent
  42. virtual bool BuildRequest(RequestBuilder& request) = 0;
  43. virtual std::shared_ptr<Aws::StringStream> GetBodyContent(RequestBuilder& requestBuilder);
  44. /// Configures the request using the custom properties of the service by calling BuildRequest()
  45. std::shared_ptr<Aws::Http::HttpRequest> InitializeRequest() override;
  46. };
  47. } // namespace AWSCore