AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Manufactory_imp.h
Go to the documentation of this file.
1 /*
2  * Copyright 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 #ifndef ACSDKMANUFACTORY_INTERNAL_MANUFACTORY_IMP_H_
17 #define ACSDKMANUFACTORY_INTERNAL_MANUFACTORY_IMP_H_
18 
19 #include <tuple>
20 
22 
26 
27 namespace alexaClientSDK {
28 namespace acsdkManufactory {
29 
30 template <typename... Exports>
31 template <typename... Parameters>
32 inline std::unique_ptr<Manufactory<Exports...>> Manufactory<Exports...>::create(
33  const Component<Parameters...>& component) {
34  static_assert(!internal::HasRequiredImport<Parameters...>::value, "Component has non satisfied Import<Type>.");
35 
36  // Check if any export is missing. If missing, assertion will fail and PrintMissingExport will print a compilation
37  // error with the name of the types missing.
38  using MissingExports = typename internal::RemoveTypes<std::tuple<Exports...>, std::tuple<Parameters...>>::type;
39  static_assert(std::tuple_size<MissingExports>() == 0, "Missing export types required by Manufactory::create.");
41 
42  auto cookBook = component.getCookBook();
44  if (!cookBook.checkCompleteness()) {
45  return nullptr;
46  }
47  return std::unique_ptr<Manufactory>(new Manufactory(cookBook));
48 }
49 
50 template <typename... Exports>
51 template <typename... Superset>
53  const std::shared_ptr<Manufactory<Superset...>>& input) {
54  // Check if any export is missing. If missing, assertion will fail and PrintMissingExport will print a compilation
55  // error with the name of the types missing.
56  using MissingExports = typename internal::RemoveTypes<std::tuple<Exports...>, std::tuple<Superset...>>::type;
57  static_assert(
58  std::tuple_size<MissingExports>() == 0,
59  "Input does not provide all the types to be exported by "
60  "subset manufactory");
62 
63  if (!input) {
65  avsCommon::utils::logger::LogEntry("Manufactory", "createSubsetManufactoryFailed")
66  .d("reason", "nullSuperSetManufactory"));
67  return nullptr;
68  }
69  return Manufactory<Exports...>::create(input->m_runtimeManufactory);
70 }
71 
72 template <typename... Exports>
73 template <typename... Subset>
74 inline std::unique_ptr<Manufactory<Subset...>> Manufactory<Exports...>::createSubsetManufactory() {
75  // Check if any export is missing. If missing, assertion will fail and PrintMissingExport will print a compilation
76  // error with the name of the types missing.
77  using MissingExports = typename internal::RemoveTypes<std::tuple<Subset...>, std::tuple<Exports...>>::type;
78  static_assert(std::tuple_size<MissingExports>() == 0, "Manufactory does not export all types in Subset...");
80 
81  return Manufactory<Subset...>::create(m_runtimeManufactory);
82 }
83 
84 template <typename... Exports>
85 template <typename Type>
87  static_assert(
88  internal::ContainsType<std::tuple<Exports...>, Type>::value,
89  "Manufactory::get() does not support requested Type");
90 
91  return m_runtimeManufactory->get<Type>();
92 }
93 
94 template <typename... Exports>
95 inline std::unique_ptr<Manufactory<Exports...>> Manufactory<Exports...>::create(
96  const std::shared_ptr<internal::RuntimeManufactory>& runtimeManufactory) {
97  // Perhaps add run-time check here that runtimeManufactory supports Exports...
98 
99  return std::unique_ptr<Manufactory>(new Manufactory(runtimeManufactory));
100 }
101 
102 template <typename... Exports>
104  m_runtimeManufactory.reset(new internal::RuntimeManufactory(cookBook));
105 }
106 
107 template <typename... Exports>
108 inline Manufactory<Exports...>::Manufactory(const std::shared_ptr<internal::RuntimeManufactory>& runtimeManufactory) :
109  m_runtimeManufactory{runtimeManufactory} {
110 }
111 
112 } // namespace acsdkManufactory
113 } // namespace alexaClientSDK
114 
115 #endif // ACSDKMANUFACTORY_INTERNAL_MANUFACTORY_IMP_H_
friend class Manufactory
Definition: Manufactory.h:88
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void acsdkError(const LogEntry &entry)
Definition: LoggerUtils.cpp:80
static std::unique_ptr< Manufactory< Exports... > > create(const Component< Parameters... > &component)
Definition: Manufactory_imp.h:32
std::unique_ptr< Manufactory< Subset... > > createSubsetManufactory()
Definition: Manufactory_imp.h:74
Type get()
Definition: Manufactory_imp.h:86
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:32

AlexaClientSDK 1.26.0 - Copyright 2016-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0