AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
APLRuntimePresentationAdapter.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_APLRUNTIMEPRESENTATIONADAPTER_H_
17 #define ALEXA_CLIENT_SDK_LIBIPCSERVERSAMPLEAPP_INCLUDE_IPCSERVERSAMPLEAPP_ALEXAPRESENTATION_APLRUNTIMEPRESENTATIONADAPTER_H_
18 
19 #include <string>
20 
21 #include <rapidjson/document.h>
22 #include <rapidjson/writer.h>
23 
38 
41 
42 namespace alexaClientSDK {
43 namespace sampleApplications {
44 namespace ipcServerSampleApp {
45 
52  , public std::enable_shared_from_this<APLRuntimePresentationAdapter> {
53 public:
60  static std::shared_ptr<APLRuntimePresentationAdapter> create(
61  const std::shared_ptr<APLRuntimeInterfaceImpl>& runtimeInterface,
62  std::shared_ptr<gui::GUIActivityEventNotifierInterface> activityEventNotifier);
63 
69  std::shared_ptr<alexaPresentationInterfaces::AlexaPresentationCapabilityAgentInterface> alexaPresentationCA);
70 
75  void setDefaultWindowId(const std::string& windowId);
76 
83 
86  void onRenderDocument(
87  const std::string& document,
88  const std::string& datasource,
90  const std::string& windowId,
92  const std::string& interfaceName,
93  const std::string& supportedViewports,
94  const aplCapabilityCommonInterfaces::PresentationSession& presentationSession,
95  const std::chrono::steady_clock::time_point& receiveTime,
96  std::shared_ptr<aplCapabilityCommonInterfaces::APLCapabilityAgentInterface> agent) override;
97 
99  override;
100 
101  void onDataSourceUpdate(
102  const std::string& sourceType,
103  const std::string& jsonPayload,
105 
108 
112  const aplCapabilityCommonInterfaces::PresentationSession& presentationSession,
114  std::unique_ptr<aplCapabilityCommonInterfaces::APLDocumentSessionInterface>&& session) override;
115 
119  const std::string& error) override;
120 
123  bool result,
124  const std::string& error,
125  const std::chrono::steady_clock::time_point& timestamp) override;
126 
128 
132 
133  void onDataSourceUpdateComplete(const std::string& token, bool result, const std::string& error) override;
134 
136 
138 
139  void onDocumentFinished(const std::string& token) override;
140 
144 
145  void onSessionEnded(const aplCapabilityCommonInterfaces::PresentationSession& presentationSession) override;
146 
147  void onActivityEvent(
149  const avsCommon::sdkInterfaces::GUIActivityEvent& event) override;
151 
154  void provideState(
156  const avsCommon::sdkInterfaces::ContextRequestToken stateRequestToken) override;
158 
162  const std::string& source,
163  const avsCommon::sdkInterfaces::GUIActivityEvent& activityEvent) override;
165 
171 
173 
177  void setExecutor(std::shared_ptr<avsCommon::utils::threading::Executor>);
178 
196  const std::string& jsonPayload,
197  const std::string& token,
198  const std::string& windowId,
199  const std::chrono::steady_clock::time_point& receiveTime,
200  const std::string& interface,
201  std::shared_ptr<aplCapabilityCommonInterfaces::APLCapabilityAgentInterface> agent);
202 
207  void clearDocument(const std::string& token);
208 
209 private:
211  const std::shared_ptr<APLRuntimeInterfaceImpl>& runtimeInterface,
212  std::unique_ptr<APLDocumentSessionManager> sessionManager,
213  std::shared_ptr<gui::GUIActivityEventNotifierInterface> activityEventNotifier);
214 
215  void executeRenderDocument(
216  const std::string& document,
217  const std::string& datasource,
219  const std::string& windowId,
221  const std::string& interfaceName,
222  const std::string& supportedViewports,
223  const aplCapabilityCommonInterfaces::PresentationSession& presentationSession,
224  const std::chrono::steady_clock::time_point& receiveTime,
225  std::shared_ptr<aplCapabilityCommonInterfaces::APLCapabilityAgentInterface> agent,
226  bool trackAsPresentation);
227  void executeClearDocument(const std::string& token);
228  void executeExecuteCommands(
229  const std::string& jsonPayload,
231  void executeDataSourceUpdate(
232  const std::string& sourceType,
233  const std::string& jsonPayload,
234  const std::string& token);
235  void executeRequestForeground(const std::string& token);
236  void executeOnCommandExecutionComplete(
237  const std::string& token,
239  const std::string& message);
240  void executeOnRenderDocumentComplete(
241  const std::string& token,
242  bool result,
243  const std::string& error,
244  const std::chrono::steady_clock::time_point& timestamp);
245  void executeOnSendEvent(const aplCapabilityCommonInterfaces::aplEventPayload::UserEvent& payload);
246  void executeOnVisualContextAvailable(
249  void executeOnDataSourceUpdateComplete(const std::string& token, bool result, const std::string& error);
250  void executeOnDataSourceFetch(
252  void executeOnRuntimeError(const aplCapabilityCommonInterfaces::aplEventPayload::RuntimeError& runtimeError);
253  void executeOnDocumentFinished(const std::string& token);
254  void executeProvideState(const std::string& aplToken, const unsigned int stateRequestToken);
255  void executeOnPlayerActivityChanged(avsCommon::avs::PlayerActivity state);
256 
263  struct PresentationAgentDocumentTracker {
270  explicit PresentationAgentDocumentTracker(
271  std::string token,
272  std::weak_ptr<aplCapabilityCommonInterfaces::APLCapabilityAgentInterface> presentationAgent,
273  bool trackAsPresentation) :
274  token{std::move(token)},
275  presentationAgent{std::move(presentationAgent)} {
276  handleOnPresentationDismissed = trackAsPresentation;
277  docCount = 1;
278  };
279 
281  std::string token;
282 
284  std::weak_ptr<aplCapabilityCommonInterfaces::APLCapabilityAgentInterface> presentationAgent;
285 
287  int docCount;
288 
290  bool handleOnPresentationDismissed;
291  };
292 
298  std::shared_ptr<PresentationAgentDocumentTracker> executeGetPresentationAgentTrackerFromToken(
299  const std::string& token);
300 
306  std::shared_ptr<aplCapabilityCommonInterfaces::APLCapabilityAgentInterface> executeGetPresentationAgentFromToken(
307  const std::string& token);
308 
315  void executeRemoveTokenFromPresentationAgentTracker(const std::string& token);
316 
322  void executeUpdateTimeoutType(
323  const std::string& aplToken,
325 
326  const std::shared_ptr<APLRuntimeInterfaceImpl> m_runtimeInterface;
327 
328  std::unique_ptr<APLDocumentSessionManager> m_sessionManager;
329 
330  std::shared_ptr<gui::GUIActivityEventNotifierInterface> m_activityEventNotifier;
331 
333  bool m_isSpeakingOrListening;
334 
336  std::shared_ptr<alexaPresentationInterfaces::AlexaPresentationCapabilityAgentInterface> m_alexaPresentationCA;
337 
339  std::unordered_map<std::string, std::shared_ptr<PresentationAgentDocumentTracker>> m_presentationAgentTrackers;
340 
342  std::unordered_map<std::shared_ptr<aplCapabilityCommonInterfaces::APLCapabilityAgentInterface>, unsigned int>
343  m_presentationTrackersPerCA;
344 
346  std::shared_ptr<avsCommon::utils::threading::Executor> m_executor;
347 };
348 } // namespace ipcServerSampleApp
349 } // namespace sampleApplications
350 } // namespace alexaClientSDK
351 #endif // ALEXA_CLIENT_SDK_LIBIPCSERVERSAMPLEAPP_INCLUDE_IPCSERVERSAMPLEAPP_ALEXAPRESENTATION_APLRUNTIMEPRESENTATIONADAPTER_H_
void setExecutor(std::shared_ptr< avsCommon::utils::threading::Executor >)
void onShowDocument(const aplCapabilityCommonInterfaces::PresentationToken &token) override
void onRenderDocumentComplete(const aplCapabilityCommonInterfaces::PresentationToken &token, bool result, const std::string &error, const std::chrono::steady_clock::time_point &timestamp) override
APLTimeoutType
Definition: APLTimeoutType.h:30
void onDataSourceUpdate(const std::string &sourceType, const std::string &jsonPayload, const aplCapabilityCommonInterfaces::PresentationToken &token) override
::std::string string
Definition: gtest-port.h:1097
void onActivityEvent(const aplCapabilityCommonInterfaces::PresentationToken &token, const avsCommon::sdkInterfaces::GUIActivityEvent &event) override
unsigned int ContextRequestToken
Alias for the token used to identify a context request.
Definition: ContextRequestToken.h:23
void onRuntimeError(const aplCapabilityCommonInterfaces::aplEventPayload::RuntimeError &payload) override
void onDataSourceUpdateComplete(const std::string &token, bool result, const std::string &error) override
void renderDocumentWithoutPresentation(const std::string &jsonPayload, const std::string &token, const std::string &windowId, const std::chrono::steady_clock::time_point &receiveTime, const std::string &interface, std::shared_ptr< aplCapabilityCommonInterfaces::APLCapabilityAgentInterface > agent)
DialogUXState
The different dialog specific AVS UX states.
Definition: DialogUXStateObserverInterface.h:32
void onActiveDocumentChanged(const aplCapabilityCommonInterfaces::PresentationToken &token, const aplCapabilityCommonInterfaces::PresentationSession &session) override
std::string PresentationToken
Alias for the token used by APL directives.
Definition: PresentationToken.h:22
void provideState(const aplCapabilityCommonInterfaces::PresentationToken &token, const avsCommon::sdkInterfaces::ContextRequestToken stateRequestToken) override
void onDataSourceFetch(const aplCapabilityCommonInterfaces::aplEventPayload::DataSourceFetch &payload) override
void onGUIActivityEventReceived(const std::string &source, const avsCommon::sdkInterfaces::GUIActivityEvent &activityEvent) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onVisualContextAvailable(const avsCommon::sdkInterfaces::ContextRequestToken requestToken, const aplCapabilityCommonInterfaces::aplEventPayload::VisualContext &context) override
GUIActivityEvent
Enumeration of activity events used to indicate the state of a GUI.
Definition: GUIActivityEvent.h:27
void onAPLDocumentSessionAvailable(const aplCapabilityCommonInterfaces::PresentationSession &presentationSession, const aplCapabilityCommonInterfaces::PresentationToken &token, std::unique_ptr< aplCapabilityCommonInterfaces::APLDocumentSessionInterface > &&session) override
void onSendEvent(const aplCapabilityCommonInterfaces::aplEventPayload::UserEvent &payload) override
void onRenderDocument(const std::string &document, const std::string &datasource, const aplCapabilityCommonInterfaces::PresentationToken &token, const std::string &windowId, const aplCapabilityCommonInterfaces::APLTimeoutType timeoutType, const std::string &interfaceName, const std::string &supportedViewports, const aplCapabilityCommonInterfaces::PresentationSession &presentationSession, const std::chrono::steady_clock::time_point &receiveTime, std::shared_ptr< aplCapabilityCommonInterfaces::APLCapabilityAgentInterface > agent) override
static std::shared_ptr< APLRuntimePresentationAdapter > create(const std::shared_ptr< APLRuntimeInterfaceImpl > &runtimeInterface, std::shared_ptr< gui::GUIActivityEventNotifierInterface > activityEventNotifier)
void onSessionEnded(const aplCapabilityCommonInterfaces::PresentationSession &presentationSession) override
APLCommandExecutionEvent
Enumeration of APL Command Execution Events that can be reported to the APL capability agent...
Definition: APLCommandExecutionEvent.h:27
PlayerActivity
Identifies the player state.
Definition: PlayerActivity.h:27
Definition: GUIActivityEventObserverInterface.h:28
void onExecuteCommands(const std::string &sourceType, const aplCapabilityCommonInterfaces::PresentationToken &token) override
tuple message
Definition: gtest_output_test.py:331
const T & move(const T &t)
Definition: gtest-port.h:1317
void onDialogUXStateChanged(avsCommon::sdkInterfaces::DialogUXStateObserverInterface::DialogUXState newState) override
void onCommandExecutionComplete(const aplCapabilityCommonInterfaces::PresentationToken &token, alexaClientSDK::aplCapabilityCommonInterfaces::APLCommandExecutionEvent event, const std::string &error) override
A dialog specific UX state observer.
Definition: DialogUXStateObserverInterface.h:29
void setAlexaPresentationCA(std::shared_ptr< alexaPresentationInterfaces::AlexaPresentationCapabilityAgentInterface > alexaPresentationCA)

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