AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AlertObserverInterface.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_ACSDKALERTSINTERFACES_INCLUDE_ACSDKALERTSINTERFACES_ALERTOBSERVERINTERFACE_H_
17 #define ALEXA_CLIENT_SDK_ACSDKALERTSINTERFACES_INCLUDE_ACSDKALERTSINTERFACES_ALERTOBSERVERINTERFACE_H_
18 
19 #include <iomanip>
20 #include <string>
21 #include <sstream>
22 
24 
25 namespace alexaClientSDK {
26 namespace acsdkAlertsInterfaces {
27 
32 public:
34  static const int ORIGINAL_TIME_FIELD_MIN = 0;
36  static const int ORIGINAL_TIME_HOUR_MAX = 23;
38  static const int ORIGINAL_TIME_MINUTE_MAX = 59;
40  static const int ORIGINAL_TIME_SECOND_MAX = 59;
42  static const int ORIGINAL_TIME_MILLISECOND_MAX = 999;
43 
52  template <class T>
53  static bool withinBounds(T value, T minVal, T maxVal) {
54  return value >= minVal && value <= maxVal;
55  }
56 
60  enum class State {
62  READY,
64  STARTED,
66  STOPPED,
68  SNOOZED,
70  COMPLETED,
72  PAST_DUE,
78  ERROR,
80  DELETED,
83  };
84 
88  enum class Type {
90  ALARM,
92  TIMER,
94  REMINDER
95  };
96 
112  struct OriginalTime {
122  int hour = ORIGINAL_TIME_FIELD_MIN,
123  int minute = ORIGINAL_TIME_FIELD_MIN,
124  int second = ORIGINAL_TIME_FIELD_MIN,
125  int millisecond = ORIGINAL_TIME_FIELD_MIN) :
126  hour{hour},
127  minute{minute},
128  second{second},
129  millisecond{millisecond} {
130  if (!withinBounds(hour, ORIGINAL_TIME_FIELD_MIN, ORIGINAL_TIME_HOUR_MAX) ||
131  !withinBounds(minute, ORIGINAL_TIME_FIELD_MIN, ORIGINAL_TIME_MINUTE_MAX) ||
132  !withinBounds(second, ORIGINAL_TIME_FIELD_MIN, ORIGINAL_TIME_SECOND_MAX) ||
133  !withinBounds(millisecond, ORIGINAL_TIME_FIELD_MIN, ORIGINAL_TIME_MILLISECOND_MAX)) {
134  this->hour = ORIGINAL_TIME_FIELD_MIN;
135  this->minute = ORIGINAL_TIME_FIELD_MIN;
136  this->second = ORIGINAL_TIME_FIELD_MIN;
137  this->millisecond = ORIGINAL_TIME_FIELD_MIN;
138  }
139  }
140 
147  bool operator==(const OriginalTime& rhs) const {
148  return hour == rhs.hour && minute == rhs.minute && second == rhs.second && millisecond == rhs.millisecond;
149  }
150 
152  int hour;
154  int minute;
156  int second;
159  };
160 
171  struct AlertInfo {
184  const std::string& token,
185  const Type type,
186  const State state,
187  const std::chrono::system_clock::time_point& scheduledTime,
190  const std::string& reason = "") :
191  token{token},
192  type{type},
193  state{state},
194  scheduledTime{scheduledTime},
195  originalTime{originalTime},
196  label{label},
197  reason{reason} {
198  }
199 
201  std::string token;
207  std::chrono::system_clock::time_point scheduledTime;
214  std::string reason;
215  };
216 
220  virtual ~AlertObserverInterface() = default;
221 
227  virtual void onAlertStateChange(const AlertInfo& alertInfo) = 0;
228 
235  static std::string stateToString(State state);
236 
243  static std::string typeToString(Type type);
244 
251  static std::string originalTimeToString(const OriginalTime& originalTime);
252 };
253 
254 inline std::string AlertObserverInterface::stateToString(State state) {
255  switch (state) {
256  case State::READY:
257  return "READY";
258  case State::STARTED:
259  return "STARTED";
260  case State::STOPPED:
261  return "STOPPED";
262  case State::SNOOZED:
263  return "SNOOZED";
264  case State::COMPLETED:
265  return "COMPLETED";
266  case State::PAST_DUE:
267  return "PAST_DUE";
269  return "FOCUS_ENTERED_FOREGROUND";
271  return "FOCUS_ENTERED_BACKGROUND";
272  case State::ERROR:
273  return "ERROR";
274  case State::DELETED:
275  return "DELETED";
277  return "SCHEDULED_FOR_LATER";
278  }
279  return "Unknown State";
280 }
281 
282 inline std::string AlertObserverInterface::typeToString(Type type) {
283  switch (type) {
284  case Type::ALARM:
285  return "ALARM";
286  case Type::TIMER:
287  return "TIMER";
288  case Type::REMINDER:
289  return "REMINDER";
290  }
291  return "Unknown Type";
292 }
293 
294 inline std::string AlertObserverInterface::originalTimeToString(const OriginalTime& originalTime) {
295  std::stringstream ss;
296  ss << std::setfill('0') << std::setw(2) << originalTime.hour << ":" << std::setfill('0') << std::setw(2)
297  << originalTime.minute << ":" << std::setfill('0') << std::setw(2) << originalTime.second << "."
298  << std::setfill('0') << std::setw(3) << originalTime.millisecond;
299  return ss.str();
300 }
301 
309 inline std::ostream& operator<<(std::ostream& stream, const AlertObserverInterface::State& state) {
310  return stream << AlertObserverInterface::stateToString(state);
311 }
312 
320 inline std::ostream& operator<<(std::ostream& stream, const AlertObserverInterface::Type& type) {
321  return stream << AlertObserverInterface::typeToString(type);
322 }
323 
331 inline std::ostream& operator<<(std::ostream& stream, const AlertObserverInterface::OriginalTime& originalTime) {
332  return stream << AlertObserverInterface::originalTimeToString(originalTime);
333 }
334 
335 } // namespace acsdkAlertsInterfaces
336 } // namespace alexaClientSDK
337 
338 #endif // ALEXA_CLIENT_SDK_ACSDKALERTSINTERFACES_INCLUDE_ACSDKALERTSINTERFACES_ALERTOBSERVERINTERFACE_H_
std::string reason
The reason for the state change.
Definition: AlertObserverInterface.h:214
static const int ORIGINAL_TIME_SECOND_MAX
The maximum value for the second field in OriginalTime.
Definition: AlertObserverInterface.h:40
std::string token
An opaque token that uniquely identifies the alert.
Definition: AlertObserverInterface.h:201
bool operator==(const OriginalTime &rhs) const
Definition: AlertObserverInterface.h:147
int second
Seconds in [0-59].
Definition: AlertObserverInterface.h:156
static std::string originalTimeToString(const OriginalTime &originalTime)
Definition: AlertObserverInterface.h:294
static bool withinBounds(T value, T minVal, T maxVal)
Definition: AlertObserverInterface.h:53
static const int ORIGINAL_TIME_MINUTE_MAX
The maximum value for the minute field in OriginalTime.
Definition: AlertObserverInterface.h:38
State state
The state of the alert.
Definition: AlertObserverInterface.h:205
std::chrono::system_clock::time_point scheduledTime
UTC timestamp for when the alert is scheduled.
Definition: AlertObserverInterface.h:207
avsCommon::utils::Optional< std::string > label
An optional label for the content of an alert.
Definition: AlertObserverInterface.h:212
The alert is ready to start, and is waiting for channel focus.
int minute
Minutes in [0-59].
Definition: AlertObserverInterface.h:154
static std::string typeToString(Type type)
Definition: AlertObserverInterface.h:282
int hour
Hours in [0-23].
Definition: AlertObserverInterface.h:152
The alert has stopped due to user or system intervention.
std::ostream & operator<<(std::ostream &stream, const AlertObserverInterface::State &state)
Definition: AlertObserverInterface.h:309
static const int ORIGINAL_TIME_FIELD_MIN
The minimum value for the field in OriginalTime.
Definition: AlertObserverInterface.h:34
virtual void onAlertStateChange(const AlertInfo &alertInfo)=0
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
avsCommon::utils::Optional< OriginalTime > originalTime
Definition: AlertObserverInterface.h:210
int millisecond
Milliseconds in [0-999].
Definition: AlertObserverInterface.h:158
AlertInfo(const std::string &token, const Type type, const State state, const std::chrono::system_clock::time_point &scheduledTime, const avsCommon::utils::Optional< OriginalTime > &originalTime=avsCommon::utils::Optional< OriginalTime >(), const avsCommon::utils::Optional< std::string > &label=avsCommon::utils::Optional< std::string >(), const std::string &reason="")
Definition: AlertObserverInterface.h:183
static std::string stateToString(State state)
Definition: AlertObserverInterface.h:254
OriginalTime(int hour=ORIGINAL_TIME_FIELD_MIN, int minute=ORIGINAL_TIME_FIELD_MIN, int second=ORIGINAL_TIME_FIELD_MIN, int millisecond=ORIGINAL_TIME_FIELD_MIN)
Definition: AlertObserverInterface.h:121
static const int ORIGINAL_TIME_HOUR_MAX
The maximum value for the hour field in OriginalTime.
Definition: AlertObserverInterface.h:36
The alert has been determined to be past-due, and will not be rendered.
Type type
The type of the alert.
Definition: AlertObserverInterface.h:203
static const int ORIGINAL_TIME_MILLISECOND_MAX
The maximum value for the millisecond field in OriginalTime.
Definition: AlertObserverInterface.h:42

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