ovr_sdk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Service/Service_NetSessionCommon.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,142 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   Service_NetSessionCommon.h
     1.7 +Content     :   Shared networking for service
     1.8 +Created     :   June 12, 2014
     1.9 +Authors     :   Kevin Jenkins, Chris Taylor
    1.10 +
    1.11 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.12 +
    1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.15 +which is provided at the time of installation or download, or which 
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +You may obtain a copy of the License at
    1.19 +
    1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.21 +
    1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.23 +distributed under the License is distributed on an "AS IS" BASIS,
    1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.25 +See the License for the specific language governing permissions and
    1.26 +limitations under the License.
    1.27 +
    1.28 +************************************************************************************/
    1.29 +
    1.30 +#ifndef OVR_Service_NetSessionCommon_h
    1.31 +#define OVR_Service_NetSessionCommon_h
    1.32 +
    1.33 +#include "../OVR_CAPI.h"
    1.34 +#include "../Net/OVR_RPC1.h"
    1.35 +#include "../Kernel/OVR_Threads.h"
    1.36 +#include "../Net/OVR_BitStream.h"
    1.37 +#include "../Kernel/OVR_System.h"
    1.38 +
    1.39 +namespace OVR {
    1.40 +
    1.41 +class HMDInfo;
    1.42 +
    1.43 +namespace Service {
    1.44 +
    1.45 +
    1.46 +//-----------------------------------------------------------------------------
    1.47 +// VirtualHmdId
    1.48 +
    1.49 +// This is an identifier that is unique to each VirtualHmd object on the server
    1.50 +// side.  The client side uses this to opaquely reference those objects.
    1.51 +
    1.52 +typedef int32_t VirtualHmdId;
    1.53 +static const int32_t InvalidVirtualHmdId = -1;
    1.54 +
    1.55 +// Localhost-bound TCP port that the service listens on for VR apps
    1.56 +static const int VRServicePort = 30322; // 0x7672 = "vr" little-endian
    1.57 +
    1.58 +// HMDInfo section related to networking
    1.59 +struct HMDNetworkInfo
    1.60 +{
    1.61 +	HMDNetworkInfo() :
    1.62 +		NetId(InvalidVirtualHmdId)
    1.63 +	{
    1.64 +	}
    1.65 +
    1.66 +	// Network identifier for HMD
    1.67 +	VirtualHmdId NetId;
    1.68 +
    1.69 +	// Name of the shared memory object
    1.70 +	String       SharedMemoryName;
    1.71 +
    1.72 +	void Serialize(Net::BitStream* bs)
    1.73 +	{
    1.74 +		bs->Write(NetId);
    1.75 +		bs->Write(SharedMemoryName);
    1.76 +	}
    1.77 +	bool Deserialize(Net::BitStream* bs)
    1.78 +	{
    1.79 +		bs->Read(NetId);
    1.80 +		return bs->Read(SharedMemoryName);
    1.81 +	}
    1.82 +};
    1.83 +
    1.84 +
    1.85 +//-------------------------------------------------------------------------------------
    1.86 +// ***** NetSessionCommon
    1.87 +
    1.88 +// Common part networking session/RPC implementation shared between client and server.
    1.89 +
    1.90 +class NetSessionCommon : public Thread
    1.91 +{
    1.92 +protected:
    1.93 +    virtual void onSystemDestroy();
    1.94 +    virtual void onThreadDestroy();
    1.95 +
    1.96 +public:
    1.97 +    NetSessionCommon();
    1.98 +    virtual ~NetSessionCommon();
    1.99 +
   1.100 +	Net::Plugins::RPC1* GetRPC1() const
   1.101 +    {
   1.102 +        return pRPC;
   1.103 +    }
   1.104 +	Net::Session* GetSession() const
   1.105 +    {
   1.106 +        return pSession;
   1.107 +    }
   1.108 +
   1.109 +	static void SerializeHMDInfo(Net::BitStream* bitStream, HMDInfo* hmdInfo);
   1.110 +	static bool DeserializeHMDInfo(Net::BitStream* bitStream, HMDInfo* hmdInfo);
   1.111 +
   1.112 +public:
   1.113 +    // Getter/setter tools
   1.114 +    enum EGetterSetters
   1.115 +    {
   1.116 +        // Note: If this enumeration changes, then the Servce_NetSessionCommon.cpp
   1.117 +        // IsServiceProperty() function should be updated.
   1.118 +
   1.119 +        EGetStringValue,
   1.120 +        EGetBoolValue,
   1.121 +        EGetIntValue,
   1.122 +        EGetNumberValue,
   1.123 +        EGetNumberValues,
   1.124 +        ESetStringValue,
   1.125 +        ESetBoolValue,
   1.126 +        ESetIntValue,
   1.127 +        ESetNumberValue,
   1.128 +        ESetNumberValues,
   1.129 +
   1.130 +        ENumTypes
   1.131 +    };
   1.132 +
   1.133 +    static const char* FilterKeyPrefix(const char* key);
   1.134 +    static bool IsServiceProperty(EGetterSetters e, const char* key);
   1.135 +
   1.136 +protected:
   1.137 +    bool                Terminated; // Thread termination flag
   1.138 +    Net::Session*       pSession;   // Networking session
   1.139 +	Net::Plugins::RPC1* pRPC;       // Remote procedure calls object
   1.140 +};
   1.141 +
   1.142 +
   1.143 +}} // namespace OVR::Service
   1.144 +
   1.145 +#endif // OVR_Service_NetSessionCommon_h