ovr_sdk
diff LibOVR/Src/Net/OVR_RPC1.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/Net/OVR_RPC1.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,105 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +PublicHeader: n/a 1.7 +Filename : OVR_RPC1.h 1.8 +Content : A network plugin that provides remote procedure call functionality. 1.9 +Created : June 10, 2014 1.10 +Authors : Kevin Jenkins 1.11 + 1.12 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.13 + 1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.16 +which is provided at the time of installation or download, or which 1.17 +otherwise accompanies this software in either electronic or hard copy form. 1.18 + 1.19 +You may obtain a copy of the License at 1.20 + 1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.22 + 1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.24 +distributed under the License is distributed on an "AS IS" BASIS, 1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.26 +See the License for the specific language governing permissions and 1.27 +limitations under the License. 1.28 + 1.29 +************************************************************************************/ 1.30 + 1.31 +#ifndef OVR_Net_RPC_h 1.32 +#define OVR_Net_RPC_h 1.33 + 1.34 +#include "OVR_NetworkPlugin.h" 1.35 +#include "../Kernel/OVR_Hash.h" 1.36 +#include "../Kernel/OVR_String.h" 1.37 +#include "OVR_BitStream.h" 1.38 +#include "../Kernel/OVR_Threads.h" 1.39 +#include "../Kernel/OVR_Delegates.h" 1.40 +#include "../Kernel//OVR_Observer.h" 1.41 + 1.42 +namespace OVR { namespace Net { namespace Plugins { 1.43 + 1.44 + 1.45 +typedef Delegate3<void, BitStream*, BitStream*, ReceivePayload*> RPCDelegate; 1.46 +typedef Delegate2<void, BitStream*, ReceivePayload*> RPCSlot; 1.47 +// typedef void ( *Slot ) ( OVR::Net::BitStream *userData, OVR::Net::ReceivePayload *pPayload ); 1.48 + 1.49 +/// NetworkPlugin that maps strings to function pointers. Can invoke the functions using blocking calls with return values, or signal/slots. Networked parameters serialized with BitStream 1.50 +class RPC1 : public NetworkPlugin, public NewOverrideBase 1.51 +{ 1.52 +public: 1.53 + RPC1(); 1.54 + virtual ~RPC1(); 1.55 + 1.56 + /// Register a slot, which is a function pointer to one or more implementations that supports this function signature 1.57 + /// When a signal occurs, all slots with the same identifier are called. 1.58 + /// \param[in] sharedIdentifier A string to identify the slot. Recommended to be the same as the name of the function. 1.59 + /// \param[in] functionPtr Pointer to the function. 1.60 + /// \param[in] callPriority Slots are called by order of the highest callPriority first. For slots with the same priority, they are called in the order they are registered 1.61 + void RegisterSlot(OVR::String sharedIdentifier, OVR::Observer<RPCSlot> *rpcSlotObserver); 1.62 + 1.63 + /// \brief Same as \a RegisterFunction, but is called with CallBlocking() instead of Call() and returns a value to the caller 1.64 + bool RegisterBlockingFunction(OVR::String uniqueID, RPCDelegate blockingFunction); 1.65 + 1.66 + /// \brief Same as UnregisterFunction, except for a blocking function 1.67 + void UnregisterBlockingFunction(OVR::String uniqueID); 1.68 + 1.69 + // \brief Same as call, but don't return until the remote system replies. 1.70 + /// Broadcasting parameter does not exist, this can only call one remote system 1.71 + /// \note This function does not return until the remote system responds, disconnects, or was never connected to begin with 1.72 + /// \param[in] Identifier originally passed to RegisterBlockingFunction() on the remote system(s) 1.73 + /// \param[in] bitStream bitStream encoded data to send to the function callback 1.74 + /// \param[in] pConnection connection to send on 1.75 + /// \param[out] returnData Written to by the function registered with RegisterBlockingFunction. 1.76 + /// \return true if successfully called. False on disconnect, function not registered, or not connected to begin with 1.77 + bool CallBlocking( OVR::String uniqueID, OVR::Net::BitStream * bitStream, Ptr<Connection> pConnection, OVR::Net::BitStream *returnData = NULL ); 1.78 + 1.79 + /// Calls zero or more functions identified by sharedIdentifier registered with RegisterSlot() 1.80 + /// \param[in] sharedIdentifier parameter of the same name passed to RegisterSlot() on the remote system 1.81 + /// \param[in] bitStream bitStream encoded data to send to the function callback 1.82 + /// \param[in] pConnection connection to send on 1.83 + bool Signal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream, Ptr<Connection> pConnection); 1.84 + void BroadcastSignal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream); 1.85 + 1.86 + 1.87 +protected: 1.88 + virtual void OnReceive(ReceivePayload *pPayload, ListenerReceiveResult *lrrOut); 1.89 + 1.90 + virtual void OnDisconnected(Connection* conn); 1.91 + virtual void OnConnected(Connection* conn); 1.92 + 1.93 + Hash< String, RPCDelegate, String::HashFunctor > registeredBlockingFunctions; 1.94 + ObserverHash< RPCSlot > slotHash; 1.95 + 1.96 + // Synchronization for RPC caller 1.97 + Lock singleRPCLock; 1.98 + Mutex callBlockingMutex; 1.99 + WaitCondition callBlockingWait; 1.100 + 1.101 + Net::BitStream* blockingReturnValue; 1.102 + Ptr<Connection> blockingOnThisConnection; 1.103 +}; 1.104 + 1.105 + 1.106 +}}} // OVR::Net::Plugins 1.107 + 1.108 +#endif // OVR_Net_RPC_h