Alexa Auto SDK  2.3.0
CBL.h
1 /*
2  * Copyright 2017-2020 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 AACE_CBL_CBL_H
17 #define AACE_CBL_CBL_H
18 
19 #include <iostream>
20 #include "CBLEngineInterface.h"
21 #include "AACE/Core/PlatformInterface.h"
22 
23 namespace aace {
24 namespace cbl {
25 
30 protected:
31  CBL() = default;
32 
33 public:
37  enum class CBLState {
38 
42  STARTING,
43 
48 
53 
58 
63 
67  STOPPING
68  };
69 
73  enum class CBLStateChangedReason {
74 
78  SUCCESS,
79 
83  ERROR,
84 
88  TIMEOUT,
89 
93  CODE_PAIR_EXPIRED,
94 
98  AUTHORIZATION_EXPIRED,
99 
103  NONE
104  };
105 
106  virtual ~CBL();
107 
111  virtual void cblStateChanged(
112  CBLState state,
113  CBLStateChangedReason reason,
114  const std::string& url,
115  const std::string& code) = 0;
116 
120  virtual void clearRefreshToken() = 0;
121 
125  virtual void setRefreshToken(const std::string& refreshToken) = 0;
126 
130  virtual std::string getRefreshToken() = 0;
131 
136  virtual void setUserProfile(const std::string& name, const std::string& email) = 0;
140  void start();
141 
145  void cancel();
146 
150  void reset();
151 
158  void setEngineInterface(std::shared_ptr<CBLEngineInterface> cblEngineInterface);
159 
160 private:
161  std::shared_ptr<CBLEngineInterface> m_cblEngineInterface;
162 };
163 
164 inline std::ostream& operator<<(std::ostream& stream, const CBL::CBLState& state) {
165  switch (state) {
167  stream << "STARTING";
168  break;
170  stream << "REQUESTING_CODE_PAIR";
171  break;
173  stream << "CODE_PAIR_RECEIVED";
174  break;
176  stream << "REFRESHING_TOKEN";
177  break;
179  stream << "REQUESTING_TOKEN";
180  break;
182  stream << "STOPPING";
183  break;
184  }
185  return stream;
186 }
187 
188 inline std::ostream& operator<<(std::ostream& stream, const CBL::CBLStateChangedReason& reason) {
189  switch (reason) {
191  stream << "SUCCESS";
192  break;
194  stream << "ERROR";
195  break;
197  stream << "TIMEOUT";
198  break;
200  stream << "CODE_PAIR_EXPIRED";
201  break;
203  stream << "AUTHORIZATION_EXPIRED";
204  break;
206  stream << "NONE";
207  break;
208  }
209  return stream;
210 }
211 
212 } // namespace cbl
213 } // namespace aace
214 
215 #endif
virtual std::string getRefreshToken()=0
void cancel()
Definition: CBL.cpp:33
CBLStateChangedReason
Definition: CBL.h:73
virtual void cblStateChanged(CBLState state, CBLStateChangedReason reason, const std::string &url, const std::string &code)=0
Definition: PlatformInterface.h:29
virtual void clearRefreshToken()=0
virtual void setRefreshToken(const std::string &refreshToken)=0
Definition: AddressBook.h:26
virtual void setUserProfile(const std::string &name, const std::string &email)=0
CBLState
Definition: CBL.h:37
void reset()
Definition: CBL.cpp:39
void start()
Definition: CBL.cpp:27
Definition: CBL.h:29

Alexa Auto SDK 2.3.0 - Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0