ovr_sdk

annotate LibOVR/Src/Service/Service_NetSessionCommon.h @ 3:f12a8f74fe1f

added the Xcode project
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 21 Jan 2015 11:37:50 +0200
parents
children
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 Filename : Service_NetSessionCommon.h
nuclear@0 4 Content : Shared networking for service
nuclear@0 5 Created : June 12, 2014
nuclear@0 6 Authors : Kevin Jenkins, Chris Taylor
nuclear@0 7
nuclear@0 8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 9
nuclear@0 10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 11 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 12 which is provided at the time of installation or download, or which
nuclear@0 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 14
nuclear@0 15 You may obtain a copy of the License at
nuclear@0 16
nuclear@0 17 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 18
nuclear@0 19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 20 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 22 See the License for the specific language governing permissions and
nuclear@0 23 limitations under the License.
nuclear@0 24
nuclear@0 25 ************************************************************************************/
nuclear@0 26
nuclear@0 27 #ifndef OVR_Service_NetSessionCommon_h
nuclear@0 28 #define OVR_Service_NetSessionCommon_h
nuclear@0 29
nuclear@0 30 #include "../OVR_CAPI.h"
nuclear@0 31 #include "../Net/OVR_RPC1.h"
nuclear@0 32 #include "../Kernel/OVR_Threads.h"
nuclear@0 33 #include "../Net/OVR_BitStream.h"
nuclear@0 34 #include "../Kernel/OVR_System.h"
nuclear@0 35
nuclear@0 36 namespace OVR {
nuclear@0 37
nuclear@0 38 class HMDInfo;
nuclear@0 39
nuclear@0 40 namespace Service {
nuclear@0 41
nuclear@0 42
nuclear@0 43 //-----------------------------------------------------------------------------
nuclear@0 44 // VirtualHmdId
nuclear@0 45
nuclear@0 46 // This is an identifier that is unique to each VirtualHmd object on the server
nuclear@0 47 // side. The client side uses this to opaquely reference those objects.
nuclear@0 48
nuclear@0 49 typedef int32_t VirtualHmdId;
nuclear@0 50 static const int32_t InvalidVirtualHmdId = -1;
nuclear@0 51
nuclear@0 52 // Localhost-bound TCP port that the service listens on for VR apps
nuclear@0 53 static const int VRServicePort = 30322; // 0x7672 = "vr" little-endian
nuclear@0 54
nuclear@0 55 // HMDInfo section related to networking
nuclear@0 56 struct HMDNetworkInfo
nuclear@0 57 {
nuclear@0 58 HMDNetworkInfo() :
nuclear@0 59 NetId(InvalidVirtualHmdId)
nuclear@0 60 {
nuclear@0 61 }
nuclear@0 62
nuclear@0 63 // Network identifier for HMD
nuclear@0 64 VirtualHmdId NetId;
nuclear@0 65
nuclear@0 66 // Name of the shared memory object
nuclear@0 67 String SharedMemoryName;
nuclear@0 68
nuclear@0 69 void Serialize(Net::BitStream* bs)
nuclear@0 70 {
nuclear@0 71 bs->Write(NetId);
nuclear@0 72 bs->Write(SharedMemoryName);
nuclear@0 73 }
nuclear@0 74 bool Deserialize(Net::BitStream* bs)
nuclear@0 75 {
nuclear@0 76 bs->Read(NetId);
nuclear@0 77 return bs->Read(SharedMemoryName);
nuclear@0 78 }
nuclear@0 79 };
nuclear@0 80
nuclear@0 81
nuclear@0 82 //-------------------------------------------------------------------------------------
nuclear@0 83 // ***** NetSessionCommon
nuclear@0 84
nuclear@0 85 // Common part networking session/RPC implementation shared between client and server.
nuclear@0 86
nuclear@0 87 class NetSessionCommon : public Thread
nuclear@0 88 {
nuclear@0 89 protected:
nuclear@0 90 virtual void onSystemDestroy();
nuclear@0 91 virtual void onThreadDestroy();
nuclear@0 92
nuclear@0 93 public:
nuclear@0 94 NetSessionCommon();
nuclear@0 95 virtual ~NetSessionCommon();
nuclear@0 96
nuclear@0 97 Net::Plugins::RPC1* GetRPC1() const
nuclear@0 98 {
nuclear@0 99 return pRPC;
nuclear@0 100 }
nuclear@0 101 Net::Session* GetSession() const
nuclear@0 102 {
nuclear@0 103 return pSession;
nuclear@0 104 }
nuclear@0 105
nuclear@0 106 static void SerializeHMDInfo(Net::BitStream* bitStream, HMDInfo* hmdInfo);
nuclear@0 107 static bool DeserializeHMDInfo(Net::BitStream* bitStream, HMDInfo* hmdInfo);
nuclear@0 108
nuclear@0 109 public:
nuclear@0 110 // Getter/setter tools
nuclear@0 111 enum EGetterSetters
nuclear@0 112 {
nuclear@0 113 // Note: If this enumeration changes, then the Servce_NetSessionCommon.cpp
nuclear@0 114 // IsServiceProperty() function should be updated.
nuclear@0 115
nuclear@0 116 EGetStringValue,
nuclear@0 117 EGetBoolValue,
nuclear@0 118 EGetIntValue,
nuclear@0 119 EGetNumberValue,
nuclear@0 120 EGetNumberValues,
nuclear@0 121 ESetStringValue,
nuclear@0 122 ESetBoolValue,
nuclear@0 123 ESetIntValue,
nuclear@0 124 ESetNumberValue,
nuclear@0 125 ESetNumberValues,
nuclear@0 126
nuclear@0 127 ENumTypes
nuclear@0 128 };
nuclear@0 129
nuclear@0 130 static const char* FilterKeyPrefix(const char* key);
nuclear@0 131 static bool IsServiceProperty(EGetterSetters e, const char* key);
nuclear@0 132
nuclear@0 133 protected:
nuclear@0 134 bool Terminated; // Thread termination flag
nuclear@0 135 Net::Session* pSession; // Networking session
nuclear@0 136 Net::Plugins::RPC1* pRPC; // Remote procedure calls object
nuclear@0 137 };
nuclear@0 138
nuclear@0 139
nuclear@0 140 }} // namespace OVR::Service
nuclear@0 141
nuclear@0 142 #endif // OVR_Service_NetSessionCommon_h