evan 2026.1.4
Evan
Loading...
Searching...
No Matches
InteractionProfile.cpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** InteractionProfile
6*/
7
8#include "evan/openxr/InteractionProfile.hpp"
9
11// Public Methods //
13
15 : utility::logging::Loggable<InteractionProfile,
16 utility::logging::DefaultLogger>()
17{
18}
19
30
43
55
58{
59 if (path == XR_NULL_PATH) {
60 return {};
61 }
62
66 if (result != XR_SUCCESS || pathStringSize == 0) {
67 return {};
68 }
69
70 std::string pathString(pathStringSize, '\0');
72 pathString.data());
73 if (result != XR_SUCCESS) {
74 return {};
75 }
76
77 if (!pathString.empty() && pathString.back() == '\0') {
78 pathString.pop_back();
79 }
80 return pathString;
81}
82
85{
86 if (session == XR_NULL_HANDLE) {
87 return {};
88 }
89
90 XrPath userPath = stringToPath(instance, userPathString);
91 if (userPath == XR_NULL_PATH) {
92 return {};
93 }
94
97 if (result != XR_SUCCESS) {
98 return {};
99 }
100
101 if (state.interactionProfile == XR_NULL_PATH) {
102 return {};
103 }
104 return pathToString(instance, state.interactionProfile);
105}
106
109{
110 std::vector<XrPath> paths;
111
113 return paths;
114 }
115
118 };
119 enumerateInfo.action = action;
120
123 session, &enumerateInfo, 0, &sourceCount, nullptr);
124 if (result != XR_SUCCESS || sourceCount == 0) {
125 return paths;
126 }
127
131 if (result != XR_SUCCESS) {
132 return {};
133 }
134
135 return paths;
136}
137
138std::vector<std::string>
141{
142 std::vector<std::string> sourcePathStrings;
143 std::vector<XrPath> sourcePaths =
144 enumerateBoundSourcesForAction(instance, session, action);
145
146 sourcePathStrings.reserve(sourcePaths.size());
148 sourcePathStrings.emplace_back(pathToString(instance, sourcePath));
149 }
150 return sourcePathStrings;
151}
152
153const std::vector<std::string> &
155{
156 static const std::vector<std::string> candidates {
157 "/interaction_profiles/oculus/touch_controller",
158 "/interaction_profiles/microsoft/mixed_reality/motion_controller",
159 "/interaction_profiles/hp/mixed_reality/motion_controller",
160 "/interaction_profiles/valve/index_controller",
161 "/interaction_profiles/khr/simple_controller",
162 };
163 return candidates;
164}
165
167 XrInstance instance, const std::vector<std::string> &candidateProfiles,
168 const std::string &fallbackProfile)
169{
170 if (instance == XR_NULL_HANDLE) {
171 return fallbackProfile;
172 }
173
174 for (const auto &candidateProfile: candidateProfiles) {
175 if (isInteractionProfileSupported(instance, candidateProfile)) {
176 return candidateProfile;
177 }
178 }
179 return fallbackProfile;
180}
181
182bool evan::InteractionProfile::isInteractionProfileSupported(
183 XrInstance instance, const std::string &profilePath)
184{
185 if (instance == XR_NULL_HANDLE) {
186 return false;
187 }
188
189 XrPath interactionProfile = stringToPath(instance, profilePath);
190 if (interactionProfile == XR_NULL_PATH) {
191 return false;
192 }
193
194 XrInteractionProfileSuggestedBinding suggestedBindings {
195 XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING
196 };
197 suggestedBindings.interactionProfile = interactionProfile;
198 suggestedBindings.countSuggestedBindings = 0;
199 suggestedBindings.suggestedBindings = nullptr;
200
201 XrResult result =
202 xrSuggestInteractionProfileBindings(instance, &suggestedBindings);
203 return result == XR_SUCCESS;
204}
A utility class for managing OpenXR interaction profiles, including retrieving runtime and system inf...
static std::vector< std::string > enumerateBoundSourcePathStringsForAction(XrInstance instance, XrSession session, XrAction action)
Enumerates the bound source path strings for a given action.
InteractionProfile()
Deleted default constructor to prevent instantiation of this utility class.
static std::string pathToString(XrInstance instance, XrPath path)
Converts an OpenXR path to a string.
static std::string getSystemName(XrInstance instance, XrSystemId systemId)
Retrieves the name of the OpenXR system.
static XrPath stringToPath(XrInstance instance, const std::string &pathString)
Converts a string to an OpenXR path.
static std::string getRuntimeName(XrInstance instance)
Retrieves the name of the OpenXR runtime in use.
static std::vector< XrPath > enumerateBoundSourcesForAction(XrInstance instance, XrSession session, XrAction action)
Enumerates the bound source paths for a given action.
static std::string getCurrentInteractionProfilePath(XrInstance instance, XrSession session, const std::string &userPathString)
Retrieves the current interaction profile path for a given user path.
static std::string getPreferredInteractionProfilePath(XrInstance instance, const std::vector< std::string > &candidateProfiles, const std::string &fallbackProfile)
Selects the preferred interaction profile path.
static const std::vector< std::string > & getDefaultProfileCandidates()
Retrieves the default interaction profile candidates.
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89