SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RPC4Plugin.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2016-2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20
21 #include "NativeFeatureIncludes.h"
22 #if _RAKNET_SUPPORT_RPC4Plugin==1
23
24 #ifndef __RPC_4_PLUGIN_H
25 #define __RPC_4_PLUGIN_H
26
27 #include "PluginInterface2.h"
28 #include "PacketPriority.h"
29 #include "types.h"
30 #include "BitStream.h"
31 #include "string.h"
32 #include "NetworkIDObject.h"
33 #include "DS_Hash.h"
34 #include "DS_OrderedList.h"
35
40
41 namespace SLNet
42 {
44 class RakPeerInterface;
45 class NetworkIDManager;
46
51 enum RPCErrorCodes
52 {
54 RPC_ERROR_FUNCTION_NOT_REGISTERED,
55 };
56
58 class RAK_DLL_EXPORT RPC4GlobalRegistration
59 {
60 public:
62 RPC4GlobalRegistration(const char* uniqueID, void ( *functionPointer ) (SLNet::BitStream *userData, Packet *packet ));
63
65 RPC4GlobalRegistration(const char* uniqueID, void ( *functionPointer ) (SLNet::BitStream *userData, Packet *packet ), int callPriority);
66
68 RPC4GlobalRegistration(const char* uniqueID, void ( *functionPointer ) (SLNet::BitStream *userData, SLNet::BitStream *returnData, Packet *packet ));
69
71 RPC4GlobalRegistration(const char* uniqueID, MessageID messageId);
72 };
73
79 class RAK_DLL_EXPORT RPC4 : public PluginInterface2
80 {
81 public:
82 // GetInstance() and DestroyInstance(instance*)
83 STATIC_FACTORY_DECLARATIONS(RPC4)
84
85 // Constructor
86 RPC4();
87
88 // Destructor
89 virtual ~RPC4();
90
99 bool RegisterFunction(const char* uniqueID, void ( *functionPointer ) (SLNet::BitStream *userData, Packet *packet ));
100
106 void RegisterSlot(const char *sharedIdentifier, void ( *functionPointer ) (SLNet::BitStream *userData, Packet *packet ), int callPriority);
107
109 bool RegisterBlockingFunction(const char* uniqueID, void ( *functionPointer ) (SLNet::BitStream *userData, SLNet::BitStream *returnData, Packet *packet ));
110
116 void RegisterLocalCallback(const char* uniqueID, MessageID messageId);
117
121 bool UnregisterFunction(const char* uniqueID);
122
124 bool UnregisterBlockingFunction(const char* uniqueID);
125
130 bool UnregisterLocalCallback(const char* uniqueID, MessageID messageId);
131
134 bool UnregisterSlot(const char* sharedIdentifier);
135
140 void CallLoopback( const char* uniqueID, SLNet::BitStream * bitStream );
141
151 void Call( const char* uniqueID, SLNet::BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast );
152
164 bool CallBlocking( const char* uniqueID, SLNet::BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, SLNet::BitStream *returnData );
165
175 void Signal(const char *sharedIdentifier, SLNet::BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, bool invokeLocal);
176
178 void InterruptSignal(void);
179
181 struct LocalCallback
182 {
183 MessageID messageId;
184 DataStructures::OrderedList<SLNet::RakString, SLNet::RakString> functions;
185 };
186 static int LocalCallbackComp(const MessageID &key, LocalCallback* const &data );
187
189 // Callable object, along with priority to call relative to other objects
190 struct LocalSlotObject
191 {
192 LocalSlotObject() {}
193 LocalSlotObject(unsigned int _registrationCount,int _callPriority, void ( *_functionPointer ) (SLNet::BitStream *userData, Packet *packet ))
194 {registrationCount=_registrationCount;callPriority=_callPriority;functionPointer=_functionPointer;}
195 ~LocalSlotObject() {}
196
197 // Used so slots are called in the order they are registered
198 unsigned int registrationCount;
199 int callPriority;
200 void ( *functionPointer ) (SLNet::BitStream *userData, Packet *packet );
201 };
202
203 static int LocalSlotObjectComp( const LocalSlotObject &key, const LocalSlotObject &data );
204
206 struct LocalSlot
207 {
208 DataStructures::OrderedList<LocalSlotObject,LocalSlotObject,LocalSlotObjectComp> slotObjects;
209 };
210 DataStructures::Hash<SLNet::RakString, LocalSlot*,256, SLNet::RakString::ToInteger> localSlots;
211
212 protected:
213
214 // --------------------------------------------------------------------------------------------
215 // Packet handling functions
216 // --------------------------------------------------------------------------------------------
217 virtual void OnAttach(void);
218 virtual PluginReceiveResult OnReceive(Packet *packet);
219
220 DataStructures::Hash<SLNet::RakString, void ( * ) (SLNet::BitStream *, Packet * ),64, SLNet::RakString::ToInteger> registeredNonblockingFunctions;
221 DataStructures::Hash<SLNet::RakString, void ( * ) (SLNet::BitStream *, SLNet::BitStream *, Packet * ),64, SLNet::RakString::ToInteger> registeredBlockingFunctions;
222 DataStructures::OrderedList<MessageID,LocalCallback*,RPC4::LocalCallbackComp> localCallbacks;
223
224 SLNet::BitStream blockingReturnValue;
225 bool gotBlockingReturnValue;
226
227 DataStructures::HashIndex GetLocalSlotIndex(const char *sharedIdentifier);
228
230 unsigned int nextSlotRegistrationCount;
231
232 bool interruptSignal;
233
234 void InvokeSignal(DataStructures::HashIndex functionIndex, SLNet::BitStream *serializedParameters, Packet *packet);
235 };
236
237 } // End namespace
238
239 #endif
240
241 #endif // _RAKNET_SUPPORT_*