ovr_sdk

annotate 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
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 PublicHeader: n/a
nuclear@0 4 Filename : OVR_RPC1.h
nuclear@0 5 Content : A network plugin that provides remote procedure call functionality.
nuclear@0 6 Created : June 10, 2014
nuclear@0 7 Authors : Kevin Jenkins
nuclear@0 8
nuclear@0 9 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 10
nuclear@0 11 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 12 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 13 which is provided at the time of installation or download, or which
nuclear@0 14 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 15
nuclear@0 16 You may obtain a copy of the License at
nuclear@0 17
nuclear@0 18 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 19
nuclear@0 20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 21 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 23 See the License for the specific language governing permissions and
nuclear@0 24 limitations under the License.
nuclear@0 25
nuclear@0 26 ************************************************************************************/
nuclear@0 27
nuclear@0 28 #ifndef OVR_Net_RPC_h
nuclear@0 29 #define OVR_Net_RPC_h
nuclear@0 30
nuclear@0 31 #include "OVR_NetworkPlugin.h"
nuclear@0 32 #include "../Kernel/OVR_Hash.h"
nuclear@0 33 #include "../Kernel/OVR_String.h"
nuclear@0 34 #include "OVR_BitStream.h"
nuclear@0 35 #include "../Kernel/OVR_Threads.h"
nuclear@0 36 #include "../Kernel/OVR_Delegates.h"
nuclear@0 37 #include "../Kernel//OVR_Observer.h"
nuclear@0 38
nuclear@0 39 namespace OVR { namespace Net { namespace Plugins {
nuclear@0 40
nuclear@0 41
nuclear@0 42 typedef Delegate3<void, BitStream*, BitStream*, ReceivePayload*> RPCDelegate;
nuclear@0 43 typedef Delegate2<void, BitStream*, ReceivePayload*> RPCSlot;
nuclear@0 44 // typedef void ( *Slot ) ( OVR::Net::BitStream *userData, OVR::Net::ReceivePayload *pPayload );
nuclear@0 45
nuclear@0 46 /// 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
nuclear@0 47 class RPC1 : public NetworkPlugin, public NewOverrideBase
nuclear@0 48 {
nuclear@0 49 public:
nuclear@0 50 RPC1();
nuclear@0 51 virtual ~RPC1();
nuclear@0 52
nuclear@0 53 /// Register a slot, which is a function pointer to one or more implementations that supports this function signature
nuclear@0 54 /// When a signal occurs, all slots with the same identifier are called.
nuclear@0 55 /// \param[in] sharedIdentifier A string to identify the slot. Recommended to be the same as the name of the function.
nuclear@0 56 /// \param[in] functionPtr Pointer to the function.
nuclear@0 57 /// \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
nuclear@0 58 void RegisterSlot(OVR::String sharedIdentifier, OVR::Observer<RPCSlot> *rpcSlotObserver);
nuclear@0 59
nuclear@0 60 /// \brief Same as \a RegisterFunction, but is called with CallBlocking() instead of Call() and returns a value to the caller
nuclear@0 61 bool RegisterBlockingFunction(OVR::String uniqueID, RPCDelegate blockingFunction);
nuclear@0 62
nuclear@0 63 /// \brief Same as UnregisterFunction, except for a blocking function
nuclear@0 64 void UnregisterBlockingFunction(OVR::String uniqueID);
nuclear@0 65
nuclear@0 66 // \brief Same as call, but don't return until the remote system replies.
nuclear@0 67 /// Broadcasting parameter does not exist, this can only call one remote system
nuclear@0 68 /// \note This function does not return until the remote system responds, disconnects, or was never connected to begin with
nuclear@0 69 /// \param[in] Identifier originally passed to RegisterBlockingFunction() on the remote system(s)
nuclear@0 70 /// \param[in] bitStream bitStream encoded data to send to the function callback
nuclear@0 71 /// \param[in] pConnection connection to send on
nuclear@0 72 /// \param[out] returnData Written to by the function registered with RegisterBlockingFunction.
nuclear@0 73 /// \return true if successfully called. False on disconnect, function not registered, or not connected to begin with
nuclear@0 74 bool CallBlocking( OVR::String uniqueID, OVR::Net::BitStream * bitStream, Ptr<Connection> pConnection, OVR::Net::BitStream *returnData = NULL );
nuclear@0 75
nuclear@0 76 /// Calls zero or more functions identified by sharedIdentifier registered with RegisterSlot()
nuclear@0 77 /// \param[in] sharedIdentifier parameter of the same name passed to RegisterSlot() on the remote system
nuclear@0 78 /// \param[in] bitStream bitStream encoded data to send to the function callback
nuclear@0 79 /// \param[in] pConnection connection to send on
nuclear@0 80 bool Signal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream, Ptr<Connection> pConnection);
nuclear@0 81 void BroadcastSignal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream);
nuclear@0 82
nuclear@0 83
nuclear@0 84 protected:
nuclear@0 85 virtual void OnReceive(ReceivePayload *pPayload, ListenerReceiveResult *lrrOut);
nuclear@0 86
nuclear@0 87 virtual void OnDisconnected(Connection* conn);
nuclear@0 88 virtual void OnConnected(Connection* conn);
nuclear@0 89
nuclear@0 90 Hash< String, RPCDelegate, String::HashFunctor > registeredBlockingFunctions;
nuclear@0 91 ObserverHash< RPCSlot > slotHash;
nuclear@0 92
nuclear@0 93 // Synchronization for RPC caller
nuclear@0 94 Lock singleRPCLock;
nuclear@0 95 Mutex callBlockingMutex;
nuclear@0 96 WaitCondition callBlockingWait;
nuclear@0 97
nuclear@0 98 Net::BitStream* blockingReturnValue;
nuclear@0 99 Ptr<Connection> blockingOnThisConnection;
nuclear@0 100 };
nuclear@0 101
nuclear@0 102
nuclear@0 103 }}} // OVR::Net::Plugins
nuclear@0 104
nuclear@0 105 #endif // OVR_Net_RPC_h