nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: PublicHeader: n/a nuclear@0: Filename : OVR_RPC1.h nuclear@0: Content : A network plugin that provides remote procedure call functionality. nuclear@0: Created : June 10, 2014 nuclear@0: Authors : Kevin Jenkins nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_Net_RPC_h nuclear@0: #define OVR_Net_RPC_h nuclear@0: nuclear@0: #include "OVR_NetworkPlugin.h" nuclear@0: #include "../Kernel/OVR_Hash.h" nuclear@0: #include "../Kernel/OVR_String.h" nuclear@0: #include "OVR_BitStream.h" nuclear@0: #include "../Kernel/OVR_Threads.h" nuclear@0: #include "../Kernel/OVR_Delegates.h" nuclear@0: #include "../Kernel//OVR_Observer.h" nuclear@0: nuclear@0: namespace OVR { namespace Net { namespace Plugins { nuclear@0: nuclear@0: nuclear@0: typedef Delegate3 RPCDelegate; nuclear@0: typedef Delegate2 RPCSlot; nuclear@0: // typedef void ( *Slot ) ( OVR::Net::BitStream *userData, OVR::Net::ReceivePayload *pPayload ); nuclear@0: nuclear@0: /// 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: class RPC1 : public NetworkPlugin, public NewOverrideBase nuclear@0: { nuclear@0: public: nuclear@0: RPC1(); nuclear@0: virtual ~RPC1(); nuclear@0: nuclear@0: /// Register a slot, which is a function pointer to one or more implementations that supports this function signature nuclear@0: /// When a signal occurs, all slots with the same identifier are called. nuclear@0: /// \param[in] sharedIdentifier A string to identify the slot. Recommended to be the same as the name of the function. nuclear@0: /// \param[in] functionPtr Pointer to the function. nuclear@0: /// \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: void RegisterSlot(OVR::String sharedIdentifier, OVR::Observer *rpcSlotObserver); nuclear@0: nuclear@0: /// \brief Same as \a RegisterFunction, but is called with CallBlocking() instead of Call() and returns a value to the caller nuclear@0: bool RegisterBlockingFunction(OVR::String uniqueID, RPCDelegate blockingFunction); nuclear@0: nuclear@0: /// \brief Same as UnregisterFunction, except for a blocking function nuclear@0: void UnregisterBlockingFunction(OVR::String uniqueID); nuclear@0: nuclear@0: // \brief Same as call, but don't return until the remote system replies. nuclear@0: /// Broadcasting parameter does not exist, this can only call one remote system nuclear@0: /// \note This function does not return until the remote system responds, disconnects, or was never connected to begin with nuclear@0: /// \param[in] Identifier originally passed to RegisterBlockingFunction() on the remote system(s) nuclear@0: /// \param[in] bitStream bitStream encoded data to send to the function callback nuclear@0: /// \param[in] pConnection connection to send on nuclear@0: /// \param[out] returnData Written to by the function registered with RegisterBlockingFunction. nuclear@0: /// \return true if successfully called. False on disconnect, function not registered, or not connected to begin with nuclear@0: bool CallBlocking( OVR::String uniqueID, OVR::Net::BitStream * bitStream, Ptr pConnection, OVR::Net::BitStream *returnData = NULL ); nuclear@0: nuclear@0: /// Calls zero or more functions identified by sharedIdentifier registered with RegisterSlot() nuclear@0: /// \param[in] sharedIdentifier parameter of the same name passed to RegisterSlot() on the remote system nuclear@0: /// \param[in] bitStream bitStream encoded data to send to the function callback nuclear@0: /// \param[in] pConnection connection to send on nuclear@0: bool Signal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream, Ptr pConnection); nuclear@0: void BroadcastSignal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream); nuclear@0: nuclear@0: nuclear@0: protected: nuclear@0: virtual void OnReceive(ReceivePayload *pPayload, ListenerReceiveResult *lrrOut); nuclear@0: nuclear@0: virtual void OnDisconnected(Connection* conn); nuclear@0: virtual void OnConnected(Connection* conn); nuclear@0: nuclear@0: Hash< String, RPCDelegate, String::HashFunctor > registeredBlockingFunctions; nuclear@0: ObserverHash< RPCSlot > slotHash; nuclear@0: nuclear@0: // Synchronization for RPC caller nuclear@0: Lock singleRPCLock; nuclear@0: Mutex callBlockingMutex; nuclear@0: WaitCondition callBlockingWait; nuclear@0: nuclear@0: Net::BitStream* blockingReturnValue; nuclear@0: Ptr blockingOnThisConnection; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: }}} // OVR::Net::Plugins nuclear@0: nuclear@0: #endif // OVR_Net_RPC_h