#include <FileFactory.hpp>
Inheritance diagram for FileFactory::

Public Methods | |
| FileFactory () | |
| virtual void | run () |
| void | init () |
| void | checkIfEmpty () |
| void | emptyPacket () |
| void | validPacket () |
| void | directWrite (TFTP_Packet *pkt) |
Private Attributes | |
| ULONG | blocksize |
| TFTP_Packet * | packet |
| ULONG | expectedBlockNo |
| bool | initialized |
| size_t | sz |
| long | rc |
| size_t | length |
| short | block |
| bool | empty |
|
|
Definition at line 6 of file FileFactory.cpp. 00007 : Basic_PThread(), 00008 expectedBlockNo( 1 ), initialized( FALSE ), 00009 sz( 0 ), rc( 0 ), length( 0 ), block( 0 ), empty( TRUE ) 00010 { 00011 blocksize = option.getBlockSizeValue(); 00012 } |
|
|
Definition at line 34 of file FileFactory.cpp. Referenced by run().
00035 {
00036 while ( empty == TRUE )
00037 {
00038 option.rwlock5_data_queue.read();
00039 empty = option.data_queue->isEmpty();
00040 option.rwlock5_data_queue.releaseRead();
00041
00042 if ( empty == TRUE )
00043 {
00044 printf("Empty Packet\n");
00045 sched_yield(); // it's empty, yield.
00046 }
00047 }
00048 }
|
|
|
Definition at line 64 of file FileFactory.cpp. 00065 {
00066 init();
00067 packet = pkt;
00068 validPacket();
00069 }
|
|
|
Definition at line 50 of file FileFactory.cpp. Referenced by run().
00051 {
00052 option.rwlock5_data_queue.read();
00053
00054 #ifdef DEBUG
00055 printf( "Packet null in list, size=%d\n", option.data_queue->size() );
00056 option.data_queue->display();
00057 #endif
00058
00059 option.rwlock5_data_queue.releaseRead();
00060 fflush( stdout );
00061 sched_yield();
00062 }
|
|
|
Definition at line 14 of file FileFactory.cpp. Referenced by directWrite(), and run().
00015 {
00016 if ( initialized == TRUE ) return;
00017 initialized = TRUE;
00018 expectedBlockNo = 1;
00019 sz = 0;
00020 rc = 0;
00021 length = 0;
00022 block = 0;
00023 empty = TRUE;
00024
00025 printf( "FileFactory::init\n");
00026 fflush( stdout );
00027
00028 option.openFile( "wb" );
00029 option.rwlock2_file.read();
00030 option.myFile->setBegin();
00031 option.rwlock2_file.releaseRead();
00032 }
|
|
|
Reimplemented from Basic_PThread. Definition at line 150 of file FileFactory.cpp. 00151 {
00152 init();
00153
00154 while ( option.isConnected() || !option.data_queue->isEmpty() )
00155 {
00156 checkIfEmpty();
00157
00158 // Read data in Write mode (modifying structure)
00159 option.rwlock5_data_queue.write();
00160 packet = option.data_queue->dequeue();
00161 option.rwlock5_data_queue.releaseWrite();
00162
00163 if ( packet != NULL )
00164 {
00165 validPacket();
00166
00167 } else { // List is empty ?!
00168
00169 if ( option.isEnding() ) return;
00170
00171 emptyPacket();
00172 // sched_yield();
00173 }
00174
00175 } // end while()
00176 }
|
|
|
Definition at line 71 of file FileFactory.cpp. Referenced by directWrite(), and run().
00072 {
00073 block = packet->getBlockNo();
00074
00075 if ( block == expectedBlockNo )
00076 {
00077 printf( "\nThis packet was in order: %d / %d\n", block, expectedBlockNo );
00078 fflush( stdout );
00079
00080 option.rwlock2_file.read(); // Read filedes to write on file
00081 length = packet->getpktLength() - 4;
00082 if ( length > 0 )
00083 {
00084 printf( "\nWriting to file: #%d, length %d\n", block, length );
00085 fflush( stdout );
00086
00087 #ifdef DEBUG
00088 option.showChar( "Data", packet->getData(), length );
00089 #endif
00090
00091 sz = option.myFile->putData( packet->getData(), length, option.getBlockSizeValue() );
00092
00093 } else if (length == 0)
00094 {
00095 sz = 0;
00096 printf( "\nNothing to write to file: #%d, length %d\n", block, length );
00097 fflush( stdout );
00098 } else
00099 {
00100 printf( "\nDid NOT write to file: #%d, length %d\n", block, length );
00101 fflush( stdout );
00102 }
00103
00104 option.rwlock2_file.releaseRead();
00105 expectedBlockNo++;
00106
00107 // Last Packet;
00108 if ( sz < option.getBlockSizeValue() )
00109 {
00110 printf( "\nThis shall be the last packet of size %d out of %d #%d\n", \
00111 sz, option.getBlockSizeValue(), block );
00112
00113 if ( option.myFile != NULL ) {
00114 delete option.myFile;
00115 option.myFile = NULL;
00116 }
00117 fflush( stdout );
00118
00119 if ( option.isReading() ) {
00120 option.state = TFTP_EndofRead;
00121 } else if ( option.isWriting() ) {
00122 option.state = TFTP_EndofWrite;
00123 } else {
00124 option.state = TFTP_Finished;
00125 }
00126 return;
00127 }
00128 else
00129 {
00130 printf("This aint the last packet\n");
00131 printf("The size is %d, Blocksize is %d\n",sz,option.getBlockSizeValue());
00132 }
00133
00134 // It's 1 NOT 0, since 0 means we started!
00135 // Loop the Window size.
00136 if ( (expectedBlockNo-1) > option.getWindowSizeValue() )
00137 {
00138 //No need for this
00139 // expectedBlockNo = 1;
00140 }
00141
00142 } else { // Trash Packet.
00143 printf( "\nTrashing Data Packet# %d / %d\n", block, expectedBlockNo );
00144 fflush( stdout );
00145 packet = NULL;
00146 delete packet;
00147 }
00148 }
|
|
|
Definition at line 37 of file FileFactory.hpp. |
|
|
Definition at line 29 of file FileFactory.hpp. |
|
|
Definition at line 38 of file FileFactory.hpp. |
|
|
Definition at line 31 of file FileFactory.hpp. |
|
|
Definition at line 33 of file FileFactory.hpp. |
|
|
Definition at line 36 of file FileFactory.hpp. |
|
|
Definition at line 30 of file FileFactory.hpp. |
|
|
Definition at line 35 of file FileFactory.hpp. |
|
|
Definition at line 34 of file FileFactory.hpp. |
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001