AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
CertifiedSender.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_CERTIFIEDSENDER_INCLUDE_CERTIFIEDSENDER_CERTIFIEDSENDER_H_
17 #define ALEXA_CLIENT_SDK_CERTIFIEDSENDER_INCLUDE_CERTIFIEDSENDER_CERTIFIEDSENDER_H_
18 
20 
32 
33 #include <deque>
34 #include <memory>
35 
36 namespace alexaClientSDK {
37 namespace certifiedSender {
38 
43 
61  , public std::enable_shared_from_this<CertifiedSender>
63 public:
73  static std::shared_ptr<CertifiedSender> create(
74  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
75  std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface> connection,
76  std::shared_ptr<MessageStorageInterface> storage,
77  std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager);
78 
82  virtual ~CertifiedSender();
83 
96  std::future<bool> sendJSONMessage(const std::string& jsonMessage, const std::string& uriPathExtension = "");
97 
101  void clearData() override;
102 
103 private:
107  class CertifiedMessageRequest : public avsCommon::avs::MessageRequest {
108  public:
117  CertifiedMessageRequest(const std::string& jsonContent, int dbId, const std::string& uriPathExtension = "");
118 
119  void exceptionReceived(const std::string& exceptionMessage) override;
120 
121  void sendCompleted(
123 
130 
136  int getDbId();
137 
141  void shutdown();
142 
143  private:
147  bool m_responseReceived;
149  std::mutex m_requestMutex;
153  int m_dbId;
155  bool m_isRequestShuttingDown;
156  };
157 
169  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
170  std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface> connection,
171  std::shared_ptr<MessageStorageInterface> storage,
172  std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager,
173  int queueSizeWarnLimit = CERTIFIED_SENDER_QUEUE_SIZE_WARN_LIMIT,
174  int queueSizeHardLimit = CERTIFIED_SENDER_QUEUE_SIZE_HARD_LIMIT);
175 
176  void onConnectionStatusChanged(
179 
185  bool init();
186 
195  bool executeSendJSONMessage(std::string jsonMessage, const std::string& uriPathExtension);
196 
197  void doShutdown() override;
198 
202  void mainloop();
203 
205  int m_queueSizeWarnLimit;
207  int m_queueSizeHardLimit;
208 
210  std::thread m_workerThread;
211 
213  bool m_isShuttingDown;
214 
216  std::mutex m_mutex;
217 
220 
222  bool m_isConnected;
223 
225  avsCommon::utils::RetryTimer m_retryTimer;
226 
228  std::deque<std::shared_ptr<CertifiedMessageRequest>> m_messagesToSend;
229 
231  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
232 
234  std::shared_ptr<CertifiedMessageRequest> m_currentMessage;
235 
236  // The connection object we are observing.
237  std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface> m_connection;
238 
240  std::shared_ptr<MessageStorageInterface> m_storage;
241 
243  std::shared_ptr<avsCommon::utils::power::PowerResource> m_powerResource;
244 
247 
248  // A condition variable for the main loop to wait for during back-off.
250 };
251 
252 } // namespace certifiedSender
253 } // namespace alexaClientSDK
254 
255 #endif // ALEXA_CLIENT_SDK_CERTIFIEDSENDER_INCLUDE_CERTIFIEDSENDER_CERTIFIEDSENDER_H_
virtual ~CertifiedSender()
Definition: CertifiedSender.cpp:142
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
Definition: MessageRequest.h:40
Definition: ConnectionStatusObserverInterface.h:31
static const int CERTIFIED_SENDER_QUEUE_SIZE_WARN_LIMIT
The number of items we can store for sending without emitting a warning.
Definition: CertifiedSender.h:40
Definition: CertifiedSender.h:58
void clearData() override
Definition: CertifiedSender.cpp:367
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::future< bool > sendJSONMessage(const std::string &jsonMessage, const std::string &uriPathExtension="")
Definition: CertifiedSender.cpp:325
Status
Definition: MessageRequestObserverInterface.h:33
void shutdown()
Definition: RequiresShutdown.cpp:135
static std::shared_ptr< CertifiedSender > create(std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< avsCommon::sdkInterfaces::AVSConnectionManagerInterface > connection, std::shared_ptr< MessageStorageInterface > storage, std::shared_ptr< registrationManager::CustomerDataManagerInterface > dataManager)
Definition: CertifiedSender.cpp:105
Status
Definition: ConnectionStatusObserverInterface.h:36
static const int CERTIFIED_SENDER_QUEUE_SIZE_HARD_LIMIT
The maximum number of items we can store for sending.
Definition: CertifiedSender.h:42

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