Skip to content

Commit

Permalink
Merge pull request #15 from OSVR/update-for-steamvr-changes
Browse files Browse the repository at this point in the history
Update for steamvr changes
  • Loading branch information
rpavlik authored Jun 29, 2016
2 parents 20ec70d + 7911c10 commit 829e278
Show file tree
Hide file tree
Showing 16 changed files with 562 additions and 98 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ add_library(ViveLoaderLib STATIC
GetComponent.h
GetProvider.h
InterfaceTraits.h
ReturnValue.h
SearchPathExtender.h
ServerDriverHost.cpp
ServerDriverHost.h
Expand Down
50 changes: 27 additions & 23 deletions DeviceHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define INCLUDED_DeviceHolder_h_GUID_58F7E011_8D87_49A3_FE26_0DB159405E77

// Internal Includes
// - none
#include "ReturnValue.h"

// Library/third-party includes
#include <openvr_driver.h>
Expand Down Expand Up @@ -77,40 +77,46 @@ namespace vive {
return *this;
}

std::pair<bool, std::uint32_t>
using IdReturnValue = ReturnValue<std::uint32_t, bool>;

IdReturnValue
addAndActivateDevice(vr::ITrackedDeviceServerDriver *dev) {
/// check to make sure it's not null and not already in there
if (!dev || findDevice(dev).first) {
return std::make_pair(false, 0);
if (!dev) {
return IdReturnValue::makeError();
}
auto it = std::find(begin(devices_), end(devices_), dev);
if (it != end(devices_)) {
auto existing = findDevice(dev);
if (existing) {
/// @todo do we return an error or the existing location? This
/// returns the existing location after re-activating.
dev->Activate(existing.value);
return existing;
}
auto newId = static_cast<std::uint32_t>(devices_.size());
devices_.push_back(dev);
dev->Activate(newId);
return std::make_pair(true, newId);
return IdReturnValue::makeValue(newId);
}

/// Add and activate a device at a reserved id.
std::pair<bool, std::uint32_t>
IdReturnValue
addAndActivateDeviceAt(vr::ITrackedDeviceServerDriver *dev,
std::uint32_t idx) {
/// check to make sure it's not null and not already in there
if (!dev) {
return std::make_pair(false, 0);
return IdReturnValue::makeError();
}
auto existing = findDevice(dev);
if (existing.first && !existing.second == idx) {
if (existing && existing.value != idx) {
// if we already found it in there and it's not at the desired
// index...
return std::make_pair(false, existing.second);
return IdReturnValue(existing.value, false);
}

if (existing.first) {
if (existing) {
// well, in this case, we might need to just activate it again.
dev->Activate(idx);
return std::make_pair(true, idx);
return IdReturnValue::makeValue(idx);
}

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

if (devices_[idx]) {
// there's already somebody else there...
return std::make_pair(false, 0);
return IdReturnValue::makeError();
}

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

return std::make_pair(true, idx);
return IdReturnValue::makeValue(idx);
}

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

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

auto it = std::find(begin(devices_), end(devices_), dev);
if (it == end(devices_)) {
return std::make_pair(false, 0);
auto it = std::find(devices_.cbegin(), devices_.cend(), dev);
if (devices_.cend() == it) {
return IdReturnValue::makeError();
}
return std::make_pair(
true,
static_cast<std::uint32_t>(std::distance(begin(devices_), it)));
return IdReturnValue::makeValue(static_cast<std::uint32_t>(
std::distance(devices_.cbegin(), it)));
}

/// @return the number of allocated/reserved ids
Expand Down
22 changes: 21 additions & 1 deletion DisplayExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ int main() {
return 1;
}

if (osvr::vive::DriverWrapper::InterfaceVersionStatus::
InterfaceMismatch ==
vive.checkServerDeviceProviderInterfaces()) {
std::cerr << PREFIX
<< "SteamVR driver requires unavailable/unsupported "
"interface versions - either too old or too new for "
"this build. Cannot continue."
<< std::endl;
for (auto iface : vive.getUnsupportedRequestedInterfaces()) {
if (osvr::vive::isInterfaceNameWeCareAbout(iface)) {
auto supported =
vive.getSupportedInterfaceVersions()
.findSupportedVersionOfInterface(iface);
std::cerr << PREFIX << " - Driver requested " << iface
<< " but we support " << supported << std::endl;
}
}
return 1;
}

/// Power the system up.
vive.serverDevProvider().LeaveStandby();
{
Expand All @@ -294,7 +314,7 @@ int main() {
<< " tracked devices at startup" << std::endl;
for (decltype(numDevices) i = 0; i < numDevices; ++i) {
auto dev = vive.serverDevProvider().GetTrackedDeviceDriver(
i, vr::ITrackedDeviceServerDriver_Version);
i);
vive.devices().addAndActivateDevice(dev);
std::cout << PREFIX << "Device " << i << std::endl;
auto disp =
Expand Down
6 changes: 3 additions & 3 deletions DriverLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ namespace vive {

bool DriverLoader::isHMDPresent(std::string const &userConfigDir) const {
auto ret = getInterface<vr::IClientTrackedDeviceProvider>();
if (ret.first) {
if (ret) {
// std::cout << "Successfully got the
// IClientTrackedDeviceProvider!";
auto clientProvider = ret.first;
auto clientProvider = ret.value;
auto isPresent =
clientProvider->BIsHmdPresent(userConfigDir.c_str());
// std::cout << " is present? " << std::boolalpha << isPresent
// << std::endl;
return isPresent;
}
// std::cout << "Couldn't get it, error code " << ret.second <<
// std::cout << "Couldn't get it, error code " << ret.errorCode <<
// std::endl;
return false;
}
Expand Down
15 changes: 8 additions & 7 deletions DriverLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// Internal Includes
#include "InterfaceTraits.h"
#include "ReturnValue.h"

// Library/third-party includes
// - none
Expand Down Expand Up @@ -105,7 +106,7 @@ namespace vive {
/// right string and do the right casting. Returns the pointer and
/// the error code in a pair.
template <typename InterfaceType>
std::pair<InterfaceType *, int> getInterface() const {
ReturnValue<InterfaceType *, int> getInterface() const {
static_assert(
InterfaceExpectedFromEntryPointTrait<InterfaceType>::value,
"Can only use this function for interface types expected to be "
Expand All @@ -115,30 +116,30 @@ namespace vive {
int returnCode = 0;
if (!(*this)) {
/// We've been reset or could never load.
return std::make_pair(ret, returnCode);
return makeError<InterfaceType *>(ret, returnCode);
}
void *product =
factory_(InterfaceNameTrait<InterfaceType>::get(), &returnCode);
if (product) {
ret = static_cast<InterfaceType *>(product);
}
return std::make_pair(ret, returnCode);
return makeReturnValue<InterfaceType *>(ret, returnCode);
}

/// Similar to the above, except that it throws in case of failure,
/// instead of returning an error code. Thus, the pointer returned is
/// always non-null.
template <typename InterfaceType>
InterfaceType *getInterfaceThrowing() const {
auto pairRet = getInterface<InterfaceType>();
auto ret = getInterface<InterfaceType>();
if (!(*this)) {
/// we early-out
throw DriverNotLoaded();
}
if (!pairRet.first) {
throw CouldNotGetInterface(pairRet.second);
if (!ret) {
throw CouldNotGetInterface(ret.errorCode);
}
return pairRet.first;
return ret.value;
}

std::string const &getDriverRoot() const { return driverRoot_; }
Expand Down
Loading

0 comments on commit 829e278

Please sign in to comment.