Kaynağa Gözat

*** empty log message ***

Mike Goslin 25 yıl önce
ebeveyn
işleme
24bb26742a
2 değiştirilmiş dosya ile 22 ekleme ve 146 silme
  1. 13 131
      panda/src/downloader/patcher.cxx
  2. 9 15
      panda/src/downloader/patcher.h

+ 13 - 131
panda/src/downloader/patcher.cxx

@@ -9,42 +9,19 @@
 #include "patcher.h"
 #include "config_downloader.h"
 
-#include <event.h>
-#include <pt_Event.h>
-#include <throw_event.h>
-#include <eventParameter.h>
 #include <filename.h>
 
 ////////////////////////////////////////////////////////////////////
 // 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;
+initiate(Filename &patch, Filename &infile) {
+  Patchfile pfile(_buffer);
+  if (pfile.apply(patch, infile) == true)
+    return PS_success;
+  return PS_error;
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: Patcher::patch 
+//     Function: Patcher::run
 //       Access: Public
-//  Description:
+//  Description: 
 ////////////////////////////////////////////////////////////////////
-bool Patcher::
-patch(Filename &patch, Filename &infile) {
-  Patchfile pfile(_buffer);
-  return pfile.apply(patch, infile);
+int Patcher::
+run(void) {
+  return PS_success;
 }

+ 9 - 15
panda/src/downloader/patcher.h

@@ -11,35 +11,29 @@
 ////////////////////////////////////////////////////////////////////
 #include <pandabase.h>
 #include <filename.h>
-#include <tokenBoard.h>
 #include <buffer.h>
-#include "asyncUtility.h"
 #include <patchfile.h>
 
-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<PatcherToken> PatcherTokenBoard;
-  PatcherTokenBoard *_token_board;
-
   PT(Buffer) _buffer;
 };