summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorkirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-03 20:09:06 +0000
committerkirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-03 20:09:06 +0000
commit7f684a13179287fe7e93b6989e120ecd0454c4b2 (patch)
treea87f7badb3b979a1ed6bfc2fe956391da4bb6a9b /examples
parent4b34f5391ade9eb6e9987aa9f56addee5c7bf634 (diff)
downloadATCD-7f684a13179287fe7e93b6989e120ecd0454c4b2.tar.gz
part of HTTP_1.1_Client example
Diffstat (limited to 'examples')
-rw-r--r--examples/Web_Crawler/Command_Processor.cpp139
-rw-r--r--examples/Web_Crawler/Command_Processor.h98
2 files changed, 237 insertions, 0 deletions
diff --git a/examples/Web_Crawler/Command_Processor.cpp b/examples/Web_Crawler/Command_Processor.cpp
new file mode 100644
index 00000000000..cb22a1b14c7
--- /dev/null
+++ b/examples/Web_Crawler/Command_Processor.cpp
@@ -0,0 +1,139 @@
+ // $Id$
+
+#include "URL.h"
+#include "HTTP_URL.h"
+#include "Options.h"
+#include "Command_Processor.h"
+#include "URL_Visitor.h"
+
+ACE_RCSID(HTTP_1.1_Client, Command_Processor, "$Id$")
+
+Command::~Command (void)
+{
+}
+
+URL_Command::URL_Command (URL *url)
+ : url_ (url)
+{
+}
+
+int
+URL_Command::execute (void)
+{
+
+ ACE_CString check_string (this->url_->url_addr ().get_path_name ());
+ if (check_string.find ("news:") >= 0)
+ return 0;
+
+ if (check_string.find (".cgi") >= 0)
+ return 0;
+
+ if (check_string.find ("mailto") >= 0)
+ return 0;
+
+ if (check_string.find (".gif") >= 0)
+ return 0;
+
+ if (check_string.find (".pdf") >= 0)
+ return 0;
+
+ if (check_string.find (".map") >= 0)
+ return 0;
+
+ if (check_string.find (".bmp") >= 0)
+ return 0;
+
+ if (check_string.find (".jpg") >= 0)
+ return 0;
+
+ if (this->url_->accept (OPTIONS::instance ()->visitor ()) !=0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "Coudnt accept url\n"));
+ return -1;
+ }
+ return 0;
+}
+
+int
+URL_Command::destroy (void)
+{
+ delete this;
+ return 0;
+}
+Command_Processor::Command_Processor (void)
+{
+}
+
+Command_Processor::~Command_Processor (void)
+{
+}
+
+int
+Command_Processor::destroy (void)
+{
+ delete this;
+ return 0;
+return 0;
+}
+
+int
+Command_Processor::execute (void)
+{
+ Command *command;
+ while (this->url_queue_.is_empty () != 1)
+ {
+ if (this->url_queue_.dequeue_head (command) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n", "dequeue_head"),
+ -1);
+ URL_Command *url_command = ACE_dynamic_cast (URL_Command *,
+ command);
+ Auto_Destroyer<URL_Command> url_command_ptr (url_command);
+ if (url_command_ptr->execute () != 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "Couldnt execute command"));
+ return -1;
+ }
+ }
+ return 0;
+}
+
+int
+Command_Processor::insert (Command *command)
+{
+ // According to the order specified the commands are removed from the queue.
+ if (this->url_queue_.is_full() != 1)
+ {
+ if (ACE_OS::strcmp (OPTIONS::instance ()->order (),"FIFO") == 0)
+ {
+ if (this->url_queue_.enqueue_tail (command) !=0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n", "enqueue_tail"),
+ - 1);
+ }
+ if (ACE_OS::strcmp (OPTIONS::instance ()->order (),"LIFO") == 0)
+ {
+ if (this->url_queue_.enqueue_head (command) !=0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n", "enqueue_head"),
+ - 1);
+ }
+ }
+ return 0;
+}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class ACE_Singleton<Options, ACE_Null_Mutex>;
+template class ACE_Unbounded_Queue<Command *>;
+template class ACE_Node<Command *>;
+template class ACE_Unbounded_Queue_Iterator<Command *>;
+template class ACE_Unbounded_Queue<Command *>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate ACE_Singleton<Options, ACE_Null_Mutex>
+#pragma instantiate ACE_Unbounded_Queue<Command *>
+#pragma instantiate ACE_Node<Command *>
+#pragma instantiate ACE_Unbounded_Queue_Iterator<Command *>
+#pragma instantiate ACE_Unbounded_Queue<Command *>
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/examples/Web_Crawler/Command_Processor.h b/examples/Web_Crawler/Command_Processor.h
new file mode 100644
index 00000000000..20ef1b61142
--- /dev/null
+++ b/examples/Web_Crawler/Command_Processor.h
@@ -0,0 +1,98 @@
+/* -*- C++ -*- */
+// $Id $
+
+// ============================================================================
+//
+// = LIBRARY
+// apps/Web
+//
+// = FILENAME
+// Command_Processor.h
+//
+// = AUTHOR
+// Douglas C. Schmidt <schmidt@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef _COMMAND_PROCESSOR_H
+#define _COMMAND_PROCESSOR_H
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+#define ACE_LACKS_PRAGMA_ONCE
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ace/Containers.h"
+#include "Options.h"
+
+// Forward decl.
+class URL;
+
+class Command
+{
+ // = TITLE
+ // Abstract base class for a command.
+ //
+ // = DESCRIPTION
+ // Each command is executed by a <Command_Processor>.
+public:
+ virtual ~Command (void);
+ // Virtual destructor.
+
+ virtual int execute (void) = 0;
+ // This is the entry point to execute the command.
+ virtual int destroy (void) = 0;
+};
+
+class URL_Command : public Command
+{
+ // = TITLE
+ // Defines an API for executing a command on a URL.
+ //
+ // = DESCRIPTION
+ // Each command is executed by a <Command_Processor>.
+public:
+ URL_Command (URL *);
+ // Constructor.
+
+ virtual int execute (void);
+ // Execute the URL command.
+
+ int destroy (void);
+ // Commit suicide.
+private:
+ URL *url_;
+ // Pointer to the URL.
+};
+
+class Command_Processor
+{
+ // = TITLE
+ // Execute commands that are passed to it.
+ //
+ // = DESCRIPTION
+ // This class implements the Command Processor pattern.
+public:
+ Command_Processor (void);
+
+ int insert (Command *);
+ // Insert a new <Command> into the <Command_Processor>'s queue.
+
+ int execute (void);
+ // Execute all the <Commands> in the queue.
+
+ int destroy (void);
+ // Destroy the <Command_Processor>.
+
+private:
+ friend class ACE_Shutup_GPlusPlus;
+ // Turn off g++ warning
+
+ ~Command_Processor (void);
+ // Ensure dynamic allocation.
+
+ // @@ You fill in here...
+ ACE_Unbounded_Queue<Command *> url_queue_;
+};
+
+
+#endif /* _COMMAND_PROCESSOR_H */