ovr_sdk
diff LibOVR/Src/OVR_Profile.h @ 0:1b39a1b46319
initial 0.4.4
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 14 Jan 2015 06:51:16 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/OVR_Profile.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,222 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : OVR_Profile.h 1.7 +Content : Structs and functions for loading and storing device profile settings 1.8 +Created : February 14, 2013 1.9 +Notes : 1.10 + Profiles are used to store per-user settings that can be transferred and used 1.11 + across multiple applications. For example, player IPD can be configured once 1.12 + and reused for a unified experience across games. Configuration and saving of profiles 1.13 + can be accomplished in game via the Profile API or by the official Oculus Configuration 1.14 + Utility. 1.15 + 1.16 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.17 + 1.18 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.19 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.20 +which is provided at the time of installation or download, or which 1.21 +otherwise accompanies this software in either electronic or hard copy form. 1.22 + 1.23 +You may obtain a copy of the License at 1.24 + 1.25 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.26 + 1.27 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.28 +distributed under the License is distributed on an "AS IS" BASIS, 1.29 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.30 +See the License for the specific language governing permissions and 1.31 +limitations under the License. 1.32 + 1.33 +************************************************************************************/ 1.34 + 1.35 +#ifndef OVR_Profile_h 1.36 +#define OVR_Profile_h 1.37 + 1.38 +#include "OVR_CAPI_Keys.h" 1.39 + 1.40 +#include "Sensors/OVR_DeviceConstants.h" 1.41 +#include "Kernel/OVR_String.h" 1.42 +#include "Kernel/OVR_RefCount.h" 1.43 +#include "Kernel/OVR_Array.h" 1.44 +#include "Kernel/OVR_StringHash.h" 1.45 +#include "Kernel/OVR_System.h" 1.46 + 1.47 +namespace OVR { 1.48 + 1.49 +class HMDInfo; // Opaque forward declaration 1.50 +class Profile; 1.51 +class JSON; 1.52 + 1.53 + 1.54 +// Device key for looking up profiles 1.55 +struct ProfileDeviceKey 1.56 +{ 1.57 + ProfileDeviceKey(const HMDInfo* info); 1.58 + 1.59 + // Initialized properly? 1.60 + bool Valid; 1.61 + 1.62 + // The HMD type 1.63 + HmdTypeEnum HmdType; 1.64 + 1.65 + // This is the 12 character serial number printed on the HMD 1.66 + String PrintedSerial; 1.67 + 1.68 + // This is the product name string of the USB sensor device 1.69 + // Note: It has been modified from the original to remove spaces and strip off "Oculus" 1.70 + String ProductName; 1.71 + 1.72 + // This is the product id from the HID info of the USB sensor device 1.73 + unsigned ProductId; 1.74 + 1.75 + static String SanitizeProductName(String productName); 1.76 +}; 1.77 + 1.78 + 1.79 +// ----------------------------------------------------------------------------- 1.80 +// ***** ProfileManager 1.81 + 1.82 +// Profiles are interfaced through a ProfileManager object. Applications should 1.83 +// create a ProfileManager each time they intend to read or write user profile data. 1.84 +// The scope of the ProfileManager object defines when disk I/O is performed. Disk 1.85 +// reads are performed on the first profile access and disk writes are performed when 1.86 +// the ProfileManager goes out of scope. All profile interactions between these times 1.87 +// are performed in local memory and are fast. A typical profile interaction might 1.88 +// look like this: 1.89 +// 1.90 +// { 1.91 +// Ptr<ProfileManager> pm = *ProfileManager::Create(); 1.92 +// Ptr<Profile> profile = pm->LoadProfile(Profile_RiftDK1, 1.93 +// pm->GetDefaultProfileName(Profile_RiftDK1)); 1.94 +// if (profile) 1.95 +// { // Retrieve the current profile settings 1.96 +// } 1.97 +// } // Profile will be destroyed and any disk I/O completed when going out of scope 1.98 +class ProfileManager : public NewOverrideBase, public SystemSingletonBase<ProfileManager> 1.99 +{ 1.100 + friend class OVR::SystemSingletonBase<ProfileManager>; 1.101 + 1.102 +protected: 1.103 + ProfileManager(bool sys_register); 1.104 + virtual ~ProfileManager(); 1.105 + virtual void OnSystemDestroy(); 1.106 + 1.107 +protected: 1.108 + // Synchronize ProfileManager access since it may be accessed from multiple threads, 1.109 + // as it's shared through DeviceManager. 1.110 + Lock ProfileLock; 1.111 + Ptr<JSON> ProfileCache; 1.112 + bool Changed; 1.113 + String TempBuff; 1.114 + String BasePath; 1.115 + 1.116 +public: 1.117 + // In the service process it is important to set the base path because this cannot be detected automatically 1.118 + void SetBasePath(String basePath); 1.119 + 1.120 + int GetUserCount(); 1.121 + const char* GetUser(unsigned int index); 1.122 + bool CreateUser(const char* user, const char* name); 1.123 + bool HasUser(const char* user); 1.124 + bool RemoveUser(const char* user); 1.125 + const char* GetDefaultUser(const ProfileDeviceKey& deviceKey); 1.126 + bool SetDefaultUser(const ProfileDeviceKey& deviceKey, const char* user); 1.127 + 1.128 + virtual Profile* CreateProfile(); 1.129 + Profile* GetProfile(const ProfileDeviceKey& deviceKey, const char* user); 1.130 + Profile* GetDefaultUserProfile(const ProfileDeviceKey& deviceKey); 1.131 + Profile* GetDefaultProfile(HmdTypeEnum device); 1.132 + Profile* GetTaggedProfile(const char** key_names, const char** keys, int num_keys); 1.133 + bool SetTaggedProfile(const char** key_names, const char** keys, int num_keys, Profile* profile); 1.134 + 1.135 + // Force re-reading the settings 1.136 + void Read(); 1.137 + 1.138 +protected: 1.139 + // Force writing the settings 1.140 + void ClearProfileData(); 1.141 + void Save(); 1.142 + 1.143 + String GetProfilePath(); 1.144 + void LoadCache(bool create); 1.145 + void LoadV1Profiles(JSON* v1); 1.146 + const char* GetDefaultUser(const char* product, const char* serial); 1.147 +}; 1.148 + 1.149 + 1.150 +//------------------------------------------------------------------- 1.151 +// ***** Profile 1.152 + 1.153 +// The base profile for all users. This object is not created directly. 1.154 +// Instead derived device objects provide add specific device members to 1.155 +// the base profile 1.156 +class Profile : public RefCountBase<Profile> 1.157 +{ 1.158 +protected: 1.159 + OVR::Hash<String, JSON*, String::HashFunctor> ValMap; 1.160 + OVR::Array<JSON*> Values; 1.161 + OVR::String TempVal; 1.162 + String BasePath; 1.163 + 1.164 +public: 1.165 + ~Profile(); 1.166 + 1.167 + int GetNumValues(const char* key) const; 1.168 + const char* GetValue(const char* key); 1.169 + char* GetValue(const char* key, char* val, int val_length) const; 1.170 + bool GetBoolValue(const char* key, bool default_val) const; 1.171 + int GetIntValue(const char* key, int default_val) const; 1.172 + float GetFloatValue(const char* key, float default_val) const; 1.173 + int GetFloatValues(const char* key, float* values, int num_vals) const; 1.174 + double GetDoubleValue(const char* key, double default_val) const; 1.175 + int GetDoubleValues(const char* key, double* values, int num_vals) const; 1.176 + 1.177 + void SetValue(const char* key, const char* val); 1.178 + void SetBoolValue(const char* key, bool val); 1.179 + void SetIntValue(const char* key, int val); 1.180 + void SetFloatValue(const char* key, float val); 1.181 + void SetFloatValues(const char* key, const float* vals, int num_vals); 1.182 + void SetDoubleValue(const char* key, double val); 1.183 + void SetDoubleValues(const char* key, const double* vals, int num_vals); 1.184 + 1.185 + bool IsDefaultProfile(); 1.186 + 1.187 + bool Close(); 1.188 + 1.189 +protected: 1.190 + Profile(String basePath) : 1.191 + BasePath(basePath) 1.192 + { 1.193 + } 1.194 + 1.195 + void SetValue(JSON* val); 1.196 + 1.197 + static bool LoadProfile(const ProfileDeviceKey& deviceKey, 1.198 + const char* user, 1.199 + Profile** profile); 1.200 + void CopyItems(JSON* root, String prefix); 1.201 + 1.202 + bool LoadDeviceFile(unsigned int device_id, const char* serial); 1.203 + bool LoadDeviceProfile(const ProfileDeviceKey& deviceKey); 1.204 + 1.205 + bool LoadProfile(JSON* root, 1.206 + const char* user, 1.207 + const char* device_model, 1.208 + const char* device_serial); 1.209 + 1.210 + bool LoadUser(JSON* root, 1.211 + const char* user, 1.212 + const char* device_name, 1.213 + const char* device_serial); 1.214 + 1.215 + friend class ProfileManager; 1.216 + friend class WProfileManager; 1.217 +}; 1.218 + 1.219 +// This path should be passed into the ProfileManager 1.220 +String GetBaseOVRPath(bool create_dir); 1.221 + 1.222 + 1.223 +} // namespace OVR 1.224 + 1.225 +#endif // OVR_Profile_h