From 24bb26742aed02d502ae69eead383a8d0c6ae68a Mon Sep 17 00:00:00 2001 From: Mike Goslin Date: Thu, 14 Dec 2000 19:43:13 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/downloader/patcher.cxx | 152 ++++--------------------------- panda/src/downloader/patcher.h | 24 ++--- 2 files changed, 26 insertions(+), 150 deletions(-) diff --git a/panda/src/downloader/patcher.cxx b/panda/src/downloader/patcher.cxx index baf38b1564..05cc37ebab 100644 --- a/panda/src/downloader/patcher.cxx +++ b/panda/src/downloader/patcher.cxx @@ -9,42 +9,19 @@ #include "patcher.h" #include "config_downloader.h" -#include -#include -#include -#include #include //////////////////////////////////////////////////////////////////// // Defines //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Class : PatcherToken -// Description : Holds a request for the patcher. -//////////////////////////////////////////////////////////////////// -class PatcherToken : public ReferenceCount { -public: - INLINE PatcherToken(uint id, const Filename &patch, - const Filename &infile, const string &event_name) { - _id = id; - _patch = patch; - _infile = infile; - _event_name = event_name; - } - int _id; - Filename _patch; - Filename _infile; - string _event_name; -}; - //////////////////////////////////////////////////////////////////// // Function: Patcher::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// Patcher:: -Patcher(void) : AsyncUtility() { +Patcher(void) { PT(Buffer) buffer = new Buffer(patcher_buffer_size); init(buffer); } @@ -55,7 +32,7 @@ Patcher(void) : AsyncUtility() { // Description: //////////////////////////////////////////////////////////////////// Patcher:: -Patcher(PT(Buffer) buffer) : AsyncUtility() { +Patcher(PT(Buffer) buffer) { init(buffer); } @@ -67,7 +44,6 @@ Patcher(PT(Buffer) buffer) : AsyncUtility() { void Patcher:: init(PT(Buffer) buffer) { nassertv(!buffer.is_null()); - _token_board = new PatcherTokenBoard; _buffer = buffer; } @@ -78,121 +54,27 @@ init(PT(Buffer) buffer) { //////////////////////////////////////////////////////////////////// Patcher:: ~Patcher(void) { - destroy_thread(); - - delete _token_board; } //////////////////////////////////////////////////////////////////// -// Function: Patcher::request_patch +// Function: Patcher::initiate // Access: Public // Description: //////////////////////////////////////////////////////////////////// int Patcher:: -request_patch(const Filename &patch, const Filename &infile, - const string &event_name) { - PT(PatcherToken) tok; - if (_threads_enabled) { - - // Make sure we actually are threaded - if (!_threaded) { - downloader_cat.info() - << "Patcher::request_patch() - create_thread() was " - << "never called! Calling it now..." << endl; - create_thread(); - } - - // We need to grab the lock in order to signal the condition variable -#ifdef HAVE_IPC - _lock.lock(); -#endif - - if (_token_board->_waiting.is_full()) { - downloader_cat.error() - << "Patcher::request_patch() - Too many pending requests\n"; - return 0; - } - - if (downloader_cat.is_debug()) { - downloader_cat.debug() - << "Patch requested for file: " << infile << endl; - } - - tok = new PatcherToken(_next_token++, patch, infile, event_name); - _token_board->_waiting.insert(tok); - -#ifdef HAVE_IPC - _request_cond->signal(); - _lock.unlock(); -#endif - - } else { - // If we're not running asynchronously, process the load request - // directly now. - if (_token_board->_waiting.is_full()) { - downloader_cat.error() - << "Patcher::request_patch() - Too many pending requests\n"; - return 0; - } - if (downloader_cat.is_debug()) { - downloader_cat.debug() - << "Patch requested for file: " << infile << endl; - } - - tok = new PatcherToken(_next_token++, patch, infile, event_name); - _token_board->_waiting.insert(tok); - process_request(); - } - - return tok->_id; -} - -//////////////////////////////////////////////////////////////////// -// Function: Patcher::process_request -// Access: Private -// Description: Serves any requests on the token board, moving them -// to the done queue. -//////////////////////////////////////////////////////////////////// -bool Patcher:: -process_request() { - if (_shutdown) { - if (downloader_cat.is_debug()) - downloader_cat.debug() - << "Patcher shutting down...\n"; - return false; - } - - // If there is actually a request token - process it - while (!_token_board->_waiting.is_empty()) { - PT(PatcherToken) tok = _token_board->_waiting.extract(); - if (patch(tok->_patch, tok->_infile)) { - _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); - } - - if (downloader_cat.is_debug()) { - downloader_cat.debug() - << "Patcher::process_request() - patching complete for " - << tok->_infile << "\n"; - } - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: Patcher::patch -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -bool Patcher:: -patch(Filename &patch, Filename &infile) { +initiate(Filename &patch, Filename &infile) { Patchfile pfile(_buffer); - return pfile.apply(patch, infile); + if (pfile.apply(patch, infile) == true) + return PS_success; + return PS_error; +} + +//////////////////////////////////////////////////////////////////// +// Function: Patcher::run +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +int Patcher:: +run(void) { + return PS_success; } diff --git a/panda/src/downloader/patcher.h b/panda/src/downloader/patcher.h index e4250875dc..a11bfa4476 100644 --- a/panda/src/downloader/patcher.h +++ b/panda/src/downloader/patcher.h @@ -11,35 +11,29 @@ //////////////////////////////////////////////////////////////////// #include #include -#include #include -#include "asyncUtility.h" #include -class PatcherToken; - //////////////////////////////////////////////////////////////////// // Class : Patcher -// Description : Applys a patch asynchronously +// Description : Applys a patch synchronously //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAEXPRESS Patcher : public AsyncUtility { +class EXPCL_PANDAEXPRESS Patcher { PUBLISHED: + enum PatcherStatus { + PS_success = 1, + PS_error = -1, + }; + Patcher(void); Patcher(PT(Buffer) buffer); virtual ~Patcher(void); - int request_patch(const Filename &patch, - const Filename &infile, const string &event_name); - - bool patch(Filename &patch, Filename &infile); + int initialize(Filename &patch, Filename &infile); + int run(void); private: void init(PT(Buffer) buffer); - virtual bool process_request(void); - - typedef TokenBoard PatcherTokenBoard; - PatcherTokenBoard *_token_board; - PT(Buffer) _buffer; };