ovr_sdk

view LibOVR/Src/Service/Service_NetSessionCommon.cpp @ 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 source
1 /************************************************************************************
3 Filename : Service_NetSessionCommon.cpp
4 Content : Server for service interface
5 Created : June 12, 2014
6 Authors : Kevin Jenkins, Chris Taylor
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 You may obtain a copy of the License at
17 http://www.oculusvr.com/licenses/LICENSE-3.2
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
25 ************************************************************************************/
27 #include "Service_NetSessionCommon.h"
28 #include "../OVR_Stereo.h"
30 namespace OVR { namespace Service {
33 //// NetSessionCommon
35 NetSessionCommon::NetSessionCommon() :
36 Terminated(false)
37 {
38 pSession = new Net::Session;
39 OVR_ASSERT(pSession != NULL);
41 pRPC = new Net::Plugins::RPC1;
42 OVR_ASSERT(pRPC != NULL);
44 pSession->AddSessionListener(pRPC);
45 }
47 NetSessionCommon::~NetSessionCommon()
48 {
49 if (pSession)
50 {
51 delete pSession;
52 pSession = NULL;
53 }
54 if (pRPC)
55 {
56 delete pRPC;
57 pRPC = NULL;
58 }
60 Terminated = true;
62 OVR_ASSERT(IsFinished());
63 }
65 void NetSessionCommon::onSystemDestroy()
66 {
67 Terminated = true;
69 Join();
71 Release();
72 }
74 void NetSessionCommon::onThreadDestroy()
75 {
76 Terminated = true;
77 if (pSession)
78 {
79 pSession->Shutdown();
80 }
81 }
83 void NetSessionCommon::SerializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdInfo)
84 {
85 bitStream->Write(hmdInfo->ProductName);
86 bitStream->Write(hmdInfo->Manufacturer);
88 int32_t w = hmdInfo->Version;
89 bitStream->Write(w);
91 w = hmdInfo->HmdType;
92 bitStream->Write(w);
94 w = hmdInfo->ResolutionInPixels.w;
95 bitStream->Write(w);
97 w = hmdInfo->ResolutionInPixels.h;
98 bitStream->Write(w);
100 w = hmdInfo->ShimInfo.DeviceNumber;
101 bitStream->Write(w);
103 w = hmdInfo->ShimInfo.NativeWidth;
104 bitStream->Write(w);
106 w = hmdInfo->ShimInfo.NativeHeight;
107 bitStream->Write(w);
109 w = hmdInfo->ShimInfo.Rotation;
110 bitStream->Write(w);
112 bitStream->Write(hmdInfo->ScreenSizeInMeters.w);
113 bitStream->Write(hmdInfo->ScreenSizeInMeters.h);
114 bitStream->Write(hmdInfo->ScreenGapSizeInMeters);
115 bitStream->Write(hmdInfo->CenterFromTopInMeters);
116 bitStream->Write(hmdInfo->LensSeparationInMeters);
118 w = hmdInfo->DesktopX;
119 bitStream->Write(w);
121 w = hmdInfo->DesktopY;
122 bitStream->Write(w);
124 w = hmdInfo->Shutter.Type;
125 bitStream->Write(w);
127 bitStream->Write(hmdInfo->Shutter.VsyncToNextVsync);
128 bitStream->Write(hmdInfo->Shutter.VsyncToFirstScanline);
129 bitStream->Write(hmdInfo->Shutter.FirstScanlineToLastScanline);
130 bitStream->Write(hmdInfo->Shutter.PixelSettleTime);
131 bitStream->Write(hmdInfo->Shutter.PixelPersistence);
132 bitStream->Write(hmdInfo->DisplayDeviceName);
134 w = hmdInfo->DisplayId;
135 bitStream->Write(w);
137 bitStream->Write(hmdInfo->PrintedSerial);
139 uint8_t b = hmdInfo->InCompatibilityMode ? 1 : 0;
140 bitStream->Write(b);
142 w = hmdInfo->VendorId;
143 bitStream->Write(w);
145 w = hmdInfo->ProductId;
146 bitStream->Write(w);
148 bitStream->Write(hmdInfo->CameraFrustumFarZInMeters);
149 bitStream->Write(hmdInfo->CameraFrustumHFovInRadians);
150 bitStream->Write(hmdInfo->CameraFrustumNearZInMeters);
151 bitStream->Write(hmdInfo->CameraFrustumVFovInRadians);
153 w = hmdInfo->FirmwareMajor;
154 bitStream->Write(w);
156 w = hmdInfo->FirmwareMinor;
157 bitStream->Write(w);
159 bitStream->Write(hmdInfo->PelOffsetR.x);
160 bitStream->Write(hmdInfo->PelOffsetR.y);
161 bitStream->Write(hmdInfo->PelOffsetB.x);
162 bitStream->Write(hmdInfo->PelOffsetB.y);
164 // Important please read before modifying!
165 // ----------------------------------------------------
166 // Please add new serialized data to the end, here.
167 // Otherwise we will break backwards compatibility
168 // and e.g. 0.4.4 runtime will not work with 0.4.3 SDK.
170 // Please also update the DeserializeHMDInfo() function
171 // below also and make sure that the members you added
172 // are initialized properly in the HMDInfo constructor.
174 // Note that whenever new fields are added here you
175 // should also update the minor version of the RPC
176 // protocol in OVR_Session.h so that clients fail at
177 // a version check instead of when this data is
178 // found to be truncated from the server.
179 }
181 bool NetSessionCommon::DeserializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdInfo)
182 {
183 bitStream->Read(hmdInfo->ProductName);
184 bitStream->Read(hmdInfo->Manufacturer);
186 int32_t w = 0;
187 if (!bitStream->Read(w))
188 {
189 // This indicates that no HMD could be found
190 return false;
191 }
192 hmdInfo->Version = w;
194 bitStream->Read(w);
195 hmdInfo->HmdType = (HmdTypeEnum)w;
197 bitStream->Read(w);
198 hmdInfo->ResolutionInPixels.w = w;
200 bitStream->Read(w);
201 hmdInfo->ResolutionInPixels.h = w;
203 bitStream->Read(w);
204 hmdInfo->ShimInfo.DeviceNumber = w;
206 bitStream->Read(w);
207 hmdInfo->ShimInfo.NativeWidth = w;
209 bitStream->Read(w);
210 hmdInfo->ShimInfo.NativeHeight = w;
212 bitStream->Read(w);
213 hmdInfo->ShimInfo.Rotation = w;
215 bitStream->Read(hmdInfo->ScreenSizeInMeters.w);
216 bitStream->Read(hmdInfo->ScreenSizeInMeters.h);
217 bitStream->Read(hmdInfo->ScreenGapSizeInMeters);
218 bitStream->Read(hmdInfo->CenterFromTopInMeters);
219 bitStream->Read(hmdInfo->LensSeparationInMeters);
221 bitStream->Read(w);
222 hmdInfo->DesktopX = w;
224 bitStream->Read(w);
225 hmdInfo->DesktopY = w;
227 bitStream->Read(w);
228 hmdInfo->Shutter.Type = (HmdShutterTypeEnum)w;
230 bitStream->Read(hmdInfo->Shutter.VsyncToNextVsync);
231 bitStream->Read(hmdInfo->Shutter.VsyncToFirstScanline);
232 bitStream->Read(hmdInfo->Shutter.FirstScanlineToLastScanline);
233 bitStream->Read(hmdInfo->Shutter.PixelSettleTime);
234 bitStream->Read(hmdInfo->Shutter.PixelPersistence);
235 bitStream->Read(hmdInfo->DisplayDeviceName);
237 bitStream->Read(w);
238 hmdInfo->DisplayId = w;
240 bitStream->Read(hmdInfo->PrintedSerial);
242 uint8_t b = 0;
243 bitStream->Read(b);
244 hmdInfo->InCompatibilityMode = (b != 0);
246 bitStream->Read(w);
247 hmdInfo->VendorId = w;
249 bitStream->Read(w);
250 hmdInfo->ProductId = w;
252 bitStream->Read(hmdInfo->CameraFrustumFarZInMeters);
253 bitStream->Read(hmdInfo->CameraFrustumHFovInRadians);
254 bitStream->Read(hmdInfo->CameraFrustumNearZInMeters);
255 bitStream->Read(hmdInfo->CameraFrustumVFovInRadians);
257 bitStream->Read(w);
258 hmdInfo->FirmwareMajor = w;
260 if (!bitStream->Read(w))
261 {
262 OVR_ASSERT(false);
263 return false;
264 }
265 hmdInfo->FirmwareMinor = w;
267 bitStream->Read(hmdInfo->PelOffsetR.x);
268 bitStream->Read(hmdInfo->PelOffsetR.y);
269 bitStream->Read(hmdInfo->PelOffsetB.x);
270 if (!bitStream->Read(hmdInfo->PelOffsetB.y))
271 {
272 OVR_ASSERT(false);
273 return false;
274 }
276 // Important please read before modifying!
277 // ----------------------------------------------------
278 // Please add new serialized data to the end, here.
279 // Otherwise we will break backwards compatibility
280 // and e.g. 0.4.4 runtime will not work with 0.4.3 SDK.
282 // Be sure to check that the very last one read properly
283 // since HMD Info truncation should be caught here.
285 return true;
286 }
288 // Prefix key names with this to pass through to server
289 static const char* BypassPrefix = "server:";
291 static const char* KeyNames[][NetSessionCommon::ENumTypes] = {
292 /* EGetStringValue */ { "CameraSerial", "CameraUUID", 0 },
293 /* EGetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 },
294 /* EGetIntValue */ { 0 },
295 /* EGetNumberValue */{ "CenterPupilDepth", "LoggingMask", 0 },
296 /* EGetNumberValues */{ "NeckModelVector3f", 0 },
297 /* ESetStringValue */ { 0 },
298 /* ESetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 },
299 /* ESetIntValue */ { 0 },
300 /* ESetNumberValue */{ "CenterPupilDepth", "LoggingMask", 0 },
301 /* ESetNumberValues */{ "NeckModelVector3f", 0 },
302 };
304 bool IsInStringArray(const char* a[], const char* key)
305 {
306 for (int i = 0; a[i]; ++i)
307 {
308 if (OVR_strcmp(a[i], key) == 0)
309 return true;
310 }
312 return false;
313 }
315 const char *NetSessionCommon::FilterKeyPrefix(const char* key)
316 {
317 // If key starts with BypassPrefix,
318 if (strstr(key, BypassPrefix) == key)
319 {
320 key += strlen(BypassPrefix);
321 }
323 return key;
324 }
326 bool NetSessionCommon::IsServiceProperty(EGetterSetters e, const char* key)
327 {
328 if ((e >= 0 && e < ENumTypes) && IsInStringArray(KeyNames[e], key))
329 {
330 return true;
331 }
333 // If key starts with BypassPrefix,
334 if (strstr(key, BypassPrefix) == key)
335 {
336 return true;
337 }
339 return false;
340 }
343 }} // namespace OVR::Service