ovr_sdk

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