Shadowrun: Awakened 29 September 2011 - Build 871
FileListTransfer.h
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "NativeFeatureIncludes.h"
00009 #if _RAKNET_SUPPORT_FileListTransfer==1 && _RAKNET_SUPPORT_FileOperations==1
00010 
00011 #ifndef __FILE_LIST_TRANFER_H
00012 #define __FILE_LIST_TRANFER_H
00013 
00014 #include "RakNetTypes.h"
00015 #include "Export.h"
00016 #include "PluginInterface2.h"
00017 #include "DS_Map.h"
00018 #include "RakNetTypes.h"
00019 #include "PacketPriority.h"
00020 #include "RakMemoryOverride.h"
00021 #include "FileList.h"
00022 #include "DS_Queue.h"
00023 #include "SimpleMutex.h"
00024 #include "ThreadPool.h"
00025 
00026 namespace RakNet
00027 {
00029 class IncrementalReadInterface;
00030 class FileListTransferCBInterface;
00031 class FileListProgress;
00032 struct FileListReceiver;
00033 
00038 
00049 class RAK_DLL_EXPORT FileListTransfer : public PluginInterface2
00050 {
00051 public:
00052 
00053     // GetInstance() and DestroyInstance(instance*)
00054     STATIC_FACTORY_DECLARATIONS(FileListTransfer)
00055 
00056     FileListTransfer();
00057     virtual ~FileListTransfer();
00058 
00062     void StartIncrementalReadThreads(int numThreads, int threadPriority=-99999);
00063     
00069     unsigned short SetupReceive(FileListTransferCBInterface *handler, bool deleteHandler, SystemAddress allowedSender);
00070 
00080     void Send(FileList *fileList, RakNet::RakPeerInterface *rakPeer, SystemAddress recipient, unsigned short setID, PacketPriority priority, char orderingChannel, IncrementalReadInterface *_incrementalReadInterface=0, unsigned int _chunkSize=262144*4*16);
00081 
00083     unsigned int GetPendingFilesToAddress(SystemAddress recipient);
00084 
00086     void CancelReceive(unsigned short setId);
00087 
00089     void RemoveReceiver(SystemAddress systemAddress);
00090 
00092     bool IsHandlerActive(unsigned short setId);
00093 
00096     void AddCallback(FileListProgress *cb);
00097 
00100     void RemoveCallback(FileListProgress *cb);
00101 
00103     void ClearCallbacks(void);
00104 
00107     void GetCallbacks(DataStructures::List<FileListProgress*> &callbacks);
00108 
00110     virtual PluginReceiveResult OnReceive(Packet *packet);
00112     virtual void OnRakPeerShutdown(void);
00114     virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
00116     virtual void Update(void);
00117 
00118 protected:
00119     bool DecodeSetHeader(Packet *packet);
00120     bool DecodeFile(Packet *packet, bool fullFile);
00121 
00122     void Clear(void);
00123 
00124     void OnReferencePush(Packet *packet, bool fullFile);
00125     void OnReferencePushAck(Packet *packet);
00126     void SendIRIToAddress(SystemAddress systemAddress);
00127 
00128     DataStructures::Map<unsigned short, FileListReceiver*> fileListReceivers;
00129     unsigned short setId;
00130     DataStructures::List<FileListProgress*> fileListProgressCallbacks;
00131 
00132     struct FileToPush
00133     {
00134         FileListNode fileListNode;
00135         PacketPriority packetPriority;
00136         char orderingChannel;
00137         unsigned int currentOffset;
00138         unsigned short setID;
00139         unsigned int setIndex;
00140         IncrementalReadInterface *incrementalReadInterface;
00141         unsigned int chunkSize;
00142     };
00143     struct FileToPushRecipient
00144     {
00145         unsigned int refCount;
00146         SimpleMutex refCountMutex;
00147         void DeleteThis(void);
00148         void AddRef(void);
00149         void Deref(void);
00150 
00151         SystemAddress systemAddress;
00152         DataStructures::Queue<FileToPush*> filesToPush;
00153     };
00154     DataStructures::List< FileToPushRecipient* > fileToPushRecipientList;
00155     SimpleMutex fileToPushRecipientListMutex;
00156     void RemoveFromList(FileToPushRecipient *ftpr);
00157 
00158     struct ThreadData
00159     {
00160         FileListTransfer *fileListTransfer;
00161         SystemAddress systemAddress;
00162     };
00163 
00164     ThreadPool<ThreadData, int> threadPool;
00165 
00166     friend int SendIRIToAddressCB(FileListTransfer::ThreadData threadData, bool *returnOutput, void* perThreadData);
00167 };
00168 
00169 } // namespace RakNet
00170 
00171 #endif
00172 
00173 #endif // _RAKNET_SUPPORT_*

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net