summaryrefslogtreecommitdiff
path: root/ACE/examples/Web_Crawler/Web_Crawler.cpp
blob: 16639a38d73e8496143b4474f99f61ab15baecc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// $Id$

#include "Options.h"
#include "URL_Visitor_Factory.h"
#include "Web_Crawler.h"

ACE_RCSID(Web_Crawler, Web_Crawler, "$Id$")

Web_Crawler::~Web_Crawler (void)
{
  delete this->url_visitor_factory_;
}

Web_Crawler::Web_Crawler (void)
  : url_visitor_factory_ (0)
{
}

int
Web_Crawler::open (int argc, ACE_TCHAR *argv[])
{
  if (OPTIONS::instance ()->parse_args (argc, argv) == -1)
    return -1;
  // @@ Put the ACE_Service_Config::open() stuff here somewhere...
  else
    {
      // For now just hardcode this to create "validation" visitors.
      ACE_NEW_RETURN (this->url_visitor_factory_,
                      URL_Validation_Visitor_Factory,
                      -1);
      return 0;
    }
}

int
Web_Crawler::run (void)
{ 
  // Make the appropriate <URL_Visitor>.
  Auto_Destroyer<URL_Visitor> visitor (this->url_visitor_factory_->make_visitor ());

  if (*visitor == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "make_visitor"),
                      -1);

  // Make the appropriate <Command_Processor>.
  Auto_Destroyer<Command_Processor> cp (this->url_visitor_factory_->make_command_processor ());

  if (*cp == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "make_command_processor"),
                      -1);

  // Set the <Command_Processor> in the <Options> to make it visible.
  OPTIONS::instance ()->command_processor (*cp);

  // Set the <URL_Visitor> in the <Options> to make it visible.
  OPTIONS::instance ()->visitor (*visitor);

  // @@ You fill in here...
  ACE_URL_Addr *url_addr;
  ACE_NEW_RETURN (url_addr,
                  ACE_URL_Addr (OPTIONS::instance()->hostname (),
                                OPTIONS::instance()->path_name (),
                                OPTIONS::instance()->port_no ()), //KIRTHIKA
                  0);
  Auto_Destroyer<ACE_URL_Addr> url_addr_ptr (url_addr);
                                                      
  HTTP_URL *http_url;
  ACE_NEW_RETURN (http_url,
                  HTTP_URL (**url_addr_ptr),
                  0);

  Auto_Destroyer<HTTP_URL> http_url_ptr (http_url);
     
  URL_Command *url_command;
  ACE_NEW_RETURN (url_command,
                  URL_Command (*http_url_ptr),
                  0);
  // Auto_Destroyer<URL_Command> url_command_ptr (url_command);
  
  if (cp->insert (url_command) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n", "insert"),
                      -1);
  
 if (cp->execute () != 0)
   ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n", "execute"),
                      -1);
  return 0;
}