AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
APLDocumentSession.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 ALEXA_CLIENT_SDK_LIBIPCSERVERSAMPLEAPP_INCLUDE_IPCSERVERSAMPLEAPP_ALEXAPRESENTATION_APLDOCUMENTSESSION_H_
17 #define ALEXA_CLIENT_SDK_LIBIPCSERVERSAMPLEAPP_INCLUDE_IPCSERVERSAMPLEAPP_ALEXAPRESENTATION_APLDOCUMENTSESSION_H_
18 
19 #include <chrono>
20 #include <string>
21 #include <unordered_set>
22 
30 
31 namespace alexaClientSDK {
32 namespace sampleApplications {
33 namespace ipcServerSampleApp {
38  , public std::enable_shared_from_this<APLDocumentSession> {
39 public:
52  const std::string& document,
53  const std::string& data,
54  const std::string& supportedViewPorts,
55  const aplCapabilityCommonInterfaces::PresentationSession& presentationSession,
56  const aplCapabilityCommonInterfaces::PresentationOptions& presentationOptions,
57  std::shared_ptr<alexaClientSDK::aplCapabilityCommonInterfaces::APLDocumentObserverInterface> observer,
58  APLViewhostInterfacePtr viewhost,
59  bool hasPresentationAssociation);
60 
61  void renderDocument(
62  const std::string& document,
63  const std::string& data,
66 
68 
71  void clearDocument() override;
72  void executeCommands(const std::string& commands) override;
73  void dataSourceUpdate(const std::string& sourceType, const std::string& payload) override;
74  void interruptCommandSequence() override;
75  void provideDocumentContext(const unsigned int stateRequestToken) override;
76  void requestForeground() override;
77  void stopTimeout() override;
78  void resetTimeout() override;
80  void updateTimeout(std::chrono::milliseconds timeout) override;
81  std::string getToken() const override;
82  bool isForegroundFocused() override;
84 
89  std::shared_ptr<presentationOrchestratorInterfaces::PresentationInterface> presentation) override;
95 
99  const std::string& token,
100  APLClient::AplCommandExecutionEvent event,
101  const std::string& message) override;
103  const std::string& token,
104  bool result,
105  const std::string& error,
106  const std::chrono::steady_clock::time_point& timestamp) override;
107  void onSendEvent(
108  const std::string& token,
109  const std::string& arguments,
110  const std::string& components,
111  const std::string& source) override;
113  const unsigned int requestToken,
114  const std::string& token,
115  const std::string& version,
116  const std::string& visualContext,
117  const std::string& datasourceContext) override;
118  void onDataSourceUpdateComplete(const std::string& token, bool result, const std::string& error) override;
119  void onDataSourceFetch(const std::string& token, const std::string& dataSourceType, const std::string& payload)
120  override;
121  void onRuntimeError(const std::string& token, const std::string& payload) override;
122  void onDocumentFinished(const std::string& token) override;
123  void onOpenURL(const std::string& token, const std::string& url) override;
124  void onDocumentCleared(const std::string& token) override;
125  void onSetDocumentIdleTimeout(const std::string& token, const std::chrono::milliseconds& timeout) override;
127 
131  void firstRender();
132 
139  static std::shared_ptr<APLDocumentSession> getDocumentSessionFromInterface(
140  const std::shared_ptr<aplCapabilityCommonInterfaces::APLDocumentSessionInterface>& aplDocumentSessionInterface);
141 
142 private:
147  class APLDocumentSessionWrapper : public aplCapabilityCommonInterfaces::APLDocumentSessionInterface {
148  public:
153  APLDocumentSessionWrapper(std::shared_ptr<APLDocumentSession> documentSession);
154 
157  void clearDocument() override;
158  void executeCommands(const std::string& commands) override;
159  void dataSourceUpdate(const std::string& sourceType, const std::string& payload) override;
160  void interruptCommandSequence() override;
161  void provideDocumentContext(const unsigned int stateRequestToken) override;
162  void requestForeground() override;
163  void stopTimeout() override;
164  void resetTimeout() override;
166  void updateTimeout(std::chrono::milliseconds timeout) override;
167  std::string getToken() const override;
168  bool isForegroundFocused() override;
170 
175  operator std::shared_ptr<APLDocumentSession> const();
176 
177  private:
179  std::shared_ptr<APLDocumentSession> m_documentSession;
180  };
181 
187  bool executeRenderDocument(bool firstRender = false);
188 
193  void executeClearDocument(bool forceClear = false);
194 
199  bool executeIsPresentationActive() const;
200 
205  bool executeIsPresentationForegrounded() const;
206 
212  bool canHandleToken(const std::string& token);
213 
215  std::weak_ptr<APLViewhostInterface> m_viewhost;
216 
218  bool m_hasPresentationAssociation;
219 
221  std::shared_ptr<presentationOrchestratorInterfaces::PresentationInterface> m_presentation;
222 
225 
227  std::string m_document;
228 
230  std::string m_data;
231 
234 
237 
239  std::shared_ptr<aplCapabilityCommonInterfaces::APLDocumentObserverInterface> m_observer;
240 
242  std::unordered_set<std::string> m_tokens;
243 
245  std::string m_supportedViewports;
246 
248  bool m_renderComplete;
249 
252 };
253 } // namespace ipcServerSampleApp
254 } // namespace sampleApplications
255 } // namespace alexaClientSDK
256 
257 #endif // ALEXA_CLIENT_SDK_LIBIPCSERVERSAMPLEAPP_INCLUDE_IPCSERVERSAMPLEAPP_ALEXAPRESENTATION_APLDOCUMENTSESSION_H_
void onCommandExecutionComplete(const std::string &token, APLClient::AplCommandExecutionEvent event, const std::string &message) override
void onDataSourceFetch(const std::string &token, const std::string &dataSourceType, const std::string &payload) override
void renderDocument(const std::string &document, const std::string &data, const alexaClientSDK::aplCapabilityCommonInterfaces::PresentationSession &presentationSession, const alexaClientSDK::aplCapabilityCommonInterfaces::PresentationOptions &presentationOptions)
void onPresentationStateChanged(presentationOrchestratorInterfaces::PresentationRequestToken id, presentationOrchestratorInterfaces::PresentationState newState) override
static std::shared_ptr< APLDocumentSession > getDocumentSessionFromInterface(const std::shared_ptr< aplCapabilityCommonInterfaces::APLDocumentSessionInterface > &aplDocumentSessionInterface)
void updateTimeout(std::chrono::milliseconds timeout) override
APLTimeoutType
Definition: APLTimeoutType.h:30
::std::string string
Definition: gtest-port.h:1097
void updateLifespan(presentationOrchestratorInterfaces::PresentationLifespan lifespan) override
Single-thread executor implementation.
Definition: Executor.h:45
void onRuntimeError(const std::string &token, const std::string &payload) override
void onSendEvent(const std::string &token, const std::string &arguments, const std::string &components, const std::string &source) override
void onDataSourceUpdateComplete(const std::string &token, bool result, const std::string &error) override
void onVisualContextAvailable(const unsigned int requestToken, const std::string &token, const std::string &version, const std::string &visualContext, const std::string &datasourceContext) override
PresentationState
Definition: PresentationTypes.h:48
void onSetDocumentIdleTimeout(const std::string &token, const std::chrono::milliseconds &timeout) override
void updateTimeoutType(const aplCapabilityCommonInterfaces::APLTimeoutType &timeoutType)
void onRenderDocumentComplete(const std::string &token, bool result, const std::string &error, const std::chrono::steady_clock::time_point &timestamp) override
std::shared_ptr< APLViewhostInterface > APLViewhostInterfacePtr
Definition: APLViewhostInterface.h:152
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void dataSourceUpdate(const std::string &sourceType, const std::string &payload) override
uint64_t PresentationRequestToken
Definition: PresentationTypes.h:25
APLDocumentSession(const std::string &document, const std::string &data, const std::string &supportedViewPorts, const aplCapabilityCommonInterfaces::PresentationSession &presentationSession, const aplCapabilityCommonInterfaces::PresentationOptions &presentationOptions, std::shared_ptr< alexaClientSDK::aplCapabilityCommonInterfaces::APLDocumentObserverInterface > observer, APLViewhostInterfacePtr viewhost, bool hasPresentationAssociation)
PresentationLifespan
Definition: PresentationTypes.h:27
bool onNavigateBack(presentationOrchestratorInterfaces::PresentationRequestToken id) override
void provideDocumentContext(const unsigned int stateRequestToken) override
tuple message
Definition: gtest_output_test.py:331
void onPresentationAvailable(presentationOrchestratorInterfaces::PresentationRequestToken id, std::shared_ptr< presentationOrchestratorInterfaces::PresentationInterface > presentation) override
void onOpenURL(const std::string &token, const std::string &url) override

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