diff --git a/panda/src/downloader/downloader.cxx b/panda/src/downloader/downloader.cxx index 920f965a39..9aa6fb6e66 100644 --- a/panda/src/downloader/downloader.cxx +++ b/panda/src/downloader/downloader.cxx @@ -43,12 +43,6 @@ enum receive_status { RS_eof }; -enum download_status { - D_error = -2, - D_timeout = -1, - D_success = 1 -}; - //////////////////////////////////////////////////////////////////// // Class : DownloaderToken // Description : Holds a request for the downloader. @@ -375,15 +369,12 @@ process_request() { int ret = download(tok->_file_name, tok->_file_dest, tok->_event_name, tok->_first_byte, tok->_last_byte, tok->_total_bytes, tok->_partial_content, tok->_sync, tok->_id); - if (ret == D_success) { + nassertr(tok->_event_name.empty() == false, false); + PT_Event return_event = new Event(tok->_event_name); + return_event->add_parameter(EventParameter((int)tok->_id)); + if (ret == DS_success) { _token_board->_done.insert(tok); - - // Throw a "done" event now. - if (!tok->_event_name.empty()) { - PT_Event done = new Event(tok->_event_name); - done->add_parameter(EventParameter((int)tok->_id)); - throw_event(done); - } + return_event->add_parameter(EventParameter(DS_success)); if (downloader_cat.is_debug()) { downloader_cat.debug() @@ -391,12 +382,9 @@ process_request() { << tok->_file_name << "\n"; } } else { - PT_Event failure = new Event(tok->_event_name); - failure->add_parameter(EventParameter((int)tok->_id)); - failure->add_parameter(EventParameter(0)); - failure->add_parameter(EventParameter(ret)); - throw_event(failure); + return_event->add_parameter(EventParameter(ret)); } + throw_event(return_event); } return true; @@ -570,12 +558,12 @@ download(const string &file_name, Filename file_dest, if (downloader_cat.is_debug()) downloader_cat.debug() << "Downloader::download() - downloading is disabled" << endl; - return D_error; + return DS_abort; } // Make sure we are still connected to the server if (connect_to_server() == false) - return D_error; + return DS_abort; // Attempt to open the destination file file_dest.set_binary(); @@ -588,7 +576,7 @@ download(const string &file_name, Filename file_dest, downloader_cat.error() << "Downloader::download() - Error opening file: " << file_dest << " for writing" << endl; - return D_error; + return DS_abort; } // Send an HTTP request for the file to the server @@ -628,12 +616,12 @@ download(const string &file_name, Filename file_dest, downloader_cat.error() << "Downloader::download() - send timed out after: " << downloader_timeout_retries << " retries" << endl; - return D_timeout; + return DS_timeout; } } if (send_ret == SS_error) - return D_error; + return DS_abort; // Create a download status to maintain download progress information DownloadStatus status(_buffer->_buffer, event_name, first_byte, last_byte, @@ -648,7 +636,7 @@ download(const string &file_name, Filename file_dest, _buffer_lock.lock(); #endif - nassertr(_frequency > 0, D_error); + nassertr(_frequency > 0, DS_abort); // If byte rate has changed, recompute read size and write buffer size if (_new_byte_rate > 0) { _read_size = (int)ceil(_new_byte_rate * _frequency); @@ -671,7 +659,7 @@ download(const string &file_name, Filename file_dest, downloader_cat.error() << "Downloader::download() - failed to flush buffer during " << "resize" << endl; - return D_error; + return DS_abort; } } @@ -704,7 +692,7 @@ download(const string &file_name, Filename file_dest, downloader_cat.error() << "Downloader::download() - Error reading from socket: " << strerror(errno) << endl; - return D_error; + return DS_abort; case RS_timeout: @@ -718,10 +706,10 @@ download(const string &file_name, Filename file_dest, downloader_cat.error() << "Downloader::download() - write to disk failed after " << "timeout!" << endl; - return D_error; + return DS_abort; } } - return D_timeout; + return DS_timeout; } case RS_success: @@ -750,8 +738,8 @@ download(const string &file_name, Filename file_dest, // when the download is complete _connected = false; if (ret == false) - return D_error; - return D_success; + return DS_abort; + return DS_success; } else { if (downloader_cat.is_debug()) downloader_cat.debug() @@ -765,7 +753,7 @@ download(const string &file_name, Filename file_dest, downloader_cat.error() << "Downloader::download() - Unknown return value from " << "attempt_read() : " << ret << endl; - return D_error; + return DS_abort; } // switch(ret) @@ -777,7 +765,7 @@ download(const string &file_name, Filename file_dest, downloader_cat.error() << "Downloader::download() - Dropped out of for loop without returning!" << endl; - return D_error; + return DS_abort; } //////////////////////////////////////////////////////////////////// @@ -968,6 +956,7 @@ write_to_disk(DownloadStatus &status) { if (!status._event_name.empty()) { PT_Event write_event = new Event(status._event_name); write_event->add_parameter(EventParameter((int)status._id)); + write_event->add_parameter(EventParameter(DS_write)); write_event->add_parameter(EventParameter(status._total_bytes_written)); throw_event(write_event); } diff --git a/panda/src/downloader/downloader.h b/panda/src/downloader/downloader.h index 101c11bcc7..7bdb5f217f 100644 --- a/panda/src/downloader/downloader.h +++ b/panda/src/downloader/downloader.h @@ -32,6 +32,12 @@ class DownloaderToken; //////////////////////////////////////////////////////////////////// class EXPCL_PANDAEXPRESS Downloader : public AsyncUtility { PUBLISHED: + enum DownloadCode { + DS_write = 2, + DS_success = 1, + DS_abort = -1, + DS_timeout = -2 + }; Downloader(void); //Downloader(PT(Buffer) buffer); virtual ~Downloader(void);