| 116 | |
| 117 | template <typename FactoryFunction> |
| 118 | inline static OSVR_ReturnCode |
| 119 | osvrDeviceGenericInit(OSVR_DeviceInitOptions options, OSVR_DeviceToken *device, |
| 120 | FactoryFunction f) { |
| 121 | |
| 122 | osvr::connection::DeviceTokenPtr dev = f(*options); |
| 123 | if (!dev) { |
| 124 | OSVR_DEV_VERBOSE("Device token factory returned a null " |
| 125 | "pointer - this shouldn't happen!"); |
| 126 | return OSVR_RETURN_FAILURE; |
| 127 | } |
| 128 | // Transfer ownership of the device token object to the plugin context. |
| 129 | try { |
| 130 | *device = |
| 131 | options->getContext()->registerDataWithGenericDelete(dev.release()); |
| 132 | /// @todo Is this too late to delete? Can we delete it earlier? |
| 133 | options->getContext()->registerDataWithGenericDelete(options); |
| 134 | options->notifyToken(*device); |
| 135 | } catch (std::exception &e) { |
| 136 | std::cerr << "Error in osvrDeviceGenericInit: " << e.what() |
| 137 | << std::endl; |
| 138 | return OSVR_RETURN_FAILURE; |
| 139 | } catch (...) { |
| 140 | return OSVR_RETURN_FAILURE; |
| 141 | } |
| 142 | return OSVR_RETURN_SUCCESS; |
| 143 | } |
| 144 | |
| 145 | template <typename FactoryFunction> |
| 146 | inline static OSVR_ReturnCode |
no test coverage detected