Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Web_Crawler / Command_Processor.cpp
blobe629a4a0ded5d764f9f03d55764fabe7966400d3
1 #include "ace/OS_NS_string.h"
2 #include "URL.h"
3 #include "HTTP_URL.h"
4 #include "Options.h"
5 #include "Command_Processor.h"
6 #include "URL_Visitor.h"
9 Command::~Command ()
13 URL_Command::URL_Command (URL *url)
14 : url_ (url)
18 int
19 URL_Command::execute ()
21 ACE_CString check_string
22 (ACE_TEXT_ALWAYS_CHAR (this->url_->url_addr ().get_path_name ()));
23 if (check_string.find ("news:") != ACE_CString::npos)
24 return 0;
26 if (check_string.find (".cgi") != ACE_CString::npos)
27 return 0;
29 if (check_string.find ("mailto") != ACE_CString::npos)
30 return 0;
32 if (check_string.find (".gif") != ACE_CString::npos)
33 return 0;
35 if (check_string.find (".pdf") != ACE_CString::npos)
36 return 0;
38 if (check_string.find (".map") != ACE_CString::npos)
39 return 0;
41 if (check_string.find (".bmp") != ACE_CString::npos)
42 return 0;
44 if (check_string.find (".jpg") != ACE_CString::npos)
45 return 0;
47 if (this->url_->accept (OPTIONS::instance ()->visitor ()) !=0)
49 ACE_DEBUG ((LM_DEBUG,
50 "Coudnt accept url\n"));
51 return -1;
53 return 0;
56 int
57 URL_Command::destroy ()
59 delete this;
60 return 0;
62 Command_Processor::Command_Processor ()
66 Command_Processor::~Command_Processor ()
70 int
71 Command_Processor::destroy ()
73 delete this;
74 return 0;
77 int
78 Command_Processor::execute ()
80 Command *command;
81 while (this->url_queue_.is_empty () != 1)
83 if (this->url_queue_.dequeue_head (command) != 0)
84 ACE_ERROR_RETURN ((LM_ERROR,
85 "%p\n", "dequeue_head"),
86 -1);
87 URL_Command *url_command = dynamic_cast<URL_Command *> (command);
88 Auto_Destroyer<URL_Command> url_command_ptr (url_command);
89 if (url_command_ptr->execute () != 0)
90 ACE_ERROR_RETURN ((LM_ERROR,
91 "%p\n", "Couldnt execute command"),
92 -1);
94 return 0;
97 int
98 Command_Processor::insert (Command *command)
100 // According to the order specified the commands are removed from the queue.
101 if (this->url_queue_.is_full() != 1)
103 if (ACE_OS::strcmp (OPTIONS::instance ()->order (), ACE_TEXT ("FIFO")) == 0)
105 if (this->url_queue_.enqueue_tail (command) !=0)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 ACE_TEXT ("%p\n"), ACE_TEXT ("enqueue_tail")),
108 - 1);
110 if (ACE_OS::strcmp (OPTIONS::instance ()->order (), ACE_TEXT ("LIFO")) == 0)
112 if (this->url_queue_.enqueue_head (command) !=0)
113 ACE_ERROR_RETURN ((LM_ERROR,
114 ACE_TEXT ("%p\n"), ACE_TEXT ("enqueue_head")),
115 - 1);
118 return 0;
121 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, Options, ACE_Null_Mutex);