ovr_sdk
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Service/Service_NetSessionCommon.cpp Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,343 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : Service_NetSessionCommon.cpp 1.7 +Content : Server for service interface 1.8 +Created : June 12, 2014 1.9 +Authors : Kevin Jenkins, Chris Taylor 1.10 + 1.11 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.12 + 1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.15 +which is provided at the time of installation or download, or which 1.16 +otherwise accompanies this software in either electronic or hard copy form. 1.17 + 1.18 +You may obtain a copy of the License at 1.19 + 1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.21 + 1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.23 +distributed under the License is distributed on an "AS IS" BASIS, 1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.25 +See the License for the specific language governing permissions and 1.26 +limitations under the License. 1.27 + 1.28 +************************************************************************************/ 1.29 + 1.30 +#include "Service_NetSessionCommon.h" 1.31 +#include "../OVR_Stereo.h" 1.32 + 1.33 +namespace OVR { namespace Service { 1.34 + 1.35 + 1.36 +//// NetSessionCommon 1.37 + 1.38 +NetSessionCommon::NetSessionCommon() : 1.39 + Terminated(false) 1.40 +{ 1.41 + pSession = new Net::Session; 1.42 + OVR_ASSERT(pSession != NULL); 1.43 + 1.44 + pRPC = new Net::Plugins::RPC1; 1.45 + OVR_ASSERT(pRPC != NULL); 1.46 + 1.47 + pSession->AddSessionListener(pRPC); 1.48 +} 1.49 + 1.50 +NetSessionCommon::~NetSessionCommon() 1.51 +{ 1.52 + if (pSession) 1.53 + { 1.54 + delete pSession; 1.55 + pSession = NULL; 1.56 + } 1.57 + if (pRPC) 1.58 + { 1.59 + delete pRPC; 1.60 + pRPC = NULL; 1.61 + } 1.62 + 1.63 + Terminated = true; 1.64 + 1.65 + OVR_ASSERT(IsFinished()); 1.66 +} 1.67 + 1.68 +void NetSessionCommon::onSystemDestroy() 1.69 +{ 1.70 + Terminated = true; 1.71 + 1.72 + Join(); 1.73 + 1.74 + Release(); 1.75 +} 1.76 + 1.77 +void NetSessionCommon::onThreadDestroy() 1.78 +{ 1.79 + Terminated = true; 1.80 + if (pSession) 1.81 + { 1.82 + pSession->Shutdown(); 1.83 + } 1.84 +} 1.85 + 1.86 +void NetSessionCommon::SerializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdInfo) 1.87 +{ 1.88 + bitStream->Write(hmdInfo->ProductName); 1.89 + bitStream->Write(hmdInfo->Manufacturer); 1.90 + 1.91 + int32_t w = hmdInfo->Version; 1.92 + bitStream->Write(w); 1.93 + 1.94 + w = hmdInfo->HmdType; 1.95 + bitStream->Write(w); 1.96 + 1.97 + w = hmdInfo->ResolutionInPixels.w; 1.98 + bitStream->Write(w); 1.99 + 1.100 + w = hmdInfo->ResolutionInPixels.h; 1.101 + bitStream->Write(w); 1.102 + 1.103 + w = hmdInfo->ShimInfo.DeviceNumber; 1.104 + bitStream->Write(w); 1.105 + 1.106 + w = hmdInfo->ShimInfo.NativeWidth; 1.107 + bitStream->Write(w); 1.108 + 1.109 + w = hmdInfo->ShimInfo.NativeHeight; 1.110 + bitStream->Write(w); 1.111 + 1.112 + w = hmdInfo->ShimInfo.Rotation; 1.113 + bitStream->Write(w); 1.114 + 1.115 + bitStream->Write(hmdInfo->ScreenSizeInMeters.w); 1.116 + bitStream->Write(hmdInfo->ScreenSizeInMeters.h); 1.117 + bitStream->Write(hmdInfo->ScreenGapSizeInMeters); 1.118 + bitStream->Write(hmdInfo->CenterFromTopInMeters); 1.119 + bitStream->Write(hmdInfo->LensSeparationInMeters); 1.120 + 1.121 + w = hmdInfo->DesktopX; 1.122 + bitStream->Write(w); 1.123 + 1.124 + w = hmdInfo->DesktopY; 1.125 + bitStream->Write(w); 1.126 + 1.127 + w = hmdInfo->Shutter.Type; 1.128 + bitStream->Write(w); 1.129 + 1.130 + bitStream->Write(hmdInfo->Shutter.VsyncToNextVsync); 1.131 + bitStream->Write(hmdInfo->Shutter.VsyncToFirstScanline); 1.132 + bitStream->Write(hmdInfo->Shutter.FirstScanlineToLastScanline); 1.133 + bitStream->Write(hmdInfo->Shutter.PixelSettleTime); 1.134 + bitStream->Write(hmdInfo->Shutter.PixelPersistence); 1.135 + bitStream->Write(hmdInfo->DisplayDeviceName); 1.136 + 1.137 + w = hmdInfo->DisplayId; 1.138 + bitStream->Write(w); 1.139 + 1.140 + bitStream->Write(hmdInfo->PrintedSerial); 1.141 + 1.142 + uint8_t b = hmdInfo->InCompatibilityMode ? 1 : 0; 1.143 + bitStream->Write(b); 1.144 + 1.145 + w = hmdInfo->VendorId; 1.146 + bitStream->Write(w); 1.147 + 1.148 + w = hmdInfo->ProductId; 1.149 + bitStream->Write(w); 1.150 + 1.151 + bitStream->Write(hmdInfo->CameraFrustumFarZInMeters); 1.152 + bitStream->Write(hmdInfo->CameraFrustumHFovInRadians); 1.153 + bitStream->Write(hmdInfo->CameraFrustumNearZInMeters); 1.154 + bitStream->Write(hmdInfo->CameraFrustumVFovInRadians); 1.155 + 1.156 + w = hmdInfo->FirmwareMajor; 1.157 + bitStream->Write(w); 1.158 + 1.159 + w = hmdInfo->FirmwareMinor; 1.160 + bitStream->Write(w); 1.161 + 1.162 + bitStream->Write(hmdInfo->PelOffsetR.x); 1.163 + bitStream->Write(hmdInfo->PelOffsetR.y); 1.164 + bitStream->Write(hmdInfo->PelOffsetB.x); 1.165 + bitStream->Write(hmdInfo->PelOffsetB.y); 1.166 + 1.167 + // Important please read before modifying! 1.168 + // ---------------------------------------------------- 1.169 + // Please add new serialized data to the end, here. 1.170 + // Otherwise we will break backwards compatibility 1.171 + // and e.g. 0.4.4 runtime will not work with 0.4.3 SDK. 1.172 + 1.173 + // Please also update the DeserializeHMDInfo() function 1.174 + // below also and make sure that the members you added 1.175 + // are initialized properly in the HMDInfo constructor. 1.176 + 1.177 + // Note that whenever new fields are added here you 1.178 + // should also update the minor version of the RPC 1.179 + // protocol in OVR_Session.h so that clients fail at 1.180 + // a version check instead of when this data is 1.181 + // found to be truncated from the server. 1.182 +} 1.183 + 1.184 +bool NetSessionCommon::DeserializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdInfo) 1.185 +{ 1.186 + bitStream->Read(hmdInfo->ProductName); 1.187 + bitStream->Read(hmdInfo->Manufacturer); 1.188 + 1.189 + int32_t w = 0; 1.190 + if (!bitStream->Read(w)) 1.191 + { 1.192 + // This indicates that no HMD could be found 1.193 + return false; 1.194 + } 1.195 + hmdInfo->Version = w; 1.196 + 1.197 + bitStream->Read(w); 1.198 + hmdInfo->HmdType = (HmdTypeEnum)w; 1.199 + 1.200 + bitStream->Read(w); 1.201 + hmdInfo->ResolutionInPixels.w = w; 1.202 + 1.203 + bitStream->Read(w); 1.204 + hmdInfo->ResolutionInPixels.h = w; 1.205 + 1.206 + bitStream->Read(w); 1.207 + hmdInfo->ShimInfo.DeviceNumber = w; 1.208 + 1.209 + bitStream->Read(w); 1.210 + hmdInfo->ShimInfo.NativeWidth = w; 1.211 + 1.212 + bitStream->Read(w); 1.213 + hmdInfo->ShimInfo.NativeHeight = w; 1.214 + 1.215 + bitStream->Read(w); 1.216 + hmdInfo->ShimInfo.Rotation = w; 1.217 + 1.218 + bitStream->Read(hmdInfo->ScreenSizeInMeters.w); 1.219 + bitStream->Read(hmdInfo->ScreenSizeInMeters.h); 1.220 + bitStream->Read(hmdInfo->ScreenGapSizeInMeters); 1.221 + bitStream->Read(hmdInfo->CenterFromTopInMeters); 1.222 + bitStream->Read(hmdInfo->LensSeparationInMeters); 1.223 + 1.224 + bitStream->Read(w); 1.225 + hmdInfo->DesktopX = w; 1.226 + 1.227 + bitStream->Read(w); 1.228 + hmdInfo->DesktopY = w; 1.229 + 1.230 + bitStream->Read(w); 1.231 + hmdInfo->Shutter.Type = (HmdShutterTypeEnum)w; 1.232 + 1.233 + bitStream->Read(hmdInfo->Shutter.VsyncToNextVsync); 1.234 + bitStream->Read(hmdInfo->Shutter.VsyncToFirstScanline); 1.235 + bitStream->Read(hmdInfo->Shutter.FirstScanlineToLastScanline); 1.236 + bitStream->Read(hmdInfo->Shutter.PixelSettleTime); 1.237 + bitStream->Read(hmdInfo->Shutter.PixelPersistence); 1.238 + bitStream->Read(hmdInfo->DisplayDeviceName); 1.239 + 1.240 + bitStream->Read(w); 1.241 + hmdInfo->DisplayId = w; 1.242 + 1.243 + bitStream->Read(hmdInfo->PrintedSerial); 1.244 + 1.245 + uint8_t b = 0; 1.246 + bitStream->Read(b); 1.247 + hmdInfo->InCompatibilityMode = (b != 0); 1.248 + 1.249 + bitStream->Read(w); 1.250 + hmdInfo->VendorId = w; 1.251 + 1.252 + bitStream->Read(w); 1.253 + hmdInfo->ProductId = w; 1.254 + 1.255 + bitStream->Read(hmdInfo->CameraFrustumFarZInMeters); 1.256 + bitStream->Read(hmdInfo->CameraFrustumHFovInRadians); 1.257 + bitStream->Read(hmdInfo->CameraFrustumNearZInMeters); 1.258 + bitStream->Read(hmdInfo->CameraFrustumVFovInRadians); 1.259 + 1.260 + bitStream->Read(w); 1.261 + hmdInfo->FirmwareMajor = w; 1.262 + 1.263 + if (!bitStream->Read(w)) 1.264 + { 1.265 + OVR_ASSERT(false); 1.266 + return false; 1.267 + } 1.268 + hmdInfo->FirmwareMinor = w; 1.269 + 1.270 + bitStream->Read(hmdInfo->PelOffsetR.x); 1.271 + bitStream->Read(hmdInfo->PelOffsetR.y); 1.272 + bitStream->Read(hmdInfo->PelOffsetB.x); 1.273 + if (!bitStream->Read(hmdInfo->PelOffsetB.y)) 1.274 + { 1.275 + OVR_ASSERT(false); 1.276 + return false; 1.277 + } 1.278 + 1.279 + // Important please read before modifying! 1.280 + // ---------------------------------------------------- 1.281 + // Please add new serialized data to the end, here. 1.282 + // Otherwise we will break backwards compatibility 1.283 + // and e.g. 0.4.4 runtime will not work with 0.4.3 SDK. 1.284 + 1.285 + // Be sure to check that the very last one read properly 1.286 + // since HMD Info truncation should be caught here. 1.287 + 1.288 + return true; 1.289 +} 1.290 + 1.291 +// Prefix key names with this to pass through to server 1.292 +static const char* BypassPrefix = "server:"; 1.293 + 1.294 +static const char* KeyNames[][NetSessionCommon::ENumTypes] = { 1.295 + /* EGetStringValue */ { "CameraSerial", "CameraUUID", 0 }, 1.296 + /* EGetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 }, 1.297 + /* EGetIntValue */ { 0 }, 1.298 + /* EGetNumberValue */{ "CenterPupilDepth", "LoggingMask", 0 }, 1.299 + /* EGetNumberValues */{ "NeckModelVector3f", 0 }, 1.300 + /* ESetStringValue */ { 0 }, 1.301 + /* ESetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 }, 1.302 + /* ESetIntValue */ { 0 }, 1.303 + /* ESetNumberValue */{ "CenterPupilDepth", "LoggingMask", 0 }, 1.304 + /* ESetNumberValues */{ "NeckModelVector3f", 0 }, 1.305 +}; 1.306 + 1.307 +bool IsInStringArray(const char* a[], const char* key) 1.308 +{ 1.309 + for (int i = 0; a[i]; ++i) 1.310 + { 1.311 + if (OVR_strcmp(a[i], key) == 0) 1.312 + return true; 1.313 + } 1.314 + 1.315 + return false; 1.316 +} 1.317 + 1.318 +const char *NetSessionCommon::FilterKeyPrefix(const char* key) 1.319 +{ 1.320 + // If key starts with BypassPrefix, 1.321 + if (strstr(key, BypassPrefix) == key) 1.322 + { 1.323 + key += strlen(BypassPrefix); 1.324 + } 1.325 + 1.326 + return key; 1.327 +} 1.328 + 1.329 +bool NetSessionCommon::IsServiceProperty(EGetterSetters e, const char* key) 1.330 +{ 1.331 + if ((e >= 0 && e < ENumTypes) && IsInStringArray(KeyNames[e], key)) 1.332 + { 1.333 + return true; 1.334 + } 1.335 + 1.336 + // If key starts with BypassPrefix, 1.337 + if (strstr(key, BypassPrefix) == key) 1.338 + { 1.339 + return true; 1.340 + } 1.341 + 1.342 + return false; 1.343 +} 1.344 + 1.345 + 1.346 +}} // namespace OVR::Service