rev |
line source |
nuclear@0
|
1 /************************************************************************************
|
nuclear@0
|
2
|
nuclear@0
|
3 Filename : OVR_Profile.h
|
nuclear@0
|
4 Content : Structs and functions for loading and storing device profile settings
|
nuclear@0
|
5 Created : February 14, 2013
|
nuclear@0
|
6 Notes :
|
nuclear@0
|
7 Profiles are used to store per-user settings that can be transferred and used
|
nuclear@0
|
8 across multiple applications. For example, player IPD can be configured once
|
nuclear@0
|
9 and reused for a unified experience across games. Configuration and saving of profiles
|
nuclear@0
|
10 can be accomplished in game via the Profile API or by the official Oculus Configuration
|
nuclear@0
|
11 Utility.
|
nuclear@0
|
12
|
nuclear@0
|
13 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
|
nuclear@0
|
14
|
nuclear@0
|
15 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
|
nuclear@0
|
16 you may not use the Oculus VR Rift SDK except in compliance with the License,
|
nuclear@0
|
17 which is provided at the time of installation or download, or which
|
nuclear@0
|
18 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@0
|
19
|
nuclear@0
|
20 You may obtain a copy of the License at
|
nuclear@0
|
21
|
nuclear@0
|
22 http://www.oculusvr.com/licenses/LICENSE-3.2
|
nuclear@0
|
23
|
nuclear@0
|
24 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
nuclear@0
|
25 distributed under the License is distributed on an "AS IS" BASIS,
|
nuclear@0
|
26 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
nuclear@0
|
27 See the License for the specific language governing permissions and
|
nuclear@0
|
28 limitations under the License.
|
nuclear@0
|
29
|
nuclear@0
|
30 ************************************************************************************/
|
nuclear@0
|
31
|
nuclear@0
|
32 #ifndef OVR_Profile_h
|
nuclear@0
|
33 #define OVR_Profile_h
|
nuclear@0
|
34
|
nuclear@0
|
35 #include "OVR_CAPI_Keys.h"
|
nuclear@0
|
36
|
nuclear@0
|
37 #include "Sensors/OVR_DeviceConstants.h"
|
nuclear@0
|
38 #include "Kernel/OVR_String.h"
|
nuclear@0
|
39 #include "Kernel/OVR_RefCount.h"
|
nuclear@0
|
40 #include "Kernel/OVR_Array.h"
|
nuclear@0
|
41 #include "Kernel/OVR_StringHash.h"
|
nuclear@0
|
42 #include "Kernel/OVR_System.h"
|
nuclear@0
|
43
|
nuclear@0
|
44 namespace OVR {
|
nuclear@0
|
45
|
nuclear@0
|
46 class HMDInfo; // Opaque forward declaration
|
nuclear@0
|
47 class Profile;
|
nuclear@0
|
48 class JSON;
|
nuclear@0
|
49
|
nuclear@0
|
50
|
nuclear@0
|
51 // Device key for looking up profiles
|
nuclear@0
|
52 struct ProfileDeviceKey
|
nuclear@0
|
53 {
|
nuclear@0
|
54 ProfileDeviceKey(const HMDInfo* info);
|
nuclear@0
|
55
|
nuclear@0
|
56 // Initialized properly?
|
nuclear@0
|
57 bool Valid;
|
nuclear@0
|
58
|
nuclear@0
|
59 // The HMD type
|
nuclear@0
|
60 HmdTypeEnum HmdType;
|
nuclear@0
|
61
|
nuclear@0
|
62 // This is the 12 character serial number printed on the HMD
|
nuclear@0
|
63 String PrintedSerial;
|
nuclear@0
|
64
|
nuclear@0
|
65 // This is the product name string of the USB sensor device
|
nuclear@0
|
66 // Note: It has been modified from the original to remove spaces and strip off "Oculus"
|
nuclear@0
|
67 String ProductName;
|
nuclear@0
|
68
|
nuclear@0
|
69 // This is the product id from the HID info of the USB sensor device
|
nuclear@0
|
70 unsigned ProductId;
|
nuclear@0
|
71
|
nuclear@0
|
72 static String SanitizeProductName(String productName);
|
nuclear@0
|
73 };
|
nuclear@0
|
74
|
nuclear@0
|
75
|
nuclear@0
|
76 // -----------------------------------------------------------------------------
|
nuclear@0
|
77 // ***** ProfileManager
|
nuclear@0
|
78
|
nuclear@0
|
79 // Profiles are interfaced through a ProfileManager object. Applications should
|
nuclear@0
|
80 // create a ProfileManager each time they intend to read or write user profile data.
|
nuclear@0
|
81 // The scope of the ProfileManager object defines when disk I/O is performed. Disk
|
nuclear@0
|
82 // reads are performed on the first profile access and disk writes are performed when
|
nuclear@0
|
83 // the ProfileManager goes out of scope. All profile interactions between these times
|
nuclear@0
|
84 // are performed in local memory and are fast. A typical profile interaction might
|
nuclear@0
|
85 // look like this:
|
nuclear@0
|
86 //
|
nuclear@0
|
87 // {
|
nuclear@0
|
88 // Ptr<ProfileManager> pm = *ProfileManager::Create();
|
nuclear@0
|
89 // Ptr<Profile> profile = pm->LoadProfile(Profile_RiftDK1,
|
nuclear@0
|
90 // pm->GetDefaultProfileName(Profile_RiftDK1));
|
nuclear@0
|
91 // if (profile)
|
nuclear@0
|
92 // { // Retrieve the current profile settings
|
nuclear@0
|
93 // }
|
nuclear@0
|
94 // } // Profile will be destroyed and any disk I/O completed when going out of scope
|
nuclear@0
|
95 class ProfileManager : public NewOverrideBase, public SystemSingletonBase<ProfileManager>
|
nuclear@0
|
96 {
|
nuclear@0
|
97 friend class OVR::SystemSingletonBase<ProfileManager>;
|
nuclear@0
|
98
|
nuclear@0
|
99 protected:
|
nuclear@0
|
100 ProfileManager(bool sys_register);
|
nuclear@0
|
101 virtual ~ProfileManager();
|
nuclear@0
|
102 virtual void OnSystemDestroy();
|
nuclear@0
|
103
|
nuclear@0
|
104 protected:
|
nuclear@0
|
105 // Synchronize ProfileManager access since it may be accessed from multiple threads,
|
nuclear@0
|
106 // as it's shared through DeviceManager.
|
nuclear@0
|
107 Lock ProfileLock;
|
nuclear@0
|
108 Ptr<JSON> ProfileCache;
|
nuclear@0
|
109 bool Changed;
|
nuclear@0
|
110 String TempBuff;
|
nuclear@0
|
111 String BasePath;
|
nuclear@0
|
112
|
nuclear@0
|
113 public:
|
nuclear@0
|
114 // In the service process it is important to set the base path because this cannot be detected automatically
|
nuclear@0
|
115 void SetBasePath(String basePath);
|
nuclear@0
|
116
|
nuclear@0
|
117 int GetUserCount();
|
nuclear@0
|
118 const char* GetUser(unsigned int index);
|
nuclear@0
|
119 bool CreateUser(const char* user, const char* name);
|
nuclear@0
|
120 bool HasUser(const char* user);
|
nuclear@0
|
121 bool RemoveUser(const char* user);
|
nuclear@0
|
122 const char* GetDefaultUser(const ProfileDeviceKey& deviceKey);
|
nuclear@0
|
123 bool SetDefaultUser(const ProfileDeviceKey& deviceKey, const char* user);
|
nuclear@0
|
124
|
nuclear@0
|
125 virtual Profile* CreateProfile();
|
nuclear@0
|
126 Profile* GetProfile(const ProfileDeviceKey& deviceKey, const char* user);
|
nuclear@0
|
127 Profile* GetDefaultUserProfile(const ProfileDeviceKey& deviceKey);
|
nuclear@0
|
128 Profile* GetDefaultProfile(HmdTypeEnum device);
|
nuclear@0
|
129 Profile* GetTaggedProfile(const char** key_names, const char** keys, int num_keys);
|
nuclear@0
|
130 bool SetTaggedProfile(const char** key_names, const char** keys, int num_keys, Profile* profile);
|
nuclear@0
|
131
|
nuclear@0
|
132 // Force re-reading the settings
|
nuclear@0
|
133 void Read();
|
nuclear@0
|
134
|
nuclear@0
|
135 protected:
|
nuclear@0
|
136 // Force writing the settings
|
nuclear@0
|
137 void ClearProfileData();
|
nuclear@0
|
138 void Save();
|
nuclear@0
|
139
|
nuclear@0
|
140 String GetProfilePath();
|
nuclear@0
|
141 void LoadCache(bool create);
|
nuclear@0
|
142 void LoadV1Profiles(JSON* v1);
|
nuclear@0
|
143 const char* GetDefaultUser(const char* product, const char* serial);
|
nuclear@0
|
144 };
|
nuclear@0
|
145
|
nuclear@0
|
146
|
nuclear@0
|
147 //-------------------------------------------------------------------
|
nuclear@0
|
148 // ***** Profile
|
nuclear@0
|
149
|
nuclear@0
|
150 // The base profile for all users. This object is not created directly.
|
nuclear@0
|
151 // Instead derived device objects provide add specific device members to
|
nuclear@0
|
152 // the base profile
|
nuclear@0
|
153 class Profile : public RefCountBase<Profile>
|
nuclear@0
|
154 {
|
nuclear@0
|
155 protected:
|
nuclear@0
|
156 OVR::Hash<String, JSON*, String::HashFunctor> ValMap;
|
nuclear@0
|
157 OVR::Array<JSON*> Values;
|
nuclear@0
|
158 OVR::String TempVal;
|
nuclear@0
|
159 String BasePath;
|
nuclear@0
|
160
|
nuclear@0
|
161 public:
|
nuclear@0
|
162 ~Profile();
|
nuclear@0
|
163
|
nuclear@0
|
164 int GetNumValues(const char* key) const;
|
nuclear@0
|
165 const char* GetValue(const char* key);
|
nuclear@0
|
166 char* GetValue(const char* key, char* val, int val_length) const;
|
nuclear@0
|
167 bool GetBoolValue(const char* key, bool default_val) const;
|
nuclear@0
|
168 int GetIntValue(const char* key, int default_val) const;
|
nuclear@0
|
169 float GetFloatValue(const char* key, float default_val) const;
|
nuclear@0
|
170 int GetFloatValues(const char* key, float* values, int num_vals) const;
|
nuclear@0
|
171 double GetDoubleValue(const char* key, double default_val) const;
|
nuclear@0
|
172 int GetDoubleValues(const char* key, double* values, int num_vals) const;
|
nuclear@0
|
173
|
nuclear@0
|
174 void SetValue(const char* key, const char* val);
|
nuclear@0
|
175 void SetBoolValue(const char* key, bool val);
|
nuclear@0
|
176 void SetIntValue(const char* key, int val);
|
nuclear@0
|
177 void SetFloatValue(const char* key, float val);
|
nuclear@0
|
178 void SetFloatValues(const char* key, const float* vals, int num_vals);
|
nuclear@0
|
179 void SetDoubleValue(const char* key, double val);
|
nuclear@0
|
180 void SetDoubleValues(const char* key, const double* vals, int num_vals);
|
nuclear@0
|
181
|
nuclear@0
|
182 bool IsDefaultProfile();
|
nuclear@0
|
183
|
nuclear@0
|
184 bool Close();
|
nuclear@0
|
185
|
nuclear@0
|
186 protected:
|
nuclear@0
|
187 Profile(String basePath) :
|
nuclear@0
|
188 BasePath(basePath)
|
nuclear@0
|
189 {
|
nuclear@0
|
190 }
|
nuclear@0
|
191
|
nuclear@0
|
192 void SetValue(JSON* val);
|
nuclear@0
|
193
|
nuclear@0
|
194 static bool LoadProfile(const ProfileDeviceKey& deviceKey,
|
nuclear@0
|
195 const char* user,
|
nuclear@0
|
196 Profile** profile);
|
nuclear@0
|
197 void CopyItems(JSON* root, String prefix);
|
nuclear@0
|
198
|
nuclear@0
|
199 bool LoadDeviceFile(unsigned int device_id, const char* serial);
|
nuclear@0
|
200 bool LoadDeviceProfile(const ProfileDeviceKey& deviceKey);
|
nuclear@0
|
201
|
nuclear@0
|
202 bool LoadProfile(JSON* root,
|
nuclear@0
|
203 const char* user,
|
nuclear@0
|
204 const char* device_model,
|
nuclear@0
|
205 const char* device_serial);
|
nuclear@0
|
206
|
nuclear@0
|
207 bool LoadUser(JSON* root,
|
nuclear@0
|
208 const char* user,
|
nuclear@0
|
209 const char* device_name,
|
nuclear@0
|
210 const char* device_serial);
|
nuclear@0
|
211
|
nuclear@0
|
212 friend class ProfileManager;
|
nuclear@0
|
213 friend class WProfileManager;
|
nuclear@0
|
214 };
|
nuclear@0
|
215
|
nuclear@0
|
216 // This path should be passed into the ProfileManager
|
nuclear@0
|
217 String GetBaseOVRPath(bool create_dir);
|
nuclear@0
|
218
|
nuclear@0
|
219
|
nuclear@0
|
220 } // namespace OVR
|
nuclear@0
|
221
|
nuclear@0
|
222 #endif // OVR_Profile_h
|