MCPcopy Create free account
hub / github.com/PhoneVR-Developers/PhoneVR / Init

Method Init

code/windows/PhoneVR/PhoneVR/driver.cpp:394–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392
393 public:
394 virtual EVRInitError Init(IVRDriverContext *drvCtx) override {
395 PVR_DB_I("[ServerProvider::Init] Initializing server");
396
397 bool hmdPaired = false;
398 auto timeout = (seconds) (PVRProp<int>({CONN_TIMEOUT}));
399
400 TimeBomb hmdBomb(timeout);
401
402 // any exception is handled by the called method
403 // Start Listening for any incoming connection on CONN_PORT(def:33333)
404 PVRStartConnectionListener([&](auto ip, auto msgType) {
405 if (msgType == PVR_MSG::PAIR_HMD && !hmd) {
406 // VR_INIT_SERVER_DRIVER_CONTEXT(drvCtx);
407
408 // #define VR_INIT_SERVER_DRIVER_CONTEXT( pContext )
409 // {
410 vr::EVRInitError eError = vr::InitServerDriverContext(drvCtx);
411 PVR_DB_I("[ServerProvider::Init::PVRStartConnectionListener] recvd PAIR_HMD Msg "
412 "from ip: " +
413 to_string(ip));
414 if (eError == vr::VRInitError_None) {
415 hmd = new HMD(ip);
416 // red = new Redirect();
417 hmdPaired =
418 VRServerDriverHost()->TrackedDeviceAdded("0", TrackedDeviceClass_HMD, hmd);
419 // hmdPaired = VRServerDriverHost()->TrackedDeviceAdded("1",
420 // TrackedDeviceClass_DisplayRedirect, red);
421 if (!hmdPaired) {
422 PVR_DB_I("[ServerProvider::Init::PVRStartConnectionListener] Error: could "
423 "not activate HMD");
424 } else
425 hmdBomb.defuse();
426 } else {
427 PVR_DB_I("[ServerProvider::Init::PVRStartConnectionListener] Error: could not "
428 "InitServerDriverContext");
429 }
430 } else if (msgType == PVR_MSG::PAIR_PHONE_CTRL) {
431 if (find(IPs.begin(), IPs.end(), ip) == IPs.end()) {
432 IPs.insert(ip);
433 PVR_DB_I("[ServerProvider::Init::PVRStartConnectionListener] Recvd "
434 "PAIR_PHONE_CTRL from ip: " +
435 to_string(ip));
436 // init controller
437 // VRServerDriverHost()->TrackedDeviceAdded(to_string(ctrls.size()).c_str(),
438 // TrackedDeviceClass_Controller, ctrl); ctrls.insert(ctrl)
439 }
440 }
441 });
442
443 hmdBomb.ignite(false);
444
445 if (!hmdPaired) {
446 PVRStopConnectionListener();
447 PVR_DB_I("[ServerProvider::Init] Pairing failed! Cause: timeout ... for " +
448 to_string(timeout.count()) + "secs");
449 return VRInitError_Init_HmdNotFound;
450 }
451

Callers

nothing calls this directly

Calls 6

InitServerDriverContextFunction · 0.85
to_stringFunction · 0.85
defuseMethod · 0.80
igniteMethod · 0.80

Tested by

no test coverage detected