aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Service/Service_NetClient.cpp
diff options
context:
space:
mode:
authorBrad Davis <[email protected]>2014-09-04 14:32:18 -0700
committerBrad Davis <[email protected]>2014-09-04 14:32:18 -0700
commit32dc394487af8e4fb1b43fb852f1d5448eaf7f31 (patch)
treebe53f49e96e8e2bba1dada04197cf508b60b4eaf /LibOVR/Src/Service/Service_NetClient.cpp
parent85d370840fa4d49a63331a203460fe763288d417 (diff)
Updating to windows 0.4.2
Diffstat (limited to 'LibOVR/Src/Service/Service_NetClient.cpp')
-rw-r--r--LibOVR/Src/Service/Service_NetClient.cpp257
1 files changed, 204 insertions, 53 deletions
diff --git a/LibOVR/Src/Service/Service_NetClient.cpp b/LibOVR/Src/Service/Service_NetClient.cpp
index b0fa464..8c3e232 100644
--- a/LibOVR/Src/Service/Service_NetClient.cpp
+++ b/LibOVR/Src/Service/Service_NetClient.cpp
@@ -27,6 +27,9 @@ limitations under the License.
#include "Service_NetClient.h"
#include "../Net/OVR_MessageIDTypes.h"
+#ifdef OVR_OS_MAC
+#define GetCurrentProcessId getpid
+#endif
OVR_DEFINE_SINGLETON(OVR::Service::NetClient);
namespace OVR { namespace Service {
@@ -37,7 +40,9 @@ using namespace OVR::Net;
//// NetClient
NetClient::NetClient() :
- LatencyTesterAvailable(false)
+ LatencyTesterAvailable(false),
+ HMDCount(0),
+ EdgeTriggeredHMDCount(false)
{
GetSession()->AddSessionListener(this);
@@ -69,10 +74,14 @@ int NetClient::Run()
while (!Terminated)
{
- if (GetSession()->GetActiveSocketsCount()==0)
- Thread::MSleep(10);
+ // Note: There is no watchdog here because the watchdog is part of the private code
GetSession()->Poll(false);
+
+ if (GetSession()->GetActiveSocketsCount() == 0)
+ {
+ Thread::MSleep(10);
+ }
}
return 0;
@@ -82,7 +91,6 @@ void NetClient::OnReceive(ReceivePayload* pPayload, ListenerReceiveResult* lrrOu
{
OVR_UNUSED(lrrOut);
OVR_UNUSED(pPayload);
-
}
void NetClient::OnDisconnected(Connection* conn)
@@ -90,13 +98,8 @@ void NetClient::OnDisconnected(Connection* conn)
OVR_UNUSED(conn);
OVR_DEBUG_LOG(("[NetClient] Disconnected"));
-}
-void NetClient::OnConnectionAttemptFailed(Net::Connection* conn)
-{
- OVR_UNUSED(conn);
-
- OVR_DEBUG_LOG(("[NetClient] OnConnectionAttemptFailed"));
+ EdgeTriggeredHMDCount = false;
}
void NetClient::OnConnected(Connection* conn)
@@ -106,9 +109,11 @@ void NetClient::OnConnected(Connection* conn)
OVR_DEBUG_LOG(("[NetClient] Connected to a server running version %d.%d.%d (my version=%d.%d.%d)",
conn->RemoteMajorVersion, conn->RemoteMinorVersion, conn->RemotePatchVersion,
RPCVersion_Major, RPCVersion_Minor, RPCVersion_Patch));
+
+ EdgeTriggeredHMDCount = false;
}
-bool NetClient::Connect()
+bool NetClient::Connect(bool blocking)
{
// Set up bind parameters
OVR::Net::BerkleyBindParameters bbp;
@@ -118,7 +123,12 @@ bool NetClient::Connect()
sa.Set("::1", VRServicePort, SOCK_STREAM);
// Attempt to connect
- return GetSession()->ConnectPTCP(&bbp, &sa, true) == Net::SessionResult_OK;
+ OVR::Net::SessionResult result = GetSession()->ConnectPTCP(&bbp, &sa, blocking);
+
+ // Already connected counts as success too
+ return result == Net::SessionResult_OK ||
+ result == Net::SessionResult_AlreadyConnected ||
+ result == Net::SessionResult_ConnectInProgress;
}
void NetClient::Disconnect()
@@ -126,7 +136,7 @@ void NetClient::Disconnect()
GetSession()->Shutdown();
}
-bool NetClient::IsConnected(bool attemptReconnect)
+bool NetClient::IsConnected(bool attemptReconnect, bool blockOnReconnect)
{
// If it was able to connect,
if (GetSession()->GetConnectionCount() > 0)
@@ -136,7 +146,7 @@ bool NetClient::IsConnected(bool attemptReconnect)
else if (attemptReconnect)
{
// Attempt to connect here
- Connect();
+ Connect(blockOnReconnect);
// If it connected,
if (GetSession()->GetConnectionCount() > 0)
@@ -176,8 +186,10 @@ bool NetClient::GetRemoteProtocolVersion(int& major, int& minor, int& patch)
const char* NetClient::GetStringValue(VirtualHmdId hmd, const char* key, const char* default_val)
{
- if (!IsConnected(true))
+ if (!IsConnected(true, true))
+ {
return "";
+ }
ProfileGetValue1_Str = default_val;
@@ -197,8 +209,10 @@ const char* NetClient::GetStringValue(VirtualHmdId hmd, const char* key, const c
}
bool NetClient::GetBoolValue(VirtualHmdId hmd, const char* key, bool default_val)
{
- if (!IsConnected(true))
+ if (!IsConnected(true, true))
+ {
return default_val;
+ }
OVR::Net::BitStream bsOut, returnData;
bsOut.Write(hmd);
@@ -217,8 +231,10 @@ bool NetClient::GetBoolValue(VirtualHmdId hmd, const char* key, bool default_val
}
int NetClient::GetIntValue(VirtualHmdId hmd, const char* key, int default_val)
{
- if (!IsConnected(true))
+ if (!IsConnected(true, true))
+ {
return default_val;
+ }
OVR::Net::BitStream bsOut, returnData;
bsOut.Write(hmd);
@@ -237,8 +253,10 @@ int NetClient::GetIntValue(VirtualHmdId hmd, const char* key, int default_val)
}
double NetClient::GetNumberValue(VirtualHmdId hmd, const char* key, double default_val)
{
- if (!IsConnected(true))
+ if (!IsConnected(true, true))
+ {
return default_val;
+ }
OVR::Net::BitStream bsOut, returnData;
bsOut.Write(hmd);
@@ -254,8 +272,10 @@ double NetClient::GetNumberValue(VirtualHmdId hmd, const char* key, double defau
}
int NetClient::GetNumberValues(VirtualHmdId hmd, const char* key, double* values, int num_vals)
{
- if (!IsConnected(true))
+ if (!IsConnected(true, true))
+ {
return 0;
+ }
OVR::Net::BitStream bsOut, returnData;
bsOut.Write(hmd);
@@ -294,10 +314,13 @@ int NetClient::GetNumberValues(VirtualHmdId hmd, const char* key, double* values
return out;
}
-void NetClient::SetStringValue(VirtualHmdId hmd, const char* key, const char* val)
+
+bool NetClient::SetStringValue(VirtualHmdId hmd, const char* key, const char* val)
{
- if (!IsConnected(true))
- return;
+ if (!IsConnected(true, true))
+ {
+ return false;
+ }
OVR::Net::BitStream bsOut;
bsOut.Write(hmd);
@@ -308,12 +331,18 @@ void NetClient::SetStringValue(VirtualHmdId hmd, const char* key, const char* va
if (!GetRPC1()->Signal("SetStringValue_1", &bsOut, GetSession()->GetConnectionAtIndex(0)))
{
OVR_ASSERT(false);
+ return false;
}
+
+ return true;
}
-void NetClient::SetBoolValue(VirtualHmdId hmd, const char* key, bool val)
+
+bool NetClient::SetBoolValue(VirtualHmdId hmd, const char* key, bool val)
{
- if (!IsConnected(true))
- return;
+ if (!IsConnected(true, true))
+ {
+ return false;
+ }
OVR::Net::BitStream bsOut;
bsOut.Write(hmd);
@@ -325,12 +354,18 @@ void NetClient::SetBoolValue(VirtualHmdId hmd, const char* key, bool val)
if (!GetRPC1()->Signal("SetBoolValue_1", &bsOut, GetSession()->GetConnectionAtIndex(0)))
{
OVR_ASSERT(false);
+ return false;
}
+
+ return true;
}
-void NetClient::SetIntValue(VirtualHmdId hmd, const char* key, int val)
+
+bool NetClient::SetIntValue(VirtualHmdId hmd, const char* key, int val)
{
- if (!IsConnected(true))
- return;
+ if (!IsConnected(true, true))
+ {
+ return false;
+ }
OVR::Net::BitStream bsOut;
bsOut.Write(hmd);
@@ -342,12 +377,18 @@ void NetClient::SetIntValue(VirtualHmdId hmd, const char* key, int val)
if (!GetRPC1()->Signal("SetIntValue_1", &bsOut, GetSession()->GetConnectionAtIndex(0)))
{
OVR_ASSERT(false);
+ return false;
}
+
+ return true;
}
-void NetClient::SetNumberValue(VirtualHmdId hmd, const char* key, double val)
+
+bool NetClient::SetNumberValue(VirtualHmdId hmd, const char* key, double val)
{
- if (!IsConnected(true))
- return;
+ if (!IsConnected(true, true))
+ {
+ return false;
+ }
OVR::Net::BitStream bsOut;
bsOut.Write(hmd);
@@ -358,13 +399,17 @@ void NetClient::SetNumberValue(VirtualHmdId hmd, const char* key, double val)
if (!GetRPC1()->Signal("SetNumberValue_1", &bsOut, GetSession()->GetConnectionAtIndex(0)))
{
OVR_ASSERT(false);
+ return false;
}
+
+ return true;
}
-void NetClient::SetNumberValues(VirtualHmdId hmd, const char* key, const double* vals, int num_vals)
+
+bool NetClient::SetNumberValues(VirtualHmdId hmd, const char* key, const double* vals, int num_vals)
{
- if (!IsConnected(true))
+ if (!IsConnected(true, true))
{
- return;
+ return false;
}
OVR::Net::BitStream bsOut;
@@ -382,16 +427,28 @@ void NetClient::SetNumberValues(VirtualHmdId hmd, const char* key, const double*
if (!GetRPC1()->Signal("SetNumberValues_1", &bsOut, GetSession()->GetConnectionAtIndex(0)))
{
OVR_ASSERT(false);
+ return false;
}
+
+ return true;
}
int NetClient::Hmd_Detect()
{
- if (!IsConnected(true))
+ if (!IsConnected(true, false))
{
return 0;
}
+ // If using edge-triggered HMD counting,
+ if (EdgeTriggeredHMDCount)
+ {
+ // Return the last update from the server
+ return HMDCount;
+ }
+
+ // Otherwise: We need to ask the first time
+
OVR::Net::BitStream bsOut, returnData;
if (!GetRPC1()->CallBlocking("Hmd_Detect_1", &bsOut, GetSession()->GetConnectionAtIndex(0), &returnData))
@@ -405,12 +462,14 @@ int NetClient::Hmd_Detect()
{
OVR_ASSERT(false);
}
+ HMDCount = out;
+ EdgeTriggeredHMDCount = true;
return out;
}
bool NetClient::Hmd_Create(int index, HMDNetworkInfo* netInfo)
{
- if (!IsConnected(true))
+ if (!IsConnected(true, true))
{
return false;
}
@@ -420,9 +479,9 @@ bool NetClient::Hmd_Create(int index, HMDNetworkInfo* netInfo)
int32_t w = (int32_t)index;
bsOut.Write(w);
-#ifdef OVR_OS_WIN32
+#if defined(OVR_OS_WIN32) || defined(OVR_OS_MAC)
// Need the Pid for driver mode
- DWORD pid = GetCurrentProcessId();
+ pid_t pid = GetCurrentProcessId();
bsOut.Write(pid);
#endif
@@ -435,10 +494,78 @@ bool NetClient::Hmd_Create(int index, HMDNetworkInfo* netInfo)
return netInfo->Deserialize(&returnData);
}
-void NetClient::Hmd_AttachToWindow(VirtualHmdId hmd, void* hWindow)
+bool NetClient::GetDriverMode(bool& driverInstalled, bool& compatMode, bool& hideDK1Mode)
{
- if (!IsConnected())
- return;
+ if (!IsConnected(true, true))
+ {
+ return false;
+ }
+
+ OVR::Net::BitStream bsOut, returnData;
+
+ bsOut.Write(InvalidVirtualHmdId);
+
+ if (!GetRPC1()->CallBlocking("GetDriverMode_1", &bsOut, GetSession()->GetConnectionAtIndex(0), &returnData))
+ {
+ OVR_ASSERT(false);
+ return false;
+ }
+
+ int32_t w_driverInstalled = 0;
+ int32_t w_compatMode = 0;
+ int32_t w_hideDK1Mode = 0;
+ returnData.Read(w_driverInstalled);
+ returnData.Read(w_compatMode);
+ if (!returnData.Read(w_hideDK1Mode))
+ {
+ return false;
+ }
+
+ driverInstalled = w_driverInstalled != 0;
+ compatMode = w_compatMode != 0;
+ hideDK1Mode = w_hideDK1Mode != 0;
+ return true;
+}
+
+bool NetClient::SetDriverMode(bool compatMode, bool hideDK1Mode)
+{
+ if (!IsConnected(true, true))
+ {
+ return false;
+ }
+
+ OVR::Net::BitStream bsOut, returnData;
+
+ bsOut.Write(InvalidVirtualHmdId);
+
+ int32_t w_compatMode, w_hideDK1Mode;
+ w_compatMode = compatMode ? 1 : 0;
+ w_hideDK1Mode = hideDK1Mode ? 1 : 0;
+ bsOut.Write(w_compatMode);
+ bsOut.Write(w_hideDK1Mode);
+
+ if (!GetRPC1()->CallBlocking("SetDriverMode_1", &bsOut, GetSession()->GetConnectionAtIndex(0), &returnData))
+ {
+ OVR_ASSERT(false);
+ return false;
+ }
+
+ int32_t out = 0;
+ if (!returnData.Read(out))
+ {
+ OVR_ASSERT(false);
+ return false;
+ }
+
+ return out != 0;
+}
+
+bool NetClient::Hmd_AttachToWindow(VirtualHmdId hmd, void* hWindow)
+{
+ if (!IsConnected(false, false))
+ {
+ return false;
+ }
OVR::Net::BitStream bsOut;
bsOut.Write(hmd);
@@ -449,13 +576,18 @@ void NetClient::Hmd_AttachToWindow(VirtualHmdId hmd, void* hWindow)
if (!GetRPC1()->CallBlocking("Hmd_AttachToWindow_1", &bsOut, GetSession()->GetConnectionAtIndex(0)))
{
OVR_ASSERT(false);
+ return false;
}
+
+ return true;
}
void NetClient::Hmd_Release(VirtualHmdId hmd)
{
- if (!IsConnected())
- return;
+ if (!IsConnected(false, false))
+ {
+ return;
+ }
OVR::Net::BitStream bsOut;
bsOut.Write(hmd);
@@ -465,10 +597,15 @@ void NetClient::Hmd_Release(VirtualHmdId hmd)
}
}
+void NetClient::SetLastError(String str)
+{
+ Hmd_GetLastError_Str = str;
+}
+
// Last string is cached locally.
const char* NetClient::Hmd_GetLastError(VirtualHmdId hmd)
{
- if (!IsConnected())
+ if (hmd == InvalidVirtualHmdId || !IsConnected(false, false))
{
return Hmd_GetLastError_Str.ToCStr();
}
@@ -492,7 +629,7 @@ const char* NetClient::Hmd_GetLastError(VirtualHmdId hmd)
// The actual descriptor is a par
bool NetClient::Hmd_GetHmdInfo(VirtualHmdId hmd, HMDInfo* hmdInfo)
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return false;
}
@@ -512,7 +649,7 @@ bool NetClient::Hmd_GetHmdInfo(VirtualHmdId hmd, HMDInfo* hmdInfo)
//-------------------------------------------------------------------------------------
unsigned int NetClient::Hmd_GetEnabledCaps(VirtualHmdId hmd)
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return 0;
}
@@ -536,7 +673,7 @@ unsigned int NetClient::Hmd_GetEnabledCaps(VirtualHmdId hmd)
// Returns new caps after modification
unsigned int NetClient::Hmd_SetEnabledCaps(VirtualHmdId hmd, unsigned int hmdCaps)
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return 0;
}
@@ -567,7 +704,7 @@ unsigned int NetClient::Hmd_SetEnabledCaps(VirtualHmdId hmd, unsigned int hmdCap
bool NetClient::Hmd_ConfigureTracking(VirtualHmdId hmd, unsigned supportedCaps, unsigned requiredCaps)
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return false;
}
@@ -598,7 +735,7 @@ bool NetClient::Hmd_ConfigureTracking(VirtualHmdId hmd, unsigned supportedCaps,
void NetClient::Hmd_ResetTracking(VirtualHmdId hmd)
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return;
}
@@ -614,7 +751,7 @@ void NetClient::Hmd_ResetTracking(VirtualHmdId hmd)
bool NetClient::LatencyUtil_ProcessInputs(double startTestSeconds, unsigned char rgbColorOut[3])
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return false;
}
@@ -648,7 +785,7 @@ bool NetClient::LatencyUtil_ProcessInputs(double startTestSeconds, unsigned char
const char* NetClient::LatencyUtil_GetResultsString()
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return NULL;
}
@@ -670,7 +807,7 @@ const char* NetClient::LatencyUtil_GetResultsString()
bool NetClient::ShutdownServer()
{
- if (!IsConnected())
+ if (!IsConnected(false, false))
{
return false;
}
@@ -692,7 +829,7 @@ void NetClient::registerRPC()
// Register RPC functions:
RPC_REGISTER_SLOT(InitialServerStateScope, InitialServerState_1);
RPC_REGISTER_SLOT(LatencyTesterAvailableScope, LatencyTesterAvailable_1);
-
+ RPC_REGISTER_SLOT(HMDCountUpdateScope, HMDCountUpdate_1);
}
void NetClient::InitialServerState_1(BitStream* userData, ReceivePayload* pPayload)
@@ -714,6 +851,20 @@ void NetClient::LatencyTesterAvailable_1(BitStream* userData, ReceivePayload* pP
LatencyTesterAvailable = (b != 0);
}
+void NetClient::HMDCountUpdate_1(BitStream* userData, ReceivePayload* pPayload)
+{
+ OVR_UNUSED(pPayload);
+
+ int32_t hmdCount = 0;
+ if (!userData->Read(hmdCount))
+ {
+ OVR_ASSERT(false);
+ return;
+ }
+
+ HMDCount = hmdCount;
+ EdgeTriggeredHMDCount = true;
+}
}} // namespace OVR::Service