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