ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/GoogleTron/GoogleTron.cpp
(Generate patch)

Comparing GoogleTron/GoogleTron.cpp (file contents):
Revision 680 by douglas, 2006-03-06T00:40:40-08:00 vs.
Revision 695 by douglas, 2006-03-09T23:42:52-08:00

# Line 17 | Line 17
17   #include "Sleep.hpp"
18   #include "Zlib/GzipWriter.hpp"
19  
20 + int Usage()
21 + {
22 +        api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=.+] -base=.+ [-fs=.*] [-blog=.*]") << ios::NewLine;
23 +
24 +        return 1;
25 + }
26 +
27   int Main(const app::Options &options)
28   {
29 <        cse::String sitemap(_B("sitemap.gz"));
29 >        cse::String sitemap(_B("sitemap.gz")), base;
30 >        _L<_R<Command> > commands;
31  
32 <        api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$"));
32 >        api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$")), base_(_B("^-base=(.+)$")), fs_(_B("^-fs=(.*)$")), blog_(_B("^-blog=(.*)$")), exclude(_B("^-exclude=(.+)$"));
33  
34          _foreach (const app::ArgumentList, arg, app::GetArguments())
35          {
36                  api::Pcre::RegEx::Match match;
37 +                _R<FileSystemCommand> fs;
38 +                _R<BlogCommand> blog;
39  
40                  if (match = sitemap_(*arg))
41                          sitemap = match[1];
42 +                else if (match = base_(*arg))
43 +                        base = match[1];
44 +                else if (match = fs_(*arg))
45 +                        commands.InsertLast(new _H<FileSystemCommand>(match[1]));
46 +                else if (match = blog_(*arg))
47 +                        commands.InsertLast(new _H<BlogCommand>(match[1]));
48                  else
49 <                {
34 <                        api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=sitemap]") << ios::NewLine;
35 <
36 <                        return 1;
37 <                }
49 >                        return Usage();
50          }
51  
52 <        GoogleTron tron(sitemap);
52 >        if (base.IsEmpty() || commands.IsEmpty())
53 >                return Usage();
54 >
55 >        GoogleTron tron(sitemap, base, commands);
56  
57          return 0;
58   }
59  
60 < GoogleTron::GoogleTron(const cse::String &sitemap) : working(true), sitemap(sitemap), output(new _H<api::Thread>(hop::BindAll(&GoogleTron::Output, this)))
60 > GoogleTron::GoogleTron(const cse::String &sitemap, const cse::String &base, const _L<_R<Command> > &commands) : working(true), sitemap(sitemap), base(base), output(hop::BindAll(&GoogleTron::Output, this))
61   {
62 <        // XXX: start some threads
62 >        _foreach (const _L<_R<Command> >, command_, commands)
63 >                if (_R<FileSystemCommand> command = dynamic_cast<FileSystemCommand *>(command_->GetValue()))
64 >                        threads.Add(hop::BindAll(&GoogleTron::FileSystem_, this, command));
65 >                else if (_R<BlogCommand> command = dynamic_cast<BlogCommand *>(command_->GetValue()))
66 >                        threads.Add(hop::BindAll(&GoogleTron::Blog_, this, command));
67   }
68  
69   GoogleTron::~GoogleTron()
70   {
71 <        // XXX: wait on threads
72 <        
71 >        threads.Join();
72 >
73          working = false;
74  
75 <        output->Join();
75 >        output.Join();
76   }
77  
78   int GoogleTron::Output()
# Line 71 | Line 90 | int GoogleTron::Output()
90                  Sleep();
91  
92                  _synchronized (queueLock)
93 <                        if (queue.size())
93 >                        if (queue.GetSize())
94                          {
95                                  xml::ScopeElement url_(writer, _B("url"));
96 <                                const Url &url(queue.front());
96 >                                const Url &url(queue.Front());
97  
98                                  {
99                                          xml::ScopeElement loc(writer, _B("loc"));
# Line 100 | Line 119 | int GoogleTron::Output()
119                                          writer.OutputText(url.GetPriority());
120                                  }
121  
122 <                                queue.pop();
122 >                                queue.Pop();
123                          }
124          }
125          while (working);
126  
127          return 0;
128   }
129 +
130 + int GoogleTron::FileSystem_(const _R<FileSystemCommand> &command)
131 + {
132 +        FileSystem fs(sitemap, base, queue, queueLock, command);
133 +
134 +        return 0;
135 + }
136 +
137 + int GoogleTron::Blog_(const _R<BlogCommand> &command)
138 + {
139 +        Blog blog(sitemap, base, queue, queueLock, command);
140 +
141 +        return 0;
142 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines