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
FileListTransfer.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_FileListTransfer==1 && _RAKNET_SUPPORT_FileOperations==1
23
24 #ifndef __FILE_LIST_TRANFER_H
25 #define __FILE_LIST_TRANFER_H
26
27 #include "types.h"
28 #include "Export.h"
29 #include "PluginInterface2.h"
30 #include "DS_Map.h"
31 #include "types.h"
32 #include "PacketPriority.h"
33 #include "memoryoverride.h"
34 #include "FileList.h"
35 #include "DS_Queue.h"
36 #include "SimpleMutex.h"
37 #include "ThreadPool.h"
38
39 namespace SLNet
40 {
42 class IncrementalReadInterface;
43 class FileListTransferCBInterface;
44 class FileListProgress;
45 struct FileListReceiver;
46
51
62 class RAK_DLL_EXPORT FileListTransfer : public PluginInterface2
63 {
64 public:
65
66 // GetInstance() and DestroyInstance(instance*)
67 STATIC_FACTORY_DECLARATIONS(FileListTransfer)
68
69 FileListTransfer();
70 virtual ~FileListTransfer();
71
75 void StartIncrementalReadThreads(int numThreads, int threadPriority=-99999);
76
82 unsigned short SetupReceive(FileListTransferCBInterface *handler, bool deleteHandler, SystemAddress allowedSender);
83
93 void Send(FileList *fileList, SLNet::RakPeerInterface *rakPeer, SystemAddress recipient, unsigned short setID, PacketPriority priority, char orderingChannel, IncrementalReadInterface *_incrementalReadInterface=0, unsigned int _chunkSize=262144*4*16);
94
96 unsigned int GetPendingFilesToAddress(SystemAddress recipient);
97
99 void CancelReceive(unsigned short inSetId);
100
102 void RemoveReceiver(SystemAddress systemAddress);
103
105 bool IsHandlerActive(unsigned short inSetId);
106
109 void AddCallback(FileListProgress *cb);
110
113 void RemoveCallback(FileListProgress *cb);
114
116 void ClearCallbacks(void);
117
120 void GetCallbacks(DataStructures::List<FileListProgress*> &callbacks);
121
123 virtual PluginReceiveResult OnReceive(Packet *packet);
125 virtual void OnRakPeerShutdown(void);
127 virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
129 virtual void Update(void);
130
131 protected:
132 bool DecodeSetHeader(Packet *packet);
133 bool DecodeFile(Packet *packet, bool fullFile);
134
135 void Clear(void);
136
137 void OnReferencePush(Packet *packet, bool fullFile);
138 void OnReferencePushAck(Packet *packet);
139 void SendIRIToAddress(SystemAddress systemAddress, unsigned short inSetId);
140
141 DataStructures::Map<unsigned short, FileListReceiver*> fileListReceivers;
142 unsigned short setId;
143 DataStructures::List<FileListProgress*> fileListProgressCallbacks;
144
145 struct FileToPush
146 {
147 FileListNode fileListNode;
148 PacketPriority packetPriority;
149 char orderingChannel;
150 unsigned int currentOffset;
152 unsigned int setIndex;
153 IncrementalReadInterface *incrementalReadInterface;
154 unsigned int chunkSize;
155 };
156 struct FileToPushRecipient
157 {
158 unsigned int refCount;
159 SimpleMutex refCountMutex;
160 void DeleteThis(void);
161 void AddRef(void);
162 void Deref(void);
163
164 SystemAddress systemAddress;
165 unsigned short setId;
166
168 DataStructures::Queue<FileToPush*> filesToPush;
169 };
170 DataStructures::List< FileToPushRecipient* > fileToPushRecipientList;
171 SimpleMutex fileToPushRecipientListMutex;
172 void RemoveFromList(FileToPushRecipient *ftpr);
173
174 struct ThreadData
175 {
176 FileListTransfer *fileListTransfer;
177 SystemAddress systemAddress;
178 unsigned short setId;
179 };
180
181 ThreadPool<ThreadData, int> threadPool;
182
183 friend int SendIRIToAddressCB(FileListTransfer::ThreadData threadData, bool *returnOutput, void* perThreadData);
184 };
185
186 } // namespace SLNet
187
188 #endif
189
190 #endif // _RAKNET_SUPPORT_*