nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: Filename : Service_NetSessionCommon.h nuclear@0: Content : Shared networking for service nuclear@0: Created : June 12, 2014 nuclear@0: Authors : Kevin Jenkins, Chris Taylor nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_Service_NetSessionCommon_h nuclear@0: #define OVR_Service_NetSessionCommon_h nuclear@0: nuclear@0: #include "../OVR_CAPI.h" nuclear@0: #include "../Net/OVR_RPC1.h" nuclear@0: #include "../Kernel/OVR_Threads.h" nuclear@0: #include "../Net/OVR_BitStream.h" nuclear@0: #include "../Kernel/OVR_System.h" nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: class HMDInfo; nuclear@0: nuclear@0: namespace Service { nuclear@0: nuclear@0: nuclear@0: //----------------------------------------------------------------------------- nuclear@0: // VirtualHmdId nuclear@0: nuclear@0: // This is an identifier that is unique to each VirtualHmd object on the server nuclear@0: // side. The client side uses this to opaquely reference those objects. nuclear@0: nuclear@0: typedef int32_t VirtualHmdId; nuclear@0: static const int32_t InvalidVirtualHmdId = -1; nuclear@0: nuclear@0: // Localhost-bound TCP port that the service listens on for VR apps nuclear@0: static const int VRServicePort = 30322; // 0x7672 = "vr" little-endian nuclear@0: nuclear@0: // HMDInfo section related to networking nuclear@0: struct HMDNetworkInfo nuclear@0: { nuclear@0: HMDNetworkInfo() : nuclear@0: NetId(InvalidVirtualHmdId) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: // Network identifier for HMD nuclear@0: VirtualHmdId NetId; nuclear@0: nuclear@0: // Name of the shared memory object nuclear@0: String SharedMemoryName; nuclear@0: nuclear@0: void Serialize(Net::BitStream* bs) nuclear@0: { nuclear@0: bs->Write(NetId); nuclear@0: bs->Write(SharedMemoryName); nuclear@0: } nuclear@0: bool Deserialize(Net::BitStream* bs) nuclear@0: { nuclear@0: bs->Read(NetId); nuclear@0: return bs->Read(SharedMemoryName); nuclear@0: } nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: //------------------------------------------------------------------------------------- nuclear@0: // ***** NetSessionCommon nuclear@0: nuclear@0: // Common part networking session/RPC implementation shared between client and server. nuclear@0: nuclear@0: class NetSessionCommon : public Thread nuclear@0: { nuclear@0: protected: nuclear@0: virtual void onSystemDestroy(); nuclear@0: virtual void onThreadDestroy(); nuclear@0: nuclear@0: public: nuclear@0: NetSessionCommon(); nuclear@0: virtual ~NetSessionCommon(); nuclear@0: nuclear@0: Net::Plugins::RPC1* GetRPC1() const nuclear@0: { nuclear@0: return pRPC; nuclear@0: } nuclear@0: Net::Session* GetSession() const nuclear@0: { nuclear@0: return pSession; nuclear@0: } nuclear@0: nuclear@0: static void SerializeHMDInfo(Net::BitStream* bitStream, HMDInfo* hmdInfo); nuclear@0: static bool DeserializeHMDInfo(Net::BitStream* bitStream, HMDInfo* hmdInfo); nuclear@0: nuclear@0: public: nuclear@0: // Getter/setter tools nuclear@0: enum EGetterSetters nuclear@0: { nuclear@0: // Note: If this enumeration changes, then the Servce_NetSessionCommon.cpp nuclear@0: // IsServiceProperty() function should be updated. nuclear@0: nuclear@0: EGetStringValue, nuclear@0: EGetBoolValue, nuclear@0: EGetIntValue, nuclear@0: EGetNumberValue, nuclear@0: EGetNumberValues, nuclear@0: ESetStringValue, nuclear@0: ESetBoolValue, nuclear@0: ESetIntValue, nuclear@0: ESetNumberValue, nuclear@0: ESetNumberValues, nuclear@0: nuclear@0: ENumTypes nuclear@0: }; nuclear@0: nuclear@0: static const char* FilterKeyPrefix(const char* key); nuclear@0: static bool IsServiceProperty(EGetterSetters e, const char* key); nuclear@0: nuclear@0: protected: nuclear@0: bool Terminated; // Thread termination flag nuclear@0: Net::Session* pSession; // Networking session nuclear@0: Net::Plugins::RPC1* pRPC; // Remote procedure calls object nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: }} // namespace OVR::Service nuclear@0: nuclear@0: #endif // OVR_Service_NetSessionCommon_h