Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

DataFactory Class Reference

#include <DataFactory.hpp>

Inheritance diagram for DataFactory::

Basic_PThread List of all members.

Public Methods

 DataFactory ()
virtual ~DataFactory ()
virtual void run ()
void init ()
void createDataPacket ()
void dummyPacket ()

Private Methods

 DataFactory (const DataFactory &)
const DataFactory & operator= (const DataFactory &)

Private Attributes

TFTP_Packetpacket
ULONG blocksize
char * buffer
char * data
ULONG blockNo
long sz
long totalSize
long neof
bool initialized
bool dummySended

Constructor & Destructor Documentation

DataFactory::DataFactory  
 

Definition at line 7 of file DataFactory.cpp.

00008  : buffer( NULL ), packet( NULL ), blocksize( 0 ), 
00009    totalSize( 0 ), dummySended( FALSE ),
00010    data( NULL ), blockNo( 0 ), sz( 0 ), neof( 1 ), 
00011    initialized( FALSE ),
00012    Basic_PThread()
00013 {
00014   option.rwlock5_data_queue.write();
00015   option.data_queue = new DList_pPacket();
00016   option.rwlock5_data_queue.releaseWrite();
00017   blocksize = option.getBlockSizeValue();
00018   printf( "DataFactory Created.\n");
00019   fflush( stdout );
00020 }

virtual DataFactory::~DataFactory   [inline, virtual]
 

Definition at line 19 of file DataFactory.hpp.

00019 { }

DataFactory::DataFactory const DataFactory &    [private]
 


Member Function Documentation

void DataFactory::createDataPacket  
 

Definition at line 63 of file DataFactory.cpp.

Referenced by run().

00064 {
00065   blockNo++;    
00066 
00067   // Read data
00068   option.rwlock2_file.read();
00069   sz = option.myFile->getData( buffer, blocksize );
00070 
00071   if ( sz < 0 ) {
00072     neof = -1;
00073     sz  *= -1;
00074   }
00075 
00076   if ( sz > 0 && buffer[sz-1] == '\0' ) sz--;
00077   totalSize += sz;
00078 #ifdef DEBUG
00079   printf("DataFact:[%d|%d|%s|%d]", neof, sz, buffer+4, blocksize );
00080 #endif
00081   option.rwlock2_file.releaseRead();
00082 
00083   printf( "enqueuing data\n" );
00084   fflush( stdout );
00085 
00086   packet = new TFTP_Packet();
00087   packet->createData( blockNo, buffer, sz );
00088 
00089   option.rwlock5_data_queue.write();
00090   option.data_queue->enqueue( packet );
00091   option.rwlock5_data_queue.releaseWrite();
00092 
00093   if (  (neof < 0)  && (( totalSize % blocksize ) == 0)  )
00094   {
00095     dummyPacket();
00096   }
00097 
00098 }

void DataFactory::dummyPacket  
 

Definition at line 100 of file DataFactory.cpp.

Referenced by createDataPacket().

00101 {
00102     if ( dummySended ) return;
00103     dummySended = TRUE;
00104 
00105     packet = new TFTP_Packet();
00106     memset( buffer, 0 , sz );
00107 
00108     blockNo++;
00109     packet->createData( blockNo, buffer, 0 );
00110    
00111     option.rwlock5_data_queue.write();
00112     option.data_queue->enqueue( packet ); 
00113     option.rwlock5_data_queue.releaseWrite();  
00114 } 

void DataFactory::init  
 

Definition at line 22 of file DataFactory.cpp.

Referenced by run().

00023 {
00024   if ( initialized == TRUE ) return;
00025 
00026   initialized = TRUE;
00027   blocksize = option.getBlockSizeValue();
00028   sz   = blocksize;
00029   neof = 1;
00030 
00031   option.rwlock2_file.read();
00032   option.myFile->setBegin();
00033   option.rwlock2_file.releaseRead();
00034 
00035   buffer = new char[ blocksize + 1 ];
00036 }

const DataFactory& DataFactory::operator= const DataFactory &    [private]
 

void DataFactory::run   [virtual]
 

Reimplemented from Basic_PThread.

Definition at line 38 of file DataFactory.cpp.

00039 {
00040   init();
00041 
00042   while( sz >= blocksize && neof > -1 )
00043   {
00044     createDataPacket();
00045     if ( blockNo % 2 == 0 ) sched_yield();
00046   }
00047 
00048   // Save Last
00049   option.LastData = blockNo;
00050   option.Done     = FALSE;
00051 
00052   option.rwlock5_data_queue.write();
00053 #ifdef DEBUG
00054   option.data_queue->display();
00055 #endif
00056   option.rwlock5_data_queue.releaseWrite();
00057 
00058   printf( "DataFactory Finished.Should send %d bytes\n",totalSize);
00059   
00060   fflush( stdout );
00061 }


Member Data Documentation

ULONG DataFactory::blockNo [private]
 

Definition at line 32 of file DataFactory.hpp.

ULONG DataFactory::blocksize [private]
 

Definition at line 29 of file DataFactory.hpp.

char* DataFactory::buffer [private]
 

Definition at line 30 of file DataFactory.hpp.

char* DataFactory::data [private]
 

Definition at line 31 of file DataFactory.hpp.

bool DataFactory::dummySended [private]
 

Definition at line 37 of file DataFactory.hpp.

bool DataFactory::initialized [private]
 

Definition at line 36 of file DataFactory.hpp.

long DataFactory::neof [private]
 

Definition at line 35 of file DataFactory.hpp.

TFTP_Packet* DataFactory::packet [private]
 

Definition at line 27 of file DataFactory.hpp.

long DataFactory::sz [private]
 

Definition at line 33 of file DataFactory.hpp.

long DataFactory::totalSize [private]
 

Definition at line 34 of file DataFactory.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:48:31 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001