Skip to content

Commit 829e278

Browse files
authored
Merge pull request #15 from OSVR/update-for-steamvr-changes
Update for steamvr changes
2 parents 20ec70d + 7911c10 commit 829e278

16 files changed

+562
-98
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ add_library(ViveLoaderLib STATIC
9595
GetComponent.h
9696
GetProvider.h
9797
InterfaceTraits.h
98+
ReturnValue.h
9899
SearchPathExtender.h
99100
ServerDriverHost.cpp
100101
ServerDriverHost.h

DeviceHolder.h

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define INCLUDED_DeviceHolder_h_GUID_58F7E011_8D87_49A3_FE26_0DB159405E77
2727

2828
// Internal Includes
29-
// - none
29+
#include "ReturnValue.h"
3030

3131
// Library/third-party includes
3232
#include <openvr_driver.h>
@@ -77,40 +77,46 @@ namespace vive {
7777
return *this;
7878
}
7979

80-
std::pair<bool, std::uint32_t>
80+
using IdReturnValue = ReturnValue<std::uint32_t, bool>;
81+
82+
IdReturnValue
8183
addAndActivateDevice(vr::ITrackedDeviceServerDriver *dev) {
8284
/// check to make sure it's not null and not already in there
83-
if (!dev || findDevice(dev).first) {
84-
return std::make_pair(false, 0);
85+
if (!dev) {
86+
return IdReturnValue::makeError();
8587
}
86-
auto it = std::find(begin(devices_), end(devices_), dev);
87-
if (it != end(devices_)) {
88+
auto existing = findDevice(dev);
89+
if (existing) {
90+
/// @todo do we return an error or the existing location? This
91+
/// returns the existing location after re-activating.
92+
dev->Activate(existing.value);
93+
return existing;
8894
}
8995
auto newId = static_cast<std::uint32_t>(devices_.size());
9096
devices_.push_back(dev);
9197
dev->Activate(newId);
92-
return std::make_pair(true, newId);
98+
return IdReturnValue::makeValue(newId);
9399
}
94100

95101
/// Add and activate a device at a reserved id.
96-
std::pair<bool, std::uint32_t>
102+
IdReturnValue
97103
addAndActivateDeviceAt(vr::ITrackedDeviceServerDriver *dev,
98104
std::uint32_t idx) {
99105
/// check to make sure it's not null and not already in there
100106
if (!dev) {
101-
return std::make_pair(false, 0);
107+
return IdReturnValue::makeError();
102108
}
103109
auto existing = findDevice(dev);
104-
if (existing.first && !existing.second == idx) {
110+
if (existing && existing.value != idx) {
105111
// if we already found it in there and it's not at the desired
106112
// index...
107-
return std::make_pair(false, existing.second);
113+
return IdReturnValue(existing.value, false);
108114
}
109115

110-
if (existing.first) {
116+
if (existing) {
111117
// well, in this case, we might need to just activate it again.
112118
dev->Activate(idx);
113-
return std::make_pair(true, idx);
119+
return IdReturnValue::makeValue(idx);
114120
}
115121

116122
if (!(idx < devices_.size())) {
@@ -120,14 +126,14 @@ namespace vive {
120126

121127
if (devices_[idx]) {
122128
// there's already somebody else there...
123-
return std::make_pair(false, 0);
129+
return IdReturnValue::makeError();
124130
}
125131

126132
/// Finally, if we made it through that, it's our turn.
127133
devices_[idx] = dev;
128134
dev->Activate(idx);
129135

130-
return std::make_pair(true, idx);
136+
return IdReturnValue::makeValue(idx);
131137
}
132138

133139
/// Reserve the first n ids, if not already allocated, for manual
@@ -153,16 +159,14 @@ namespace vive {
153159
}
154160

155161
/// @return a (found, index) pair for a non-null device pointer.
156-
std::pair<bool, std::uint32_t>
157-
findDevice(vr::ITrackedDeviceServerDriver *dev) {
162+
IdReturnValue findDevice(vr::ITrackedDeviceServerDriver *dev) {
158163

159-
auto it = std::find(begin(devices_), end(devices_), dev);
160-
if (it == end(devices_)) {
161-
return std::make_pair(false, 0);
164+
auto it = std::find(devices_.cbegin(), devices_.cend(), dev);
165+
if (devices_.cend() == it) {
166+
return IdReturnValue::makeError();
162167
}
163-
return std::make_pair(
164-
true,
165-
static_cast<std::uint32_t>(std::distance(begin(devices_), it)));
168+
return IdReturnValue::makeValue(static_cast<std::uint32_t>(
169+
std::distance(devices_.cbegin(), it)));
166170
}
167171

168172
/// @return the number of allocated/reserved ids

DisplayExtractor.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,26 @@ int main() {
286286
return 1;
287287
}
288288

289+
if (osvr::vive::DriverWrapper::InterfaceVersionStatus::
290+
InterfaceMismatch ==
291+
vive.checkServerDeviceProviderInterfaces()) {
292+
std::cerr << PREFIX
293+
<< "SteamVR driver requires unavailable/unsupported "
294+
"interface versions - either too old or too new for "
295+
"this build. Cannot continue."
296+
<< std::endl;
297+
for (auto iface : vive.getUnsupportedRequestedInterfaces()) {
298+
if (osvr::vive::isInterfaceNameWeCareAbout(iface)) {
299+
auto supported =
300+
vive.getSupportedInterfaceVersions()
301+
.findSupportedVersionOfInterface(iface);
302+
std::cerr << PREFIX << " - Driver requested " << iface
303+
<< " but we support " << supported << std::endl;
304+
}
305+
}
306+
return 1;
307+
}
308+
289309
/// Power the system up.
290310
vive.serverDevProvider().LeaveStandby();
291311
{
@@ -294,7 +314,7 @@ int main() {
294314
<< " tracked devices at startup" << std::endl;
295315
for (decltype(numDevices) i = 0; i < numDevices; ++i) {
296316
auto dev = vive.serverDevProvider().GetTrackedDeviceDriver(
297-
i, vr::ITrackedDeviceServerDriver_Version);
317+
i);
298318
vive.devices().addAndActivateDevice(dev);
299319
std::cout << PREFIX << "Device " << i << std::endl;
300320
auto disp =

DriverLoader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@ namespace vive {
129129

130130
bool DriverLoader::isHMDPresent(std::string const &userConfigDir) const {
131131
auto ret = getInterface<vr::IClientTrackedDeviceProvider>();
132-
if (ret.first) {
132+
if (ret) {
133133
// std::cout << "Successfully got the
134134
// IClientTrackedDeviceProvider!";
135-
auto clientProvider = ret.first;
135+
auto clientProvider = ret.value;
136136
auto isPresent =
137137
clientProvider->BIsHmdPresent(userConfigDir.c_str());
138138
// std::cout << " is present? " << std::boolalpha << isPresent
139139
// << std::endl;
140140
return isPresent;
141141
}
142-
// std::cout << "Couldn't get it, error code " << ret.second <<
142+
// std::cout << "Couldn't get it, error code " << ret.errorCode <<
143143
// std::endl;
144144
return false;
145145
}

DriverLoader.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
// Internal Includes
2929
#include "InterfaceTraits.h"
30+
#include "ReturnValue.h"
3031

3132
// Library/third-party includes
3233
// - none
@@ -105,7 +106,7 @@ namespace vive {
105106
/// right string and do the right casting. Returns the pointer and
106107
/// the error code in a pair.
107108
template <typename InterfaceType>
108-
std::pair<InterfaceType *, int> getInterface() const {
109+
ReturnValue<InterfaceType *, int> getInterface() const {
109110
static_assert(
110111
InterfaceExpectedFromEntryPointTrait<InterfaceType>::value,
111112
"Can only use this function for interface types expected to be "
@@ -115,30 +116,30 @@ namespace vive {
115116
int returnCode = 0;
116117
if (!(*this)) {
117118
/// We've been reset or could never load.
118-
return std::make_pair(ret, returnCode);
119+
return makeError<InterfaceType *>(ret, returnCode);
119120
}
120121
void *product =
121122
factory_(InterfaceNameTrait<InterfaceType>::get(), &returnCode);
122123
if (product) {
123124
ret = static_cast<InterfaceType *>(product);
124125
}
125-
return std::make_pair(ret, returnCode);
126+
return makeReturnValue<InterfaceType *>(ret, returnCode);
126127
}
127128

128129
/// Similar to the above, except that it throws in case of failure,
129130
/// instead of returning an error code. Thus, the pointer returned is
130131
/// always non-null.
131132
template <typename InterfaceType>
132133
InterfaceType *getInterfaceThrowing() const {
133-
auto pairRet = getInterface<InterfaceType>();
134+
auto ret = getInterface<InterfaceType>();
134135
if (!(*this)) {
135136
/// we early-out
136137
throw DriverNotLoaded();
137138
}
138-
if (!pairRet.first) {
139-
throw CouldNotGetInterface(pairRet.second);
139+
if (!ret) {
140+
throw CouldNotGetInterface(ret.errorCode);
140141
}
141-
return pairRet.first;
142+
return ret.value;
142143
}
143144

144145
std::string const &getDriverRoot() const { return driverRoot_; }

0 commit comments

Comments
 (0)