summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Service/Service_NetSessionCommon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LibOVR/Src/Service/Service_NetSessionCommon.cpp')
-rw-r--r--LibOVR/Src/Service/Service_NetSessionCommon.cpp276
1 files changed, 91 insertions, 185 deletions
diff --git a/LibOVR/Src/Service/Service_NetSessionCommon.cpp b/LibOVR/Src/Service/Service_NetSessionCommon.cpp
index ba2c773..4a9fda6 100644
--- a/LibOVR/Src/Service/Service_NetSessionCommon.cpp
+++ b/LibOVR/Src/Service/Service_NetSessionCommon.cpp
@@ -30,7 +30,8 @@ limitations under the License.
namespace OVR { namespace Service {
-//// NetSessionCommon
+//-----------------------------------------------------------------------------
+// NetSessionCommon
NetSessionCommon::NetSessionCommon() :
Terminated(false)
@@ -57,14 +58,14 @@ NetSessionCommon::~NetSessionCommon()
pRPC = NULL;
}
- Terminated = true;
+ Terminated.store(true, std::memory_order_relaxed);
OVR_ASSERT(IsFinished());
}
void NetSessionCommon::onSystemDestroy()
{
- Terminated = true;
+ Terminated.store(true, std::memory_order_relaxed);
Join();
@@ -73,93 +74,106 @@ void NetSessionCommon::onSystemDestroy()
void NetSessionCommon::onThreadDestroy()
{
- Terminated = true;
+ Terminated.store(true, std::memory_order_relaxed);
if (pSession)
{
pSession->Shutdown();
}
}
-void NetSessionCommon::SerializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdInfo)
+template<typename T>
+static bool SerializeUInt32(bool write, Net::BitStream* bitStream, T& data)
{
- bitStream->Write(hmdInfo->ProductName);
- bitStream->Write(hmdInfo->Manufacturer);
-
- int32_t w = hmdInfo->Version;
- bitStream->Write(w);
-
- w = hmdInfo->HmdType;
- bitStream->Write(w);
-
- w = hmdInfo->ResolutionInPixels.w;
- bitStream->Write(w);
-
- w = hmdInfo->ResolutionInPixels.h;
- bitStream->Write(w);
+ int32_t w = 0;
+ bool result = false;
- w = hmdInfo->ShimInfo.DeviceNumber;
- bitStream->Write(w);
+ if (write)
+ {
+ w = (int32_t)data;
+ result = bitStream->Serialize(write, w);
+ }
+ else
+ {
+ result = bitStream->Serialize(write, w);
+ data = (T)w;
+ }
- w = hmdInfo->ShimInfo.NativeWidth;
- bitStream->Write(w);
+ return result;
+}
- w = hmdInfo->ShimInfo.NativeHeight;
- bitStream->Write(w);
+static bool SerializeBool(bool write, Net::BitStream* bitStream, bool& data)
+{
+ uint8_t x = 0;
+ bool result = false;
- w = hmdInfo->ShimInfo.Rotation;
- bitStream->Write(w);
+ if (write)
+ {
+ x = data ? 1 : 0;
+ result = bitStream->Serialize(write, x);
+ }
+ else
+ {
+ result = bitStream->Serialize(write, x);
+ data = (x != 0);
+ }
- bitStream->Write(hmdInfo->ScreenSizeInMeters.w);
- bitStream->Write(hmdInfo->ScreenSizeInMeters.h);
- bitStream->Write(hmdInfo->ScreenGapSizeInMeters);
- bitStream->Write(hmdInfo->CenterFromTopInMeters);
- bitStream->Write(hmdInfo->LensSeparationInMeters);
+ return result;
+}
- w = hmdInfo->DesktopX;
- bitStream->Write(w);
+bool NetSessionCommon::SerializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdInfo, bool write)
+{
+ bool result = false;
- w = hmdInfo->DesktopY;
- bitStream->Write(w);
+ bitStream->Serialize(write, hmdInfo->ProductName);
+ bitStream->Serialize(write, hmdInfo->Manufacturer);
- w = hmdInfo->Shutter.Type;
- bitStream->Write(w);
+ SerializeUInt32(write, bitStream, hmdInfo->Version);
+ SerializeUInt32(write, bitStream, hmdInfo->HmdType);
+ SerializeUInt32(write, bitStream, hmdInfo->ResolutionInPixels.w);
+ SerializeUInt32(write, bitStream, hmdInfo->ResolutionInPixels.h);
+ SerializeUInt32(write, bitStream, hmdInfo->ShimInfo.DeviceNumber);
+ SerializeUInt32(write, bitStream, hmdInfo->ShimInfo.NativeWidth);
+ SerializeUInt32(write, bitStream, hmdInfo->ShimInfo.NativeHeight);
+ SerializeUInt32(write, bitStream, hmdInfo->ShimInfo.Rotation);
- bitStream->Write(hmdInfo->Shutter.VsyncToNextVsync);
- bitStream->Write(hmdInfo->Shutter.VsyncToFirstScanline);
- bitStream->Write(hmdInfo->Shutter.FirstScanlineToLastScanline);
- bitStream->Write(hmdInfo->Shutter.PixelSettleTime);
- bitStream->Write(hmdInfo->Shutter.PixelPersistence);
- bitStream->Write(hmdInfo->DisplayDeviceName);
+ bitStream->Serialize(write, hmdInfo->ScreenSizeInMeters.w);
+ bitStream->Serialize(write, hmdInfo->ScreenSizeInMeters.h);
+ bitStream->Serialize(write, hmdInfo->ScreenGapSizeInMeters);
+ bitStream->Serialize(write, hmdInfo->CenterFromTopInMeters);
+ bitStream->Serialize(write, hmdInfo->LensSeparationInMeters);
- w = hmdInfo->DisplayId;
- bitStream->Write(w);
+ SerializeUInt32(write, bitStream, hmdInfo->DesktopX);
+ SerializeUInt32(write, bitStream, hmdInfo->DesktopY);
+ SerializeUInt32(write, bitStream, hmdInfo->Shutter.Type);
- bitStream->Write(hmdInfo->PrintedSerial);
+ bitStream->Serialize(write, hmdInfo->Shutter.VsyncToNextVsync);
+ bitStream->Serialize(write, hmdInfo->Shutter.VsyncToFirstScanline);
+ bitStream->Serialize(write, hmdInfo->Shutter.FirstScanlineToLastScanline);
+ bitStream->Serialize(write, hmdInfo->Shutter.PixelSettleTime);
+ bitStream->Serialize(write, hmdInfo->Shutter.PixelPersistence);
+ bitStream->Serialize(write, hmdInfo->DisplayDeviceName);
- uint8_t b = hmdInfo->InCompatibilityMode ? 1 : 0;
- bitStream->Write(b);
+ SerializeUInt32(write, bitStream, hmdInfo->DisplayId);
- w = hmdInfo->VendorId;
- bitStream->Write(w);
+ bitStream->Serialize(write, hmdInfo->PrintedSerial);
- w = hmdInfo->ProductId;
- bitStream->Write(w);
+ SerializeBool(write, bitStream, hmdInfo->InCompatibilityMode);
- bitStream->Write(hmdInfo->CameraFrustumFarZInMeters);
- bitStream->Write(hmdInfo->CameraFrustumHFovInRadians);
- bitStream->Write(hmdInfo->CameraFrustumNearZInMeters);
- bitStream->Write(hmdInfo->CameraFrustumVFovInRadians);
+ SerializeUInt32(write, bitStream, hmdInfo->VendorId);
+ SerializeUInt32(write, bitStream, hmdInfo->ProductId);
- w = hmdInfo->FirmwareMajor;
- bitStream->Write(w);
+ bitStream->Serialize(write, hmdInfo->CameraFrustumFarZInMeters);
+ bitStream->Serialize(write, hmdInfo->CameraFrustumHFovInRadians);
+ bitStream->Serialize(write, hmdInfo->CameraFrustumNearZInMeters);
+ bitStream->Serialize(write, hmdInfo->CameraFrustumVFovInRadians);
- w = hmdInfo->FirmwareMinor;
- bitStream->Write(w);
+ SerializeUInt32(write, bitStream, hmdInfo->FirmwareMajor);
+ SerializeUInt32(write, bitStream, hmdInfo->FirmwareMinor);
- bitStream->Write(hmdInfo->PelOffsetR.x);
- bitStream->Write(hmdInfo->PelOffsetR.y);
- bitStream->Write(hmdInfo->PelOffsetB.x);
- bitStream->Write(hmdInfo->PelOffsetB.y);
+ bitStream->Serialize(write, hmdInfo->PelOffsetR.x);
+ bitStream->Serialize(write, hmdInfo->PelOffsetR.y);
+ bitStream->Serialize(write, hmdInfo->PelOffsetB.x);
+ result = bitStream->Serialize(write, hmdInfo->PelOffsetB.y);
// Important please read before modifying!
// ----------------------------------------------------
@@ -167,138 +181,30 @@ void NetSessionCommon::SerializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdI
// Otherwise we will break backwards compatibility
// and e.g. 0.4.4 runtime will not work with 0.4.3 SDK.
- // Please also update the DeserializeHMDInfo() function
- // below also and make sure that the members you added
- // are initialized properly in the HMDInfo constructor.
-
// Note that whenever new fields are added here you
// should also update the minor version of the RPC
// protocol in OVR_Session.h so that clients fail at
// a version check instead of when this data is
// found to be truncated from the server.
-}
-
-bool NetSessionCommon::DeserializeHMDInfo(Net::BitStream *bitStream, HMDInfo* hmdInfo)
-{
- bitStream->Read(hmdInfo->ProductName);
- bitStream->Read(hmdInfo->Manufacturer);
-
- int32_t w = 0;
- if (!bitStream->Read(w))
- {
- // This indicates that no HMD could be found
- return false;
- }
- hmdInfo->Version = w;
-
- bitStream->Read(w);
- hmdInfo->HmdType = (HmdTypeEnum)w;
-
- bitStream->Read(w);
- hmdInfo->ResolutionInPixels.w = w;
-
- bitStream->Read(w);
- hmdInfo->ResolutionInPixels.h = w;
-
- bitStream->Read(w);
- hmdInfo->ShimInfo.DeviceNumber = w;
-
- bitStream->Read(w);
- hmdInfo->ShimInfo.NativeWidth = w;
-
- bitStream->Read(w);
- hmdInfo->ShimInfo.NativeHeight = w;
-
- bitStream->Read(w);
- hmdInfo->ShimInfo.Rotation = w;
-
- bitStream->Read(hmdInfo->ScreenSizeInMeters.w);
- bitStream->Read(hmdInfo->ScreenSizeInMeters.h);
- bitStream->Read(hmdInfo->ScreenGapSizeInMeters);
- bitStream->Read(hmdInfo->CenterFromTopInMeters);
- bitStream->Read(hmdInfo->LensSeparationInMeters);
-
- bitStream->Read(w);
- hmdInfo->DesktopX = w;
-
- bitStream->Read(w);
- hmdInfo->DesktopY = w;
-
- bitStream->Read(w);
- hmdInfo->Shutter.Type = (HmdShutterTypeEnum)w;
-
- bitStream->Read(hmdInfo->Shutter.VsyncToNextVsync);
- bitStream->Read(hmdInfo->Shutter.VsyncToFirstScanline);
- bitStream->Read(hmdInfo->Shutter.FirstScanlineToLastScanline);
- bitStream->Read(hmdInfo->Shutter.PixelSettleTime);
- bitStream->Read(hmdInfo->Shutter.PixelPersistence);
- bitStream->Read(hmdInfo->DisplayDeviceName);
-
- bitStream->Read(w);
- hmdInfo->DisplayId = w;
-
- bitStream->Read(hmdInfo->PrintedSerial);
-
- uint8_t b = 0;
- bitStream->Read(b);
- hmdInfo->InCompatibilityMode = (b != 0);
-
- bitStream->Read(w);
- hmdInfo->VendorId = w;
-
- bitStream->Read(w);
- hmdInfo->ProductId = w;
-
- bitStream->Read(hmdInfo->CameraFrustumFarZInMeters);
- bitStream->Read(hmdInfo->CameraFrustumHFovInRadians);
- bitStream->Read(hmdInfo->CameraFrustumNearZInMeters);
- bitStream->Read(hmdInfo->CameraFrustumVFovInRadians);
-
- bitStream->Read(w);
- hmdInfo->FirmwareMajor = w;
-
- if (!bitStream->Read(w))
- {
- OVR_ASSERT(false);
- return false;
- }
- hmdInfo->FirmwareMinor = w;
-
- bitStream->Read(hmdInfo->PelOffsetR.x);
- bitStream->Read(hmdInfo->PelOffsetR.y);
- bitStream->Read(hmdInfo->PelOffsetB.x);
- if (!bitStream->Read(hmdInfo->PelOffsetB.y))
- {
- OVR_ASSERT(false);
- return false;
- }
-
- // Important please read before modifying!
- // ----------------------------------------------------
- // Please add new serialized data to the end, here.
- // Otherwise we will break backwards compatibility
- // and e.g. 0.4.4 runtime will not work with 0.4.3 SDK.
-
- // Be sure to check that the very last one read properly
- // since HMD Info truncation should be caught here.
- return true;
+ // The result of the final serialize should be returned to the caller.
+ return result;
}
// Prefix key names with this to pass through to server
static const char* BypassPrefix = "server:";
static const char* KeyNames[][NetSessionCommon::ENumTypes] = {
- /* EGetStringValue */ { "CameraSerial", "CameraUUID", 0 },
- /* EGetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 },
- /* EGetIntValue */ { 0 },
- /* EGetNumberValue */{ "CenterPupilDepth", "LoggingMask", 0 },
- /* EGetNumberValues */{ "NeckModelVector3f", 0 },
- /* ESetStringValue */ { 0 },
- /* ESetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 },
- /* ESetIntValue */ { 0 },
- /* ESetNumberValue */{ "CenterPupilDepth", "LoggingMask", 0 },
- /* ESetNumberValues */{ "NeckModelVector3f", 0 },
+ /* EGetStringValue */ { "CameraSerial", "CameraUUID", 0 },
+ /* EGetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 },
+ /* EGetIntValue */ { 0 },
+ /* EGetNumberValue */ { "CenterPupilDepth", "LoggingMask", 0 },
+ /* EGetNumberValues */ { "NeckModelVector3f", 0 },
+ /* ESetStringValue */ { 0 },
+ /* ESetBoolValue */ { "ReleaseDK2Sensors", "ReleaseLegacySensors", 0 },
+ /* ESetIntValue */ { 0 },
+ /* ESetNumberValue */ { "CenterPupilDepth", "LoggingMask", 0 },
+ /* ESetNumberValues */ { "NeckModelVector3f", 0 },
};
bool IsInStringArray(const char* a[], const char* key)