*** empty log message ***

This commit is contained in:
Mike Goslin 2000-12-14 19:43:13 +00:00
parent bcf1f9bd14
commit 24bb26742a
2 changed files with 26 additions and 150 deletions

View File

@ -9,42 +9,19 @@
#include "patcher.h" #include "patcher.h"
#include "config_downloader.h" #include "config_downloader.h"
#include <event.h>
#include <pt_Event.h>
#include <throw_event.h>
#include <eventParameter.h>
#include <filename.h> #include <filename.h>
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Defines // 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 // Function: Patcher::Constructor
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
Patcher:: Patcher::
Patcher(void) : AsyncUtility() { Patcher(void) {
PT(Buffer) buffer = new Buffer(patcher_buffer_size); PT(Buffer) buffer = new Buffer(patcher_buffer_size);
init(buffer); init(buffer);
} }
@ -55,7 +32,7 @@ Patcher(void) : AsyncUtility() {
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
Patcher:: Patcher::
Patcher(PT(Buffer) buffer) : AsyncUtility() { Patcher(PT(Buffer) buffer) {
init(buffer); init(buffer);
} }
@ -67,7 +44,6 @@ Patcher(PT(Buffer) buffer) : AsyncUtility() {
void Patcher:: void Patcher::
init(PT(Buffer) buffer) { init(PT(Buffer) buffer) {
nassertv(!buffer.is_null()); nassertv(!buffer.is_null());
_token_board = new PatcherTokenBoard;
_buffer = buffer; _buffer = buffer;
} }
@ -78,121 +54,27 @@ init(PT(Buffer) buffer) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
Patcher:: Patcher::
~Patcher(void) { ~Patcher(void) {
destroy_thread();
delete _token_board;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: Patcher::request_patch // Function: Patcher::initiate
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int Patcher:: int Patcher::
request_patch(const Filename &patch, const Filename &infile, initiate(Filename &patch, Filename &infile) {
const string &event_name) { Patchfile pfile(_buffer);
PT(PatcherToken) tok; if (pfile.apply(patch, infile) == true)
if (_threads_enabled) { return PS_success;
return PS_error;
// 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 // Function: Patcher::run
// 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 // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Patcher:: int Patcher::
patch(Filename &patch, Filename &infile) { run(void) {
Patchfile pfile(_buffer); return PS_success;
return pfile.apply(patch, infile);
} }

View File

@ -11,35 +11,29 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#include <pandabase.h> #include <pandabase.h>
#include <filename.h> #include <filename.h>
#include <tokenBoard.h>
#include <buffer.h> #include <buffer.h>
#include "asyncUtility.h"
#include <patchfile.h> #include <patchfile.h>
class PatcherToken;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : Patcher // Class : Patcher
// Description : Applys a patch asynchronously // Description : Applys a patch synchronously
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEXPRESS Patcher : public AsyncUtility { class EXPCL_PANDAEXPRESS Patcher {
PUBLISHED: PUBLISHED:
enum PatcherStatus {
PS_success = 1,
PS_error = -1,
};
Patcher(void); Patcher(void);
Patcher(PT(Buffer) buffer); Patcher(PT(Buffer) buffer);
virtual ~Patcher(void); virtual ~Patcher(void);
int request_patch(const Filename &patch, int initialize(Filename &patch, Filename &infile);
const Filename &infile, const string &event_name); int run(void);
bool patch(Filename &patch, Filename &infile);
private: private:
void init(PT(Buffer) buffer); void init(PT(Buffer) buffer);
virtual bool process_request(void);
typedef TokenBoard<PatcherToken> PatcherTokenBoard;
PatcherTokenBoard *_token_board;
PT(Buffer) _buffer; PT(Buffer) _buffer;
}; };