Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / Web_Crawler / Web_Crawler.cpp
blob29a6ad3ed9f3a3ebe9de343073dfb70f7399bb8f
1 #include "Options.h"
2 #include "URL_Visitor_Factory.h"
3 #include "Web_Crawler.h"
6 Web_Crawler::~Web_Crawler ()
8 delete this->url_visitor_factory_;
11 Web_Crawler::Web_Crawler ()
12 : url_visitor_factory_ (0)
16 int
17 Web_Crawler::open (int argc, ACE_TCHAR *argv[])
19 if (OPTIONS::instance ()->parse_args (argc, argv) == -1)
20 return -1;
21 // @@ Put the ACE_Service_Config::open() stuff here somewhere...
22 else
24 // For now just hardcode this to create "validation" visitors.
25 ACE_NEW_RETURN (this->url_visitor_factory_,
26 URL_Validation_Visitor_Factory,
27 -1);
28 return 0;
32 int
33 Web_Crawler::run ()
35 // Make the appropriate <URL_Visitor>.
36 Auto_Destroyer<URL_Visitor> visitor (this->url_visitor_factory_->make_visitor ());
38 if (*visitor == 0)
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "%p\n",
41 "make_visitor"),
42 -1);
44 // Make the appropriate <Command_Processor>.
45 Auto_Destroyer<Command_Processor> cp (this->url_visitor_factory_->make_command_processor ());
47 if (*cp == 0)
48 ACE_ERROR_RETURN ((LM_ERROR,
49 "%p\n",
50 "make_command_processor"),
51 -1);
53 // Set the <Command_Processor> in the <Options> to make it visible.
54 OPTIONS::instance ()->command_processor (*cp);
56 // Set the <URL_Visitor> in the <Options> to make it visible.
57 OPTIONS::instance ()->visitor (*visitor);
59 // @@ You fill in here...
60 ACE_URL_Addr *url_addr;
61 ACE_NEW_RETURN (url_addr,
62 ACE_URL_Addr (OPTIONS::instance()->hostname (),
63 OPTIONS::instance()->path_name (),
64 OPTIONS::instance()->port_no ()), //KIRTHIKA
65 0);
66 Auto_Destroyer<ACE_URL_Addr> url_addr_ptr (url_addr);
68 HTTP_URL *http_url;
69 ACE_NEW_RETURN (http_url,
70 HTTP_URL (**url_addr_ptr),
71 0);
73 Auto_Destroyer<HTTP_URL> http_url_ptr (http_url);
75 URL_Command *url_command;
76 ACE_NEW_RETURN (url_command,
77 URL_Command (*http_url_ptr),
78 0);
79 // Auto_Destroyer<URL_Command> url_command_ptr (url_command);
81 if (cp->insert (url_command) != 0)
82 ACE_ERROR_RETURN ((LM_ERROR,
83 "%p\n", "insert"),
84 -1);
86 if (cp->execute () != 0)
87 ACE_ERROR_RETURN ((LM_ERROR,
88 "%p\n", "execute"),
89 -1);
90 return 0;