ovr_sdk

view LibOVR/Src/Service/Service_NetSessionCommon.h @ 0:1b39a1b46319

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