![]() |
VR-Link API Documentation for HLA 1.3
|
00001 /********************************************************************* 00002 ** Copyright (c) 2004 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: vlFileTransport.h,v $ $Revision: 1.2.6.1 $ $State: Exp $ 00007 *********************************************************************/ 00008 #ifndef vlFileTransport_H_ 00009 #define vlFileTransport_H_ 00010 00014 00015 #ifndef VXWORKS 00016 00017 #include <vlutil/vlFilename.h> 00018 #include <vlutil/vlString.h> 00019 #include <vlutil/vlUtil.h> 00020 #include "vlSocket.h" 00021 00022 #include <fstream> 00023 #include <map> 00024 00025 #ifdef DtUSE_UTILITIES_NAMESPACE 00026 namespace DtUSE_UTILITIES_NAMESPACE 00027 { 00028 #endif 00029 00030 00031 class DtTcpSocket; 00032 class DtTcpSocketMgr; 00033 00034 class DT_DLL_NETCOMPAT DtFileTransportObject 00035 { 00036 public: 00037 DtFileTransportObject(); 00038 DtFileTransportObject(const DtFileTransportObject&); 00039 00040 DtFileTransportObject& operator=(const DtFileTransportObject&); 00041 00042 int myFileIdentifier; 00043 DtFilename myFilename; 00044 int myFileLength; 00045 unsigned long myBufferLength; 00046 unsigned long myBytesReceived; 00047 std::vector<char> myBuffer; 00048 int myFlags; 00049 }; 00050 00051 class DT_DLL_NETCOMPAT DtFileTransporter 00052 { 00053 public: 00054 00055 typedef void (*DtFileTransferedCallbackFn) 00056 (const DtFilename& file, void* usr); 00057 00058 typedef std::map<int, DtFileTransportObject> DtFileObjectMap; 00059 00060 enum DtFileTransportFlags 00061 { 00062 DtFileNormal = 0, 00063 DtFileCompressed = 1, 00064 DtFileEncrypted = 2 00065 }; 00066 00067 public: 00068 00076 DtFileTransporter( 00077 int port = DtDEFAULT_PORT, 00078 bool findFirstAvailable = false, 00079 int portRangeToTry = 10, 00080 const DtFilename &tagetDirectory = ".", 00081 int *status = 0); 00082 00084 virtual ~DtFileTransporter(); 00085 00087 virtual void tick(); 00088 00091 virtual unsigned int port() const; 00092 00095 virtual void addFileTransferedCallback( 00096 DtFileTransferedCallbackFn fn, void* data); 00097 virtual void removeFileTransferedCallback( 00098 DtFileTransferedCallbackFn fn, void* data); 00099 00101 virtual bool sendFile( 00102 const DtFilename& filename, DtIpv4Addr destAddr, int port); 00103 00105 virtual bool sendFile( 00106 const DtFilename& filename, DtIpv4Addr destAddr); 00107 00112 const DtFilename& targetDirectory() const; 00113 void setTargetDirectory(const DtFilename& f); 00114 00115 public: 00116 00118 static void receiveFileCb(DtTcpSocket* sock, void* usr); 00119 00120 protected: 00121 00126 virtual void receiveFile(DtTcpSocket* sock); 00127 00131 virtual int nextFileIdentifier(); 00132 00139 virtual bool readFileToBuffer(std::ifstream& inFile, 00140 std::vector<char>& fileBuffer, int fileLengthInBytes, int& retBufLen, 00141 DtFileTransportFlags& flags); 00142 00144 virtual void finishFile(DtFileTransportObject& object); 00145 00146 virtual DtFileTransportObject& transportObject(int iFileIdentifier); 00147 00148 protected: 00149 00151 DtFileTransporter(const DtFileTransporter&); 00152 00154 DtFileTransporter& operator=(const DtFileTransporter&); 00155 00156 protected: 00157 00158 typedef std::map<DtFileTransferedCallbackFn, void*> FileTransferedCallbackMapType; 00159 00160 protected: 00161 00162 FileTransferedCallbackMapType myCallbacks; 00163 int myPort; 00164 DtTcpSocketMgr* mySocketMgr; 00165 DtFilename myTargetDirectory; 00166 00167 DtFileObjectMap myActiveFiles; 00168 }; 00169 00170 #ifdef DtUSE_UTILITIES_NAMESPACE 00171 } 00172 #endif 00173 00174 #endif //! !VXWORKS 00175 00176 00177 00178 #endif //! vlFileTransport_H_ 00179 00180