![]() |
MAK RTIspy API Documentation for HLA 1516
|
00001 /********************************************************************* 00002 ** Copyright (c) 2007 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: fileDistributor.h,v $ $Revision: 1.19 $ $State: Exp $ 00007 *********************************************************************/ 00008 00011 00012 #ifndef DtFileDistributor_H_ 00013 #define DtFileDistributor_H_ 00014 00015 #include "rtiMsConfig.h" 00016 #include <vlutil/vlFilename.h> 00017 #include <map> 00018 #include <set> 00019 #include <list> 00020 #include "rtiMsg.h" 00021 #include "connectMgr.h" 00022 00025 class DtFomModuleDistributionMsg; 00026 class DtFomModuleRequestMsg; 00027 class DtFedExec; 00028 class DtFileName; 00029 class DtFileDistributor; 00030 00031 typedef enum DtDistributorType_enum 00032 { 00033 execFedMgrDistributor, 00034 rtiExecDistributor 00035 } DtDistributorType; 00036 00037 //DtFileDistributorThread creator callback signature 00038 typedef DtFileDistributor* (*DtFileDistributorCreator) 00039 (const int fedEx, 00040 const MAKRti::DtString& fedExName, 00041 DtConnectionMgr* connMgr ); 00042 00043 00045 00046 class DtFileInformation 00047 { 00048 public: 00049 DtFileInformation(MAKRti::DtString fomModFileName, 00050 unsigned int numBlocks = 0, 00051 FILE* fp = 0, 00052 char* buff = 0, 00053 bool fullyReceived = false, 00054 unsigned int fileSize = 0, 00055 bool owned = true ) : 00056 myFomModFileName(fomModFileName), 00057 myNumBlocks(numBlocks), 00058 myFilePointer(fp), 00059 myBuffer(buff), 00060 myFullyReceived(fullyReceived), 00061 myFileSize(fileSize), 00062 myFileOwned(owned), 00063 myBlocksReceived(0) 00064 { 00065 if ( !myFullyReceived ) 00066 { 00067 //We'll need to keep track of the received blocks 00068 myBlocksReceived = new bool[myNumBlocks]; 00069 for ( unsigned int iter(0); iter < numBlocks; ++iter) 00070 { 00071 myBlocksReceived[iter] = false; 00072 } 00073 } 00074 } 00075 00076 ~DtFileInformation() 00077 { 00078 if ( myFileOwned ) 00079 { 00080 if ( myFilePointer ) 00081 { 00082 fclose(myFilePointer); 00083 } 00084 if ( myBlocksReceived ) 00085 { 00086 delete [] myBlocksReceived; 00087 } 00088 if ( myBuffer ) 00089 { 00090 delete [] myBuffer; 00091 } 00092 } 00093 } 00094 00095 //The name of the file that I represent 00096 MAKRti::DtString myFomModFileName; 00098 const unsigned int myNumBlocks; 00100 unsigned int myFileSize; 00102 FILE* myFilePointer; 00104 bool myFileOwned; 00106 char* myBuffer; 00108 bool myFullyReceived; 00110 bool* myBlocksReceived; 00111 private: 00112 00113 DtFileInformation(); 00114 DtFileInformation(const DtFileInformation& orig); 00115 DtFileInformation& operator=(const DtFileInformation& orig); 00116 }; 00117 00118 00119 00120 00126 class DT_DLL_LRC DtFileDistributor 00127 { 00128 00129 protected: 00130 00132 DtFileDistributor( const int fedExHandle, 00133 const int federateHandle, 00134 const MAKRti::DtString& fedExName ); 00135 00137 virtual ~DtFileDistributor(); 00138 00139 00140 public: 00141 00142 00143 static void setCreatorFunction( DtFileDistributorCreator fn); 00144 00145 00148 virtual bool sendFedFile(const std::vector<MAKRti::DtString>& modules); 00149 00151 virtual bool pushFedFile( DtConnectionMgr* connMgr, const MAKRti::DtString& fileName, 00152 const unsigned int fileSize, 00153 const char* fileBuffer, 00154 const DtFederateHandle destination = 0 ); 00155 00156 00158 virtual void fedFileUploaded(const MAKRti::DtString fileUploaded); 00159 00160 virtual bool fileReceived(const DtFomModuleDistributionMsg& msg, bool& areAllHere ); 00161 virtual bool fileRequested(const DtFomModuleRequestMsg& msg ); 00162 00163 00165 virtual void removeFile( const MAKRti::DtString fileName ); 00166 00168 virtual void removeFiles( const std::vector<MAKRti::DtString>& modules ); 00169 00170 00172 virtual bool fedFileReady(const MAKRti::DtString& fileName) const; 00173 00175 virtual bool fedFilesReady( const std::vector<MAKRti::DtString>* fileNames ) const; 00176 00178 const FILE* fedFilePtr(MAKRti::DtString fileName) const; 00179 00181 const char * fedFileBuff( MAKRti::DtString fileName ) const; 00182 00185 DtFileInformation* takeFedFile(MAKRti::DtString fileName); 00186 00187 unsigned int fileSize(MAKRti::DtString fileName) const; 00188 00189 FILE* getTmpFile(); 00190 00194 void setFedHandle(unsigned int newHandle); 00195 00196 void setFedexHandle( unsigned int newHandle ); 00197 00199 bool requestsPending() const; 00200 00201 00202 00203 00204 private: 00205 DtFileDistributor(); 00206 DtFileDistributor(const DtFileDistributor& orig); 00207 DtFileDistributor& operator=(const DtFileDistributor& orig); 00208 00209 00210 protected: 00211 00212 00214 //Really the string associated with the file when their contents were uploaded. 00215 //All files stored as tmpFiles. 00216 std::map<MAKRti::DtString, DtFileInformation*> myFiles; 00217 std::set<std::pair<DtFederateHandle, MAKRti::DtString> > myPendingRequests; 00218 00219 MAKRti::DtString myFedExName; 00220 int myFedExHandle; 00221 int myFederateHandle; 00222 std::map<MAKRti::DtString, FILE* > myOpenFileHandles; 00223 00224 00225 protected: 00226 typedef std::list< DtRtiMsg* > rtiMsgList; 00227 00228 static DtFileDistributorCreator theCreator; 00229 00230 00231 }; 00232 00233 #endif //! DtFileDistributor_H_