-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathSettings.cpp
162 lines (143 loc) · 6.24 KB
/
Settings.cpp
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/** @file
@brief Implementation
@date 2016
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/
// Copyright 2016 Razer Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Internal Includes
// Library/third-party includes
#include "Settings.h"
#include "ValveStrCpy.h"
// Standard includes
#include <iostream>
using namespace vr;
Settings::Settings() : m_logger(osvr::util::log::make_logger("Settings")) {
m_settingStore.set<bool>("disableimu", false);
m_settingStore.set<std::string>("usedisambiguation", "tdm");
m_settingStore.set<int32_t>("disambiguationdebug", 0);
m_settingStore.set<int32_t>("primarybasestation", 0);
m_settingStore.set<bool>("dbhistory", false);
m_settingStore.set<bool>("trackedCamera", true);
m_settingStore.set<float>("cameraFrameCaptureOffsetTime", 0.0);
m_settingStore.set<int32_t>("cameraFrameRate", 30);
m_settingStore.set<int32_t>("cameraSensorFrameRate", 30);
m_settingStore.set<bool>("cameraEdgeEnhancement", true);
m_settingStore.set<int32_t>("cameraISPSyncDivisor", 1);
m_settingStore.set<bool>("enableCamera", true);
m_settingStore.set<bool>("fakeHtcHmdMainboard", false);
m_settingStore.set<int32_t>("deactivateStandbyOverride", 1);
}
const char *
Settings::GetSettingsErrorNameFromEnum(vr::EVRSettingsError eError) {
m_logger->debug("GetSettingsErrorNameFromEnum: ") << eError;
return "Error";
}
bool Settings::Sync(bool bForce, vr::EVRSettingsError *peError) {
m_logger->debug("Sync: ") << bForce << ", " << peError;
return true;
}
bool Settings::GetBool(const char *pchSection, const char *pchSettingsKey,
vr::EVRSettingsError *peError) {
m_logger->debug("GetBool: ") << pchSection << ", " << pchSettingsKey;
if (m_settingStore.contains<bool>(pchSettingsKey)) {
bool val = m_settingStore.get<bool>(pchSettingsKey);
return val;
} else {
m_logger->info("GetBool doesn't contain the settingKey: ")
<< pchSettingsKey;
peError = new vr::EVRSettingsError(VRSettingsError_ReadFailed);
return false;
}
}
void Settings::SetBool(const char *pchSection, const char *pchSettingsKey,
bool bValue, vr::EVRSettingsError *peError) {
m_logger->debug("SetBool: ") << pchSection << ", " << pchSettingsKey;
m_settingStore.set<bool>(pchSettingsKey, bValue);
}
int32_t Settings::GetInt32(const char *pchSection, const char *pchSettingsKey,
vr::EVRSettingsError *peError) {
m_logger->debug("GetInt32: ") << pchSection << ", " << pchSettingsKey;
if (m_settingStore.contains<int32_t>(pchSettingsKey)) {
int32_t val = m_settingStore.get<int32_t>(pchSettingsKey);
return val;
} else {
m_logger->info("GetInt32 doesn't contain the settingKey: ")
<< pchSettingsKey;
peError = new vr::EVRSettingsError(VRSettingsError_ReadFailed);
return 0;
}
}
void Settings::SetInt32(const char *pchSection, const char *pchSettingsKey,
int32_t nValue, vr::EVRSettingsError *peError) {
m_logger->debug("SetInt32: ") << pchSection << ", " << pchSettingsKey;
m_settingStore.set<int32_t>(pchSettingsKey, nValue);
}
float Settings::GetFloat(const char *pchSection, const char *pchSettingsKey,
vr::EVRSettingsError *peError) {
m_logger->debug("GetFloat: ") << pchSection << ", " << pchSettingsKey;
if (m_settingStore.contains<float>(pchSettingsKey)) {
float val = m_settingStore.get<float>(pchSettingsKey);
return val;
} else {
m_logger->info("GetFloat doesn't contain the settingKey: ")
<< pchSettingsKey;
peError = new vr::EVRSettingsError(VRSettingsError_ReadFailed);
return 0;
}
}
void Settings::SetFloat(const char *pchSection, const char *pchSettingsKey,
float flValue, vr::EVRSettingsError *peError) {
m_logger->debug("SetFloat: ") << pchSection << ", " << pchSettingsKey;
m_settingStore.set<float>(pchSettingsKey, flValue);
}
void Settings::GetString(const char *pchSection, const char *pchSettingsKey,
char *pchValue, uint32_t unValueLen,
vr::EVRSettingsError *peError) {
m_logger->debug("GetString: ")
<< pchSection << ", " << pchSettingsKey << ", " << unValueLen;
if (m_settingStore.contains<std::string>(pchSettingsKey)) {
std::string val = m_settingStore.get<std::string>(pchSettingsKey);
if (unValueLen < val.length()) {
peError = new vr::EVRSettingsError(VRSettingsError_ReadFailed);
} else {
auto ret = valveStrCpy(val, pchValue, unValueLen);
if (!ret) {
peError = new vr::EVRSettingsError(VRSettingsError_ReadFailed);
}
}
} else {
m_logger->info("GetString doesn't contain the settingKey: ")
<< pchSettingsKey;
peError = new vr::EVRSettingsError(VRSettingsError_ReadFailed);
}
}
void Settings::SetString(const char *pchSection, const char *pchSettingsKey,
const char *pchValue, vr::EVRSettingsError *peError) {
m_logger->debug("SetString: ") << pchSection << ", " << pchSettingsKey;
m_settingStore.set<std::string>(pchSettingsKey, pchValue);
}
void Settings::RemoveSection(const char *pchSection,
vr::EVRSettingsError *peError) {
m_logger->debug("We don't remove section: ") << pchSection;
}
void Settings::RemoveKeyInSection(const char *pchSection,
const char *pchSettingsKey,
vr::EVRSettingsError *peError) {
m_logger->debug("RemoveKeyInSection: ")
<< pchSection << ", " << pchSettingsKey;
m_settingStore.erase(pchSettingsKey);
}