Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_Profile.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 PublicHeader: OVR.h
4 Filename : OVR_Profile.h
5 Content : Structs and functions for loading and storing device profile settings
6 Created : February 14, 2013
7 Notes :
8  Profiles are used to store per-user settings that can be transferred and used
9  across multiple applications. For example, player IPD can be configured once
10  and reused for a unified experience across games. Configuration and saving of profiles
11  can be accomplished in game via the Profile API or by the official Oculus Configuration
12  Utility.
13 
14 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
15 
16 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
17 you may not use the Oculus VR Rift SDK except in compliance with the License,
18 which is provided at the time of installation or download, or which
19 otherwise accompanies this software in either electronic or hard copy form.
20 
21 You may obtain a copy of the License at
22 
23 http://www.oculusvr.com/licenses/LICENSE-3.1
24 
25 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
26 distributed under the License is distributed on an "AS IS" BASIS,
27 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 See the License for the specific language governing permissions and
29 limitations under the License.
30 
31 ************************************************************************************/
32 
33 #ifndef OVR_Profile_h
34 #define OVR_Profile_h
35 
36 #include "OVR_DeviceConstants.h"
37 #include "Kernel/OVR_String.h"
38 #include "Kernel/OVR_RefCount.h"
39 #include "Kernel/OVR_Array.h"
40 #include "Kernel/OVR_StringHash.h"
41 
42 namespace OVR {
43 
44 class Profile;
45 class DeviceBase;
46 class JSON;
47 
48 // -----------------------------------------------------------------------------
49 // ***** ProfileManager
50 
51 // Profiles are interfaced through a ProfileManager object. Applications should
52 // create a ProfileManager each time they intend to read or write user profile data.
53 // The scope of the ProfileManager object defines when disk I/O is performed. Disk
54 // reads are performed on the first profile access and disk writes are performed when
55 // the ProfileManager goes out of scope. All profile interactions between these times
56 // are performed in local memory and are fast. A typical profile interaction might
57 // look like this:
58 //
59 // {
60 // Ptr<ProfileManager> pm = *ProfileManager::Create();
61 // Ptr<Profile> profile = pm->LoadProfile(Profile_RiftDK1,
62 // pm->GetDefaultProfileName(Profile_RiftDK1));
63 // if (profile)
64 // { // Retrieve the current profile settings
65 // }
66 // } // Profile will be destroyed and any disk I/O completed when going out of scope
67 class ProfileManager : public RefCountBase<ProfileManager>
68 {
69 protected:
70  // Synchronize ProfileManager access since it may be accessed from multiple threads,
71  // as it's shared through DeviceManager.
74  bool Changed;
76 
77 public:
78  static ProfileManager* Create();
79 
80  int GetUserCount();
81  const char* GetUser(unsigned int index);
82  bool CreateUser(const char* user, const char* name);
83  bool RemoveUser(const char* user);
84  const char* GetDefaultUser(const DeviceBase* device);
85  bool SetDefaultUser(const DeviceBase* device, const char* user);
86 
87  virtual Profile* CreateProfile();
88  Profile* GetProfile(const DeviceBase* device, const char* user);
89  Profile* GetDefaultProfile(const DeviceBase* device);
90  Profile* GetTaggedProfile(const char** key_names, const char** keys, int num_keys);
91  bool SetTaggedProfile(const char** key_names, const char** keys, int num_keys, Profile* profile);
92 
93  bool GetDeviceTags(const DeviceBase* device, String& product, String& serial);
94 
95 protected:
98  String GetProfilePath(bool create_dir);
99  void LoadCache(bool create);
100  void ClearCache();
101  void LoadV1Profiles(JSON* v1);
102 
103 
104 };
105 
106 
107 //-------------------------------------------------------------------
108 // ***** Profile
109 
110 // The base profile for all users. This object is not created directly.
111 // Instead derived device objects provide add specific device members to
112 // the base profile
113 class Profile : public RefCountBase<Profile>
114 {
115 protected:
119 
120 public:
121  ~Profile();
122 
123  int GetNumValues(const char* key) const;
124  const char* GetValue(const char* key);
125  char* GetValue(const char* key, char* val, int val_length) const;
126  bool GetBoolValue(const char* key, bool default_val) const;
127  int GetIntValue(const char* key, int default_val) const;
128  float GetFloatValue(const char* key, float default_val) const;
129  int GetFloatValues(const char* key, float* values, int num_vals) const;
130  double GetDoubleValue(const char* key, double default_val) const;
131  int GetDoubleValues(const char* key, double* values, int num_vals) const;
132 
133  void SetValue(const char* key, const char* val);
134  void SetBoolValue(const char* key, bool val);
135  void SetIntValue(const char* key, int val);
136  void SetFloatValue(const char* key, float val);
137  void SetFloatValues(const char* key, const float* vals, int num_vals);
138  void SetDoubleValue(const char* key, double val);
139  void SetDoubleValues(const char* key, const double* vals, int num_vals);
140 
141  bool Close();
142 
143 protected:
144  Profile() {};
145 
146 
147  void SetValue(JSON* val);
148 
149 
150  static bool LoadProfile(const DeviceBase* device,
151  const char* user,
152  Profile** profile);
153  void CopyItems(JSON* root, String prefix);
154 
155  bool LoadDeviceFile(unsigned int device_id, const char* serial);
156  bool LoadDeviceProfile(const DeviceBase* device);
157 
158  bool LoadProfile(JSON* root,
159  const char* user,
160  const char* device_model,
161  const char* device_serial);
162 
163  bool LoadUser(JSON* root,
164  const char* user,
165  const char* device_name,
166  const char* device_serial);
167 
168 
169  friend class ProfileManager;
170 };
171 
172 // # defined() check for CAPI compatibility near term that re-defines these
173 // for now. To be unified.
174 #if !defined(OVR_KEY_USER)
175 
176 #define OVR_KEY_USER "User"
177 #define OVR_KEY_NAME "Name"
178 #define OVR_KEY_GENDER "Gender"
179 #define OVR_KEY_PLAYER_HEIGHT "PlayerHeight"
180 #define OVR_KEY_EYE_HEIGHT "EyeHeight"
181 #define OVR_KEY_IPD "IPD"
182 #define OVR_KEY_NECK_TO_EYE_DISTANCE "NeckEyeDistance"
183 #define OVR_KEY_EYE_RELIEF_DIAL "EyeReliefDial"
184 #define OVR_KEY_EYE_TO_NOSE_DISTANCE "EyeToNoseDist"
185 #define OVR_KEY_MAX_EYE_TO_PLATE_DISTANCE "MaxEyeToPlateDist"
186 #define OVR_KEY_EYE_CUP "EyeCup"
187 #define OVR_KEY_CUSTOM_EYE_RENDER "CustomEyeRender"
188 
189 #define OVR_DEFAULT_GENDER "Male"
190 #define OVR_DEFAULT_PLAYER_HEIGHT 1.778f
191 #define OVR_DEFAULT_EYE_HEIGHT 1.675f
192 #define OVR_DEFAULT_IPD 0.064f
193 #define OVR_DEFAULT_NECK_TO_EYE_HORIZONTAL 0.09f
194 #define OVR_DEFAULT_NECK_TO_EYE_VERTICAL 0.15f
195 #define OVR_DEFAULT_EYE_RELIEF_DIAL 3
196 
197 #endif // OVR_KEY_USER
198 
199 String GetBaseOVRPath(bool create_dir);
200 
201 }
202 
203 #endif // OVR_Profile_h
void SetDoubleValues(const char *key, const double *vals, int num_vals)
void LoadCache(bool create)
bool CreateUser(const char *user, const char *name)
virtual Profile * CreateProfile()
const char * GetValue(const char *key)
float GetFloatValue(const char *key, float default_val) const
bool LoadUser(JSON *root, const char *user, const char *device_name, const char *device_serial)
int GetNumValues(const char *key) const
int GetIntValue(const char *key, int default_val) const
OVR::Hash< String, JSON *, String::HashFunctor > ValMap
Definition: OVR_Profile.h:116
static ProfileManager * Create()
String GetProfilePath(bool create_dir)
void SetBoolValue(const char *key, bool val)
OVR::Array< JSON * > Values
Definition: OVR_Profile.h:117
String GetBaseOVRPath(bool create_dir)
Definition: OVR_Profile.cpp:64
const char * GetDefaultUser(const DeviceBase *device)
Profile * GetProfile(const DeviceBase *device, const char *user)
bool LoadDeviceFile(unsigned int device_id, const char *serial)
const char * GetUser(unsigned int index)
Ptr< JSON > ProfileCache
Definition: OVR_Profile.h:73
OVR::String TempVal
Definition: OVR_Profile.h:118
void SetValue(const char *key, const char *val)
void SetIntValue(const char *key, int val)
int GetFloatValues(const char *key, float *values, int num_vals) const
bool GetBoolValue(const char *key, bool default_val) const
void SetDoubleValue(const char *key, double val)
Profile * GetDefaultProfile(const DeviceBase *device)
void LoadV1Profiles(JSON *v1)
void SetFloatValues(const char *key, const float *vals, int num_vals)
bool SetTaggedProfile(const char **key_names, const char **keys, int num_keys, Profile *profile)
void CopyItems(JSON *root, String prefix)
bool LoadDeviceProfile(const DeviceBase *device)
int GetDoubleValues(const char *key, double *values, int num_vals) const
int char * index(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1))
static bool LoadProfile(const DeviceBase *device, const char *user, Profile **profile)
bool RemoveUser(const char *user)
void SetFloatValue(const char *key, float val)
Profile * GetTaggedProfile(const char **key_names, const char **keys, int num_keys)
bool SetDefaultUser(const DeviceBase *device, const char *user)
bool GetDeviceTags(const DeviceBase *device, String &product, String &serial)
double GetDoubleValue(const char *key, double default_val) const