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 686 by douglas, 2006-03-06T17:40:59-08:00 vs.
Revision 707 by douglas, 2006-03-18T23:54:29-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=.*] [-wiki=.*] [...]") << 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=(.+)$")), fs(_B("^-fs=(.*)$"));
32 >        api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$")), base_(_B("^-base=(.+)$")), fs(_B("^-fs=(.*)$")), blog(_B("^-blog=(.*)$")), wiki(_B("^-wiki=(.*)$"));
33  
34          _foreach (const app::ArgumentList, arg, app::GetArguments())
35          {
# Line 30 | Line 37 | int Main(const app::Options &options)
37  
38                  if (match = sitemap_(*arg))
39                          sitemap = match[1];
40 +                else if (match = base_(*arg))
41 +                        base = match[1];
42                  else if (match = fs(*arg))
43                          commands.InsertLast(new _H<FileSystemCommand>(match[1]));
44 +                else if (match = blog(*arg))
45 +                        commands.InsertLast(new _H<BlogCommand>(match[1]));
46 +                else if (match = wiki(*arg))
47 +                        commands.InsertLast(new _H<WikiCommand>(match[1]));
48                  else
49 <                {
37 <                        api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=.+] [-fs=.*]") << ios::NewLine;
38 <
39 <                        return 1;
40 <                }
49 >                        return Usage();
50          }
51  
52 <        GoogleTron tron(sitemap, commands);
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, const _L<_R<Command> > &commands) : working(true), sitemap(sitemap), output(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 +        api::Apr::CheckError(::apr_initialize());
63 +
64          _foreach (const _L<_R<Command> >, command_, commands)
65                  if (_R<FileSystemCommand> command = dynamic_cast<FileSystemCommand *>(command_->GetValue()))
66                          threads.Add(hop::BindAll(&GoogleTron::FileSystem_, this, command));
67 +                else if (_R<BlogCommand> command = dynamic_cast<BlogCommand *>(command_->GetValue()))
68 +                        threads.Add(hop::BindAll(&GoogleTron::Blog_, this, command));
69 +                else if (_R<WikiCommand> command = dynamic_cast<WikiCommand *>(command_->GetValue()))
70 +                        threads.Add(hop::BindAll(&GoogleTron::Wiki_, this, command));
71   }
72  
73   GoogleTron::~GoogleTron()
# Line 59 | Line 77 | GoogleTron::~GoogleTron()
77          working = false;
78  
79          output.Join();
80 +
81 +        ::apr_terminate();
82   }
83  
84   int GoogleTron::Output()
# Line 71 | Line 91 | int GoogleTron::Output()
91          writer.SetAttribute(_B("xmlns:xsi"), _B("http://www.w3.org/2001/XMLSchema-instance"));
92          writer.SetAttribute(_B("xsi:schemaLocation"), _B("http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"));
93  
94 <        do
95 <        {
96 <                Sleep();
77 <
78 <                _synchronized (queueLock)
79 <                        if (queue.size())
94 >        _synchronized (queueLock)
95 >                do
96 >                        _desynchronized (queueLock)
97                          {
98 <                                xml::ScopeElement url_(writer, _B("url"));
99 <                                const Url &url(queue.front());
98 >                                Sleep();
99 >
100 >                                _synchronized (queueLock)
101 >                                        if (queue.GetSize())
102 >                                        {
103 >                                                xml::ScopeElement url_(writer, _B("url"));
104 >                                                const Url &url(queue.Front());
105  
106 <                                {
107 <                                        xml::ScopeElement loc(writer, _B("loc"));
106 >                                                {
107 >                                                        xml::ScopeElement loc(writer, _B("loc"));
108  
109 <                                        writer.OutputText(url.GetLocation());
110 <                                }
109 >                                                        writer.OutputText(url.GetLocation());
110 >                                                }
111  
112 <                                {
113 <                                        xml::ScopeElement lastmod(writer, _B("lastmod"));
112 >                                                {
113 >                                                        xml::ScopeElement lastmod(writer, _B("lastmod"));
114  
115 <                                        writer.OutputText(url.GetModified());
116 <                                }
115 >                                                        writer.OutputText(url.GetModified());
116 >                                                }
117  
118 <                                {
119 <                                        xml::ScopeElement changefreq(writer, _B("changefreq"));
118 >                                                {
119 >                                                        xml::ScopeElement changefreq(writer, _B("changefreq"));
120  
121 <                                        writer.OutputText(url.GetFrequency());
122 <                                }
121 >                                                        writer.OutputText(url.GetFrequency());
122 >                                                }
123  
124 <                                {
125 <                                        xml::ScopeElement priority(writer, _B("priority"));
124 >                                                {
125 >                                                        xml::ScopeElement priority(writer, _B("priority"));
126  
127 <                                        writer.OutputText(url.GetPriority());
128 <                                }
127 >                                                        writer.OutputText(url.GetPriority());
128 >                                                }
129  
130 <                                queue.pop();
130 >                                                queue.Pop();
131 >                                        }
132                          }
133 <        }
111 <        while (working);
133 >                while (working || queue.GetSize());
134  
135          return 0;
136   }
137  
138   int GoogleTron::FileSystem_(const _R<FileSystemCommand> &command)
139   {
140 <        FileSystem fs(sitemap, queue, queueLock, command);
140 >        FileSystem fs(sitemap, base, queue, queueLock, command);
141 >
142 >        return 0;
143 > }
144 >
145 > int GoogleTron::Blog_(const _R<BlogCommand> &command)
146 > {
147 >        Blog blog(sitemap, base, queue, queueLock, command);
148 >
149 >        return 0;
150 > }
151 >
152 > int GoogleTron::Wiki_(const _R<WikiCommand> &command)
153 > {
154 >        Wiki wiki(sitemap, base, queue, queueLock, command);
155  
156          return 0;
157   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines