aboutsummaryrefslogtreecommitdiff
path: root/src/privet/privet_types.h
blob: 49c4522fc0ab094ec5d974d92bdc01228c980584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2015 The Weave Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef LIBWEAVE_SRC_PRIVET_PRIVET_TYPES_H_
#define LIBWEAVE_SRC_PRIVET_PRIVET_TYPES_H_

#include <string>

#include <base/logging.h>
#include <weave/error.h>
#include <weave/settings.h>

namespace weave {
namespace privet {

enum class CryptoType {
  kSpake_p224,
};

enum class AuthType {
  kAnonymous,
  kPairing,
  kLocal,
};

enum class WifiType {
  kWifi24,
  kWifi50,
};

class UserInfo {
 public:
  explicit UserInfo(AuthScope scope = AuthScope::kNone,
                    const std::string& user_id = {})
      : scope_{scope}, user_id_{scope == AuthScope::kNone ? "" : user_id} {}
  AuthScope scope() const { return scope_; }
  const std::string& user_id() const { return user_id_; }

 private:
  AuthScope scope_;
  std::string user_id_;
};

class ConnectionState final {
 public:
  enum Status {
    kDisabled,
    kUnconfigured,
    kConnecting,
    kOnline,
    kOffline,
  };

  explicit ConnectionState(Status status) : status_(status) {}
  explicit ConnectionState(ErrorPtr error)
      : status_(kOffline), error_(std::move(error)) {}

  Status status() const {
    CHECK(!error_);
    return status_;
  }

  bool IsStatusEqual(Status status) const {
    if (error_)
      return false;
    return status_ == status;
  }

  const Error* error() const { return error_.get(); }

 private:
  Status status_;
  ErrorPtr error_;
};

class SetupState final {
 public:
  enum Status {
    kNone,
    kInProgress,
    kSuccess,
  };

  explicit SetupState(Status status) : status_(status) {}
  explicit SetupState(ErrorPtr error)
      : status_(kNone), error_(std::move(error)) {}

  Status status() const {
    CHECK(!error_);
    return status_;
  }

  bool IsStatusEqual(Status status) const {
    if (error_)
      return false;
    return status_ == status;
  }

  const Error* error() const { return error_.get(); }

 private:
  Status status_;
  ErrorPtr error_;
};

}  // namespace privet
}  // namespace weave

#endif  // LIBWEAVE_SRC_PRIVET_PRIVET_TYPES_H_