aboutsummaryrefslogtreecommitdiff
path: root/src/privet/privet_types.cc
blob: dd291b3df61d028c56b10482cd6bc6953fb10208 (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
// 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.

#include "src/privet/privet_types.h"

#include <string>

#include <weave/enum_to_string.h>
#include <weave/export.h>
#include <weave/provider/network.h>

namespace weave {

namespace {

using privet::AuthType;
using privet::ConnectionState;
using privet::CryptoType;
using privet::SetupState;
using privet::WifiType;
using provider::Network;

const EnumToStringMap<PairingType>::Map kPairingTypeMap[] = {
    {PairingType::kPinCode, "pinCode"},
    {PairingType::kEmbeddedCode, "embeddedCode"},
};

const EnumToStringMap<AuthType>::Map kAuthTypeMap[] = {
    {AuthType::kAnonymous, "anonymous"},
    {AuthType::kPairing, "pairing"},
    {AuthType::kLocal, "local"},
};

const EnumToStringMap<ConnectionState::Status>::Map kConnectionStateMap[] = {
    {ConnectionState::kDisabled, "disabled"},
    {ConnectionState::kUnconfigured, "unconfigured"},
    {ConnectionState::kConnecting, "connecting"},
    {ConnectionState::kOnline, "online"},
    {ConnectionState::kOffline, "offline"},
};

const EnumToStringMap<SetupState::Status>::Map kSetupStateMap[] = {
    {SetupState::kNone, nullptr},
    {SetupState::kInProgress, "inProgress"},
    {SetupState::kSuccess, "success"},
};

const EnumToStringMap<WifiType>::Map kWifiTypeMap[] = {
    {WifiType::kWifi24, "2.4GHz"},
    {WifiType::kWifi50, "5.0GHz"},
};

const EnumToStringMap<CryptoType>::Map kCryptoTypeMap[] = {
    {CryptoType::kNone, "none"},
    {CryptoType::kSpake_p224, "p224_spake2"},
};

const EnumToStringMap<AuthScope>::Map kAuthScopeMap[] = {
    {AuthScope::kNone, "none"},
    {AuthScope::kViewer, "viewer"},
    {AuthScope::kUser, "user"},
    {AuthScope::kManager, "manager"},
    {AuthScope::kOwner, "owner"},
};

const EnumToStringMap<Network::State>::Map kNetworkStateMap[] = {
    {Network::State::kOffline, "offline"},
    {Network::State::kError, "error"},
    {Network::State::kConnecting, "connecting"},
    {Network::State::kOnline, "online"},
};

}  // namespace

template <>
LIBWEAVE_EXPORT EnumToStringMap<PairingType>::EnumToStringMap()
    : EnumToStringMap(kPairingTypeMap) {}

template <>
LIBWEAVE_EXPORT EnumToStringMap<AuthType>::EnumToStringMap()
    : EnumToStringMap(kAuthTypeMap) {}

template <>
LIBWEAVE_EXPORT EnumToStringMap<ConnectionState::Status>::EnumToStringMap()
    : EnumToStringMap(kConnectionStateMap) {}

template <>
LIBWEAVE_EXPORT EnumToStringMap<SetupState::Status>::EnumToStringMap()
    : EnumToStringMap(kSetupStateMap) {}

template <>
LIBWEAVE_EXPORT EnumToStringMap<WifiType>::EnumToStringMap()
    : EnumToStringMap(kWifiTypeMap) {}

template <>
LIBWEAVE_EXPORT EnumToStringMap<CryptoType>::EnumToStringMap()
    : EnumToStringMap(kCryptoTypeMap) {}

template <>
LIBWEAVE_EXPORT EnumToStringMap<AuthScope>::EnumToStringMap()
    : EnumToStringMap(kAuthScopeMap) {}

template <>
LIBWEAVE_EXPORT EnumToStringMap<Network::State>::EnumToStringMap()
    : EnumToStringMap(kNetworkStateMap) {}

}  // namespace weave