MAK RTIspy API Documentation for HLA 1516
fileDistributor.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2007 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: fileDistributor.h,v $ $Revision: 1.19 $ $State: Exp $
7 *********************************************************************/
8 
11 
12 #ifndef DtFileDistributor_H_
13 #define DtFileDistributor_H_
14 
15 #include "rtiMsConfig.h"
16 #include <vlutil/vlFilename.h>
17 #include <map>
18 #include <set>
19 #include <list>
20 #include "rtiMsg.h"
21 #include "connectMgr.h"
22 
27 class DtFedExec;
28 class DtFileName;
29 class DtFileDistributor;
30 
32 {
36 
37 //DtFileDistributorThread creator callback signature
38 typedef DtFileDistributor* (*DtFileDistributorCreator)
39  (const int fedEx,
40  const MAKRti::DtString& fedExName,
41  DtConnectionMgr* connMgr );
42 
43 
45 
47 {
48 public:
49  DtFileInformation(MAKRti::DtString fomModFileName,
50  unsigned int numBlocks = 0,
51  FILE* fp = 0,
52  char* buff = 0,
53  bool fullyReceived = false,
54  unsigned int fileSize = 0,
55  bool owned = true ) :
56  myFomModFileName(fomModFileName),
57  myNumBlocks(numBlocks),
58  myFilePointer(fp),
59  myBuffer(buff),
60  myFullyReceived(fullyReceived),
61  myFileSize(fileSize),
62  myFileOwned(owned),
64  {
65  if ( !myFullyReceived )
66  {
67  //We'll need to keep track of the received blocks
68  myBlocksReceived = new bool[myNumBlocks];
69  for ( unsigned int iter(0); iter < numBlocks; ++iter)
70  {
71  myBlocksReceived[iter] = false;
72  }
73  }
74  }
75 
77  {
78  if ( myFileOwned )
79  {
80  if ( myFilePointer )
81  {
82  fclose(myFilePointer);
83  }
84  if ( myBlocksReceived )
85  {
86  delete [] myBlocksReceived;
87  }
88  if ( myBuffer )
89  {
90  delete [] myBuffer;
91  }
92  }
93  }
94 
95  //The name of the file that I represent
96  MAKRti::DtString myFomModFileName;
98  const unsigned int myNumBlocks;
100  unsigned int myFileSize;
106  char* myBuffer;
111 private:
112 
116 };
117 
118 
119 
120 
127 {
128 
129 protected:
130 
132  DtFileDistributor( const int fedExHandle,
133  const int federateHandle,
134  const MAKRti::DtString& fedExName );
135 
137  virtual ~DtFileDistributor();
138 
139 
140 public:
141 
142 
143  static void setCreatorFunction( DtFileDistributorCreator fn);
144 
145 
148  virtual bool sendFedFile(const std::vector<MAKRti::DtString>& modules);
149 
151  virtual bool pushFedFile( DtConnectionMgr* connMgr, const MAKRti::DtString& fileName,
152  const unsigned int fileSize,
153  const char* fileBuffer,
154  const DtFederateHandle destination = 0 );
155 
156 
158  virtual void fedFileUploaded(const MAKRti::DtString fileUploaded);
159 
160  virtual bool fileReceived(const DtFomModuleDistributionMsg& msg, bool& areAllHere );
161  virtual bool fileRequested(const DtFomModuleRequestMsg& msg );
162 
163 
165  virtual void removeFile( const MAKRti::DtString fileName );
166 
168  virtual void removeFiles( const std::vector<MAKRti::DtString>& modules );
169 
170 
172  virtual bool fedFileReady(const MAKRti::DtString& fileName) const;
173 
175  virtual bool fedFilesReady( const std::vector<MAKRti::DtString>* fileNames ) const;
176 
178  const FILE* fedFilePtr(MAKRti::DtString fileName) const;
179 
181  const char * fedFileBuff( MAKRti::DtString fileName ) const;
182 
185  DtFileInformation* takeFedFile(MAKRti::DtString fileName);
186 
187  unsigned int fileSize(MAKRti::DtString fileName) const;
188 
189  FILE* getTmpFile();
190 
194  void setFedHandle(unsigned int newHandle);
195 
196  void setFedexHandle( unsigned int newHandle );
197 
199  bool requestsPending() const;
200 
201 
202 
203 
204 private:
207  DtFileDistributor& operator=(const DtFileDistributor& orig);
208 
209 
210 protected:
211 
212 
214  //Really the string associated with the file when their contents were uploaded.
215  //All files stored as tmpFiles.
216  std::map<MAKRti::DtString, DtFileInformation*> myFiles;
217  std::set<std::pair<DtFederateHandle, MAKRti::DtString> > myPendingRequests;
218 
219  MAKRti::DtString myFedExName;
222  std::map<MAKRti::DtString, FILE* > myOpenFileHandles;
223 
224 
225 protected:
226  typedef std::list< DtRtiMsg* > rtiMsgList;
227 
229 
230 
231 };
232 
233 #endif

Document ID: Generated on Fri Mar 14 19:08:55 EDT 2014 from SVN revision 137085
Copyright © 2005-2014 VT MÄK Inc. All Rights Reserved (www.mak.com)