ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/GoogleTron/GoogleTron.cpp
Revision: 686
Committed: 2006-03-06T17:40:59-08:00 (19 years, 3 months ago) by douglas
File size: 2699 byte(s)
Log Message:
dynamic_cast<Cool *>(stuff);

File Contents

# User Rev Content
1 douglas 672 // Google Tron
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include <cxx/standard.hh>
8    
9 douglas 679 #include <api/exename.hpp>
10     #include <api/pcre/regex.hpp>
11 douglas 673 #include <api/process.hpp>
12 douglas 672 #include <app/simple.hpp>
13 douglas 680 #include <hop/bind.hpp>
14 douglas 673 #include <xml/textwriter.hpp>
15 douglas 672
16 douglas 676 #include "GoogleTron.hpp"
17 douglas 677 #include "Sleep.hpp"
18 douglas 680 #include "Zlib/GzipWriter.hpp"
19 douglas 674
20 douglas 672 int Main(const app::Options &options)
21     {
22 douglas 679 cse::String sitemap(_B("sitemap.gz"));
23 douglas 686 _L<_R<Command> > commands;
24 douglas 676
25 douglas 686 api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$")), fs(_B("^-fs=(.*)$"));
26 douglas 679
27     _foreach (const app::ArgumentList, arg, app::GetArguments())
28     {
29     api::Pcre::RegEx::Match match;
30    
31     if (match = sitemap_(*arg))
32     sitemap = match[1];
33 douglas 686 else if (match = fs(*arg))
34     commands.InsertLast(new _H<FileSystemCommand>(match[1]));
35 douglas 679 else
36     {
37 douglas 686 api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=.+] [-fs=.*]") << ios::NewLine;
38 douglas 679
39     return 1;
40     }
41     }
42    
43 douglas 686 GoogleTron tron(sitemap, commands);
44 douglas 679
45 douglas 676 return 0;
46     }
47    
48 douglas 686 GoogleTron::GoogleTron(const cse::String &sitemap, const _L<_R<Command> > &commands) : working(true), sitemap(sitemap), output(hop::BindAll(&GoogleTron::Output, this))
49 douglas 676 {
50 douglas 686 _foreach (const _L<_R<Command> >, command_, commands)
51     if (_R<FileSystemCommand> command = dynamic_cast<FileSystemCommand *>(command_->GetValue()))
52     threads.Add(hop::BindAll(&GoogleTron::FileSystem_, this, command));
53 douglas 676 }
54    
55     GoogleTron::~GoogleTron()
56     {
57 douglas 681 threads.Join();
58    
59 douglas 677 working = false;
60    
61 douglas 681 output.Join();
62 douglas 676 }
63    
64     int GoogleTron::Output()
65     {
66 douglas 680 _S<Zlib::GzipWriter> gzip(sitemap);
67 douglas 674 _S<xml::TextWriter> writer(gzip);
68 douglas 673 xml::ScopeElement urlset(writer, _B("urlset"));
69    
70     writer.SetAttribute(_B("xmlns"), _B("http://www.google.com/schemas/sitemap/0.84"));
71 douglas 679 writer.SetAttribute(_B("xmlns:xsi"), _B("http://www.w3.org/2001/XMLSchema-instance"));
72     writer.SetAttribute(_B("xsi:schemaLocation"), _B("http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"));
73 douglas 673
74 douglas 677 do
75     {
76     Sleep();
77    
78     _synchronized (queueLock)
79     if (queue.size())
80     {
81     xml::ScopeElement url_(writer, _B("url"));
82     const Url &url(queue.front());
83    
84     {
85     xml::ScopeElement loc(writer, _B("loc"));
86    
87     writer.OutputText(url.GetLocation());
88     }
89    
90     {
91     xml::ScopeElement lastmod(writer, _B("lastmod"));
92    
93     writer.OutputText(url.GetModified());
94     }
95    
96     {
97     xml::ScopeElement changefreq(writer, _B("changefreq"));
98    
99     writer.OutputText(url.GetFrequency());
100     }
101    
102     {
103     xml::ScopeElement priority(writer, _B("priority"));
104    
105     writer.OutputText(url.GetPriority());
106     }
107    
108     queue.pop();
109     }
110     }
111     while (working);
112    
113 douglas 672 return 0;
114     }
115 douglas 686
116     int GoogleTron::FileSystem_(const _R<FileSystemCommand> &command)
117     {
118     FileSystem fs(sitemap, queue, queueLock, command);
119    
120     return 0;
121     }

Properties

Name Value
svn:eol-style native
svn:keywords Id